users@jersey.java.net

Re: [Jersey] Passing files or very long strings into a RESTful webservice

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Mon, 15 Mar 2010 10:02:50 +0100

On Mar 15, 2010, at 4:55 AM, Rameswara Sashi Kiran Challa wrote:

> Dear All,
>
> (How do I get to know that my questions are answered when I post to
> this mailing list. Where do I need to subscribe for this mailing
> list ? )
>

See:

   https://jersey.dev.java.net/servlets/ProjectMailingListList


> Earlier I had posted a question on passing a string with hyphens,
> slashes using @PathParam. Here is that question
> https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=10345
>
> Thanks for your answers.
>

What web/app server and version are you using. Some web/app servers
have issues with %2F in the URI path, see:

http://markmail.org/search/?q=list%3Anet.java.dev.jersey.users++Escaping+a+PathParam+slash#query
:list%3Anet.java.dev.jersey.users%20%20Escaping%20a%20PathParam%20slash
+page:1+mid:fw2hbcqa3s55jegw+state:results


> I got it working using @QueryParam by passing my InChI string as a
> parameter. Is it correct to do this ??
>

There is nothing wrong with that approach in general (but see below
for why it is wrong for one of your cases).


> Service A returns a String(in XML format) which is very long and I
> want to pass that to another Service B which takes that long string,
> extracts some particular information and should return an array. How
> should I be passing this long string from Service A to Service B.
>
> I was trying to write a client like this:
>
> Client client = Client.create();
> WebResource webResource = client.resource("http://localhost:8080/CEfeed/atom/ceurl
> "); //url structure that I specified in @Path.
> MultivaluedMap<String, String> queryParams = new
> MultivaluedMapImpl();
> queryParams.add("url", "http://wwmm.che.uk/ce/feed/orm/feed.xml
> "); //passing the url as a query parameter to the service
> String s =
> webResource.queryParams(queryParams).get(String.class);
> System.out.println(s);// this is printing out the xml string
> that this service is supposed to return.
>
> // now pass this string s to 2nd webservice
> WebResource webResource1 = client.resource("http://localhost:8080/InChIExtractor/atom/InChIs
> ");
> MultivaluedMap<String, String> queryParams1 = new
> MultivaluedMapImpl();
> queryParams1.add("atomfeed",s);
> String outInchis =
> webResource1.queryParams(queryParams1).get(String.class); // I did
> not know what to use here instead of String.class if I am getting an
> array.
> System.out.println(outInchis);
>
> The second part does not work. I get the ClientHandlerException:
> Error writing to server.
>

You may be running into hard coded limits on the length of an ASCII
encoded URI string.

Content such as an atom feed is not really suitable for embedding in
the URI. Instead you should use a POST request to the second URI where
the content of the POST, the entity body, is the string you received
from the first request.

Paul.


> Am I supposed to create another client ?? What is the optimal way to
> do this passing of long string to another service and how should
> that service return array.
>
> Please correct me as to where I am doiing it wrong.
>
> Thanks in advance
>
> Regards
>
> --
> Sashikiran Challa
>
>