users@jersey.java.net

[Jersey] Re: WS itself playing the role of web-client

From: Arthur Yeo <artyyeo_at_gmail.com>
Date: Wed, 23 Mar 2011 14:05:28 -0700

I am having problems receiving an image using the Client class. The error I
am getting in the Server log is this:
-------
WC1406: Servlet.service() for servlet ServletAdaptor threw exception
com.sun.jersey.api.client.ClientHandlerException: A message body reader for
Java type, class java.awt.Image, and MIME media type, image/png, was not
found at
--------

here's the code I am running ... is it too simplistic here?

------
   @POST
   @Consumes("application/x-www-form-urlencoded")
   @Produces("image/*")
   public Image genQrc( @FormParam("upc") String blah1,
                           @FormParam("descr") String blah2) throws
IOException
   {

      String extUrl = "https://SomeWsCreatedByOthers";

      Client client = Client.create();
      WebResource wr = client.resource(extUrl );

      Image r = wr.get(Image.class);
      return (r);
   }

On Wed, Mar 23, 2011 at 9:17 AM, Arthur Yeo <artyyeo_at_gmail.com> wrote:

> Thanks, Pavel, for pointing me to the right direction.
> I found Jakub's blog.
>
> Now, one more question: if the WS I am calling is returning an image,
> what's the right way to handle this?
>
> Thanks,
> Art
>
>
> On Wed, Mar 23, 2011 at 3:46 AM, Pavel Bucek <pavel.bucek_at_oracle.com>wrote:
>
>> On 03/23/2011 05:20 AM, Arthur Yeo wrote:
>>
>>> All,
>>> In the mix of things, I need one of my WS's to call another WS provided
>>> by another organization. In other words, my WS is now playing the role of a
>>> web client.
>>>
>>> What's the best way to do this in Jersey?
>>> Do I just stuff Java client code, like making use of the std URL class,
>>> in there?
>>> Or, Is there something else in Jersey you recommend?
>>>
>>
>> former, you need to create Client and WebResource by yourself, there is
>> nothing better yet (but it might be soon).
>>
>> you might want to cache created client instance in some singleton,
>> Client.create() is relatively expensive operation.
>>
>> Pavel
>>
>>
>>> --
>>> Arthur Y.
>>>
>>
>>
>
>
> --
> Arthur Y.
>



-- 
Arthur Y.