|
View:
New views
19 Messages
—
Rating Filter:
Alert me
|
|
|
Handling RESTClient post() responses with no content-type or body.Hi,
I'm using RESTClient from the HTTP Builder module to send a POST request to GeoServer. However, the response to my request doesn't contain a content-type or body so I get the following followed by a number of exceptions: 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType WARNING: Could not parse content-type header in response Followed by exceptions. How can I get around this? All I want from the response is the status code, I'm not interested in anything else. My code is shown below. Thanks, Jon Code: def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ // setup the restclient def geoserver = new RESTClient(geoserverUrl) // do the authing geoserver.auth.basic user, pass // post it def res = geoserver.post( path: "geoserver/rest/workspaces", requestContentType: XML, body: "<workspace><name>${wsName}</name></workspace>" ) } def code = createWorkspace("hello", "http://localhost:8080/", "admin", "geoserver") |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hmm interesting. I was under the assumption that a POST response
should include _some_ sort of response body, but maybe that's not technically required by the HTTP spec. If you can send me the exception stack trace I'm sure I can fix it, but I can't tell you what you yourself can do until you give me some more details. Better yet, if you can file a JIRA here: http://jira.codehaus.org/browse/GMOD that would be super awesome (put the bug under the "HTTPBuilder" module). And If you really want to earn karma points, give enough of an example that I can reproduce the error condition myself :) I don't konw if GeoServer has an open API, but if they do I can add it to the unit tests. Thanks. -Tom On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton <man_kills_everything@...> wrote: > > Hi, > I'm using RESTClient from the HTTP Builder module to send a POST request to > GeoServer. However, the response to my request doesn't contain a > content-type or body so I get the following followed by a number of > exceptions: > > 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType > WARNING: Could not parse content-type header in response > > Followed by exceptions. How can I get around this? All I want from the > response is the status code, I'm not interested in anything else. My code > is shown below. > > Thanks, > > Jon > > Code: > > def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ > // setup the restclient > def geoserver = new RESTClient(geoserverUrl) > // do the authing > geoserver.auth.basic user, pass > // post it > def res = geoserver.post( path: "geoserver/rest/workspaces", > requestContentType: XML, > body: "<workspace><name>${wsName}</name></workspace>" > ) > } > > def code = createWorkspace("hello", "http://localhost:8080/", "admin", > "geoserver") > -- > View this message in context: http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Tom, thanks for the quick response.
The equivalent response using cUrl looks like: curl -d'<workspace><name>dwins</name></workspace>' -H'Content-type: text/xml' http://admin:geoserver@localhost:8080/geoserver/rest/workspaces -D - HTTP/1.1 201 Created Date: Wed, 04 Nov 2009 16:19:11 GMT Location: http://localhost:8080/geoserver/rest/workspaces/dwins Server: Noelios-Restlet-Engine/1.0..8 Transfer-Encoding: chunked The API reference for the GeoServer REST interface can be found here: http://docs.geoserver.org/trunk/en/user/extensions/rest/rest-config-api.html I'm new to REST as well as Groovy so I thought it might be a problem with my code. Anyway, I'll check out JIRA now :-) Thanks for the help, Jon |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Sorry, forgot the full stack trace:
05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType WARNING: Could not parse content-type header in response java.lang.NullPointerException at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) at groovyx.net.http.RESTClient.post(RESTClient.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) at groovy.lang.GroovyShell.run(GroovyShell.java:219) at groovy.lang.GroovyShell.run(GroovyShell.java:149) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) at groovy.ui.GroovyMain.run(GroovyMain.java:309) at groovy.ui.GroovyMain.process(GroovyMain.java:295) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) at groovy.ui.GroovyMain.main(GroovyMain.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest WARNING: Error parsing 'null' response java.lang.IllegalArgumentException: Could not parse content-type from response at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) at groovyx.net.http.RESTClient.post(RESTClient.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) 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:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) at groovy.lang.GroovyShell.run(GroovyShell.java:219) at groovy.lang.GroovyShell.run(GroovyShell.java:149) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) at groovy.ui.GroovyMain.run(GroovyMain.java:309) at groovy.ui.GroovyMain.process(GroovyMain.java:295) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) at groovy.ui.GroovyMain.main(GroovyMain.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) Caught: groovyx.net.http.ResponseParseException: Created at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) at com.example.jon.GroovyTest.run(GroovyTest.groovy:60)
|
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Nope, you're right; in that case, the response object should be
available, and the 'data' property (which is the parsed response body) should just be null. Definitely a bug. However, after looking at the stack trace, I don't think you should be getting an NPE but an IllegalArgumentException (this is still erroneous in the case of RESTClient, but it's due to RESTClient's underlying use of HTTPBuilder). What version of HTTPBuilder are you using? In either case, the bug still stands; I'll start working on it soon-ish. You can work around it for now by using the HTTPBuilder class directly, which other than being slightly more verbose can do the exact thing you're doing with RESTClient. import static groovyx.net.http.Method.POST import static groovyx.net.http.ContentType.XML def http = new HTTPBuilder( 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) http.handler.SUCCESS = { return it } def response = http.request( POST, XML ) { body = '<workspace><name>dwins</name></workspace>' } assert response.status == 201 Let me know if you have any trouble with the above example. -Tom On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton <man_kills_everything@...> wrote: > > Sorry, forgot the full stack trace: > > 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType > WARNING: Could not parse content-type header in response > java.lang.NullPointerException > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > 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:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest > WARNING: Error parsing 'null' response > java.lang.IllegalArgumentException: Could not parse content-type from > response > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > 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:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > Caught: groovyx.net.http.ResponseParseException: Created > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > > > Tom Nichols wrote: >> >> Hmm interesting. I was under the assumption that a POST response >> should include _some_ sort of response body, but maybe that's not >> technically required by the HTTP spec. If you can send me the >> exception stack trace I'm sure I can fix it, but I can't tell you what >> you yourself can do until you give me some more details. >> >> Better yet, if you can file a JIRA here: >> http://jira.codehaus.org/browse/GMOD >> that would be super awesome (put the bug under the "HTTPBuilder" >> module). And If you really want to earn karma points, give enough of >> an example that I can reproduce the error condition myself :) I don't >> konw if GeoServer has an open API, but if they do I can add it to the >> unit tests. >> >> Thanks. >> -Tom >> >> >> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >> <man_kills_everything@...> wrote: >>> >>> Hi, >>> I'm using RESTClient from the HTTP Builder module to send a POST request >>> to >>> GeoServer. However, the response to my request doesn't contain a >>> content-type or body so I get the following followed by a number of >>> exceptions: >>> >>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType >>> WARNING: Could not parse content-type header in response >>> >>> Followed by exceptions. How can I get around this? All I want from the >>> response is the status code, I'm not interested in anything else. My >>> code >>> is shown below. >>> >>> Thanks, >>> >>> Jon >>> >>> Code: >>> >>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >>> // setup the restclient >>> def geoserver = new RESTClient(geoserverUrl) >>> // do the authing >>> geoserver.auth.basic user, pass >>> // post it >>> def res = geoserver.post( path: "geoserver/rest/workspaces", >>> requestContentType: XML, >>> body: "<workspace><name>${wsName}</name></workspace>" >>> ) >>> } >>> >>> def code = createWorkspace("hello", "http://localhost:8080/", "admin", >>> "geoserver") >>> -- >>> View this message in context: >>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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 |
|
|
|
RE: Handling RESTClient post() responses with no content-type or body.This sounds familiar to the problem I reported to you earlier in the year. I used RESTEasy's simple example and the status code was 201 and no body returned at all. The real case I am using does a POST and does return a body so it wasn't a real problem for me.
> Date: Thu, 5 Nov 2009 11:32:58 -0500 > From: tmnichols@... > To: user@... > Subject: Re: [groovy-user] Handling RESTClient post() responses with no content-type or body. > > Nope, you're right; in that case, the response object should be > available, and the 'data' property (which is the parsed response body) > should just be null. Definitely a bug. > > However, after looking at the stack trace, I don't think you should be > getting an NPE but an IllegalArgumentException (this is still > erroneous in the case of RESTClient, but it's due to RESTClient's > underlying use of HTTPBuilder). What version of HTTPBuilder are you > using? > > In either case, the bug still stands; I'll start working on it > soon-ish. You can work around it for now by using the HTTPBuilder > class directly, which other than being slightly more verbose can do > the exact thing you're doing with RESTClient. > > import static groovyx.net.http.Method.POST > import static groovyx.net.http.ContentType.XML > > def http = new HTTPBuilder( > 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) > http.handler.SUCCESS = { return it } > > def response = http.request( POST, XML ) { > body = '<workspace><name>dwins</name></workspace>' > } > > assert response.status == 201 > > > Let me know if you have any trouble with the above example. > -Tom > > > On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton > <man_kills_everything@...> wrote: > > > > Sorry, forgot the full stack trace: > > > > 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType > > WARNING: Could not parse content-type header in response > > java.lang.NullPointerException > > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) > > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > 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:40) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > > at > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > at > > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > at > > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > > 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest > > WARNING: Error parsing 'null' response > > java.lang.IllegalArgumentException: Could not parse content-type from > > response > > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) > > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > 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:40) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > > at > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > > at > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > at > > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > at java.lang.reflect.Method.invoke(Unknown Source) > > at > > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > > Caught: groovyx.net.http.ResponseParseException: Created > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > > > > > > > Tom Nichols wrote: > >> > >> Hmm interesting. I was under the assumption that a POST response > >> should include _some_ sort of response body, but maybe that's not > >> technically required by the HTTP spec. If you can send me the > >> exception stack trace I'm sure I can fix it, but I can't tell you what > >> you yourself can do until you give me some more details. > >> > >> Better yet, if you can file a JIRA here: > >> http://jira.codehaus.org/browse/GMOD > >> that would be super awesome (put the bug under the "HTTPBuilder" > >> module). And If you really want to earn karma points, give enough of > >> an example that I can reproduce the error condition myself :) I don't > >> konw if GeoServer has an open API, but if they do I can add it to the > >> unit tests. > >> > >> Thanks. > >> -Tom > >> > >> > >> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton > >> <man_kills_everything@...> wrote: > >>> > >>> Hi, > >>> I'm using RESTClient from the HTTP Builder module to send a POST request > >>> to > >>> GeoServer. However, the response to my request doesn't contain a > >>> content-type or body so I get the following followed by a number of > >>> exceptions: > >>> > >>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType > >>> WARNING: Could not parse content-type header in response > >>> > >>> Followed by exceptions. How can I get around this? All I want from the > >>> response is the status code, I'm not interested in anything else. My > >>> code > >>> is shown below. > >>> > >>> Thanks, > >>> > >>> Jon > >>> > >>> Code: > >>> > >>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ > >>> // setup the restclient > >>> def geoserver = new RESTClient(geoserverUrl) > >>> // do the authing > >>> geoserver.auth.basic user, pass > >>> // post it > >>> def res = geoserver.post( path: "geoserver/rest/workspaces", > >>> requestContentType: XML, > >>> body: "<workspace><name>${wsName}</name></workspace>" > >>> ) > >>> } > >>> > >>> def code = createWorkspace("hello", "http://localhost:8080/", "admin", > >>> "geoserver") > >>> -- > >>> View this message in context: > >>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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 > > |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Mike,
Yes, I recall your question; I fixed the NPE that Jon is seeing (that's why I think he's using an older version of HTTPBuilder.) However I think even after he upgrades he might still encounter an exception. I don't think I fully understood the context of your problem where the 201 doesn't return any response body, but RESTClient expects one. At least, taking a quick look at the current source code, I _think_ there will still be a problem once Jon upgrades to 0.5.0-RC2. But Jon, it would be helpful to see the behavior from the lastest version. Thanks for pointing that out Mike. -Tom On Thu, Nov 5, 2009 at 11:40 AM, Mike Miller <mikemil@...> wrote: > > Hey Tom, > > This sounds familiar to the problem I reported to you earlier in the year. I used RESTEasy's simple example and the status code was 201 and no body returned at all. The real case I am using does a POST and does return a body so it wasn't a real problem for me. > > > > > > > EMAILING FOR THE GREATER GOOD > Join me > > > > Date: Thu, 5 Nov 2009 11:32:58 -0500 > > From: tmnichols@... > > To: user@... > > Subject: Re: [groovy-user] Handling RESTClient post() responses with no content-type or body. > > > > Nope, you're right; in that case, the response object should be > > available, and the 'data' property (which is the parsed response body) > > should just be null. Definitely a bug. > > > > However, after looking at the stack trace, I don't think you should be > > getting an NPE but an IllegalArgumentException (this is still > > erroneous in the case of RESTClient, but it's due to RESTClient's > > underlying use of HTTPBuilder). What version of HTTPBuilder are you > > using? > > > > In either case, the bug still stands; I'll start working on it > > soon-ish. You can work around it for now by using the HTTPBuilder > > class directly, which other than being slightly more verbose can do > > the exact thing you're doing with RESTClient. > > > > import static groovyx.net.http.Method.POST > > import static groovyx.net.http.ContentType.XML > > > > def http = new HTTPBuilder( > > 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) > > http.handler.SUCCESS = { return it } > > > > def response = http.request( POST, XML ) { > > body = '<workspace><name>dwins</name></workspace>' > > } > > > > assert response.status == 201 > > > > > > Let me know if you have any trouble with the above example. > > -Tom > > > > > > On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton > > <man_kills_everything@...> wrote: > > > > > > Sorry, forgot the full stack trace: > > > > > > 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType > > > WARNING: Could not parse content-type header in response > > > java.lang.NullPointerException > > > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) > > > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > > > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > > at java.lang.reflect.Method.invoke(Unknown Source) > > > 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:40) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > > > at > > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > > at > > > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > > at java.lang.reflect.Method.invoke(Unknown Source) > > > at > > > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > > > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > > > 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest > > > WARNING: Error parsing 'null' response > > > java.lang.IllegalArgumentException: Could not parse content-type from > > > response > > > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) > > > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > > > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > > at java.lang.reflect.Method.invoke(Unknown Source) > > > 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:40) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > > at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) > > > at > > > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > > > at > > > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > > at > > > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > > > at java.lang.reflect.Method.invoke(Unknown Source) > > > at > > > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > > > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > > > Caught: groovyx.net.http.ResponseParseException: Created > > > at com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > > > > > > > > > > > > Tom Nichols wrote: > > >> > > >> Hmm interesting. I was under the assumption that a POST response > > >> should include _some_ sort of response body, but maybe that's not > > >> technically required by the HTTP spec. If you can send me the > > >> exception stack trace I'm sure I can fix it, but I can't tell you what > > >> you yourself can do until you give me some more details. > > >> > > >> Better yet, if you can file a JIRA here: > > >> http://jira.codehaus.org/browse/GMOD > > >> that would be super awesome (put the bug under the "HTTPBuilder" > > >> module). And If you really want to earn karma points, give enough of > > >> an example that I can reproduce the error condition myself :) I don't > > >> konw if GeoServer has an open API, but if they do I can add it to the > > >> unit tests. > > >> > > >> Thanks. > > >> -Tom > > >> > > >> > > >> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton > > >> <man_kills_everything@...> wrote: > > >>> > > >>> Hi, > > >>> I'm using RESTClient from the HTTP Builder module to send a POST request > > >>> to > > >>> GeoServer. However, the response to my request doesn't contain a > > >>> content-type or body so I get the following followed by a number of > > >>> exceptions: > > >>> > > >>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType > > >>> WARNING: Could not parse content-type header in response > > >>> > > >>> Followed by exceptions. How can I get around this? All I want from the > > >>> response is the status code, I'm not interested in anything else. My > > >>> code > > >>> is shown below. > > >>> > > >>> Thanks, > > >>> > > >>> Jon > > >>> > > >>> Code: > > >>> > > >>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ > > >>> // setup the restclient > > >>> def geoserver = new RESTClient(geoserverUrl) > > >>> // do the authing > > >>> geoserver.auth.basic user, pass > > >>> // post it > > >>> def res = geoserver.post( path: "geoserver/rest/workspaces", > > >>> requestContentType: XML, > > >>> body: "<workspace><name>${wsName}</name></workspace>" > > >>> ) > > >>> } > > >>> > > >>> def code = createWorkspace("hello", "http://localhost:8080/", "admin", > > >>> "geoserver") > > >>> -- > > >>> View this message in context: > > >>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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 > > > > --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi,
I was using 0.5.0-RC2 when I send my post now I'm using 0.5.0-SNAPSHOT with the same result. Jon
|
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Actually 0.5.0-RC2 should be sufficient. But I'm still confused how
you could be seeing that NPE seeing as how in RC2 it's caught and wrapped: http://fisheye.codehaus.org/browse/gmod/httpbuilder/tags/0.5.0-RC2/src/main/java/groovyx/net/http/ParserRegistry.java?r=HEAD#l153 Again, not to say there isn't a bug in my parsing logic (there is!) but I'm just confused about the exception you're seeing. Did you happen to open up a JIRA? I just wanted to check before I open up a duplicate on accident. Thanks. -Tom 2009/11/6 Jon Britton <man_kills_everything@...>: > > Hi, > > I was using 0.5.0-RC2 when I send my post now I'm using 0.5.0-SNAPSHOT with > the same result. > > Jon > > > Tom Nichols wrote: >> >> Hi Mike, >> >> Yes, I recall your question; I fixed the NPE that Jon is seeing >> (that's why I think he's using an older version of HTTPBuilder.) >> However I think even after he upgrades he might still encounter an >> exception. I don't think I fully understood the context of your >> problem where the 201 doesn't return any response body, but RESTClient >> expects one. At least, taking a quick look at the current source >> code, I _think_ there will still be a problem once Jon upgrades to >> 0.5.0-RC2. But Jon, it would be helpful to see the behavior from the >> lastest version. >> >> Thanks for pointing that out Mike. >> -Tom >> >> On Thu, Nov 5, 2009 at 11:40 AM, Mike Miller <mikemil@...> wrote: >>> >>> Hey Tom, >>> >>> This sounds familiar to the problem I reported to you earlier in the >>> year. I used RESTEasy's simple example and the status code was 201 and >>> no body returned at all. The real case I am using does a POST and does >>> return a body so it wasn't a real problem for me. >>> >>> >>> >>> >>> >>> >>> EMAILING FOR THE GREATER GOOD >>> Join me >>> >>> >>> > Date: Thu, 5 Nov 2009 11:32:58 -0500 >>> > From: tmnichols@... >>> > To: user@... >>> > Subject: Re: [groovy-user] Handling RESTClient post() responses with no >>> content-type or body. >>> > >>> > Nope, you're right; in that case, the response object should be >>> > available, and the 'data' property (which is the parsed response body) >>> > should just be null. Definitely a bug. >>> > >>> > However, after looking at the stack trace, I don't think you should be >>> > getting an NPE but an IllegalArgumentException (this is still >>> > erroneous in the case of RESTClient, but it's due to RESTClient's >>> > underlying use of HTTPBuilder). What version of HTTPBuilder are you >>> > using? >>> > >>> > In either case, the bug still stands; I'll start working on it >>> > soon-ish. You can work around it for now by using the HTTPBuilder >>> > class directly, which other than being slightly more verbose can do >>> > the exact thing you're doing with RESTClient. >>> > >>> > import static groovyx.net.http.Method.POST >>> > import static groovyx.net.http.ContentType.XML >>> > >>> > def http = new HTTPBuilder( >>> > 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) >>> > http.handler.SUCCESS = { return it } >>> > >>> > def response = http.request( POST, XML ) { >>> > body = '<workspace><name>dwins</name></workspace>' >>> > } >>> > >>> > assert response.status == 201 >>> > >>> > >>> > Let me know if you have any trouble with the above example. >>> > -Tom >>> > >>> > >>> > On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton >>> > <man_kills_everything@...> wrote: >>> > > >>> > > Sorry, forgot the full stack trace: >>> > > >>> > > 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType >>> > > WARNING: Could not parse content-type header in response >>> > > java.lang.NullPointerException >>> > > at >>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) >>> > > at >>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>> > > at >>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>> > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>> Source) >>> > > at java.lang.reflect.Method.invoke(Unknown Source) >>> > > 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:40) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>> > > at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> > > at >>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>> > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> > > at >>> > > >>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>> > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>> > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>> > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>> > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>> > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>> > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>> > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>> Source) >>> > > at java.lang.reflect.Method.invoke(Unknown Source) >>> > > at >>> > > >>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>> > > at >>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>> > > 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest >>> > > WARNING: Error parsing 'null' response >>> > > java.lang.IllegalArgumentException: Could not parse content-type from >>> > > response >>> > > at >>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) >>> > > at >>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>> > > at >>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>> > > at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>> Source) >>> > > at java.lang.reflect.Method.invoke(Unknown Source) >>> > > 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:40) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>> > > at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> > > at >>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown Source) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>> > > at >>> > > >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>> > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> > > at >>> > > >>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>> > > at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>> > > at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>> > > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>> > > at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>> > > at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>> > > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>> > > at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> > > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> > > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>> Source) >>> > > at java.lang.reflect.Method.invoke(Unknown Source) >>> > > at >>> > > >>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>> > > at >>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>> > > Caught: groovyx.net.http.ResponseParseException: Created >>> > > at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> > > at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> > > >>> > > >>> > > >>> > > Tom Nichols wrote: >>> > >> >>> > >> Hmm interesting. I was under the assumption that a POST response >>> > >> should include _some_ sort of response body, but maybe that's not >>> > >> technically required by the HTTP spec. If you can send me the >>> > >> exception stack trace I'm sure I can fix it, but I can't tell you >>> what >>> > >> you yourself can do until you give me some more details. >>> > >> >>> > >> Better yet, if you can file a JIRA here: >>> > >> http://jira.codehaus.org/browse/GMOD >>> > >> that would be super awesome (put the bug under the "HTTPBuilder" >>> > >> module). And If you really want to earn karma points, give enough >>> of >>> > >> an example that I can reproduce the error condition myself :) I >>> don't >>> > >> konw if GeoServer has an open API, but if they do I can add it to >>> the >>> > >> unit tests. >>> > >> >>> > >> Thanks. >>> > >> -Tom >>> > >> >>> > >> >>> > >> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >>> > >> <man_kills_everything@...> wrote: >>> > >>> >>> > >>> Hi, >>> > >>> I'm using RESTClient from the HTTP Builder module to send a POST >>> request >>> > >>> to >>> > >>> GeoServer. However, the response to my request doesn't contain a >>> > >>> content-type or body so I get the following followed by a number of >>> > >>> exceptions: >>> > >>> >>> > >>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType >>> > >>> WARNING: Could not parse content-type header in response >>> > >>> >>> > >>> Followed by exceptions. How can I get around this? All I want >>> from the >>> > >>> response is the status code, I'm not interested in anything else. >>> My >>> > >>> code >>> > >>> is shown below. >>> > >>> >>> > >>> Thanks, >>> > >>> >>> > >>> Jon >>> > >>> >>> > >>> Code: >>> > >>> >>> > >>> def createWorkspace(def wsName, def geoserverUrl, def user, def >>> pass){ >>> > >>> // setup the restclient >>> > >>> def geoserver = new RESTClient(geoserverUrl) >>> > >>> // do the authing >>> > >>> geoserver.auth.basic user, pass >>> > >>> // post it >>> > >>> def res = geoserver.post( path: "geoserver/rest/workspaces", >>> > >>> requestContentType: XML, >>> > >>> body: >>> "<workspace><name>${wsName}</name></workspace>" >>> > >>> ) >>> > >>> } >>> > >>> >>> > >>> def code = createWorkspace("hello", "http://localhost:8080/", >>> "admin", >>> > >>> "geoserver") >>> > >>> -- >>> > >>> View this message in context: >>> > >>> >>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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 >>> > >>> > >> >> --------------------------------------------------------------------- >> To unsubscribe from this list, please visit: >> >> http://xircles.codehaus.org/manage_email >> >> >> >> > > -- > View this message in context: http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26229831.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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi again, I'm just trying your example without using RESTClient but it doesn't work. My code is below, followed by the error I receive. What's could be causing this?
Thanks, Jon CODE: def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ def http = new HTTPBuilder( "${geoserverUrl}/geoserver/rest/workspaces" ) http.handler.SUCCESS = { return it } def response = http.request( POST, XML ) { body = "<workspace><name>${wsName}</name></workspace>" } assert response.status == 201 } //Call method def code = createWorkspace("hello1", "http://admin:geoserver@localhost:8080/", "admin", "geoserver") OUTPUT: Caught: groovy.lang.MissingMethodException: No signature of method: groovyx.net.http.HTTPBuilder.request() is applicable for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, uk.ac.glam.rest.GroovyTest$_createWorkspace _closure2) values: [POST, application/xml, uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70)
|
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.hmm, I'm not sure what to tell you; I just copied your example into a
Groovy console and ran it, and I didn't get the MissingMethodException that you're seeing there, using 0.5.0-RC2. Try this variation: def http = new groovyx.net.http.HTTPBuilder( "http://localhost:8080/geoserver/rest/workspaces" ) http.handler.SUCCESS = { return it } def response = http.post( headers:['Content-Type': 'text/xml'], body: "<workspace><name>bob</name></workspace>" ) assert response.status == 201 2009/11/6 Jon Britton <man_kills_everything@...>: > > Hi again, I'm just trying your example without using RESTClient but it > doesn't work. My code is below, followed by the error I receive. What's > could be causing this? > > Thanks, > > Jon > > CODE: > > def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ > def http = new HTTPBuilder( "${geoserverUrl}/geoserver/rest/workspaces" ) > http.handler.SUCCESS = { return it } > > def response = http.request( POST, XML ) { > body = "<workspace><name>${wsName}</name></workspace>" > } > > assert response.status == 201 > } > > //Call method > def code = createWorkspace("hello1", > "http://admin:geoserver@localhost:8080/", "admin", "geoserver") > > OUTPUT: > > Caught: groovy.lang.MissingMethodException: No signature of method: > groovyx.net.http.HTTPBuilder.request() is applicable > for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, > uk.ac.glam.rest.GroovyTest$_createWorkspace > _closure2) values: [POST, application/xml, > uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70) > > > > Tom Nichols wrote: >> >> Nope, you're right; in that case, the response object should be >> available, and the 'data' property (which is the parsed response body) >> should just be null. Definitely a bug. >> >> However, after looking at the stack trace, I don't think you should be >> getting an NPE but an IllegalArgumentException (this is still >> erroneous in the case of RESTClient, but it's due to RESTClient's >> underlying use of HTTPBuilder). What version of HTTPBuilder are you >> using? >> >> In either case, the bug still stands; I'll start working on it >> soon-ish. You can work around it for now by using the HTTPBuilder >> class directly, which other than being slightly more verbose can do >> the exact thing you're doing with RESTClient. >> >> import static groovyx.net.http.Method.POST >> import static groovyx.net.http.ContentType.XML >> >> def http = new HTTPBuilder( >> 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) >> http.handler.SUCCESS = { return it } >> >> def response = http.request( POST, XML ) { >> body = '<workspace><name>dwins</name></workspace>' >> } >> >> assert response.status == 201 >> >> >> Let me know if you have any trouble with the above example. >> -Tom >> >> >> On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton >> <man_kills_everything@...> wrote: >>> >>> Sorry, forgot the full stack trace: >>> >>> 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType >>> WARNING: Could not parse content-type header in response >>> java.lang.NullPointerException >>> at >>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) >>> at >>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>> at java.lang.reflect.Method.invoke(Unknown Source) >>> 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:40) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>> at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>> Source) >>> at >>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> at >>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>> at java.lang.reflect.Method.invoke(Unknown Source) >>> at >>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>> at >>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>> 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest >>> WARNING: Error parsing 'null' response >>> java.lang.IllegalArgumentException: Could not parse content-type from >>> response >>> at >>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) >>> at >>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>> at java.lang.reflect.Method.invoke(Unknown Source) >>> 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:40) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>> at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>> Source) >>> at >>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>> at >>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> at >>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>> at java.lang.reflect.Method.invoke(Unknown Source) >>> at >>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>> at >>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>> Caught: groovyx.net.http.ResponseParseException: Created >>> at >>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>> >>> >>> >>> Tom Nichols wrote: >>>> >>>> Hmm interesting. I was under the assumption that a POST response >>>> should include _some_ sort of response body, but maybe that's not >>>> technically required by the HTTP spec. If you can send me the >>>> exception stack trace I'm sure I can fix it, but I can't tell you what >>>> you yourself can do until you give me some more details. >>>> >>>> Better yet, if you can file a JIRA here: >>>> http://jira.codehaus.org/browse/GMOD >>>> that would be super awesome (put the bug under the "HTTPBuilder" >>>> module). And If you really want to earn karma points, give enough of >>>> an example that I can reproduce the error condition myself :) I don't >>>> konw if GeoServer has an open API, but if they do I can add it to the >>>> unit tests. >>>> >>>> Thanks. >>>> -Tom >>>> >>>> >>>> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >>>> <man_kills_everything@...> wrote: >>>>> >>>>> Hi, >>>>> I'm using RESTClient from the HTTP Builder module to send a POST >>>>> request >>>>> to >>>>> GeoServer. However, the response to my request doesn't contain a >>>>> content-type or body so I get the following followed by a number of >>>>> exceptions: >>>>> >>>>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType >>>>> WARNING: Could not parse content-type header in response >>>>> >>>>> Followed by exceptions. How can I get around this? All I want from >>>>> the >>>>> response is the status code, I'm not interested in anything else. My >>>>> code >>>>> is shown below. >>>>> >>>>> Thanks, >>>>> >>>>> Jon >>>>> >>>>> Code: >>>>> >>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >>>>> // setup the restclient >>>>> def geoserver = new RESTClient(geoserverUrl) >>>>> // do the authing >>>>> geoserver.auth.basic user, pass >>>>> // post it >>>>> def res = geoserver.post( path: "geoserver/rest/workspaces", >>>>> requestContentType: XML, >>>>> body: "<workspace><name>${wsName}</name></workspace>" >>>>> ) >>>>> } >>>>> >>>>> def code = createWorkspace("hello", "http://localhost:8080/", "admin", >>>>> "geoserver") >>>>> -- >>>>> View this message in context: >>>>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26230809.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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Jon,
I just deployed a new 0.5.0-SNAPSHOT release; this should fix the empty response body issue. For RESTClient responses, response.data should simply be null. But all header/ response code information should be readily available. Please give it a try and let me know what you find. Thanks. -Tom On Fri, Nov 6, 2009 at 11:11 AM, Tom Nichols <tmnichols@...> wrote: > hmm, I'm not sure what to tell you; I just copied your example into a > Groovy console and ran it, and I didn't get the MissingMethodException > that you're seeing there, using 0.5.0-RC2. > > Try this variation: > def http = new groovyx.net.http.HTTPBuilder( > "http://localhost:8080/geoserver/rest/workspaces" ) > http.handler.SUCCESS = { return it } > > def response = http.post( headers:['Content-Type': 'text/xml'], > body: "<workspace><name>bob</name></workspace>" ) > > assert response.status == 201 > > > > 2009/11/6 Jon Britton <man_kills_everything@...>: >> >> Hi again, I'm just trying your example without using RESTClient but it >> doesn't work. My code is below, followed by the error I receive. What's >> could be causing this? >> >> Thanks, >> >> Jon >> >> CODE: >> >> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >> def http = new HTTPBuilder( "${geoserverUrl}/geoserver/rest/workspaces" ) >> http.handler.SUCCESS = { return it } >> >> def response = http.request( POST, XML ) { >> body = "<workspace><name>${wsName}</name></workspace>" >> } >> >> assert response.status == 201 >> } >> >> //Call method >> def code = createWorkspace("hello1", >> "http://admin:geoserver@localhost:8080/", "admin", "geoserver") >> >> OUTPUT: >> >> Caught: groovy.lang.MissingMethodException: No signature of method: >> groovyx.net.http.HTTPBuilder.request() is applicable >> for argument types: (groovyx.net.http.Method, groovyx.net.http.ContentType, >> uk.ac.glam.rest.GroovyTest$_createWorkspace >> _closure2) values: [POST, application/xml, >> uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] >> at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) >> at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70) >> >> >> >> Tom Nichols wrote: >>> >>> Nope, you're right; in that case, the response object should be >>> available, and the 'data' property (which is the parsed response body) >>> should just be null. Definitely a bug. >>> >>> However, after looking at the stack trace, I don't think you should be >>> getting an NPE but an IllegalArgumentException (this is still >>> erroneous in the case of RESTClient, but it's due to RESTClient's >>> underlying use of HTTPBuilder). What version of HTTPBuilder are you >>> using? >>> >>> In either case, the bug still stands; I'll start working on it >>> soon-ish. You can work around it for now by using the HTTPBuilder >>> class directly, which other than being slightly more verbose can do >>> the exact thing you're doing with RESTClient. >>> >>> import static groovyx.net.http.Method.POST >>> import static groovyx.net.http.ContentType.XML >>> >>> def http = new HTTPBuilder( >>> 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) >>> http.handler.SUCCESS = { return it } >>> >>> def response = http.request( POST, XML ) { >>> body = '<workspace><name>dwins</name></workspace>' >>> } >>> >>> assert response.status == 201 >>> >>> >>> Let me know if you have any trouble with the above example. >>> -Tom >>> >>> >>> On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton >>> <man_kills_everything@...> wrote: >>>> >>>> Sorry, forgot the full stack trace: >>>> >>>> 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType >>>> WARNING: Could not parse content-type header in response >>>> java.lang.NullPointerException >>>> at >>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) >>>> at >>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>> 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:40) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>> at >>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>> at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>> Source) >>>> at >>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>> at >>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>> at >>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>> at >>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>> 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest >>>> WARNING: Error parsing 'null' response >>>> java.lang.IllegalArgumentException: Could not parse content-type from >>>> response >>>> at >>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) >>>> at >>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>> 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:40) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>> at >>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>> at com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>> Source) >>>> at >>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>> at >>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>> at >>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) >>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>> at >>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>> at >>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>> Caught: groovyx.net.http.ResponseParseException: Created >>>> at >>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>> >>>> >>>> >>>> Tom Nichols wrote: >>>>> >>>>> Hmm interesting. I was under the assumption that a POST response >>>>> should include _some_ sort of response body, but maybe that's not >>>>> technically required by the HTTP spec. If you can send me the >>>>> exception stack trace I'm sure I can fix it, but I can't tell you what >>>>> you yourself can do until you give me some more details. >>>>> >>>>> Better yet, if you can file a JIRA here: >>>>> http://jira.codehaus.org/browse/GMOD >>>>> that would be super awesome (put the bug under the "HTTPBuilder" >>>>> module). And If you really want to earn karma points, give enough of >>>>> an example that I can reproduce the error condition myself :) I don't >>>>> konw if GeoServer has an open API, but if they do I can add it to the >>>>> unit tests. >>>>> >>>>> Thanks. >>>>> -Tom >>>>> >>>>> >>>>> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >>>>> <man_kills_everything@...> wrote: >>>>>> >>>>>> Hi, >>>>>> I'm using RESTClient from the HTTP Builder module to send a POST >>>>>> request >>>>>> to >>>>>> GeoServer. However, the response to my request doesn't contain a >>>>>> content-type or body so I get the following followed by a number of >>>>>> exceptions: >>>>>> >>>>>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType >>>>>> WARNING: Could not parse content-type header in response >>>>>> >>>>>> Followed by exceptions. How can I get around this? All I want from >>>>>> the >>>>>> response is the status code, I'm not interested in anything else. My >>>>>> code >>>>>> is shown below. >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Jon >>>>>> >>>>>> Code: >>>>>> >>>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >>>>>> // setup the restclient >>>>>> def geoserver = new RESTClient(geoserverUrl) >>>>>> // do the authing >>>>>> geoserver.auth.basic user, pass >>>>>> // post it >>>>>> def res = geoserver.post( path: "geoserver/rest/workspaces", >>>>>> requestContentType: XML, >>>>>> body: "<workspace><name>${wsName}</name></workspace>" >>>>>> ) >>>>>> } >>>>>> >>>>>> def code = createWorkspace("hello", "http://localhost:8080/", "admin", >>>>>> "geoserver") >>>>>> -- >>>>>> View this message in context: >>>>>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26230809.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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Not to be picky, nor I am saying the link I am providing is authoritative, but 201 SHOULD return a response which is the locations of the entity created. I realize that is being 'opinionated' and 'technical', as opposed to "Well here's the real world..." But that has always been my understanding. CREATED means there is a new resource and a URI for it. Those representations, even if only one, should be in the entity returned with the most specific in the Location header
http://restpatterns.org/HTTP_Status_Codes/201_-_Created --------------------------------------- Jeff Gortatowsky, Fullerton, CA | Twitter: JeffGortatowsky --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.MMmm, you're right; in most cases, the entity is returned, not just
the Location header. Unfortunately, REST is a somewhat loosely defined spec and I'm sure there are going to be plenty of examples of divergances from what "should" be done. The RESTClient should be able to handle a POST without a response entity, so I've updated the latest SNAPSHOT to handle it. -Tom On Sun, Nov 8, 2009 at 3:15 PM, Jeff Gortatowsky <indanapt@...> wrote: > Not to be picky, nor I am saying the link I am providing is authoritative, but 201 SHOULD return a response which is the locations of the entity created. I realize that is being 'opinionated' and 'technical', as opposed to "Well here's the real world..." But that has always been my understanding. CREATED means there is a new resource and a URI for it. Those representations, even if only one, should be in the entity returned with the most specific in the Location header > > http://restpatterns.org/HTTP_Status_Codes/201_-_Created > --------------------------------------- > Jeff Gortatowsky, Fullerton, CA | Twitter: JeffGortatowsky > > --------------------------------------------------------------------- > 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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Tom,
I've just tried again with 0.5.0-SNAPSHOT and my original code (the RESTClient one) and I'm still getting the same exceptions (NullPointerException, IllegalArgumentException and ResponseParseException). Again, here is the code I'm using: def createWorkspace(workspace, geoserverUrl, user, pass){ // setup the restclient def geoserver = new RESTClient(geoserverUrl) // do the authing geoserver.auth.basic user, pass // post it def res = geoserver.post( path: "/geoserver/rest/workspaces", requestContentType: XML, body: "<workspace><name>${workspace}</name></workspace>" ).getStatus() } I guess this is all GeoServers fault? Jon
|
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Jon,
Are you sure you got an updated snapshot? It was published on Nov 6th. You can get the timestamped version of the JAR here: http://snapshots.repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/0.5.0-SNAPSHOT/http-builder-0.5.0-20091107.042829-12.jar I'm surprised that you'd see _no_ change in the behavior. Although part of the problem is I'm trying to fix this "blind," so to speak, without being able to reproduce it myself. Can you point me to a public GeoServer instance, or your dev server which I can use to test things while I develop the fix? I'm certain this is not just GeoServer's fault. While uncommon, it's not a requirement for a response to contain a body. Therefore RESTClient should be able to handle the case and I'm more than willing to work with you to get it fixed in the HTTPBuilder code. Can you please also verify that the exception stack trace is identical, once you've verified that you're using an updated snapshot? Thanks. -Tom On Tue, Nov 10, 2009 at 9:29 AM, Jon Britton <man_kills_everything@...> wrote: > > Hi Tom, > > I've just tried again with 0.5.0-SNAPSHOT and my original code (the > RESTClient one) and I'm still getting the same exceptions > (NullPointerException, IllegalArgumentException and ResponseParseException). > > Again, here is the code I'm using: > > def createWorkspace(workspace, geoserverUrl, user, pass){ > // setup the restclient > def geoserver = new RESTClient(geoserverUrl) > // do the authing > geoserver.auth.basic user, pass > // post it > def res = geoserver.post( path: "/geoserver/rest/workspaces", > requestContentType: XML, > body: "<workspace><name>${workspace}</name></workspace>" > ).getStatus() > } > > I guess this is all GeoServers fault? > > Jon > > > Tom Nichols wrote: >> >> Hi Jon, >> >> I just deployed a new 0.5.0-SNAPSHOT release; this should fix the >> empty response body issue. For RESTClient responses, response.data >> should simply be null. But all header/ response code information >> should be readily available. Please give it a try and let me know >> what you find. >> >> Thanks. >> -Tom >> >> >> >> On Fri, Nov 6, 2009 at 11:11 AM, Tom Nichols <tmnichols@...> wrote: >>> hmm, I'm not sure what to tell you; I just copied your example into a >>> Groovy console and ran it, and I didn't get the MissingMethodException >>> that you're seeing there, using 0.5.0-RC2. >>> >>> Try this variation: >>> def http = new groovyx.net.http.HTTPBuilder( >>> "http://localhost:8080/geoserver/rest/workspaces" ) >>> http.handler.SUCCESS = { return it } >>> >>> def response = http.post( headers:['Content-Type': 'text/xml'], >>> body: "<workspace><name>bob</name></workspace>" ) >>> >>> assert response.status == 201 >>> >>> >>> >>> 2009/11/6 Jon Britton <man_kills_everything@...>: >>>> >>>> Hi again, I'm just trying your example without using RESTClient but it >>>> doesn't work. My code is below, followed by the error I receive. What's >>>> could be causing this? >>>> >>>> Thanks, >>>> >>>> Jon >>>> >>>> CODE: >>>> >>>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >>>> def http = new HTTPBuilder( >>>> "${geoserverUrl}/geoserver/rest/workspaces" ) >>>> http.handler.SUCCESS = { return it } >>>> >>>> def response = http.request( POST, XML ) { >>>> body = "<workspace><name>${wsName}</name></workspace>" >>>> } >>>> >>>> assert response.status == 201 >>>> } >>>> >>>> //Call method >>>> def code = createWorkspace("hello1", >>>> "http://admin:geoserver@localhost:8080/", "admin", "geoserver") >>>> >>>> OUTPUT: >>>> >>>> Caught: groovy.lang.MissingMethodException: No signature of method: >>>> groovyx.net.http.HTTPBuilder.request() is applicable >>>> for argument types: (groovyx.net.http.Method, >>>> groovyx.net.http.ContentType, >>>> uk.ac.glam.rest.GroovyTest$_createWorkspace >>>> _closure2) values: [POST, application/xml, >>>> uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] >>>> at >>>> uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) >>>> at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70) >>>> >>>> >>>> >>>> Tom Nichols wrote: >>>>> >>>>> Nope, you're right; in that case, the response object should be >>>>> available, and the 'data' property (which is the parsed response body) >>>>> should just be null. Definitely a bug. >>>>> >>>>> However, after looking at the stack trace, I don't think you should be >>>>> getting an NPE but an IllegalArgumentException (this is still >>>>> erroneous in the case of RESTClient, but it's due to RESTClient's >>>>> underlying use of HTTPBuilder). What version of HTTPBuilder are you >>>>> using? >>>>> >>>>> In either case, the bug still stands; I'll start working on it >>>>> soon-ish. You can work around it for now by using the HTTPBuilder >>>>> class directly, which other than being slightly more verbose can do >>>>> the exact thing you're doing with RESTClient. >>>>> >>>>> import static groovyx.net.http.Method.POST >>>>> import static groovyx.net.http.ContentType.XML >>>>> >>>>> def http = new HTTPBuilder( >>>>> 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) >>>>> http.handler.SUCCESS = { return it } >>>>> >>>>> def response = http.request( POST, XML ) { >>>>> body = '<workspace><name>dwins</name></workspace>' >>>>> } >>>>> >>>>> assert response.status == 201 >>>>> >>>>> >>>>> Let me know if you have any trouble with the above example. >>>>> -Tom >>>>> >>>>> >>>>> On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton >>>>> <man_kills_everything@...> wrote: >>>>>> >>>>>> Sorry, forgot the full stack trace: >>>>>> >>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType >>>>>> WARNING: Could not parse content-type header in response >>>>>> java.lang.NullPointerException >>>>>> at >>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) >>>>>> at >>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>>>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>> Source) >>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>> 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:40) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>>>> at >>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>> at >>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>>>> Source) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>> at >>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>> Source) >>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>> at >>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>>>> at >>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest >>>>>> WARNING: Error parsing 'null' response >>>>>> java.lang.IllegalArgumentException: Could not parse content-type from >>>>>> response >>>>>> at >>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) >>>>>> at >>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>>>> at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>> Source) >>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>> 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:40) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>>>> at >>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>> at >>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>>>> Source) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>>>> at >>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>> at >>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) >>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) >>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>> Source) >>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>> at >>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>>>> at >>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>>>> Caught: groovyx.net.http.ResponseParseException: Created >>>>>> at >>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>> >>>>>> >>>>>> >>>>>> Tom Nichols wrote: >>>>>>> >>>>>>> Hmm interesting. I was under the assumption that a POST response >>>>>>> should include _some_ sort of response body, but maybe that's not >>>>>>> technically required by the HTTP spec. If you can send me the >>>>>>> exception stack trace I'm sure I can fix it, but I can't tell you >>>>>>> what >>>>>>> you yourself can do until you give me some more details. >>>>>>> >>>>>>> Better yet, if you can file a JIRA here: >>>>>>> http://jira.codehaus.org/browse/GMOD >>>>>>> that would be super awesome (put the bug under the "HTTPBuilder" >>>>>>> module). And If you really want to earn karma points, give enough of >>>>>>> an example that I can reproduce the error condition myself :) I >>>>>>> don't >>>>>>> konw if GeoServer has an open API, but if they do I can add it to the >>>>>>> unit tests. >>>>>>> >>>>>>> Thanks. >>>>>>> -Tom >>>>>>> >>>>>>> >>>>>>> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >>>>>>> <man_kills_everything@...> wrote: >>>>>>>> >>>>>>>> Hi, >>>>>>>> I'm using RESTClient from the HTTP Builder module to send a POST >>>>>>>> request >>>>>>>> to >>>>>>>> GeoServer. However, the response to my request doesn't contain a >>>>>>>> content-type or body so I get the following followed by a number of >>>>>>>> exceptions: >>>>>>>> >>>>>>>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry getContentType >>>>>>>> WARNING: Could not parse content-type header in response >>>>>>>> >>>>>>>> Followed by exceptions. How can I get around this? All I want from >>>>>>>> the >>>>>>>> response is the status code, I'm not interested in anything else. >>>>>>>> My >>>>>>>> code >>>>>>>> is shown below. >>>>>>>> >>>>>>>> Thanks, >>>>>>>> >>>>>>>> Jon >>>>>>>> >>>>>>>> Code: >>>>>>>> >>>>>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def >>>>>>>> pass){ >>>>>>>> // setup the restclient >>>>>>>> def geoserver = new RESTClient(geoserverUrl) >>>>>>>> // do the authing >>>>>>>> geoserver.auth.basic user, pass >>>>>>>> // post it >>>>>>>> def res = geoserver.post( path: "geoserver/rest/workspaces", >>>>>>>> requestContentType: XML, >>>>>>>> body: "<workspace><name>${wsName}</name></workspace>" >>>>>>>> ) >>>>>>>> } >>>>>>>> >>>>>>>> def code = createWorkspace("hello", "http://localhost:8080/", >>>>>>>> "admin", >>>>>>>> "geoserver") >>>>>>>> -- >>>>>>>> View this message in context: >>>>>>>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26230809.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26284361.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 |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi,
I used Maven to update my dependencies and I'm pretty certain that I'm using the right JAR. I don't have access to a public GeoServer instance unfortunately, although it's pretty easy to install GeoServer on a local machine (you also need the GeoServer REST plugin which you need to put in webapps/geoserver/web-inf/lib/) especially if you happen to have Tomcat running (you can get a WAR). One strange thing is that Eclipse seems to show http-builder-0.5.0-SNAPSHOT.jar, even though Maven downloaded the timestamped version. I'm not sure if it actually replaced it, but it doesn't matter because I get the same result regardless of the JAR I use. Here is the stack trace again so you can see the line numbers etc: 10-Nov-2009 17:18:42 groovyx.net.http.ParserRegistry getContentType WARNING: Could not parse content-type header in response java.lang.NullPointerException at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:151) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) at groovyx.net.http.RESTClient.post(RESTClient.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi te.java:229) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) at groovy.lang.GroovyShell.run(GroovyShell.java:219) at groovy.lang.GroovyShell.run(GroovyShell.java:149) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) at groovy.ui.GroovyMain.run(GroovyMain.java:309) at groovy.ui.GroovyMain.process(GroovyMain.java:295) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) at groovy.ui.GroovyMain.main(GroovyMain.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) 10-Nov-2009 17:18:42 groovyx.net.http.HTTPBuilder doRequest WARNING: Error parsing 'null' response java.lang.IllegalArgumentException: Could not parse content-type from response at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:155) at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) at groovyx.net.http.RESTClient.post(RESTClient.java:140) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi te.java:229) at org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) at org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) at groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) at groovy.lang.GroovyShell.run(GroovyShell.java:219) at groovy.lang.GroovyShell.run(GroovyShell.java:149) at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) at groovy.ui.GroovyMain.run(GroovyMain.java:309) at groovy.ui.GroovyMain.process(GroovyMain.java:295) at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) at groovy.ui.GroovyMain.main(GroovyMain.java:93) at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) at java.lang.reflect.Method.invoke(Unknown Source) at org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) Caught: groovyx.net.http.ResponseParseException: Internal Server Error at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69)
|
|
|
|
RE: Handling RESTClient post() responses with no content-type or body.
> Date: Tue, 10 Nov 2009 09:20:44 -0800 > From: man_kills_everything@... > To: user@... > Subject: Re: [groovy-user] Handling RESTClient post() responses with no content-type or body. > > > Hi, > > I used Maven to update my dependencies and I'm pretty certain that I'm using > the right JAR. I don't have access to a public GeoServer instance > unfortunately, although it's pretty easy to install GeoServer on a local > machine (you also need the GeoServer REST plugin which you need to put in > webapps/geoserver/web-inf/lib/) especially if you happen to have Tomcat > running (you can get a WAR). > > One strange thing is that Eclipse seems to show > http-builder-0.5.0-SNAPSHOT.jar, even though Maven downloaded the > timestamped version. I'm not sure if it actually replaced it, but it > doesn't matter because I get the same result regardless of the JAR I use. > > Here is the stack trace again so you can see the line numbers etc: > > 10-Nov-2009 17:18:42 groovyx.net.http.ParserRegistry getContentType > WARNING: Could not parse content-type header in response > java.lang.NullPointerException > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:151) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi > te.java:229) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > 10-Nov-2009 17:18:42 groovyx.net.http.HTTPBuilder doRequest > WARNING: Error parsing 'null' response > java.lang.IllegalArgumentException: Could not parse content-type from > response > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:155) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi > te.java:229) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > Caught: groovyx.net.http.ResponseParseException: Internal Server Error > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > > > > Tom Nichols wrote: > > > > Hi Jon, > > > > Are you sure you got an updated snapshot? It was published on Nov > > 6th. You can get the timestamped version of the JAR here: > > http://snapshots.repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/0.5.0-SNAPSHOT/http-builder-0.5.0-20091107.042829-12.jar > > > > I'm surprised that you'd see _no_ change in the behavior. Although > > part of the problem is I'm trying to fix this "blind," so to speak, > > without being able to reproduce it myself. Can you point me to a > > public GeoServer instance, or your dev server which I can use to test > > things while I develop the fix? I'm certain this is not just > > GeoServer's fault. While uncommon, it's not a requirement for a > > response to contain a body. Therefore RESTClient should be able to > > handle the case and I'm more than willing to work with you to get it > > fixed in the HTTPBuilder code. > > > > Can you please also verify that the exception stack trace is > > identical, once you've verified that you're using an updated snapshot? > > Thanks. > > > > -Tom > > > > On Tue, Nov 10, 2009 at 9:29 AM, Jon Britton > > <man_kills_everything@...> wrote: > >> > >> Hi Tom, > >> > >> I've just tried again with 0.5.0-SNAPSHOT and my original code (the > >> RESTClient one) and I'm still getting the same exceptions > >> (NullPointerException, IllegalArgumentException and > >> ResponseParseException). > >> > >> Again, here is the code I'm using: > >> > >> def createWorkspace(workspace, geoserverUrl, user, pass){ > >> // setup the restclient > >> def geoserver = new RESTClient(geoserverUrl) > >> // do the authing > >> geoserver.auth.basic user, pass > >> // post it > >> def res = geoserver.post( path: "/geoserver/rest/workspaces", > >> requestContentType: XML, > >> body: "<workspace><name>${workspace}</name></workspace>" > >> ).getStatus() > >> } > >> > >> I guess this is all GeoServers fault? > >> > >> Jon > >> > >> > >> Tom Nichols wrote: > >>> > >>> Hi Jon, > >>> > >>> I just deployed a new 0.5.0-SNAPSHOT release; this should fix the > >>> empty response body issue. For RESTClient responses, response.data > >>> should simply be null. But all header/ response code information > >>> should be readily available. Please give it a try and let me know > >>> what you find. > >>> > >>> Thanks. > >>> -Tom > >>> > >>> > >>> > >>> On Fri, Nov 6, 2009 at 11:11 AM, Tom Nichols <tmnichols@...> > >>> wrote: > >>>> hmm, I'm not sure what to tell you; I just copied your example into a > >>>> Groovy console and ran it, and I didn't get the MissingMethodException > >>>> that you're seeing there, using 0.5.0-RC2. > >>>> > >>>> Try this variation: > >>>> def http = new groovyx.net.http.HTTPBuilder( > >>>> "http://localhost:8080/geoserver/rest/workspaces" ) > >>>> http.handler.SUCCESS = { return it } > >>>> > >>>> def response = http.post( headers:['Content-Type': 'text/xml'], > >>>> body: "<workspace><name>bob</name></workspace>" ) > >>>> > >>>> assert response.status == 201 > >>>> > >>>> > >>>> > >>>> 2009/11/6 Jon Britton <man_kills_everything@...>: > >>>>> > >>>>> Hi again, I'm just trying your example without using RESTClient but it > >>>>> doesn't work. My code is below, followed by the error I receive. > >>>>> What's > >>>>> could be causing this? > >>>>> > >>>>> Thanks, > >>>>> > >>>>> Jon > >>>>> > >>>>> CODE: > >>>>> > >>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ > >>>>> def http = new HTTPBuilder( > >>>>> "${geoserverUrl}/geoserver/rest/workspaces" ) > >>>>> http.handler.SUCCESS = { return it } > >>>>> > >>>>> def response = http.request( POST, XML ) { > >>>>> body = "<workspace><name>${wsName}</name></workspace>" > >>>>> } > >>>>> > >>>>> assert response.status == 201 > >>>>> } > >>>>> > >>>>> //Call method > >>>>> def code = createWorkspace("hello1", > >>>>> "http://admin:geoserver@localhost:8080/", "admin", "geoserver") > >>>>> > >>>>> OUTPUT: > >>>>> > >>>>> Caught: groovy.lang.MissingMethodException: No signature of method: > >>>>> groovyx.net.http.HTTPBuilder.request() is applicable > >>>>> for argument types: (groovyx.net.http.Method, > >>>>> groovyx.net.http.ContentType, > >>>>> uk.ac.glam.rest.GroovyTest$_createWorkspace > >>>>> _closure2) values: [POST, application/xml, > >>>>> uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] > >>>>> at > >>>>> uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) > >>>>> at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70) > >>>>> > >>>>> > >>>>> > >>>>> Tom Nichols wrote: > >>>>>> > >>>>>> Nope, you're right; in that case, the response object should be > >>>>>> available, and the 'data' property (which is the parsed response > >>>>>> body) > >>>>>> should just be null. Definitely a bug. > >>>>>> > >>>>>> However, after looking at the stack trace, I don't think you should > >>>>>> be > >>>>>> getting an NPE but an IllegalArgumentException (this is still > >>>>>> erroneous in the case of RESTClient, but it's due to RESTClient's > >>>>>> underlying use of HTTPBuilder). What version of HTTPBuilder are you > >>>>>> using? > >>>>>> > >>>>>> In either case, the bug still stands; I'll start working on it > >>>>>> soon-ish. You can work around it for now by using the HTTPBuilder > >>>>>> class directly, which other than being slightly more verbose can do > >>>>>> the exact thing you're doing with RESTClient. > >>>>>> > >>>>>> import static groovyx.net.http.Method.POST > >>>>>> import static groovyx.net.http.ContentType.XML > >>>>>> > >>>>>> def http = new HTTPBuilder( > >>>>>> 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) > >>>>>> http.handler.SUCCESS = { return it } > >>>>>> > >>>>>> def response = http.request( POST, XML ) { > >>>>>> body = '<workspace><name>dwins</name></workspace>' > >>>>>> } > >>>>>> > >>>>>> assert response.status == 201 > >>>>>> > >>>>>> > >>>>>> Let me know if you have any trouble with the above example. > >>>>>> -Tom > >>>>>> > >>>>>> > >>>>>> On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton > >>>>>> <man_kills_everything@...> wrote: > >>>>>>> > >>>>>>> Sorry, forgot the full stack trace: > >>>>>>> > >>>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType > >>>>>>> WARNING: Could not parse content-type header in response > >>>>>>> java.lang.NullPointerException > >>>>>>> at > >>>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) > >>>>>>> at > >>>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > >>>>>>> at > >>>>>>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > >>>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > >>>>>>> Method) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) > >>>>>>> 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:40) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > >>>>>>> at > >>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > >>>>>>> at > >>>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown > >>>>>>> Source) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > >>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > >>>>>>> at > >>>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > >>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) > >>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) > >>>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > >>>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) > >>>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) > >>>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > >>>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > >>>>>>> Method) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) > >>>>>>> at > >>>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > >>>>>>> at > >>>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > >>>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest > >>>>>>> WARNING: Error parsing 'null' response > >>>>>>> java.lang.IllegalArgumentException: Could not parse content-type > >>>>>>> from > >>>>>>> response > >>>>>>> at > >>>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) > >>>>>>> at > >>>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) > >>>>>>> at > >>>>>>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) > >>>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > >>>>>>> Method) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) > >>>>>>> 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:40) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > >>>>>>> at > >>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > >>>>>>> at > >>>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown > >>>>>>> Source) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > >>>>>>> at > >>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > >>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > >>>>>>> at > >>>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > >>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) > >>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) > >>>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > >>>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) > >>>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) > >>>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > >>>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native > >>>>>>> Method) > >>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown > >>>>>>> Source) > >>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) > >>>>>>> at > >>>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > >>>>>>> at > >>>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > >>>>>>> Caught: groovyx.net.http.ResponseParseException: Created > >>>>>>> at > >>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) > >>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) > >>>>>>> > >>>>>>> > >>>>>>> > >>>>>>> Tom Nichols wrote: > >>>>>>>> > >>>>>>>> Hmm interesting. I was under the assumption that a POST response > >>>>>>>> should include _some_ sort of response body, but maybe that's not > >>>>>>>> technically required by the HTTP spec. If you can send me the > >>>>>>>> exception stack trace I'm sure I can fix it, but I can't tell you > >>>>>>>> what > >>>>>>>> you yourself can do until you give me some more details. > >>>>>>>> > >>>>>>>> Better yet, if you can file a JIRA here: > >>>>>>>> http://jira.codehaus.org/browse/GMOD > >>>>>>>> that would be super awesome (put the bug under the "HTTPBuilder" > >>>>>>>> module). And If you really want to earn karma points, give enough > >>>>>>>> of > >>>>>>>> an example that I can reproduce the error condition myself :) I > >>>>>>>> don't > >>>>>>>> konw if GeoServer has an open API, but if they do I can add it to > >>>>>>>> the > >>>>>>>> unit tests. > >>>>>>>> > >>>>>>>> Thanks. > >>>>>>>> -Tom > >>>>>>>> > >>>>>>>> > >>>>>>>> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton > >>>>>>>> <man_kills_everything@...> wrote: > >>>>>>>>> > >>>>>>>>> Hi, > >>>>>>>>> I'm using RESTClient from the HTTP Builder module to send a POST > >>>>>>>>> request > >>>>>>>>> to > >>>>>>>>> GeoServer. However, the response to my request doesn't contain a > >>>>>>>>> content-type or body so I get the following followed by a number > >>>>>>>>> of > >>>>>>>>> exceptions: > >>>>>>>>> > >>>>>>>>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry > >>>>>>>>> getContentType > >>>>>>>>> WARNING: Could not parse content-type header in response > >>>>>>>>> > >>>>>>>>> Followed by exceptions. How can I get around this? All I want > >>>>>>>>> from > >>>>>>>>> the > >>>>>>>>> response is the status code, I'm not interested in anything else. > >>>>>>>>> My > >>>>>>>>> code > >>>>>>>>> is shown below. > >>>>>>>>> > >>>>>>>>> Thanks, > >>>>>>>>> > >>>>>>>>> Jon > >>>>>>>>> > >>>>>>>>> Code: > >>>>>>>>> > >>>>>>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def > >>>>>>>>> pass){ > >>>>>>>>> // setup the restclient > >>>>>>>>> def geoserver = new RESTClient(geoserverUrl) > >>>>>>>>> // do the authing > >>>>>>>>> geoserver.auth.basic user, pass > >>>>>>>>> // post it > >>>>>>>>> def res = geoserver.post( path: > >>>>>>>>> "geoserver/rest/workspaces", > >>>>>>>>> requestContentType: XML, > >>>>>>>>> body: > >>>>>>>>> "<workspace><name>${wsName}</name></workspace>" > >>>>>>>>> ) > >>>>>>>>> } > >>>>>>>>> > >>>>>>>>> def code = createWorkspace("hello", "http://localhost:8080/", > >>>>>>>>> "admin", > >>>>>>>>> "geoserver") > >>>>>>>>> -- > >>>>>>>>> View this message in context: > >>>>>>>>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26230809.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26284361.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26287336.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 > > |
|
|
|
Re: Handling RESTClient post() responses with no content-type or body.Hi Jon,
I fired up a GeoServer instance to track down how the HttpClient API behaves when there's no response body; it's slightly different than advertised in the JavaDocs, which is what caused me grief. Anyway, I fixed HTTPBuilder/ RESTClient's behavior for your situation, so the latest 0.5.0-SNAPSHOT (just deployed) should handle this gracefully now. When you update, use the -U maven flag to force it to check for a new snapshot. Maven renames the latest timestamped snapshot JAR to artifactName-version-SNAPSHOT.jar when it's downloaded to the local repository I think; that's why you might see Maven download a timestamped JAR but then it shows up in the classpath as -SNAPSHOT.jar. Anyway, let me know if you have any troubles with it now. -Tom 2009/11/10 Jon Britton <man_kills_everything@...>: > > Hi, > > I used Maven to update my dependencies and I'm pretty certain that I'm using > the right JAR. I don't have access to a public GeoServer instance > unfortunately, although it's pretty easy to install GeoServer on a local > machine (you also need the GeoServer REST plugin which you need to put in > webapps/geoserver/web-inf/lib/) especially if you happen to have Tomcat > running (you can get a WAR). > > One strange thing is that Eclipse seems to show > http-builder-0.5.0-SNAPSHOT.jar, even though Maven downloaded the > timestamped version. I'm not sure if it actually replaced it, but it > doesn't matter because I get the same result regardless of the JAR I use. > > Here is the stack trace again so you can see the line numbers etc: > > 10-Nov-2009 17:18:42 groovyx.net.http.ParserRegistry getContentType > WARNING: Could not parse content-type header in response > java.lang.NullPointerException > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:151) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi > te.java:229) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > 10-Nov-2009 17:18:42 groovyx.net.http.HTTPBuilder doRequest > WARNING: Error parsing 'null' response > java.lang.IllegalArgumentException: Could not parse content-type from > response > at groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:155) > at groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:511) > at groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:462) > at groovyx.net.http.RESTClient.post(RESTClient.java:140) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite$PojoCachedMethodSiteNoUnwrapNoCoerce.invoke(PojoMetaMethodSi > te.java:229) > at > org.codehaus.groovy.runtime.callsite.PojoMetaMethodSite.call(PojoMetaMethodSite.java:52) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:40) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest$createWorkspace.callCurrent(Unknown Source) > at > org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) > at > org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > at > groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) > at groovy.lang.GroovyShell.run(GroovyShell.java:219) > at groovy.lang.GroovyShell.run(GroovyShell.java:149) > at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) > at groovy.ui.GroovyMain.run(GroovyMain.java:309) > at groovy.ui.GroovyMain.process(GroovyMain.java:295) > at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) > at groovy.ui.GroovyMain.main(GroovyMain.java:93) > at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) > at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source) > at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source) > at java.lang.reflect.Method.invoke(Unknown Source) > at > org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) > at org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) > Caught: groovyx.net.http.ResponseParseException: Internal Server Error > at uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:46) > at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:69) > > > > Tom Nichols wrote: >> >> Hi Jon, >> >> Are you sure you got an updated snapshot? It was published on Nov >> 6th. You can get the timestamped version of the JAR here: >> http://snapshots.repository.codehaus.org/org/codehaus/groovy/modules/http-builder/http-builder/0.5.0-SNAPSHOT/http-builder-0.5.0-20091107.042829-12.jar >> >> I'm surprised that you'd see _no_ change in the behavior. Although >> part of the problem is I'm trying to fix this "blind," so to speak, >> without being able to reproduce it myself. Can you point me to a >> public GeoServer instance, or your dev server which I can use to test >> things while I develop the fix? I'm certain this is not just >> GeoServer's fault. While uncommon, it's not a requirement for a >> response to contain a body. Therefore RESTClient should be able to >> handle the case and I'm more than willing to work with you to get it >> fixed in the HTTPBuilder code. >> >> Can you please also verify that the exception stack trace is >> identical, once you've verified that you're using an updated snapshot? >> Thanks. >> >> -Tom >> >> On Tue, Nov 10, 2009 at 9:29 AM, Jon Britton >> <man_kills_everything@...> wrote: >>> >>> Hi Tom, >>> >>> I've just tried again with 0.5.0-SNAPSHOT and my original code (the >>> RESTClient one) and I'm still getting the same exceptions >>> (NullPointerException, IllegalArgumentException and >>> ResponseParseException). >>> >>> Again, here is the code I'm using: >>> >>> def createWorkspace(workspace, geoserverUrl, user, pass){ >>> // setup the restclient >>> def geoserver = new RESTClient(geoserverUrl) >>> // do the authing >>> geoserver.auth.basic user, pass >>> // post it >>> def res = geoserver.post( path: "/geoserver/rest/workspaces", >>> requestContentType: XML, >>> body: "<workspace><name>${workspace}</name></workspace>" >>> ).getStatus() >>> } >>> >>> I guess this is all GeoServers fault? >>> >>> Jon >>> >>> >>> Tom Nichols wrote: >>>> >>>> Hi Jon, >>>> >>>> I just deployed a new 0.5.0-SNAPSHOT release; this should fix the >>>> empty response body issue. For RESTClient responses, response.data >>>> should simply be null. But all header/ response code information >>>> should be readily available. Please give it a try and let me know >>>> what you find. >>>> >>>> Thanks. >>>> -Tom >>>> >>>> >>>> >>>> On Fri, Nov 6, 2009 at 11:11 AM, Tom Nichols <tmnichols@...> >>>> wrote: >>>>> hmm, I'm not sure what to tell you; I just copied your example into a >>>>> Groovy console and ran it, and I didn't get the MissingMethodException >>>>> that you're seeing there, using 0.5.0-RC2. >>>>> >>>>> Try this variation: >>>>> def http = new groovyx.net.http.HTTPBuilder( >>>>> "http://localhost:8080/geoserver/rest/workspaces" ) >>>>> http.handler.SUCCESS = { return it } >>>>> >>>>> def response = http.post( headers:['Content-Type': 'text/xml'], >>>>> body: "<workspace><name>bob</name></workspace>" ) >>>>> >>>>> assert response.status == 201 >>>>> >>>>> >>>>> >>>>> 2009/11/6 Jon Britton <man_kills_everything@...>: >>>>>> >>>>>> Hi again, I'm just trying your example without using RESTClient but it >>>>>> doesn't work. My code is below, followed by the error I receive. >>>>>> What's >>>>>> could be causing this? >>>>>> >>>>>> Thanks, >>>>>> >>>>>> Jon >>>>>> >>>>>> CODE: >>>>>> >>>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def pass){ >>>>>> def http = new HTTPBuilder( >>>>>> "${geoserverUrl}/geoserver/rest/workspaces" ) >>>>>> http.handler.SUCCESS = { return it } >>>>>> >>>>>> def response = http.request( POST, XML ) { >>>>>> body = "<workspace><name>${wsName}</name></workspace>" >>>>>> } >>>>>> >>>>>> assert response.status == 201 >>>>>> } >>>>>> >>>>>> //Call method >>>>>> def code = createWorkspace("hello1", >>>>>> "http://admin:geoserver@localhost:8080/", "admin", "geoserver") >>>>>> >>>>>> OUTPUT: >>>>>> >>>>>> Caught: groovy.lang.MissingMethodException: No signature of method: >>>>>> groovyx.net.http.HTTPBuilder.request() is applicable >>>>>> for argument types: (groovyx.net.http.Method, >>>>>> groovyx.net.http.ContentType, >>>>>> uk.ac.glam.rest.GroovyTest$_createWorkspace >>>>>> _closure2) values: [POST, application/xml, >>>>>> uk.ac.glam.rest.GroovyTest$_createWorkspace_closure2@2fb002] >>>>>> at >>>>>> uk.ac.glam.rest.GroovyTest.createWorkspace(GroovyTest.groovy:54) >>>>>> at uk.ac.glam.rest.GroovyTest.run(GroovyTest.groovy:70) >>>>>> >>>>>> >>>>>> >>>>>> Tom Nichols wrote: >>>>>>> >>>>>>> Nope, you're right; in that case, the response object should be >>>>>>> available, and the 'data' property (which is the parsed response >>>>>>> body) >>>>>>> should just be null. Definitely a bug. >>>>>>> >>>>>>> However, after looking at the stack trace, I don't think you should >>>>>>> be >>>>>>> getting an NPE but an IllegalArgumentException (this is still >>>>>>> erroneous in the case of RESTClient, but it's due to RESTClient's >>>>>>> underlying use of HTTPBuilder). What version of HTTPBuilder are you >>>>>>> using? >>>>>>> >>>>>>> In either case, the bug still stands; I'll start working on it >>>>>>> soon-ish. You can work around it for now by using the HTTPBuilder >>>>>>> class directly, which other than being slightly more verbose can do >>>>>>> the exact thing you're doing with RESTClient. >>>>>>> >>>>>>> import static groovyx.net.http.Method.POST >>>>>>> import static groovyx.net.http.ContentType.XML >>>>>>> >>>>>>> def http = new HTTPBuilder( >>>>>>> 'http://admin:geoserver@localhost:8080/geoserver/rest/workspaces' ) >>>>>>> http.handler.SUCCESS = { return it } >>>>>>> >>>>>>> def response = http.request( POST, XML ) { >>>>>>> body = '<workspace><name>dwins</name></workspace>' >>>>>>> } >>>>>>> >>>>>>> assert response.status == 201 >>>>>>> >>>>>>> >>>>>>> Let me know if you have any trouble with the above example. >>>>>>> -Tom >>>>>>> >>>>>>> >>>>>>> On Thu, Nov 5, 2009 at 9:45 AM, Jon Britton >>>>>>> <man_kills_everything@...> wrote: >>>>>>>> >>>>>>>> Sorry, forgot the full stack trace: >>>>>>>> >>>>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.ParserRegistry getContentType >>>>>>>> WARNING: Could not parse content-type header in response >>>>>>>> java.lang.NullPointerException >>>>>>>> at >>>>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:153) >>>>>>>> at >>>>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>>>>>> at >>>>>>>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >>>>>>>> Method) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>>>> 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:40) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>>>>>> at >>>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>>>> at >>>>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>>>>>> Source) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>>>> at >>>>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >>>>>>>> Method) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>>>> at >>>>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>>>>>> at >>>>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>>>>>> 05-Nov-2009 14:45:22 groovyx.net.http.HTTPBuilder doRequest >>>>>>>> WARNING: Error parsing 'null' response >>>>>>>> java.lang.IllegalArgumentException: Could not parse content-type >>>>>>>> from >>>>>>>> response >>>>>>>> at >>>>>>>> groovyx.net.http.ParserRegistry.getContentType(ParserRegistry.java:157) >>>>>>>> at >>>>>>>> groovyx.net.http.HTTPBuilder.parseResponse(HTTPBuilder.java:510) >>>>>>>> at >>>>>>>> groovyx.net.http.HTTPBuilder.doRequest(HTTPBuilder.java:460) >>>>>>>> at groovyx.net.http.RESTClient.post(RESTClient.java:140) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >>>>>>>> Method) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>>>> 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:40) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:117) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125) >>>>>>>> at >>>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>>>> at >>>>>>>> com.example.jon.GroovyTest$createWorkspace.callCurrent(Unknown >>>>>>>> Source) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCallCurrent(CallSiteArray.java:44) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:143) >>>>>>>> at >>>>>>>> org.codehaus.groovy.runtime.callsite.AbstractCallSite.callCurrent(AbstractCallSite.java:163) >>>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>>>> at >>>>>>>> groovy.lang.GroovyShell.runScriptOrMainOrTestOrRunnable(GroovyShell.java:256) >>>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:219) >>>>>>>> at groovy.lang.GroovyShell.run(GroovyShell.java:149) >>>>>>>> at groovy.ui.GroovyMain.processOnce(GroovyMain.java:494) >>>>>>>> at groovy.ui.GroovyMain.run(GroovyMain.java:309) >>>>>>>> at groovy.ui.GroovyMain.process(GroovyMain.java:295) >>>>>>>> at groovy.ui.GroovyMain.processArgs(GroovyMain.java:112) >>>>>>>> at groovy.ui.GroovyMain.main(GroovyMain.java:93) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke0(Native >>>>>>>> Method) >>>>>>>> at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown >>>>>>>> Source) >>>>>>>> at java.lang.reflect.Method.invoke(Unknown Source) >>>>>>>> at >>>>>>>> org.codehaus.groovy.tools.GroovyStarter.rootLoader(GroovyStarter.java:108) >>>>>>>> at >>>>>>>> org.codehaus.groovy.tools.GroovyStarter.main(GroovyStarter.java:130) >>>>>>>> Caught: groovyx.net.http.ResponseParseException: Created >>>>>>>> at >>>>>>>> com.example.jon.GroovyTest.createWorkspace(GroovyTest.groovy:45) >>>>>>>> at com.example.jon.GroovyTest.run(GroovyTest.groovy:60) >>>>>>>> >>>>>>>> >>>>>>>> >>>>>>>> Tom Nichols wrote: >>>>>>>>> >>>>>>>>> Hmm interesting. I was under the assumption that a POST response >>>>>>>>> should include _some_ sort of response body, but maybe that's not >>>>>>>>> technically required by the HTTP spec. If you can send me the >>>>>>>>> exception stack trace I'm sure I can fix it, but I can't tell you >>>>>>>>> what >>>>>>>>> you yourself can do until you give me some more details. >>>>>>>>> >>>>>>>>> Better yet, if you can file a JIRA here: >>>>>>>>> http://jira.codehaus.org/browse/GMOD >>>>>>>>> that would be super awesome (put the bug under the "HTTPBuilder" >>>>>>>>> module). And If you really want to earn karma points, give enough >>>>>>>>> of >>>>>>>>> an example that I can reproduce the error condition myself :) I >>>>>>>>> don't >>>>>>>>> konw if GeoServer has an open API, but if they do I can add it to >>>>>>>>> the >>>>>>>>> unit tests. >>>>>>>>> >>>>>>>>> Thanks. >>>>>>>>> -Tom >>>>>>>>> >>>>>>>>> >>>>>>>>> On Thu, Nov 5, 2009 at 9:22 AM, Jon Britton >>>>>>>>> <man_kills_everything@...> wrote: >>>>>>>>>> >>>>>>>>>> Hi, >>>>>>>>>> I'm using RESTClient from the HTTP Builder module to send a POST >>>>>>>>>> request >>>>>>>>>> to >>>>>>>>>> GeoServer. However, the response to my request doesn't contain a >>>>>>>>>> content-type or body so I get the following followed by a number >>>>>>>>>> of >>>>>>>>>> exceptions: >>>>>>>>>> >>>>>>>>>> 05-Nov-2009 14:12:42 groovyx.net.http.ParserRegistry >>>>>>>>>> getContentType >>>>>>>>>> WARNING: Could not parse content-type header in response >>>>>>>>>> >>>>>>>>>> Followed by exceptions. How can I get around this? All I want >>>>>>>>>> from >>>>>>>>>> the >>>>>>>>>> response is the status code, I'm not interested in anything else. >>>>>>>>>> My >>>>>>>>>> code >>>>>>>>>> is shown below. >>>>>>>>>> >>>>>>>>>> Thanks, >>>>>>>>>> >>>>>>>>>> Jon >>>>>>>>>> >>>>>>>>>> Code: >>>>>>>>>> >>>>>>>>>> def createWorkspace(def wsName, def geoserverUrl, def user, def >>>>>>>>>> pass){ >>>>>>>>>> // setup the restclient >>>>>>>>>> def geoserver = new RESTClient(geoserverUrl) >>>>>>>>>> // do the authing >>>>>>>>>> geoserver.auth.basic user, pass >>>>>>>>>> // post it >>>>>>>>>> def res = geoserver.post( path: >>>>>>>>>> "geoserver/rest/workspaces", >>>>>>>>>> requestContentType: XML, >>>>>>>>>> body: >>>>>>>>>> "<workspace><name>${wsName}</name></workspace>" >>>>>>>>>> ) >>>>>>>>>> } >>>>>>>>>> >>>>>>>>>> def code = createWorkspace("hello", "http://localhost:8080/", >>>>>>>>>> "admin", >>>>>>>>>> "geoserver") >>>>>>>>>> -- >>>>>>>>>> View this message in context: >>>>>>>>>> http://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215319.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26215728.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26230809.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26284361.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://old.nabble.com/Handling-RESTClient-post%28%29-responses-with-no-content-type-or-body.-tp26215319p26287336.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 |
| Free embeddable forum powered by Nabble | Forum Help |