From: Solomon D. <sd...@gm...> - 2009-04-24 22:00:04
|
I'll try to take a look at this over the weekend... Ping me again if I don't get back to you. -Solomon On Fri, Apr 24, 2009 at 5:49 PM, Jeff S <jt...@ho...> wrote: > So far I am pretty much at a loss at how to wrap the JSON provider in > RESTEasy so that I can take the provider's output and wrap it with the > callback. The searching I've done looks like people are using CXF's JAX-RS > implementation, and they're talking about creating filters to achieve the > wrapping. I already have a filter that can do it, but it seems to mess up > RESTEasy. > > Is there any more light you can shed on using the current JSON provider to > do the actual marshalling, then I can just wrap it with the callback? Even > some psuedocode would help me navigate through the RESTEasy code... > > - Jeff > > > > ------------------------------ > Date: Tue, 21 Apr 2009 14:57:05 -0400 > Subject: Re: [Resteasy-developers] Marshalling to JSON for cross-domain > javascript apps? > From: sd...@gm... > To: jt...@ho... > CC: res...@li... > > > You have quite a bit going on here. Let me start with the following: > > 1) http://www.jboss.org/community/wiki/JAXRSExtensionMappings - you can > use extensions (/foo.xml, /foo.json) to set the Content-Type > > 2) About the callbacks - search for: "jax-rs callback json." You'll get a > whole bunch of json callback implementations for other jax-rs > implementations. I'll try to get something similar up and running for > RESTEasy, but those other implementations should give you a good idea on how > to implement your own json callback "@Provider" for RESTEasy. > > -Solomon > > On Tue, Apr 21, 2009 at 12:37 PM, Jeff S <jt...@ho...> wrote: > > Has anyone already written a provider to "wrap" JSON in an executable > javascript statement for cross-domain requests? > > Read below if you want some background on the problem I'm having: > > I have a JS GUI that is making cross-domain requests to my rest service. I > am using EXT-JS's ScriptTagProxy to get around the problem of doing AJAX > requests across domains. The main problem with that is that I can't set the > Accept header to "application/json" or "text/javascript" with > ScriptTagProxy. To get around it, I'm passing it in as a URL parameter and > using a servlet filter to add it as a header. > > In order to get the JSON to be read correctly by the JS gui, the rest > service has to return a executable javascript statement, so returning plain > JSON doesn't work. EXT-JS's ScriptTagProxy makes the request and > automatically puts adds a URL parameter "callback" and sets it equal to > whatever you want, or defaults to a value if you don't supply anything. > What EXT-JS expects to see returned from the service is something like > "someCallbackName({some JSON});". > > I was using the filter that added the accept header based on what was > passed in as the accept URL parameter, and also writing whatever was in the > callback parameter to the response stream before passing the request and > response along the filter chain, then adding the closing parenthesis and > semicolon after the chain returned. This works but sometimes I get an error > from RESTeasy when the filter isn't attempting to modify the response stream > (ie. the request is from my JSF gui, and doesn't specify a callback param, > so the filter will just add teh accept param as a header): > > Could not find a message body reader for type: interface > javax.ws.rs.core.SecurityContext of content type: application/xml > > My rest service methods use the @Context annotation to inject the security > context and somehow RESTEasy is thinking it has to unmarshall it? I'm > guessing that the filter is screwing up the streams and in turn RESTEasy is > getting confused. I don't know how it's happening, since the filter is > pretty simple, but I'm using other filters (like Spring Security). If I had > time to look into it further I could probably pinpoint it, but someone here > might know much more quickly the exact problem. > > It might be a coincidence, but when I comment out the filter and just use > my JSF gui (which doesn't suffer from the cross-domain problems, since the > communication is server to server and I'm using the RESTEasy client > framework for the REST calls) I don't get the error. Other times, the code > works fine with the filter... > > ------------------------------ > Rediscover Hotmail®: Get quick friend updates right in your inbox. Check > it out.<http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009> > > > ------------------------------------------------------------------------------ > Stay on top of everything new and different, both inside and > around Java (TM) technology - register by April 22, and save > $200 on the JavaOne (SM) conference, June 2-5, 2009, San Francisco. > 300 plus technical and hands-on sessions. Register today. > Use priority code J9JMT32. http://p.sf.net/sfu/p > _______________________________________________ > Resteasy-developers mailing list > Res...@li... > https://lists.sourceforge.net/lists/listinfo/resteasy-developers > > > > ------------------------------ > Rediscover Hotmail®: Get quick friend updates right in your inbox. Check > it out.<http://windowslive.com/RediscoverHotmail?ocid=TXT_TAGLM_WL_HM_Rediscover_Updates2_042009> > |