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.
Related
Im new to spring MVC and REST.. I'm having an issue with a simple test controller I've put together from example I've found here and from the spring docs..
When I hit the url http://localhost:8080/test-api/user/14 I get the error below
Im getting the error:
Sep 23, 2015 11:26:55 AM org.springframework.web.servlet.PageNotFound noHandlerFound
WARNING: No mapping found for HTTP request with URI [/test-api/user/14] in DispatcherServlet with name 'testapi'
Im using xml to config.. Im not ready to move to java config.
web.xml
Spring Web MVC Application
<servlet>
<servlet-name>springtest</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>springtest</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/testapi-servlet.xml</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
testapi-servlet.xml - only contains the component scan and annotation driven elements
<context:component-scan base-package="com.springtest.testapi" />
<mvc:annotation-driven />
SpringTest.java
package com.springtest.testapi.api;
#RestController
public class SpringTest {
#RequestMapping(value="/user/{id}", method = RequestMethod.GET)
public User getUser(#PathVariable int id) {
User u = new User(id,"Test","Me");
return u;
}
What handler should I be defining.. None of the examples or docs state that a handler needs to be defined..
Remove the contextConfigLocation.
Replace the following:
<servlet-mapping>
<servlet-name>springtest</servlet-name>
<url-pattern>/test-api</url-pattern>
</servlet-mapping>
Make sure your xml file is test-api-servlet.xml and not testapi-servlet.xml
I found my issue. I mispelled the package in the component scan. The sample code I have was edited so It didn't fully represent what I had and was actually correct.
I'm sure this is a noob question, and I've spent the better part of an hour trawling stackoverflow for an answer but nobody seems to have my case so here we go...
I have a new webapp that uses Spring MVC. Most of the app (99%) is pure REST, so it doesn't have a "view" as such but rather simply sends JSON back down the wire, or sends an alternate HTTP Status for errors etc.
The exception is the login page which needs to be an actual JSP, but somehow the configuration I am using to map my REST controllers is leaving me in a state where normal JSP mappings fail.
Here's what I've got:
In my dispatcher servlet config, the relevant portions are:
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix" value="/WEB-INF/pages/"/>
<property name="suffix" value=".jsp"/>
</bean>
In my attempts to get it working, I have also added a mapping to the "HomeController" which currently just redirects to my login JSP:
<bean name="/" class="com.somepackage.HomeController"/>
Now, in the web.xml I have:
<servlet>
<servlet-name>spring-dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>
/WEB-INF/spring-dispatcher-servlet.xml
</param-value>
</context-param>
This works fine for my RESTful controllers, which look like this:
#Controller
#RequestMapping(value = "/api/user")
public class BlahBlahController {...
My "HomeController", which just looks like this:
#Controller
#RequestMapping(value = "/")
public class HomeController extends AbstractController {
#Override
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView("login");
}
}
IS triggered when I hit the "/" url, but I get this error in the logs:
WARNING: No mapping found for HTTP request with URI [/WEB-INF/pages/login.jsp] in DispatcherServlet with name 'spring-dispatcher'
Now I get what it's saying, it doesn't know how to resolve /WEB-INF/pages/login.jsp (this page does exist btw), but I'm stuck as to how I need to alter things to get this to work.
I'm a little confused on how it's supposed to work. Anyone got any clues?
Thanks.
OK.. I found the answer, it's the url-pattern in the dispatcher config.
Instead of:
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
It should be
<servlet-mapping>
<servlet-name>spring-dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
I had actually found this answer elsewhere and tried it but "thought" it wasn't working, then realized the reason I thought this was unrelated to the root cause.
No idea why this would work and the other wouldn't.. but one problem at a time...
Put RequestMapping at the method level, I tried at my code and it worked. You don't need to define HomeController bean if you are using #Controller and having a proper "context:component-scan"
#Override
#RequestMapping(value = "/")
protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception {
return new ModelAndView("login");
}
you can also use below code if you just want to redirect a login view for all "/" access.
<mvc:view-controller path="/" view-name="login"/>
Checkout the mvc show case project from github for a helpful reference.
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.
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!
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