« Return to Thread: RESTClient get NPE when response status = 201

Re: Re: RE[groovy-user] STClient get NPE when response status = 201

by Tom Nichols :: Rate this Message:

Reply to Author | View in Thread

Hi Mike,

First off, thanks for testing this out.  Unfortunately I'm a little
more confused now, since that error you've got should not have
anything to do with the response.

Let me explain - the error - an NPE, mind you, not an
UnsupportedOperationException (which really should be an
IllegalArgumentException, actually) seems to indicate you're
attempting to set a _request_ body when you're not using a PUT or POST
operation.  i.e. the HTTP spec says a GET can't send a request body.
Furthermore, it's actually causing an NPE seemingly because the
underlying HttpRequest instance is null... Which should never be the
case since that is set in the RequestConfigDelegate constructor.

So I'm not sure how or why this error is actually occurring... Can you
send me a code example? (for your client-side)

To answer your second question, I don't believe a PUT or POST are
required to return a response body.  But if the response body is
empty, RESTClient/ HTTPBuilder should already be able to handle this,
and the response.data property should just return null.

-Tom


On Mon, Jun 29, 2009 at 10:05 AM, mikemil<mikemil@...> wrote:

>
> Tom,
>
> Here's what I got using the version of HttpBuilder that was attached to the
> defect, which seems to agree with what I said earlier.   Looks like the code
> is throwing an UnsupportedOperationException because the request is not an
> instance of HttpEntityEnclosingRequest.  The Location header is set in the
> response to contain the uri for the created resource,  but there is on
> entity-body returned - content-length=0.
>
> I am just starting to learn about REST and have not read the spec so I am
> not sure if the service is REQUIRED or SUGGESTED to return content in the
> body?
>
> Again, this is new to me but is there a way for me to register a
> responseHandler to handle the 201 status that overrides what is currently
> being run?
>
> Exception thrown: null
>
> java.lang.NullPointerException
>
>        at
> groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setBody(HTTPBuilder.java:1103)
>
>        at
> groovyx.net.http.HTTPBuilder$RequestConfigDelegate.setPropertiesFromMap(HTTPBuilder.java:1021)
>
>        at
> groovyx.net.http.HTTPBuilder$RequestConfigDelegate.<init>(HTTPBuilder.java:863)
>
>        at groovyx.net.http.RESTClient.post(RESTClient.java:140)
>
>        at RESTClientPOST.run(RESTClientPOST.groovy:10)
>
>
>
>
>
> Tom Nichols wrote:
>>
>> It's a simple maven build; the SVN location is on the project website.
>> Check out the 0.5.0-RC-1 tag, replace that class and run 'mvn package'
>>
>> If you have trouble just let me know and I'll release a second RC.
>>
>>
>> On Saturday, June 27, 2009, mikemil <mikemil@...> wrote:
>>>
>>> I am willing to try the patch.   What's involved in 'building from
>>> source'?
>>> Is it just a couple of maven targets or something more involved?
>>>
>>> This is fairly easy to recreate.  I was just testing with the RESTEasy
>>> code,
>>> using their 'Simple' example.  The first thing that needs to be done is
>>> calling with a POST and that code always returns a 201.
>>>
>>>
>>>
>>> Tom Nichols wrote:
>>>>
>>>> It sounds the same as this bug report:
>>>> http://jira.codehaus.org/browse/GMOD-95
>>>> If you're willing to build from source, try the RC-1 tag with the
>>>> replacement HTTPBuilder.java that's attached to the bug report.  This
>>>> is something difficult for me to test myself, as I don't know of a
>>>> public web service that emulates the behavior.
>>>>
>>>> But the NPE is thrown from w/in a catch block, which means it's
>>>> masking some other error that's occurring during parsing.  If you can
>>>> try out that patch, please let me know your result.
>>>>
>>>> On Sat, Jun 27, 2009 at 12:42 AM, mikemil<mikemil@...> wrote:
>>>>>
>>>>> I am trying to use the RESTClient class to do a post to a RESTful web
>>>>> service.   I am getting an NPE at HTTPBuilder.java:461 - after turning
>>>>> on
>>>>> the debugging log (see below) it appears that my post is working and
>>>>> the
>>>>> resource is created, but I still get the NPE.   I do see the status
>>>>> code
>>>>> =
>>>>> 201 and no XML is returned.  Am I doing something wrong or is this a
>>>>> bug???
>>>>>
>>>>>
>>>>>
>>>>> 2009-06-26 23:23:01,859 [Thread-8] DEBUG http.RESTClient  - POST
>>>>> http://localhost:8080/simple/rest-services/customers/
>>>>> 2009-06-26 23:23:02,250 [Thread-8] DEBUG conn.SingleClientConnManager
>>>>>  -
>>>>> Get
>>>>> connection for route HttpRoute[{}->http://localhost:8080]
>>>>> 2009-06-26 23:23:02,312 [Thread-8] DEBUG client.ClientParamsStack  -
>>>>> 'http.protocol.version': HTTP/1.1
>>>>> 2009-06-26 23:23:02,312 [Thread-8] DEBUG client.ClientParamsStack  -
>>>>> 'http.useragent': Apache-HttpClient/4.0-beta2 (java 1.5)
>>>>> 2009-06-26 23:23:02,312 [Thread-8] DEBUG client.ClientParamsStack  -
>>>>> 'http.protocol.expect-continue': true
>>>>> 2009-06-26 23:23:02,312 [Thread-8] DEBUG protocol.RequestAddCookies  -
>>>>> CookieSpec selected: best-match
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG client.DefaultRequestDirector
>>>>>  -
>>>>> Attempt 1 to execute request
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >> "POST
>>>>> /simple/rest-services/customers/ HTTP/1.1[EOL]"
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >> "Accept:
>>>>> */*[EOL]"
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >>
>>>>> "Content-Length:
>>>>> 196[EOL]"
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >> "Content-Type:
>>>>> application/xml[EOL]"
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >> "Host:
>>>>> localhost:8080[EOL]"
>>>>> 2009-06-26 23:23:02,343 [Thread-8] DEBUG http.wire  - >> "Connection:
>>>>> Keep-Alive[EOL]"
>>>>> 2009-06-26 23:23:02,375 [Thread-8] DEBUG http.wire  - >> "User-Agent:
>>>>> Apache-HttpClient/4.0-beta2 (java 1.5)[EOL]"
>>>>> 2009-06-26 23:23:02,390 [Thread-8] DEBUG http.wire  - >> "Expect:
>>>>> 100-Continue[EOL]"
>>>>> 2009-06-26 23:23:02,421 [Thread-8] DEBUG http.wire  - >>
>>>>> "Accept-Encoding:
>>>>> gzip,deflate[EOL]"
>>>>> 2009-06-26 23:23:02,453 [Thread-8] DEBUG http.wire  - >> "[EOL]"
>>>>> 2009-06-26 23:23:02,468 [Thread-8] DEBUG http.headers  - >> POST
>>>>> /simple/rest-services/customers/ HTTP/1.1
>>>>> 2009-06-26 23:23:02,500 [Thread-8] DEBUG http.headers  - >> Accept: */*
>>>>> 2009-06-26 23:23:02,515 [Thread-8] DEBUG http.headers  - >>
>>>>> Content-Length:
>>>>> 196
>>>>> 2009-06-26 23:23:02,546 [Thread-8] DEBUG http.headers  - >>
>>>>> Content-Type:
>>>>> application/xml
>>>>> 2009-06-26 23:23:02,578 [Thread-8] DEBUG http.headers  - >> Host:
>>>>> localhost:8080
>>>>> 2009-06-26 23:23:02,593 [Thread-8] DEBUG http.headers  - >> Connection:
>>>>> Keep-Alive
>>>>> 2009-06-26 23:23:02,625 [Thread-8] DEBUG http.headers  - >> User-Agent:
>>>>> Apache-HttpClient/4.0-beta2 (java 1.5)
>>>>> 2009-06-26 23:23:02,656 [Thread-8] DEBUG http.headers  - >> --
>>> View this message in context:
>>> http://www.nabble.com/RESTClient-get-NPE-when-response-status-%3D-201-tp24230427p24238226.html
>>> Sent from the groovy - user mailing list archive at Nabble.com.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe from this list, please visit:
>>>
>>>     http://xircles.codehaus.org/manage_email
>>>
>>>
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe from this list, please visit:
>>
>>     http://xircles.codehaus.org/manage_email
>>
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/RESTClient-get-NPE-when-response-status-%3D-201-tp24230427p24254741.html
> Sent from the groovy - user mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe from this list, please visit:
>
>    http://xircles.codehaus.org/manage_email
>
>
>

---------------------------------------------------------------------
To unsubscribe from this list, please visit:

    http://xircles.codehaus.org/manage_email


 « Return to Thread: RESTClient get NPE when response status = 201