Hi Tamer, I think this is more of a discuss topic, so I'm moving it there.
On Jun 30, 2009, at 9:13 AM, tameremil wrote: > Hello, > I am currently working on an application where I have to provide a > rich web > client as well as a REST API. I chose to use RESTLET for my REST > API. Now > when it comes to the web interface, I have two choices: > 1. either infest my application with countless javascript code > (which would > call the REST API then render) [Side note: don't reject JavaScript out of hand. With an appropriate toolkit to patch over the inter-browser messiness (I like jQuery and YUI) and good unit tests, a dynamic, JS-based UI could be your best bet.] > 2. use servlets and jsps. > > I chose to stay away from javascript as much as possible and rely on > servlets and jsps to render web UI. However, now I am facing a > dilema. In > order to call the REST API from my servlets I am using the RESTLET > CLIENT, > this approach has proved to be inefficient. Every time I make a call > I have > to parse the returned JSON and go through pain to extract API call > response. It sounds like you have (conceptually) a single server which provides both an HTML-based web GUI and a JSON API. If that's so, that's a common case. You can use Restlet for both representations -- in fact, this sort of thing is one of the things the RESTful architecture style excels at. The idea is that you implement the same Resources, with the same associated logic, but allow them to return different Representations based on what the client requests. This concept is "Content Negotiation" and Restlet supports it. I'd suggest reading the O'Reilly "RESTful Web Services" book for more info. One caveat is that I don't think you can use JSP to render a Restlet Representation. You can use FreeMarker, though, which is similar (some would say better). > I read about the Servlet Convertor, but I am not sure how I can use > it here. > I am not concerned about tight integration between Servlets and > Restlets as > long as I can have my RESTLETs not depend on my servlets (but I do > not care > about the opposite). The Servlet Convertor is to allow you to serve your Restlet application via a Servlet container. > > My Questions: > 1. What is the best way to integrate my servlet with the RESTLETs? > > 2. Is there a way for me to pass java objects from the restlet to the > servlet? This way in the servlet I can extract java objects and not > rely on > re-assembling the JSON or XML contained in the Response > Representation? For a new application (and assuming I understand what you're trying to do), I'd suggest using content negotation in Restlet and not using Servlet/JSP at all. If you really don't want to do that, or if you already have a large investment in JSP-based views, I'd extract the business logic into a separate layer and make it available to both your servlets and your restlets. Rhett > > Please let me know if my question is not clear. > > I am in a tough bind and would appreciate any and all help. > > Thank you, > > Tamer > -- > View this message in context: > http://n2.nabble.com/The-best-way-to-integrate-servlets-with-restlets-tp3182669p3182669.html > Sent from the Restlet Code mailing list archive at Nabble.com. > > ------------------------------------------------------ > http://restlet.tigris.org/ds/viewMessage.do?dsForumId=7458&dsMessageId=2366718 ------------------------------------------------------ http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2366777