users@jersey.java.net

Re: JSONp with Jersey 1.4?

From: Jakub Podlesak <jakub.podlesak_at_oracle.com>
Date: Thu, 11 Nov 2010 19:21:29 +0100

Hi Dominique,

Please try to wrap your org.epcis.fosstrak.restadapter.model.Resource
instance with com.sun.jersey.api.json.JSONWithPadding
as demonstrated in example [1]. You will still
be able to get JSON response, when needed,
but will be also capable of generating the JavaScript as requested.

HTH,

~Jakub

[1]http://download.java.net/maven/2/com/sun/jersey/samples/jsonp/1.4/jsonp-1.4-project.zip

On 11/10/2010 01:56 AM, dguinard_at_ethz.ch wrote:
> Dear Jersey people,
>
> We are currently in the process of opensourcing a framework for RFID
> tracking based on Jersey.
>
> I wanted to add JSONp support before going live.
> I read in a number of mails on this list that a jsonp response is
> triggered by:
>
> (Paul Sandoz):
> "JSONWithPadding writing is triggered for the following media types:
>
> javascriptTypes.put("application", new
> HashSet<String>(Arrays.asList("x-javascript", "ecmascript",
> "javascript"))); javascriptTypes.put("text", new
> HashSet<String>(Arrays.asList("ecmascript", "jscript")));"
>
> I added this to my resources:
>
> @Path(EPCIS_ROOT)
> @Produces({Config.TEXT_HTML_WEBKIT_SAFE, APPLICATION_JSON,
> APPLICATION_XHTML_XML, TEXT_XML, "application/x-javascript"})
> public class RESTfulEPCIS implements ICaptureResource, IQueryResource,
> IRESTfulEPCISResource, ISubscriptionResource {
>
> but whenever I try a cURL (I'm actually using Poster but anyways) for
> application/javascript I trigger an exception:
>
> javax.ws.rs.WebApplicationException:
> com.sun.jersey.api.MessageException: A message body writer for Java
> class org.epcis.fosstrak.restadapter.model.Resource, and Java type
> class
> org.epcis.fosstrak.restadapter.model.Resource, and MIME media type
> application/x-javascript was not found
> at
> com.sun.jersey.spi.container.ContainerResponse.write(ContainerResponse.
> java:278)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl._handleReques
> t(WebApplicationImpl.java:1326)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest
> (WebApplicationImpl.java:1239)
> at
> com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest
> (WebApplicationImpl.java:1229)
> at
> com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.
> java:420)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletCo
> ntainer.java:497)
> at
> com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletCo
> ntainer.java:684)
> at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
> at
> org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(Applic
> ationFilterChain.java:290)
> at
> org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFil
> terChain.java:206)
> at
> org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperVal
> ve.java:233)
> at
> org.apache.catalina.core.StandardContextValve.invoke(StandardContextVal
> ve.java:191)
> at
> org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.jav
> a:127)
> at
> org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.jav
> a:102)
> at
> org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve
> .java:109)
> at
> org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:
> 298)
> at
> org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:8
> 59)
> at
> org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process
> (Http11Protocol.java:588)
> at
> org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
> at java.lang.Thread.run(Thread.java:636)
> Caused by: com.sun.jersey.api.MessageException: A message body writer
> for Java class org.epcis.fosstrak.restadapter.model.Resource, and Java
> type class org.epcis.fosstrak.restadapter.model.Resource, and MIME
> media
> type application/x-javascript was not found
>
> Any idea what's going on? Did I get it wrong? Isn't the JSONp writer
> triggered automatically?
>
> I'm deploying the app in Tomcat (6.28).
>
> Thanks a lot for your help,
>
> Jersey rocks ;-)
>
> -- Dominique Guinard, Web of Things Researcher
> MIT Auto-ID labs
> www.guinard.org