Re: Restlet JAX-RS question
Hi again... by the way the JAX-RS module has already a dependency on the servlet API (http://restlet.tigris.org/source/browse/*checkout*/restlet/trunk/modules/org.restlet.ext.jaxrs/pom.xml?revision=5522content-type=text%2Fplain) -Fabio On Thu, Mar 25, 2010 at 12:35 PM, Jerome Louvel jerome.lou...@noelios.com wrote: Hi guys, Sorry for being late to the discussion. The dependency on the Servlet API is an issue indeed, but I think you should be able to achieve what you want by injecting the Restlet request/response and then from that retrieving the Servlet request/response. org.restlet.ext.servlet.internal.ServletCall class has this static method to help: getRequest(org.restlet.Request) : HttpServletRequest In order to make this more obvious, I've just added to SVN trunk a ServletUtils class to the Servlet extension with two static methods to easily retrieve the Servlet request/response. Best regards, Jerome Louvel -- Restlet ~ Founder and Technical Lead ~ http://www.restlet.org Noelios Technologies ~ http://www.noelios.com -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2464894
Re: Restlet JAX-RS question
On Thu, Mar 25, 2010 at 12:35 PM, Jerome Louvel jerome.lou...@noelios.com wrote: Hi guys, Sorry for being late to the discussion. The dependency on the Servlet API is an issue indeed, but I think you should be able to achieve what you want by injecting the Restlet request/response and then from that retrieving the Servlet request/response. org.restlet.ext.servlet.internal.ServletCall class has this static method to help: getRequest(org.restlet.Request) : HttpServletRequest In order to make this more obvious, I've just added to SVN trunk a ServletUtils class to the Servlet extension with two static methods to easily retrieve the Servlet request/response. Best regards, Jerome Louvel -- Hi, I don't know if you have seen it, but I contributed a patch... Actually I inject directly the HttpServletRequest using something that maybe is similar to what you describe there (hence, the ext.servlet dependency) By injecting the Restlet Request we would remove the dependency and we provide a way for retrieving the HttpServletRequest in the JAX-RS resources. It is indeed a good idea! And is almost implemented in the patch I sent (it's just a matter of removing some lines, providing that the rest is good :)) Thanks for the feedback! -Fabio P.S.: Link to the patch : http://restlet.tigris.org/issues/show_bug.cgi?id=722 -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2464893
Dynamic JAX-RS application
Hi everybody, I have the following use case: I would like to setup a dynamic JAX-RS application where you can dynamically add and remove resources at runtime. Now I have successfully managed to add/remove resources in the following way : 1) I create a new javax.ws.rs.core.Application whose getClasses method returns the new set of classes (at time T) 2) I detach the current org.restlet.ext.jaxrs.JaxRsApplication from the component defaultHost. 3) I create a new org.restlet.ext.jaxrs.JaxRsApplication 4) I add to the JaxRsApplication created in 3) the configuration created in 1) 5) I attach the new application instance to the component. Things seems to work without problems. I posted the code on http://pastebin.com/9F4BBJYL The behavior is the correct one 1) /another doesn't exist 2) /hello is accessed 3) The /another resource starts to respond 4) The /hello resource is gone So my question is : has this code something wrong (e.g., a possible memory leak or whatever) ? Are there other more elegant ways to realize my use case? Thanks. Regards, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2457143
Re: When to use POST??
On Tue, Dec 22, 2009 at 4:18 PM, Conor Moran conor.j.mo...@gmail.com wrote: I found an interview with Jerome on infoQ recently which states it is best to use PUT for both Create Update --- http://www.infoq.com/articles/restlet-louvel-interview --- InfoQ: Can you elaborate a little on your criticism of Rails in this regard? What's unnatural about its CRUD mapping in your opinion? JL: Beside the GET and DELETE HTTP methods that map nicely to SQL SELECT and DELETE verbs, I find the usage by Rails of POST method for creation rather unfortunate. The best method for creation in REST is PUT which is also used for updates. The advantage of PUT over POST is that if the operation fails it can be safely repeated which isn't the case for POST. Also, ... --- Should I ever use POST? If so, can you give an example of what to use this for? Imho, you use PUT for creating resources when the client is able to know and decide what URI the resource should have. You use POST for creating resources when the URI is assigned by the server (i.e., the client is unable to figure out what URI the newly created resource should have). Examples: PUT : http://docs.amazonwebservices.com/AmazonS3/2006-03-01/API/ POST : posting a comment in some kind of restful forum : POST http://foo/post/1/comments will create a comment whose URI is something like http://foo/post/1/comments/12345 (the client cannot know what the ID of the comment will be, so it does a POST on the parent resource) -Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2432354
Re: JAX-RS instantiation policies
On Tue, May 26, 2009 at 11:18 PM, Stephan Koops stephan.ko...@web.de wrote: That is the intended default lifecycle, but you could change it by returning providers from javax.ws.rs.Application.getClasses() or resources from javax.ws.rs.Application.getSingleton(). Thanks Stephan for your hint. Regards, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=2355685
Multiple applications
Dear all, is it possible to define multiple applications in a web.xml, each one attached to a servlet rooted at a different base URI? Apparently it's not possible because the application class is defined as a context parameter not linked to a servlet, but maybe I am missing something. Thank you for your help. Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1592443
RE: Re: Multiple applications
You probably want to declare your application - url mapping in some configuration files outside of the code. If you're talking about web.xml file only, it seems you can't. Actually I was talking about web.xml file only. Thank you for your hints about solving the problem. Regards, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1592971
Media types specified as a query parameter
Hi everybody, I would like to use query parameters in order to specify the media type to be sent to the client. Tunneling and metadata services should do the trick. However I cannot achieve this. I called in createRoot() of the JaxRsApplication (I am the using JAX-RS extension) getTunnelService().setEnabled(true); getTunnelService().setExtensionsTunnel(true); getMetadataService().addCommonExtensions() getMetadataService().setEnabled(true) and request some URI using: ?media=json ?media=application/json ?accept=application/json but it doesn't seem to work. Any hint? Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1574220
RE: Re: Media types specified as a query parameter
Hi Rhett, thanks for the hint. I activated the query service but still no luck. I am starting to think that the ?media mechanism is not supported when using the JAX-RS extension. Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1577899
RE: Re: Media types specified as a query parameter
I am starting to think that the ?media mechanism is not supported when using the JAX-RS extension. This is probably the reason... Anyway I did this very simple application http://pastebin.com/m5e963eea Could somebody confirm the incompatibility, or hint a solution if I am doing something wrong? :) Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1578357
Multipart parsing
Dear all, I am using JAX-RS for handing a Multipart form for file upload. I have a method: @POST @Consumes(MediaType.MULTIPART_FORM_DATA) public Attachment addAttachment(Multipart multipart) ... Now the problem is that multipart contains information to be parsed in order to be extracted (I am talking about form fields) Something like: Content-Disposition : form-data; name=field1 Content-Disposition : form-data; name=field2 Content-Disposition : form-data; name=file; filename=someuploadedcontent.png Is there already, in Restlet, a convenient way for parsing this kind of thing or should I write some pattern matching magic? Cheers, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1563072
Re: Servlet container's filters, getParameters() and POSTing www-form-urlencoded data
On Fri, Mar 13, 2009 at 1:17 PM, Jerome Louvel jerome.lou...@noelios.com wrote: Hi Fabio, I don't have a clean solution for you in a Servlet+JAX-RS scenario. Using the Restlet API, you would have a workaround because we cache the result of Request#getEntityAsForm() so you can call it several times. Maybe you can write a Servlet filter that extract all that you will need downstream and stick it into Servlet Request's attributes? Well that's not possible, but I put in place a workaround... I wrote a Restlet filter and from there I retrieved the original httprequest and stored it into Restlet's context attributes. If an application/x-www-form-urlencoded entity is sent I try to use getParameter*() to retrieve the information by retrieving the original httprequest from the Restlet context. Not the best wrt cleanliness but it worked :) Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1318221
Servlet container's filters, getParameters() and POSTing www-form-urlencoded data
Dear all, this is a quite known issue[1][2] but I am wondering if you already have a solution to the following problem: Suppose you have a servlet filter that uses one of the getParameter*() method in order to get some data from the request. What happens is that if the request is a POST+www-form-urlencoded data this method consumes the body and when the request reaches Restlet, its body appears to be empty (i.e., subsequent calls to getInputStream() return and empty stream). Do you know a workaround to circumvent this behavior (except not using getParameter*() in the filter)? RequestWrappers don't work very well [1] Thank you for your answer. Cheers, Fabio [1] http://mail-archives.apache.org/mod_mbox/tomcat-users/200505.mbox/%3c428afc4b.2060...@softwareag.com%3e [2] http://markmail.org/message/hk3i7fak2hfxjbna#query:getinputstream%20post%20form%20urlencoded%20filter%20getparameters+page:1+mid:xwyf3dorrbqcdq6v+state:results -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1277500
JAX-RS and media types
Dear all, I am playing with the Restlet JAX-RS extension and I have a question to ask about media types. I defined two MessageBodyWriter for MyType, one annotated with @Produces(text/xml) and the other with @Produces(text/plain). Now the problem is that when Safari asks for a resource that gives a representation of MyType using the following header: Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5 The text/plain representation is returned. Actually the returned representation varies randomly at each server restart. Sometimes the text/xml is returned. I suspect that this is due by the fact that providers are put in a Set returned by the getClasses() method, where the order is not taken into account. Anyway I would have expected that with such an Accept header, the text/xml would have always been returned and I don't understand why, being a text/xml writer available, the text/plain is selected. Any idea? Thank you, Fabio P.S.: If I use simpler Accept headers, everything works fine: Accept: text/plain - returns text/plain. Accept: text/xml - returns text/xml. -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1150226
Retrieving the UriTemplate associated to a Resource class
Dear all, I have already implemented this by building additional infrastructure, but I was wondering if, from inside a Resource, there is a way for retrieving which UriTemplate is associated to a given Resource class. To be more explicit: In application: router.attach(/myResource, MyResource.class) In MyResource I would like to have something like: getUriTemplateFor(MyResource.class) - /myResource I digged a bit into the API but I haven't find anything like this. Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1010096
Application and Resource lifecycle
Dear all, I am using Restlet with an IoC container (i.e., Plexus) and I would like to ask some questions about the lifecycle of some Restlet objects in order to decide which policy I have to choose for their instantiation and how to handle them. 1) Is ServletServer.createApplication() called only once during application lifetime? 2) Is Application.createRoot() called only once during application lifetime? (Probably a positive answer to 1 will also answer this) 3) Are resource re-usable? I mean, if I have an instance of a Resource, may I call init() in order to make the same instance serve different requests? Thanks for your help. -Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1007325
RE: Exception-resistant filters
Did it with a custom StatusService. I have some code duplication in the filter for successful requests and in the StatusService for handling exceptional cases. I don't think it's possible to do otherwise, but I am open to suggestions :) Thanks. -Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=1008161
RE: Metadata service
Yes I was able to solve the issue. It was the getTunnelService().setExtensionsTunnel(true); that had to be called to enable conneg via extensions. Thank you for your help and merry xmas! :) Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=992502
Metadata service
Dear all, maybe this is a trivial question but I cannot get the MetadataService to work as I expect. I started from the HelloWorld example in http://www.restlet.org/documentation/1.1/firstSteps I added a new Variant to the HelloWorldResource (APPLICATION_ATOM_XML) and attached it to the /hello route. When I GET /hello.atom the variant requested is always TEXT/PLAIN and not, APPLICATION_ATOM_XML. I tried different things in FirstStepsApplication.createRoot() method: - getMetadataService().addCommonExtensions() - getMetadataService().setEnabled(true) - getMetadataService().start() But I always get the same behavior (i.e., the .atom extension does not trigger a request for the ATOM variant) What is the correct way to setup this behavior? Thanks, Fabio -- http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447dsMessageId=990945