Re: java.lang.AbstractMethodError: org.restlet.util.Engine.fireContextChanged
Doh!! Ok, so I've done that, now I'm getting an NPE here, this code worked fine in 1.0.x: client.getContext().getParameters().add(converter, com.noelios.restlet.http.HttpClientConverter); client.getContext().getParameters().add(connectionManagerTimeout, 100); Any ideas? Ian. On Mon, Dec 1, 2008 at 1:08 PM, Rhett Sutphin [EMAIL PROTECTED] wrote: You need to upgrade the com.noelios.restlet dependencies to 1.1.1, too. -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Ph: +1 512 422 3588 Fax: +1 512 276 6674 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=544101
Code hanging doing a HTTP get
My code is hanging here (while trying to do a HTTP get) - any ideas? Thread [main] (Suspended) Object.wait(long) line: not available [native method] MultiThreadedHttpConnectionManager.doGetConnection(HostConfiguration, long) line: 518 MultiThreadedHttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long) line: 416 HttpMethodDirector.executeMethod(HttpMethod) line: 153 HttpClient.executeMethod(HostConfiguration, HttpMethod, HttpState) line: 397 HttpClient.executeMethod(HttpMethod) line: 323 HttpMethodCall.sendRequest(Request) line: 313 HttpClientConverter.commit(HttpClientCall, Request, Response) line: 418 HttpClientHelper(HttpClientHelper).handle(Request, Response) line: 108 Client.handle(Request, Response) line: 157 Client(Uniform).handle(Request) line: 108 ApiAuthTest.get(String, String, String) line: 87 ApiAuthTest.testAuth() line: 74 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 MethodHelper.invokeMethod(Method, Object, Object[]) line: 580 Invoker.invokeMethod(Object[], int, ITestNGMethod, Object[], XmlSuite, MapString,String, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods) line: 478 Invoker.invokeTestMethod(Object[], ITestNGMethod, Object[], XmlSuite, MapString,String, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods) line: 617 Invoker.invokeTestMethods(ITestNGMethod, ITestNGMethod[], int, XmlSuite, MapString,String, ConfigurationGroupMethods, Object[], ITestContext) line: 885 TestMethodWorker.invokeTestMethods(ITestNGMethod, Object[], ITestContext) line: 126 TestMethodWorker.run() line: 110 TestRunner.runWorkers(ListIMethodWorker, String) line: 712 TestRunner.privateRun(XmlTest) line: 582 TestRunner.run() line: 477 SuiteRunner.runTest(TestRunner) line: 324 SuiteRunner.runSequentially() line: 319 SuiteRunner.privateRun() line: 292 SuiteRunner.run() line: 198 RemoteTestNG(TestNG).createAndRunSuiteRunners(XmlSuite) line: 823 RemoteTestNG(TestNG).runSuitesLocally() line: 790 RemoteTestNG(TestNG).run() line: 708 RemoteTestNG.run() line: 73 RemoteTestNG.main(String[]) line: 124 -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Ph: +1 512 422 3588 Fax: +1 512 276 6674 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=598120
Re: Code hanging doing a HTTP get
That seems to have cracked it - thanks! Ian. On Tue, Dec 2, 2008 at 11:10 AM, Jerome Louvel [EMAIL PROTECTED] wrote: Hi Ian, Are you consuming your response entities fully? If not, you can use the release() method if necessary. Best regards, Jerome Louvel -- Restlet ~ Founder and Lead developer ~ http://www.restlet.org Noelios Technologies ~ Co-founder ~ http://www.noelios.com -Message d'origine- De : Ian Clarke [mailto:[EMAIL PROTECTED] Envoye : mardi 2 decembre 2008 18:02 A : discuss@restlet.tigris.org Objet : Code hanging doing a HTTP get My code is hanging here (while trying to do a HTTP get) - any ideas? Thread [main] (Suspended) Object.wait(long) line: not available [native method] MultiThreadedHttpConnectionManager.doGetConnection(HostConfiguration, long) line: 518 MultiThreadedHttpConnectionManager.getConnectionWithTimeout(HostConfiguration, long) line: 416 HttpMethodDirector.executeMethod(HttpMethod) line: 153 HttpClient.executeMethod(HostConfiguration, HttpMethod, HttpState) line: 397 HttpClient.executeMethod(HttpMethod) line: 323 HttpMethodCall.sendRequest(Request) line: 313 HttpClientConverter.commit(HttpClientCall, Request, Response) line: 418 HttpClientHelper(HttpClientHelper).handle(Request, Response) line: 108 Client.handle(Request, Response) line: 157 Client(Uniform).handle(Request) line: 108 ApiAuthTest.get(String, String, String) line: 87 ApiAuthTest.testAuth() line: 74 NativeMethodAccessorImpl.invoke0(Method, Object, Object[]) line: not available [native method] NativeMethodAccessorImpl.invoke(Object, Object[]) line: 39 DelegatingMethodAccessorImpl.invoke(Object, Object[]) line: 25 Method.invoke(Object, Object...) line: 597 MethodHelper.invokeMethod(Method, Object, Object[]) line: 580 Invoker.invokeMethod(Object[], int, ITestNGMethod, Object[], XmlSuite, MapString,String, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods) line: 478 Invoker.invokeTestMethod(Object[], ITestNGMethod, Object[], XmlSuite, MapString,String, ITestClass, ITestNGMethod[], ITestNGMethod[], ConfigurationGroupMethods) line: 617 Invoker.invokeTestMethods(ITestNGMethod, ITestNGMethod[], int, XmlSuite, MapString,String, ConfigurationGroupMethods, Object[], ITestContext) line: 885 TestMethodWorker.invokeTestMethods(ITestNGMethod, Object[], ITestContext) line: 126 TestMethodWorker.run() line: 110 TestRunner.runWorkers(ListIMethodWorker, String) line: 712 TestRunner.privateRun(XmlTest) line: 582 TestRunner.run() line: 477 SuiteRunner.runTest(TestRunner) line: 324 SuiteRunner.runSequentially() line: 319 SuiteRunner.privateRun() line: 292 SuiteRunner.run() line: 198 RemoteTestNG(TestNG).createAndRunSuiteRunners(XmlSuite) line: 823 RemoteTestNG(TestNG).runSuitesLocally() line: 790 RemoteTestNG(TestNG).run() line: 708 RemoteTestNG.run() line: 73 RemoteTestNG.main(String[]) line: 124 -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Ph: +1 512 422 3588 Fax: +1 512 276 6674 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=598120 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=598123 -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Ph: +1 512 422 3588 Fax: +1 512 276 6674 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=663338
Should Restlet ever hold on to a TCP port after calling Component.stop()
I'm creating a HTTP listener and calling Component.stop() after every method in a unit test, and I keep getting exceptions complaining that the listen port is already in use. This even happened after I introduced a 1/2 second delay. When I switch this to only create the listener before the tests, and stop it after all are complete, it seems to work fine. Should Component.stop() release the TCP listen port immediately? Ian. -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Ph: +1 512 422 3588 Fax: +1 512 276 6674 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=728389
Getting 403 Forbidden rather than 401 Unauthorized when using HTTP Basic auth
I followed the code in this tutorial: http://www.restlet.org/documentation/1.0/tutorial#part09 But when the authentication fails, I'm getting a 403 error, rather than a 401 error as the code suggests. This is with Restlet v1.0.11 - any ideas? Regards, Ian. -- Ian Clarke CEO, Uprizer Labs Email: [EMAIL PROTECTED] Cell: +1 512 422 3588
Confusing exception
Hi, I'm seeing this exception in Restlet 1.0.9 (running on Java 1.6 on OSX), can anyone think of what might be causing it? :- java.io.IOException: Empty parameter name detected. at com.noelios.restlet.util.PreferenceReader.readPreference(PreferenceReader.java:141) at com.noelios.restlet.http.ContentType.init(ContentType.java:56) at com.noelios.restlet.http.HttpServerCall.getRequestEntity(HttpServerCall.java:146) at com.noelios.restlet.http.HttpRequest.getEntity(HttpRequest.java:364) at com.noelios.restlet.application.Decoder.beforeHandle(Decoder.java:86) at org.restlet.Filter.handle(Filter.java:134) at org.restlet.Filter.doHandle(Filter.java:105) at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:96) at org.restlet.Application.handle(Application.java:294) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Router.handle(Router.java:445) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Router.handle(Router.java:445) at org.restlet.Filter.doHandle(Filter.java:105) at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87) at org.restlet.Filter.handle(Filter.java:135) at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:118) at org.restlet.Component.handle(Component.java:231) at org.restlet.Server.handle(Server.java:282) at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:99) at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94) at com.noelios.restlet.ext.simple.SimpleProtocolHandler.handle(SimpleProtocolHandler.java:67) at simple.http.Dispatcher.run(Dispatcher.java:83) at simple.util.process.Daemon.execute(Daemon.java:121) at simple.util.process.Daemon.run(Daemon.java:106) Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Confusing exception
Ah, figured it out - I was ending the header value with a ';'. Ian. On Mon, Jun 23, 2008 at 10:50 AM, Ian Clarke [EMAIL PROTECTED] wrote: Hi, I'm seeing this exception in Restlet 1.0.9 (running on Java 1.6 on OSX), can anyone think of what might be causing it? :- java.io.IOException: Empty parameter name detected. at com.noelios.restlet.util.PreferenceReader.readPreference(PreferenceReader.java:141) at com.noelios.restlet.http.ContentType.init(ContentType.java:56) at com.noelios.restlet.http.HttpServerCall.getRequestEntity(HttpServerCall.java:146) at com.noelios.restlet.http.HttpRequest.getEntity(HttpRequest.java:364) at com.noelios.restlet.application.Decoder.beforeHandle(Decoder.java:86) at org.restlet.Filter.handle(Filter.java:134) at org.restlet.Filter.doHandle(Filter.java:105) at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at com.noelios.restlet.application.ApplicationHelper.handle(ApplicationHelper.java:96) at org.restlet.Application.handle(Application.java:294) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Router.handle(Router.java:445) at org.restlet.Filter.doHandle(Filter.java:105) at org.restlet.Filter.handle(Filter.java:135) at org.restlet.Router.handle(Router.java:445) at org.restlet.Filter.doHandle(Filter.java:105) at com.noelios.restlet.StatusFilter.doHandle(StatusFilter.java:87) at org.restlet.Filter.handle(Filter.java:135) at com.noelios.restlet.component.ComponentHelper.handle(ComponentHelper.java:118) at org.restlet.Component.handle(Component.java:231) at org.restlet.Server.handle(Server.java:282) at com.noelios.restlet.ServerHelper.handle(ServerHelper.java:99) at com.noelios.restlet.http.HttpServerHelper.handle(HttpServerHelper.java:94) at com.noelios.restlet.ext.simple.SimpleProtocolHandler.handle(SimpleProtocolHandler.java:67) at simple.http.Dispatcher.run(Dispatcher.java:83) at simple.util.process.Daemon.execute(Daemon.java:121) at simple.util.process.Daemon.run(Daemon.java:106) Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Is the Simple HTTP server adequate for a high-traffic API
Hi, I'm using the Simple web server connector (v3.1) in its default configuration for an API that must be able to deal with a high request volume (10-20 requests per second, with each request having a duration of 10ms - 1s each). Is the Simple web server adequate for this? Are there any configuration options I should modify or tweak, and if so, how do I tweak them? Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Help! Weird timeout on GET to Restlet API
On Tue, Apr 8, 2008 at 8:38 AM, Rob Heittman [EMAIL PROTECTED] wrote: Since one of the main objectives of 1.1 has been to respond to issues that confuse or frustrate people coming to the platform, the changes in 1.1 are extremely on point for the needs of a new Restlet user. Ok, I'll take your advice and switch to 1.1 as soon as I get a chance. Can you point me to a convenient upgrade guide? Kind regards, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: How do I switch off log output?
Personally I blame the design of logging frameworks. I find them to be over-engineered, and unintuitive to use. I hate to say it, but maybe we need a new logging framework :-) Ian. On Tue, Apr 8, 2008 at 6:37 AM, Rob Heittman [EMAIL PROTECTED] wrote: Yes, it can be a bit of a challenge to find and manage logging output from all the different connectors and plugins that you might possibly be using (a list that grows all the time), not just Restlet itself. I wonder if anybody has any good ideas for easily centralizing this, maybe as part of the future deployable Restlet configuration effort. On Tue, Apr 8, 2008 at 5:58 AM, Steve Loughran [EMAIL PROTECTED] wrote: That's httpclient logging at INFO; if you have commons-logging and log4j on the classpath, it will log via log4j -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: How do I switch off log output?
That didn't work, I think this is commons-logging, I don't have log4j on my classpath. Here is how I solved it: // Switch off logging (stupid f$%king logging frameworks!) component.getLogService().setEnabled(false); System.setProperty(org.apache.commons.logging.Log, org.apache.commons.logging.impl.SimpleLog); System.setProperty(org.apache.commons.logging.simplelog.showdatetime, true); System.setProperty(org.apache.commons.logging.simplelog.log.org.apache.commons.httpclient, error); I definitely feel a blog rant coming on about today's Java logging frameworks :-) Ian. On Tue, Apr 8, 2008 at 4:58 AM, Steve Loughran [EMAIL PROTECTED] wrote: On Tue, Apr 8, 2008 at 6:27 AM, Ian Clarke [EMAIL PROTECTED] wrote: Thanks for the tip, although I'm afraid it wasn't entirely effective. I used getLogService().setEnabled(false) - but I'm still getting the following: Apr 8, 2008 12:23:48 AM org.apache.commons.httpclient.HttpMethodBase readResponseBody INFO: Response content length is not known That's httpclient logging at INFO; if you have commons-logging and log4j on the classpath, it will log via log4j in your log4j.properties you could tell HttpClient to only warn you . log4j.logger.org.apache.commons.httpclient=WARN -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: How do I switch off log output?
It seems ridiculous, I know, but unfortunately if all the existing options are over-engineered and hard to use, and produce spurious output in their default configuration, then the natural alternative is to create a framework that doesn't suffer from these problems. Of course, a simple solution to the immediate issue is to ensure that logging is switched off by default in all code and libraries shipped with Restlet. Ian. On Tue, Apr 8, 2008 at 11:31 AM, Kevin Conaway [EMAIL PROTECTED] wrote: So the solution to the confusion surrounding the various log frameworks in use by Restlet and its components isanother log framework? :) As much as I'm against using one of the bridge frameworks for logging, it might make sense for Restlet seeing as how the various components all could (and some indeed do) use different frameworks. You could also adopt a discovery policy similar to what jetty does On Tue, Apr 8, 2008 at 11:17 AM, Ian Clarke [EMAIL PROTECTED] wrote: Does your colleague have any plans to release his framework under a commercial-friendly license (eg. LGPL)? If so, I'll definitely take a look at it for my own project :-) Ian. On Tue, Apr 8, 2008 at 8:46 AM, Rob Heittman [EMAIL PROTECTED] wrote: Heh. One of the guys at my office has been ad-hoc building his own personal logging framework to talk to the logging frameworks. Originally I was going to complain about this on principle, but in truth his code's delightfully easy to read -- simply because his logging classes are intentionally simpler and more ad hoc to the application environment and the information being logged. Forward a pointer to the blog rant please ;-) On Tue, Apr 8, 2008 at 9:38 AM, Ian Clarke [EMAIL PROTECTED] wrote: Personally I blame the design of logging frameworks. I find them to be over-engineered, and unintuitive to use. I hate to say it, but maybe we need a new logging framework :-) Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Help! Weird timeout on GET to Restlet API
I keep getting the following timeout when I try to do a HTTP GET on a resource (I'm using Restlet both server and client side, v1.0.9). It only seems to happen if I PUT and then DELETE the resource, and then try to GET it after its been deleted. If I never create the resource in the first place, then the request returns with a 404 as it should. If I create, and don't delete the resource, then it returns with a 200 as it should. So far as I can tell, the request never arrives server-side (ie. it never makes it to the constructor of the Resource object when the Client times out). This suggests that the problem may be on the client side of the connection... Help would be much-appreciated, I've been pulling my hair out over this for the last few hours... Here is the exception when it times out: Apr 7, 2008 4:22:03 PM org.apache.commons.httpclient.HttpMethodBase readResponseBody INFO: Response content length is not known Apr 7, 2008 4:22:05 PM com.noelios.restlet.ext.httpclient.HttpMethodCall sendRequest WARNING: An error occurred during the communication with the remote HTTP server. org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497) at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at com.noelios.restlet.ext.httpclient.HttpMethodCall.sendRequest(HttpMethodCall.java:183) at com.noelios.restlet.http.HttpClientConverter.commit(HttpClientConverter.java:100) at com.noelios.restlet.http.HttpClientHelper.handle(HttpClientHelper.java:79) at org.restlet.Client.handle(Client.java:111) at org.restlet.Uniform.handle(Uniform.java:97) Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Help! Weird timeout on GET to Restlet API
Ok, I think I fixed it - the problem was that after some calls I wasn't doing a getEntity().getText() (I didn't require the entity). Its a bit of a nasty pitfall for newbies... Ian. On Mon, Apr 7, 2008 at 4:29 PM, Ian Clarke [EMAIL PROTECTED] wrote: I keep getting the following timeout when I try to do a HTTP GET on a resource (I'm using Restlet both server and client side, v1.0.9). It only seems to happen if I PUT and then DELETE the resource, and then try to GET it after its been deleted. If I never create the resource in the first place, then the request returns with a 404 as it should. If I create, and don't delete the resource, then it returns with a 200 as it should. So far as I can tell, the request never arrives server-side (ie. it never makes it to the constructor of the Resource object when the Client times out). This suggests that the problem may be on the client side of the connection... Help would be much-appreciated, I've been pulling my hair out over this for the last few hours... Here is the exception when it times out: Apr 7, 2008 4:22:03 PM org.apache.commons.httpclient.HttpMethodBase readResponseBody INFO: Response content length is not known Apr 7, 2008 4:22:05 PM com.noelios.restlet.ext.httpclient.HttpMethodCall sendRequest WARNING: An error occurred during the communication with the remote HTTP server. org.apache.commons.httpclient.ConnectionPoolTimeoutException: Timeout waiting for connection at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.doGetConnection(MultiThreadedHttpConnectionManager.java:497) at org.apache.commons.httpclient.MultiThreadedHttpConnectionManager.getConnectionWithTimeout(MultiThreadedHttpConnectionManager.java:416) at org.apache.commons.httpclient.HttpMethodDirector.executeMethod(HttpMethodDirector.java:153) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:397) at org.apache.commons.httpclient.HttpClient.executeMethod(HttpClient.java:323) at com.noelios.restlet.ext.httpclient.HttpMethodCall.sendRequest(HttpMethodCall.java:183) at com.noelios.restlet.http.HttpClientConverter.commit(HttpClientConverter.java:100) at com.noelios.restlet.http.HttpClientHelper.handle(HttpClientHelper.java:79) at org.restlet.Client.handle(Client.java:111) at org.restlet.Uniform.handle(Uniform.java:97) Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
How do I switch off log output?
How do I stop Restlet from logging to the console? Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: How do I switch off log output?
Thanks for the tip, although I'm afraid it wasn't entirely effective. I used getLogService().setEnabled(false) - but I'm still getting the following: Apr 8, 2008 12:23:48 AM org.apache.commons.httpclient.HttpMethodBase readResponseBody INFO: Response content length is not known Any ideas? Ian. On Mon, Apr 7, 2008 at 9:53 PM, Rob Heittman [EMAIL PROTECTED] wrote: How do you stop a bull from charging? You take away his credit cards :-) Here's a neat little recipe for how to fiddle with Java Logging with regard to Restlet: http://www.naviquan.com/blog/restlet-cookbook-log On Mon, Apr 7, 2008 at 9:22 PM, Ian Clarke [EMAIL PROTECTED] wrote: How do I stop Restlet from logging to the console? Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: another question: adding attributes to a context
Just want to ping the list again as I haven't yet seen a response to the question below. Does anyone have any ideas? :- Ian. On Tue, Apr 1, 2008 at 11:21 AM, Ian Clarke [EMAIL PROTECTED] wrote: I want to pass two objects, cf and rs, in to several resources. Here is a code snippet that doesn't work: --snip-- apiListenerComponent = new Component(); apiListenerComponent.getServers().add(Protocol.HTTP, listenPort); apiListenerComponent.getContext().getAttributes().put(cf, cf); apiListenerComponent.getContext().getAttributes().put(rs, rs); // Attach the sample application. apiListenerComponent.getDefaultHost().attach( new Application(apiListenerComponent.getContext()) { @Override public Restlet createRoot() { // Create a root router Router router = new Router(getContext()); router.attach(/users/{id}, UserResource.class); --snip-- However, I find that if I add the attributes directly to the router object when I create it inside createRoot(), that works fine. Why isn't the router inheriting the attributes from the Component? Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Newbie question: Override Resource.post() or Resource.handlePost() ?
When creating a subclass of Resource, is it preferable to override post() or handlePost() (ditto for put/handlePut - etc)? What is the difference? (Note: I'm using restlet v 1.0.8) Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Submitting JSON object to Resource via a HTTP PUT
I'm implementing Resource.put(), and I want to standardize on JSON as my data representation language. This resource is a User object called 'u', that contains one main field, a Set of Integers called tags. Can someone let me know if I'm doing this right, and in the idiomatic manner - or if I should be doing this a different way: @Override public void put(Representation entity) { try { JSONObject nu = new JsonRepresentation(entity).toJsonObject(); JSONArray jStags = nu.getJSONArray(tags); SetUser tags = new HashSetUser(); for (int x=0; xjStags.length(); x++) { tags.add(cf.users.get(jStags.getInt(x))); } u.setTags(tags); } catch (Exception e) { log.error(Error parsing JSON while modifying a user, e); this.getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage()); return; } } Can anyone give me some advice on how I should document this for client writers (who will probably be using languages other than Java)? Many thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Submitting JSON object to Resource via a HTTP PUT
Hi Rob, Thanks for the feedback. I certainly agree that examples are often the best form of documentation. But, my particular concern was, how do I explain, in a language (and library) neutral way, how to send a JSON object to a resource via a HTTP PUT request. I'm also concerned to ensure that the method I'm using to interpret the PUT request (see code in my original email) is correct. Regards, Ian. On Mon, Mar 24, 2008 at 9:19 AM, Rob Heittman [EMAIL PROTECTED] wrote: Hi Ian, At my outfit, when we've written elaborate REST API documentation, evidence indicates hardly anyone reads it :-) I've had the best results with documentation by example ... to start with, write out a few examples of the actual representation in likely use cases, and if time permits, give a couple examples of how to construct and send it in the most likely client languages (Javascript, Ruby, etc.). I think a great use of time is ensuring that your Web service emits informative and helpful error messages in the response entity if something is malformed or unexpected. I think the majority of developers (especially in scripting and dynamic languages) like to just whip something together and try it out. - R On Mon, Mar 24, 2008 at 10:04 AM, Ian Clarke [EMAIL PROTECTED] wrote: Can anyone give me some advice on how I should document this for client writers (who will probably be using languages other than Java)? -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Submitting JSON object to Resource via a HTTP PUT
I'm using Restlet 1.0.8 - would you recommend using 1.1? How stable is it relative to 1.0.8 - and what are the benefits? Does the use of methods like getRepresentation() and storeRepresentation() not cause a problem because they decouple Restlet from the underlying HTTP protocol terminology? Specifically, if I say to a client writer that isn't using Restlet that they should store a representation in a URL, it is less likely that they will know what do to relative to saying that they should PUT it (this being the name of the HTTP method they should use). Probably not the best example, but generally, wouldn't it be better to stick with terminology that will be familiar to people who are only going on the HTTP spec? Or perhaps we are assuming a familiarity with REST terminology, rather than HTTP terminology alone? Regards, Ian. On Mon, Mar 24, 2008 at 10:00 AM, Rob Heittman [EMAIL PROTECTED] wrote: I'll let someone who uses JSON more than me answer about the idiom of the JSON traversal, but it looks OK to me. If you are using the 1.1 Restlet API, you want to override storeRepresentation() instead of put(). For my 2 cents, I don't think you need to explain the HTTP PUT operation. Whatever implementation language and/or HTTP client library people are using, they should have documentation and/or existing knowledge for that -- and the means may vary *dramatically*. If there is a very likely use case (JavaScript and XmlHttpRequest, etc.) you can document it in full. Otherwise, maybe give some pointers to existing Web documentation ... personally, I wouldn't reinvent the wheel in explaining how to make HTTP calls -- or create JSON structured objects. That seems like a heavy documentary load to lift. - R On 3/24/08, Ian Clarke [EMAIL PROTECTED] wrote: Hi Rob, Thanks for the feedback. I certainly agree that examples are often the best form of documentation. But, my particular concern was, how do I explain, in a language (and library) neutral way, how to send a JSON object to a resource via a HTTP PUT request. I'm also concerned to ensure that the method I'm using to interpret the PUT request (see code in my original email) is correct. Regards, Ian. On Mon, Mar 24, 2008 at 9:19 AM, Rob Heittman [EMAIL PROTECTED] wrote: Hi Ian, At my outfit, when we've written elaborate REST API documentation, evidence indicates hardly anyone reads it :-) I've had the best results with documentation by example ... to start with, write out a few examples of the actual representation in likely use cases, and if time permits, give a couple examples of how to construct and send it in the most likely client languages (Javascript, Ruby, etc.). I think a great use of time is ensuring that your Web service emits informative and helpful error messages in the response entity if something is malformed or unexpected. I think the majority of developers (especially in scripting and dynamic languages) like to just whip something together and try it out. - R On Mon, Mar 24, 2008 at 10:04 AM, Ian Clarke [EMAIL PROTECTED] wrote: Can anyone give me some advice on how I should document this for client writers (who will probably be using languages other than Java)? -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Submitting JSON object to Resource via a HTTP PUT
On Mon, Mar 24, 2008 at 10:07 AM, Kevin Conaway [EMAIL PROTECTED] wrote: I believe you should override Resource.storeRepresentation() and override Resource.allowPut() - true instead of overriding Resource.put() I don't think there is a Resource.storeRepresentation() method in 1.0.8. Are you recommending this because my approach won't work, or because .storeRepresentation() is better in some way? Two pieces of advice on opening up to third-party clients. First, some languages (or their associated libraries) other than Java have poor or non-existent support for the HTTP PUT method. Just be aware of this when recommending implementation languages. Hmm, well, one language is C#, which seems to support it in its HttpWebRequest class. Do you recommend using POST instead for this reason? Will using .storeRepresentation() support storing a representation through POST as well as PUT? Second, while JSON is slightly easier to work with programmatically, a lot of languages don't have native support for it. Depending on who your clients are, they might balk at having to download and install a third party library to access your service. XML might work out better because most languages have native support for it. I think it will be ok. Of course, I can always support both, and let them choose when they make the request. Many thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Handling of errors in Resource and elsewhere
What is the appropriate way to report an error back to the caller of a HTTP REST call from a Resource class? For example, what if I'm using JSON and there is some kind of JSON parsing error? Obviously, it would be nice to return a useful error message to the caller of the API. I'd really appreciate some example code, say, from within a Resource.put() method. Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Re: Handling of errors in Resource and elsewhere
Maybe I've just found the answer to my own question - is it something like this: public Representation getRepresentation(Variant variant) { snip... } catch (JSONException e) { log.error(Error constructing JSON response while returning a user, e); this.getResponse().setStatus( Status.CLIENT_ERROR_BAD_REQUEST, e.getMessage()); } return null; } On Sun, Mar 23, 2008 at 9:05 PM, Ian Clarke [EMAIL PROTECTED] wrote: What is the appropriate way to report an error back to the caller of a HTTP REST call from a Resource class? For example, what if I'm using JSON and there is some kind of JSON parsing error? Obviously, it would be nice to return a useful error message to the caller of the API. I'd really appreciate some example code, say, from within a Resource.put() method. Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity
Another newbie question: when is it appropriate to use GET parameters?
When is it appropriate to use a query string to pass parameters to a REST API call? For example, why is: http://blah/user/1234 better than: http://blah/user?id=1234 ? I'm guessing that if I have a GET request which can return a list of a variable length (such as a search), then a GET parameter should be used to indicate how many results should be provided - is this correct? In the event that it is appropriate to use a GET parameter, what is the best way to extract it from a Request? Thanks, Ian. -- Email: [EMAIL PROTECTED] Cell: +1 512 422 3588 Skype: sanity