users@jersey.java.net

Re: Generating urls and controlling rendering/serialization

From: Jo Størset <jo.storset_at_usit.uio.no>
Date: Tue, 4 Mar 2008 01:15:17 +0100

Hi,

what I tried to do was use the implicit viewable mechanism, that's why
I get

java.lang.IllegalArgumentException: A message body writer for Java
type, class no.uio.total.frida.resources.Test, and MIME media type,
text/html, was not found

I tried using an explicit Viewble as well, and that worked. Thanks for
the help, I didn't find the related classes by myself (the bookstore
only uses implicit views).

Den 3. mars. 2008 kl. 14.57 skrev Paul Sandoz:

> If you can send me your Freemarker code i may be able to get
> something working for you.

My web.xml looks like this:

   <servlet>
     <servlet-name>Resources</servlet-name>
     <servlet-class>no.uio.total.spring.SpringServlet</servlet-class>
     <init-param>
       <param-
name>com.sun.ws.rest.config.property.resourceConfigClass</param-name>
       <param-value>com.sun.ws.rest.api.core.PackagesResourceConfig</
param-value>
     </init-param>
     <init-param>
       <param-name>com.sun.ws.rest.config.feature.ImplicitViewables</
param-name>
       <param-value>true</param-value>
     </init-param>
     <init-param>
       <param-name>com.sun.ws.rest.config.feature.Redirect</param-name>
       <param-value>true</param-value>
     </init-param>
     <init-param>
       <param-name>com.sun.ws.rest.config.property.packages</param-name>
       <param-value>no.uio.total</param-value>
     </init-param>
     <load-on-startup>1</load-on-startup>
   </servlet>

As you see I use the package config (that was how I mvn jetty:run to
work, which out of the box seemed to have problems with the default
setup). Based on the bookstore example I was expecting my
templateprocessors resolve method to be called when returning a Test
object, I haven't gotten that to work yet. In summary, the explicit
view returned works but not the implicit feature:

@Path("/test/")
public class TestResource {

     @GET
     @ProduceMime("text/html")
     // Never calls my resolve method
     public Test getTest() {
         return new Test();
     }

     @GET
     @ProduceMime("text/html")
     @Path("viewable")
     // Picks up corresponding index.ftl as expected
     public Viewable getViewable() {
         return new Viewable("index", new Test());
     }
}

I attached the processor, in case it tells you anything.