This is a similar question to those that have been asked before, but still different, and I simply can't figure it out.
I have a controller for a REST webservice implemented with MVC which should be handling requests for the path '/users/contacts', the problem is that in my client test app, when I try to hit that path I get:
No mapping found for HTTP request with URI /users/users/contacts in DispatcherServlet with name 'webservice' Again, in my client test app, when I change the request path to something like '/WHATEVERusers/contacts', I'll get an error that it can't resolve '/WHATEVERusers/contacts'
I don't know why when I try to hit a path handled by a controller it get's mangled, but when I request some garbage path, it doesn't.
I don't have the code in front of me, but will be able to answer questions when I get home.
Here's code from my test client:
private static void TestGetContacts() { UserCreateRequest request = new UserCreateRequest(); Gson gson = new Gson(); try { HttpClient client = new DefaultHttpClient(); StringEntity string = new StringEntity(gson.toJson(request), HTTP.UTF_8); string.setContentType("application/json"); URI uri = URIUtils.createURI("http", "localhost", 8888, "/users/contacts", null, null); HttpPost post = new HttpPost(uri); post.setEntity(string); client.execute(post); } catch(Exception ex) { System.out.println(ex.getMessage()); } } Here's my controller class:
@Controller @RequestMapping("/users/contacts") public class UserContactService { private @Autowired ApplicationContext appContext; @RequestMapping(method=RequestMethod.POST, consumes="application/json", produces="application/json") public GetContactsResponse GetContacts(@RequestBody UserCreateRequest request) { GetContactsResponse response = new GetContactsResponse(); return response; } } Here's my servlet config:
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p" xmlns:context="http://www.springframework.org/schema/context" xmlns:oxm="http://www.springframework.org/schema/oxm" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm-3.0.xsd"> <!-- - The controllers are autodetected POJOs labeled with the @Controller annotation. --> <context:component-scan base-package="com.impersonal.server.restservice.users"/> <bean class="org.springframework.web.servlet.mvc.annotation.AnnotationMethodHandlerAdapter"> <property name="messageConverters"> <list> <ref bean="jsonConverter" /> <!-- <ref bean="marshallingConverter" /> <ref bean="atomConverter" /> --> </list> </property> </bean> <bean id="jsonConverter" class="org.springframework.http.converter.json.MappingJacksonHttpMessageConverter"> <property name="supportedMediaTypes" value="application/json" /> </bean> And here's my web config:
<?xml version="1.0" encoding="utf-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 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" version="2.5"> <context-param> <param-name>contextConfigLocation</param-name> <param-value>classpath:/**/applicationContext.xml</param-value> </context-param> <servlet> <servlet-name>webservice</servlet-name> <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>webservice</servlet-name> <url-pattern>/*</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> </welcome-file-list> Update: My requests are handled in my controller, but after the request is handled, the server prints out that it couldn't resolve /users/users/contacts. For some reason another request is getting to DispsatcherServlet, and I don't know why..
Thanks, Mark