I am trying to make a simple REST web application using Tomcat 7, Apache Wink and Jackson JSON Processor, but it seems to hit the wall. If I look in the web.xml file, I see:
<!DOCTYPE web-app PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN" "http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app> <display-name>Example Web Application</display-name> <servlet> <servlet-name>ExampleServlet</servlet-name> <servlet-class>org.apache.wink.server.internal.servlet.RestServlet</servlet-class> <init-param> <param-name>javax.ws.rs.Application</param-name> <param-value>com.dummy.example.server.ExampleApplication</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>ExampleServlet</servlet-name> <url-pattern>/services/*</url-pattern> </servlet-mapping> </web-app>
Now, if I instead of / URL instead of the URL character, the REST call works, but when I use / services / *, it fails.
In my ExampleApplication application, I see:
package com.dummy.example.server; import java.util.HashSet; import java.util.Set; import javax.ws.rs.core.Application; import org.codehaus.jackson.jaxrs.JacksonJaxbJsonProvider; import org.codehaus.jackson.map.AnnotationIntrospector; import org.codehaus.jackson.map.ObjectMapper; import org.codehaus.jackson.map.introspect.JacksonAnnotationIntrospector; import org.codehaus.jackson.xc.JaxbAnnotationIntrospector; public class ExampleApplication extends Application { @Override public Set<Class<?>> getClasses() { Set<Class<?>> serviceClasses = new HashSet<Class<?>>(); serviceClasses.add(com.dummy.example.server.services.Employee.class); return serviceClasses; } @SuppressWarnings("deprecation") @Override public Set<Object> getSingletons() { Set<Object> s = new HashSet<Object>();
And in my Employee class, I have:
package com.dummy.example.server.services; import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces; import javax.ws.rs.core.MediaType; import org.json.simple.JSONObject; @Path("/services/employee") @Produces(MediaType.APPLICATION_JSON) @SuppressWarnings("unchecked") public class Employee { @GET public JSONObject get() { JSONObject json = new JSONObject(); json.put("Name", "Example"); return json; } }
Any ideas? For several seconds I hit my head about it.
source share