GWT: Servlet URL mapping gives a 404 error - eclipse

I have read the other GWT Servlet questions, but I'm having trouble solving my problem still. My package is called Maps, and it has a service named MyService (which was set up according to a GWT Tutorial). The web.xml file includes the following:
<servlet>
<servlet-name>MyServiceImpl</servlet-name>
<servlet-class>com.xerox.maps.maps.server.MyServiceImpl</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MyServiceImpl</servlet-name>
<url-pattern>/Maps/service</url-pattern>
</servlet-mapping>
In MyService, I have the line:
#RemoteServiceRelativePath("service")
public interface MyService extends RemoteService { ...
However, when I try to make an RPC call, there is an error thrown. The details of the error say that it is a 404 HTTP error. How can I fix this, to make sure that the mapping is correct?
Edit 7.27
MyService.java contains the annotation:
#RemoteServiceRelativePath("service")
And web.xml contains:
<servlet-name>MyServiceImpl</servlet-name>
<url-pattern>/com.x.maps.Maps/service</url-pattern>
If I follow the XHR with FireBug, it shows me that there is a call to com.x.maps.Maps

404 Not found is thrown usually when service endpoint path is inferred wrongly by GWT. Try removing #RemoteServiceRelativePath("service") and recompile and check, If that does not work find out the URL endpoint of the service manually (by hitting likely paths from a browser till the error changes to 500 internal error) and then give the correct path as argument to #RemoteServiceRelativePath("correct/path"). Few trials I would try right away is #RemoteServiceRelativePath("/Maps/service") and #RemoteServiceRelativePath("Maps/service") without the slash

According to this tutorial:
https://developers.google.com/web-toolkit/doc/latest/tutorial/RPC
The servlet-mapping should be composed of the module "rename-to" and the service "RemoteServiceRelativePath". So, if you have, in your *.gwt.xml file, the following line:
<module rename-to='XXX'>
And in your *Service.java file you have the following line:
#RemoteServiceRelativePath("YYY")
Then, in your "web.xml" file, you should have the following lines:
<servlet-mapping>
<servlet-name>...servlet-name>
<url-pattern>/XXX/YYY</url-pattern>
</servlet-mapping>

New answer after all the comments :
Cool, you have made progress!
You are hitting this URL -
http://127.0.0.1:8888/com.x.maps.maps.Maps
With this POST data I assume - /%7C98544A4AED8C7D42E80C55859E9CEC4C%7Ccom.x.maps.maps.client.MyService%7CreadFile%7Cjava.lang.String/2004016611%7CPrinterList.xls%7C1%7C2%7C3%7C4%7C1%7C5%7C6%7C
This is where the problem is, your servlet is mapped to respond to XHR requests coming to <url-pattern>/Maps/service</url-pattern> but you are hitting /com.x.maps.maps.Maps instead. Hence you are getting the 404 path not found status code.
Alter the url-pattern on the server-side web.xml to match what the browser is making,
OR
Alter the GWT code using the RemoteServiceRelativePath annotation to make the request to /Maps/service instead of to /com.x.maps.maps.Maps

I have had the same problem but I solved it changing the url-pattern of the Servlet in the web.xml
Try to put in your web.xml the path to the directory where your GWT javascript module is generated, behind WEB-INF/deploy. in my case:
<url-pattern>/gwtmodulemain/selection</url-pattern>
You can also rename your module name in your gwt.xml file:
<module rename-to='gwtmodulemain'>
so you can refer your module from your HTML in this way:
<script type="text/javascript" language="javascript" src="gwtmodulemain/gwtmodulemain.nocache.js"></script>
Good luck!

Related

Where do I verify the load path for my REST webservice

I have just finished coding webservices. I need to be able to debug the webservice load path. When I sudo restart service tomcat7, the /var/log/tomcat7/catalina.2014-09-29.log provides us with the package path for the webservice
INFO: Scanning for root resource and provider classes in the packages:
com.swipex.backend.webservices
INFO: Root resource classes found:
class com.swipex.backend.webservices.Registration
class com.swipex.backend.webservices.Activation
When I run the junit test code to call these webservices, on running I get /var/log/tomcat7/localhost_access_log.2014-09-29.txt
"POST /SwipeXBackEnd/backend/Activation/Request HTTP/1.1" 404 1049
web.xml
<xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
id="WebApp_ID" version="2.5">
<display-name>de.vogella.jersey.jaxb</display-name>
<servlet>
<servlet-name>SwipeXBackendServices</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.swipex.backend.webservices</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>SwipeXBackendServices</servlet-name>
<url-pattern>/backend/*</url-pattern>
</servlet-mapping>
</web-app>
Calling http://localhost:8080/SwipeXBackEnd/backend/Activation/Request from junit, I get
com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/SwipeXBackEnd/backend/Activation/Request returned a response status of 304 Not Modified
Calling http://localhost:8080/Activation/Request from junit, I get
com.sun.jersey.api.client.UniformInterfaceException: POST http://localhost:8080/Activation/Request returned a response status of 404 Not Found
Is there a log file that verifies if the path /SwipeXBackEnd/backend/Activation/Request is correct for class com.swipex.backend.webservices.Activation
I was not able to find any log file that has the load path defined. I surely hope someone can point it out. But I did find that the log4j prints into catalina.out. This is good enough to know for now, since this is where we can check if our load path got access via a junit test.
Junit Test
ClientConfig config = new DefaultClientConfig();
Client client = Client.create(config);
//
// Activation Service
//
URI url = UriBuilder.fromUri(
"http://" + Globals.SERVER + ":" + Globals.PORT
+ "/MyCompanyBackend/Activate/Device").build();
WebResource service = client.resource(url);
System.out.println(url);
// Get the data ready
CDeviceDetails newDevice = new CDeviceDetails(all parameters here);
String deviceUniqueIdentity = service.type(MediaType.APPLICATION_JSON)
.post(String.class, newDevice);
assertNotNull(deviceUniqueIdentity);
System.out.println("Activation Passed " + deviceUniqueIdentity);
catalina.out : Here al log4j are printed
catalina.2014.. date : Here if your webservices load, you will notice something like this.
INFO: Root resource classes found:
class com.yourpath.backend.webservices.Registration
class com.yourpath.backend.webservices.Activation
Here you will also notice errors on the webserivces when you restart tomcat.
SEVERE: The web application [/MyCompanyBackend] created a ThreadLocal with key of type [java.lang.ThreadLocal] (value [java.lang.ThreadLocal#e08586]) and a value of type [com.sun.jersey.server.impl.application.WebApplicationContext] (value [com.sun.jersey.server.impl.application.WebApplicationContext#81bfd8]) but failed to remove it when the web application was stopped. This is very likely to create a memory leak.This is very likely to create a memory leak.
localhost.2014-date : Here if there is a load issue, you will notice some errors.

404 error from Servlet using Eclipse & Tomcat 6

I've looked at all the other questions on this matter (and there is a LOT of them), and they all end up being a typo with the address, or a misconfigured servlet mapping, or similar. I've tried all of this stuff and I'm still coming back with a 404 error whenever I try to access a page from my servlet.
Here's the servlet code (basic hello world example taken from mkyong's site)
/**
* #see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
PrintWriter out = response.getWriter();
out.println("<html>");
out.println("<body>");
out.println("<h1>Hello World!</h1>");
out.println("</body>");
out.println("</html>");
}
And here's my servlet definition and mapping in the deployment descriptor
<servlet>
<description></description>
<display-name>TestServlet</display-name>
<servlet-name>TestServlet</servlet-name>
<servlet-class>com.TestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>TestServlet</servlet-name>
<url-pattern>/testservlet</url-pattern>
</servlet-mapping>
Here's the error I'm getting
HTTP Status 404 - /testserver/testservlet
type Status report
message /testserver/testservlet
description The requested resource (/testserver/testservlet) is not available.
Apache Tomcat/6.0.33
Anybody got any idea what might be causing this?
EDIT: I just tested the JSP and Servlet hello world given here
http://www.ibm.com/developerworks/opensource/library/os-eclipse-tomcat/
and it worked fine, so I think the problem is with my servlet. Anybody got any ideas what might be wrong with it?
You need to specify the name of the war file. If you have a war file named 'testme.war', you have to access it like this.
localhost:8080/testme/testservlet
According to your mapping, you should be accessing it through : http://localhost:8080/testservlet
Where does the "testserver" come from ? Do you have any reason to use it ?

GWT: how to write client side logs into a log file in GWT

HI guys i am facing a big problem to write logs in a file in GWT.
i ahd gone through all the posts over internet but i didn't find any valuable information
there.
What i did ...
added remote logging servlet in web.xml file
inherited the logging module in my .gwt.xml file.
But my question is here now suppose i have written one log in my Entry Point class.
like ....
//Main class to start the appliation.....
public void onModuleLoad() {
Logger logger=Logger.getLogger(SYTMain.class.getName());
logger.info("Test Log in Module File");
}
and now i want to write this client side log into a test.log file .
How i can achieve this???/
Please if anyone knows the answer then plz provide me the complete solution, i don't want example on a fly. if you really know then only plz tell me don't give the answer which is already available in net.....
mY delivery date is very near so plz update on same ASAP, i'll be very thankful to you.
In your module file add the following:
<inherits name='com.google.gwt.logging.Logging'/>
<set-property name="gwt.logging.enabled" value="TRUE"/>
<!-- Set logging level to INFO -->
<set-property name="gwt.logging.logLevel" value="INFO"/>
<set-property name="gwt.logging.simpleRemoteHandler" value="ENABLED" />
<!-- Add compiler.stackMode to get a readable stacktrace from JavaScript
It generates a set of files in WEB-INF/deploy; those files need to
be placed on the server
-->
<set-property name="compiler.stackMode" value="emulated" />
In your web.xml add the following:
<servlet>
<servlet-name>remoteLoggingService</servlet-name>
<servlet-class>com.google.gwt.logging.server.RemoteLoggingServiceImpl</servlet-class>
</servlet>
<!-- Servlet Mapping -->
<servlet-mapping>
<servlet-name>remoteLoggingService</servlet-name>
<url-pattern>/<your module name>/remote_logging</url-pattern>
</servlet-mapping>
Replace <your module name> with as it says your module name.
To log simply use the code as your mentions. Use the import from java.util.logging.
On the client side, GWT compiles to Javascript, and Javascript cannot in general write files to the client's filesystem. (It should be obvious why this could be a bad idea). See for example this discussion.
If what you need is logs to use for debugging, one obvious solution is to have the logger append to a text area on the page. You can always copy and past manually into another file. Or, if you want to debug remotely, you could have the logger write to the server.
Just create a RPC service to log it into the server-side.
Use the servlet-side threadlocal to get info about the client: ThreadLocal to store ServletRequest and Response in servlet: what for?.

No Endpoint mapping found using annotation driven Spring WS 2.0.2 with dynamic wsdl

Im using annotation driven Spring WS 2.0.2 to create a simple Webservice, but the enpoint mapping was not found.
Input and Output are jdom Elements to keep it as simple as possible.
The Webservice is running with Java 1.6 on Tomcat 6.0.29 wich returns an error
page (The requested Resource () is not available) to my SoapUI Service Test.
Here is the Error I get in my logging:
WARNING: No endpoint found for [SaajSoapMessage (http://foo.bar/myTest)myRequest]
Here are the parts of the configuration I deem relvant for the Endpoint mapping:
(If there are more relevant parts I am missing please ask back...)
Schema (WEB-INF/xsd/myTest.xsd)
targetNamespace="http://foo.bar/myTest"
...
<element name="myRequest" type="tns:string"/>
<element name="myResponse" type="tns:string"/>
web.xml (WEB-INF/web.xml)
<servlet-class>
org.springframework.ws.transport.http.MessageDispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/config.xml</param-value>
</init-param>
<init-param>
<param-name>transformWsdlLocations</param-name>
<param-value>true</param-value>
</init-param>
Spring config (/WEB-INF/spring/config.xml)
<sws:annotation-driven/>
<sws:dynamic-wsdl id="myTest"
portTypeName="myTest"
localUri="/"
targetNamespace="http://foo.bar/myTest">
<sws:xsd location="/WEB-INF/xsd/myTest.xsd"/>
</sws:dynamic-wsdl>
Endpoint (src/main/java/bar/foo/MyEndpoint.java)
#Endpoint
public class MyEndpoint{
#PayloadRoot(localPart="myRequest",namespace="http://foo.bar/myTest")
#ResponsePayload
public Element mySearch( #RequestPayload Element myRequest){
return myRequest;
}
}
Searching for a sollution I found it contained in this answer
Adding
...
xmlns:context="http://www.springframework.org/schema/context"
...
xsi:schemaLocation=" ...
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.0.xsd ... "
<context:component-scan base-package="bar.foo"/>
to my Spring configuration let the servlet find my Endpoint.
My problem was, that no sample code in a spring documentation I found contained
this step and its relevance.
Well - actually I found this code snipplet in a tutorial earlier, but it was a bit overloaded with features I did not need, and as in the official docs it was not explained why it was necessary.

coding a server on using restlet 2.0

I am coding a server for a project of mine using restlet 2.0. I have a java class which starts the server (starting it on a port and all those stuff). I am stuck at a point where i need to map the uri's of different services i intend to offer. If i were to include uri mapping part in a servlet how do i go about it. what are the changes i need to make in the web.xml. i have found very little documentation regarding this.
Any help appreciated
In fact, the routing configuration must be done in your Restlet application class. You need to override the createInboundRoot method to attach your resources to paths, as described below:
public class MyRestletApplication extends Application {
public Restlet createInboundRoot() {
Router router = new Router(getContext());
router.attach("/path/{id}", MyServerResource.class);
(...)
return router;
}
}
The configured resources can be then reached through the configured Restlet server. For example, with the address http://localhost:8082/path/12 if you implement your Restlet server as following:
public static void main(String[] args) {
try {
Server server = new Server(Protocol.HTTP, 8182);
server.setNext(new MyRestletApplication());
server.start();
(...)
} catch(Exception ex) {}
}
Restlet also provides a servlet adapter with its org.restlet.ext.servlet extension. The latter allows using the ServerServlet servlet in order to access the configured resources. When configuring this servlet you need to specify the application class to use (the application contains the paths for your resources) through the org.restlet.application context parameter. The servlet can be configured as every servlet and be mapped on the /* pattern, as described below:
<web-app>
<context-param>
<param-name>org.restlet.application</param-name>
<param-value>org.restlet.example.MyApplication</param-value>
</context-param>
<servlet>
<servlet-name>ServerServlet</servlet-name>
<servlet-class>org.restlet.ext.servlet.ServerServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>ServerServlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
In this case, your RESTful application implemented with Restlet will be accessed through a servlet container. In this case, your application needs to be packaged as a Java EE web application and will be reached with address: http://localhost:8080/mywebapp/path/12.
Hope it'll help you.
Thierry