users@jersey.java.net

[Jersey] Cannot more _at_provider classes

From: Schwascho <schwarzenberger.georg_at_googlemail.com>
Date: Mon, 22 Jun 2009 07:29:55 -0700 (PDT)

Hi,
I'm just new on JAX-RS and I did a little example on Jersey. I built two
provider classes that should print out the information of the classes called
"Car" and "Truck". If i do a GET request on the first ressource resource it
works. On the the second request i get the follwing message:

javax.servlet.ServletException: non-HTTP request or response
        at
com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:241)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.jboss.web.tomcat.filters.ReplyHeaderFilter.doFilter(ReplyHeaderFilter.java:96)
        at
org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
        at
org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
        at
org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:235)
        at
org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
        at
org.jboss.web.tomcat.security.SecurityAssociationValve.invoke(SecurityAssociationValve.java:190)
        at
org.jboss.web.tomcat.security.JaccContextValve.invoke(JaccContextValve.java:92)
        at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.process(SecurityContextEstablishmentValve.java:126)
        at
org.jboss.web.tomcat.security.SecurityContextEstablishmentValve.invoke(SecurityContextEstablishmentValve.java:70)
        at
org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
        at
org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
        at
org.jboss.web.tomcat.service.jca.CachedConnectionValve.invoke(CachedConnectionValve.java:158)
        at
org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
        at
org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:330)
        at
org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:828)
        at
org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:601)
        at
org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:447)
        at java.lang.Thread.run(Thread.java:619)

Here my web.xml

<?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" id="WebApp_ID"
version="2.5">
  <display-name>JerseyTest</display-name>
  <servlet>
          <display-name>JAX_RS REST Servlet</display-name>
          <servlet-name>REST-Servlet</servlet-name>
  
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
   </servlet>
  <servlet-mapping>
          <servlet-name>REST-Servlet</servlet-name>
        <url-pattern>/services/*</url-pattern>
  </servlet-mapping>
</web-app>

The Car class and the Truck class have the follwing format:

public class Car {
        private String marke;
        private String modell;
        
        public Car() {
        }
        
        public Car(String marke, String modell) {
                this.marke = marke;
                this.modell = modell;
        }
        
       //Getters and Setters
}

The first Ressource:

@Path("test2")
public class CarService {
        
        @GET
        @Path("car")
        @Produces(MediaType.TEXT_PLAIN)
        public Car getCar(@Context HttpHeaders headers) {
                MediaType type = headers.getMediaType();
                Car c1 = new Car("VW", "Passat");
                return c1;
        }
}

The other one:

@Path("test1")
public class TruckService {
        
        @GET
        @Path("truck")
        @Produces(MediaType.TEXT_PLAIN)
        public Truck getTruck(@Context HttpHeaders headers) {
                MediaType type = headers.getMediaType();
                Truck t1 = new Truck("Scania", "L2");
                return t1;
        }
}

The first provider:

@Provider
@Produces(MediaType.TEXT_PLAIN)
public class TruckWriter implements MessageBodyWriter<Truck> {

        @Override
        public long getSize(Truck arg0, Class<?> arg1, Type arg2,
                        Annotation[] arg3, MediaType arg4) {
                // TODO Auto-generated method stub
                return -1;
        }

        @Override
        public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
                        MediaType arg3) {
                // TODO Auto-generated method stub
                return true;
        }

        @Override
        public void writeTo(Truck t, Class<?> arg1, Type arg2,
                        Annotation[] arg3, MediaType arg4,
                        MultivaluedMap<String, Object> arg5, OutputStream outputStream)
                        throws IOException, WebApplicationException {
                        PrintWriter out = new PrintWriter(outputStream);
                        out.write("Marke :" + t.getMarke());
        }

}


And the second provider:

@Provider
@Produces(MediaType.TEXT_PLAIN)
public class CarWriter implements MessageBodyWriter<Car> {

        @Override
        public long getSize(Car arg0, Class<?> arg1, Type arg2, Annotation[] arg3,
                        MediaType arg4) {
                // TODO Auto-generated method stub
                return -1;
        }

        @Override
        public boolean isWriteable(Class<?> arg0, Type arg1, Annotation[] arg2,
                        MediaType arg3) {
                // TODO Auto-generated method stub
                return true;
        }

        @Override
        public void writeTo(Car car, Class<?> arg1, Type arg2, Annotation[] arg3,
                        MediaType arg4, MultivaluedMap<String, Object> arg5,
                        OutputStream outputStream) throws IOException, WebApplicationException {
                        PrintWriter out = new PrintWriter(outputStream);
                        out.write(car.getMarke());
                
        }

}

Has anybody an idea? Thanks







-- 
View this message in context: http://n2.nabble.com/Cannot-more-%40provider-classes-tp3136533p3136533.html
Sent from the Jersey mailing list archive at Nabble.com.