users@jersey.java.net

Re: [Jersey] Struggling to post file to a REST web service through Jersey Client

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Wed, 10 Mar 2010 09:53:04 +0100

Hi,

A 509 response is a non-standardized code indicating a limit exceeded
in bandwidth:

   http://en.wikipedia.org/wiki/List_of_HTTP_status_codes#5xx_Server_Error

It could be that the IP address of your client has been limited, or
the query is taking too long to complete, or would produce a result
that if sent would be too big. You need to contact the owners of the
service.

The Jersey client API specifies that for any type other than
ClientResponse the API will throw a uniform interface exception if the
status code of the response is >= 300.

https://jersey.dev.java.net/nonav/apidocs/latest/jersey/com/sun/jersey/api/client/WebResource.html
#post%28java.lang.Class,%20java.lang.Object%29

This is not a Jersey client API issue. The code you sent works and
allows one to catch for certain status code, but the service is not
behaving as you would like, namely getting a result to the query you
sent.

Paul.

On Mar 9, 2010, at 10:09 PM, Monika Solanki wrote:

> The code finally worked with this change:
>
> String response;
> try {
> response =
> service.type(MediaType.TEXT_XML).post(String.class,f);
> } catch (UniformInterfaceException e) {
> System.out.println(e.getResponse().toString());
> }
>
> But I do not understand this. Why do I need to get the response
> object from the exception object. I did try using the ClientResponse
> object on its own
> instead of the String, but then the server threw 509. Any pointers
> much appreciated.
>
> Monika
>
>
> Paul Sandoz wrote:
>> On Mar 9, 2010, at 5:36 PM, Monika Solanki wrote:
>>
>>
>>> Hi Paul,
>>>
>>> One thing that was mentioned to me was that I should provide the
>>>
>>> "Content-Type", which should be "text/xml"
>>>
>>>
>>> but I thought I took care of this.
>>>
>>
>> Yes, the type method takes care of that.
>>
>>
>>
>>> Other than that I don't know what
>>> else to look for.
>>>
>>>
>>
>> Do you have access to the server logs? or is this a public service?
>>
>> If you enable logging you might get some clues if there is any info
>> in the 500 response.
>>
>> client.addFilter(new LoggingFilter());
>>
>> My own suspicious are that the server cannot process the XML
>> document in the post.xml file.
>>
>> Paul.
>>
>>
>>> Monka
>>> Paul Sandoz wrote:
>>>
>>>> Hi Monika,
>>>>
>>>> Your client code looks OK.
>>>>
>>>> What is the server side? any more details in the server logs?
>>>>
>>>> Paul.
>>>>
>>>> On Mar 9, 2010, at 2:36 PM, Monika Solanki wrote:
>>>>
>>>>
>>>>
>>>>> Hello,
>>>>>
>>>>> I am trying to send an XML file and get the response back as text/
>>>>> xml. The server is throwing 500. Please could someone help me with
>>>>> my code below
>>>>> {
>>>>> ClientConfig config = new DefaultClientConfig();
>>>>> Client client = Client.create(config);
>>>>> WebResource service = client.resource(getBaseURI());
>>>>> File f = new File("/home/monika/post.xml");
>>>>> System.out.println(f.exists());
>>>>> String response;
>>>>> response =
>>>>> service
>>>>> .type
>>>>> (MediaType
>>>>> .TEXT_XML).accept(MediaType.TEXT_XML).post(String.class, f);
>>>>>
>>>>> }
>>>>>
>>>>> private static URI getBaseURI() {
>>>>> return UriBuilder.fromUri(
>>>>> "http://lod.openlinksw.com/fct/service").build();
>>>>> }
>>>>>
>>>>> --
>>>>> Dr Monika Solanki
>>>>> F27 Department of Computer Science
>>>>> University of Leicester
>>>>> Leicester LE1 7RH
>>>>> United Kingdom
>>>>> Tel: +44 116 252 3828
>>>>> Google: 52.653791,-1.158414
>>>>> http://www.cs.le.ac.uk/people/ms491
>>>>>
>>>>>
>>>>>
>>>>>
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>>
>>>>>
>>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>>
>>>>
>>>>
>>> --
>>> Dr Monika Solanki
>>> F27 Department of Computer Science
>>> University of Leicester
>>> Leicester LE1 7RH
>>> United Kingdom
>>> WebID: http://www.cs.le.ac.uk/people/ms491/foaf.rdf#monika
>>> Google Coordinates: 52.653791,-1.158414
>>> Tel: +44 116 252 3828
>>> Web: http://www.cs.le.ac.uk/people/ms491/
>>>
>>>
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>>
>>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
>> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>>
>>
>
> --
> Dr Monika Solanki
> F27 Department of Computer Science
> University of Leicester
> Leicester LE1 7RH
> United Kingdom
> Tel: +44 116 252 3828
> Google: 52.653791,-1.158414
> http://www.cs.le.ac.uk/people/ms491
>
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
> For additional commands, e-mail: users-help_at_jersey.dev.java.net
>