Jakub,
You don't know how helpful this is!
Many thanks!!!
--
Art
On Wed, Mar 23, 2011 at 3:27 PM, Jakub Podlesak
<jakub.podlesak_at_oracle.com>wrote:
> Hi Art,
>
> Jersey does not provide message body workers for java.awt.Image class
> out of the box. You can get access to the message body input stream,
> or get it (the message body) written into a temporary file and process
> it from there, e.g.:
>
> File imgFile = wr.accept("image/*").get(File.class);
> Image image = ImageIO.read(imgFile);
>
> After you fix this, you will get similar problem, when
> trying to return the Image instance out from your resource method.
> This time, you will be getting a missing message body writer error.
> And again, you can return an OutputStream/File instead of the Image
> to fix this.
>
> Another approach would be, if you wish to make your original code
> work intact, to implement your custom java.awt.Image message
> body workers. Please see the entity-provider example [1]
> for reference.
>
> HTH,
>
> ~Jakub
>
> [1]
> http://download.java.net/maven/2/com/sun/jersey/samples/entity-provider/1.5/entity-provider-1.5-project.zip
>
>
> On 03/23/2011 10:05 PM, Arthur Yeo wrote:
>
>> 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
>> <mailto: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
>> <mailto: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.
>>
>
>
--
Arthur Y.