definitely is not a requirement. So I'll fix that bug (there's
>
> Retried this at home and got a better result (not sure what happened this
> morning?). Looks like the source of the NPE is from
> ParserRegistry.java:115. My Accept header is */* (I think I was having
> problems setting it to application/xml previously), my request content-type
> is application/xml, status code still 201 without any content coming back.
> The ParserRegistry.getContentType - looks like you had a TODO that for a
> potential NPE, which I apparently found - because I don't see the
> content-type on the response - partly because there is NO RESPONSE body...
>
>
>
> 2009-06-29 21:04:06,312 [Thread-8] DEBUG http.RESTClient - POST
>
http://localhost:8080/simple/rest-services/customers/> 2009-06-29 21:04:06,750 [Thread-8] DEBUG conn.SingleClientConnManager - Get
> connection for route HttpRoute[{}->
http://localhost:8080]
> 2009-06-29 21:04:06,828 [Thread-8] DEBUG client.ClientParamsStack -
> 'http.protocol.version': HTTP/1.1
> 2009-06-29 21:04:06,843 [Thread-8] DEBUG client.ClientParamsStack -
> 'http.useragent': Apache-HttpClient/4.0-beta2 (java 1.5)
> 2009-06-29 21:04:06,859 [Thread-8] DEBUG client.ClientParamsStack -
> 'http.protocol.expect-continue': true
> 2009-06-29 21:04:06,875 [Thread-8] DEBUG protocol.RequestAddCookies -
> CookieSpec selected: best-match
> 2009-06-29 21:04:06,921 [Thread-8] DEBUG client.DefaultRequestDirector -
> Attempt 1 to execute request
> 2009-06-29 21:04:06,937 [Thread-8] DEBUG http.wire - >> "POST
> /simple/rest-services/customers/ HTTP/1.1[EOL]"
> 2009-06-29 21:04:06,953 [Thread-8] DEBUG http.wire - >> "Accept: */*[EOL]"
> 2009-06-29 21:04:06,968 [Thread-8] DEBUG http.wire - >> "Content-Length:
> 196[EOL]"
> 2009-06-29 21:04:06,984 [Thread-8] DEBUG http.wire - >> "Content-Type:
> application/xml[EOL]"
> 2009-06-29 21:04:07,000 [Thread-8] DEBUG http.wire - >> "Host:
> localhost:8080[EOL]"
> 2009-06-29 21:04:07,000 [Thread-8] DEBUG http.wire - >> "Connection:
> Keep-Alive[EOL]"
> 2009-06-29 21:04:07,015 [Thread-8] DEBUG http.wire - >> "User-Agent:
> Apache-HttpClient/4.0-beta2 (java 1.5)[EOL]"
> 2009-06-29 21:04:07,031 [Thread-8] DEBUG http.wire - >> "Expect:
> 100-Continue[EOL]"
> 2009-06-29 21:04:07,046 [Thread-8] DEBUG http.wire - >> "Accept-Encoding:
> gzip,deflate[EOL]"
> 2009-06-29 21:04:07,062 [Thread-8] DEBUG http.wire - >> "[EOL]"
> 2009-06-29 21:04:07,078 [Thread-8] DEBUG http.headers - >> POST
> /simple/rest-services/customers/ HTTP/1.1
> 2009-06-29 21:04:07,093 [Thread-8] DEBUG http.headers - >> Accept: */*
> 2009-06-29 21:04:07,109 [Thread-8] DEBUG http.headers - >> Content-Length:
> 196
> 2009-06-29 21:04:07,125 [Thread-8] DEBUG http.headers - >> Content-Type:
> application/xml
> 2009-06-29 21:04:07,140 [Thread-8] DEBUG http.headers - >> Host:
> localhost:8080
> 2009-06-29 21:04:07,156 [Thread-8] DEBUG http.headers - >> Connection:
> Keep-Alive
> 2009-06-29 21:04:07,171 [Thread-8] DEBUG http.headers - >> User-Agent:
> Apache-HttpClient/4.0-beta2 (java 1.5)
> 2009-06-29 21:04:07,187 [Thread-8] DEBUG http.headers - >> Expect:
> 100-Continue
> 2009-06-29 21:04:07,203 [Thread-8] DEBUG http.headers - >> Accept-Encoding:
> gzip,deflate
> 2009-06-29 21:04:07,218 [Thread-8] DEBUG http.wire - << "HTTP/1.1 100
> Continue[EOL]"
> 2009-06-29 21:04:07,234 [Thread-8] DEBUG http.headers - << HTTP/1.1 100
> Continue
> 2009-06-29 21:04:07,250 [Thread-8] DEBUG http.wire - >>
> "<customer><firstname>Mike</firstname><lastname>Miller</lastname><street>2713
> River
> Bend Trail</street><city>Flower
> Mound</city><state>Texas</state><zip>75022</zip><country>USA</country></customer>"
> 2009-06-29 21:04:07,281 [Thread-8] DEBUG http.wire - << "HTTP/1.1 201
> Created[EOL]"
> 2009-06-29 21:04:07,296 [Thread-8] DEBUG http.wire - << "Server:
> Apache-Coyote/1.1[EOL]"
> 2009-06-29 21:04:07,312 [Thread-8] DEBUG http.wire - << "Location:
>
http://localhost:8080/simple/rest-services/customers/2[EOL]"
> 2009-06-29 21:04:07,328 [Thread-8] DEBUG http.wire - << "Content-Length:
> 0[EOL]"
> 2009-06-29 21:04:07,343 [Thread-8] DEBUG http.wire - << "Date: Tue, 30 Jun
> 2009 02:04:07 GMT[EOL]"
> 2009-06-29 21:04:07,359 [Thread-8] DEBUG http.headers - << HTTP/1.1 201
> Created
> 2009-06-29 21:04:07,375 [Thread-8] DEBUG http.headers - << Server:
> Apache-Coyote/1.1
> 2009-06-29 21:04:07,390 [Thread-8] DEBUG http.headers - << Location:
>
http://localhost:8080/simple/rest-services/customers/2> 2009-06-29 21:04:07,406 [Thread-8] DEBUG http.headers - << Content-Length:
> 0
> 2009-06-29 21:04:07,421 [Thread-8] DEBUG http.headers - << Date: Tue, 30
> Jun 2009 02:04:07 GMT
> 2009-06-29 21:04:07,453 [Thread-8] DEBUG client.DefaultRequestDirector -
> Connection can be kept alive for -1 ms
> 2009-06-29 21:04:07,468 [Thread-8] DEBUG http.RESTClient - Response code:
> 201; found handler: org.codehaus.groovy.runtime.MethodClosure@46e
> f2a
> 2009-06-29 21:04:07,500 [Thread-8] WARN http.RESTClient - Error parsing
> 'null' response
> java.lang.NullPointerException
> at
> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:115)
> at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:509)
> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:459)
> at groovyx.net.http.RESTClient.post(RESTClient.java:140)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSite.java:229)
> at
> org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52)
> at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:124)
> at RESTClientPOST.run(RESTClientPOST.groovy:5)
> at
> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256)
> at groovy.lang.GroovyShell.run(GroovyShell.java:471)
> at groovy.lang.GroovyShell.run(GroovyShell.java:451)
> at groovy.lang.GroovyShell.run(GroovyShell.java:160)
> at groovy.lang.GroovyShell$run.call(Unknown Source)
> at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:43)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:116)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:132)
> at
> groovy.ui.Console$_runScriptImpl_closure13.doCall(Console.groovy:732)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite$PogoCachedMethodSiteNoUnwrapNoCoerce.invoke(PogoMetaMethodSite.java:266)
> at
> org.codehaus.groovy.runtime.callsite.PogoMetaMethodSite.callCurrent(PogoMetaMethodSite.java:51)
> at
> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:47)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:142)
> at
> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:150)
> at groovy.ui.Console$_runScriptImpl_closure13.doCall(Console.groovy)
> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
> at
> sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
> at
> sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
> at java.lang.reflect.Method.invoke(Method.java:597)
> at
> org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:86)
> at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:234)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1061)
> at
> groovy.lang.ExpandoMetaClass.invokeMethod(ExpandoMetaClass.java:910)
> at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:892)
> at groovy.lang.Closure.call(Closure.java:279)
> at groovy.lang.Closure.call(Closure.java:274)
> at groovy.lang.Closure.run(Closure.java:355)
> at java.lang.Thread.run(Thread.java:619)
> 2009-06-29 21:04:08,171 [Thread-8] DEBUG conn.SingleClientConnManager -
> Releasing connection org.apache.http.impl.conn.SingleClientConnMana
> ger$ConnAdapter@282f55
>
>
>
>
> Tom Nichols wrote:
>>
>> 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>>
>>
>>
>>
>
> --
> View this message in context:
http://www.nabble.com/RESTClient-get-NPE-when-response-status-%3D-201-tp24230427p24262138.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>
>
>