Yuri, In addition, I've entered this RFE for 1.1:
"Automatically create required client connectors" http://restlet.tigris.org/issues/show_bug.cgi?id=293 Best regards, Jerome > -----Message d'origine----- > De : Jerome Louvel > Envoyé : jeudi 3 mai 2007 17:48 > À : [email protected] > Objet : RE: Example of a Restlet Application/Servlet using > both Client and Server > > > Hi Yuri, > > > Looking at Peter's code I had a question about the best way > > to use a client > > connector from within a Restlet application. Peter's code is > > instantiating a new HTTP client connector and using. > > All applications hosted within a given component should share > the same server and client connectors. This is possible > because those connectors are mostly stateless in nature. > > > My impression from the design is that Client connectors, > > along with Server > > connectors should be added to the Component and automatically > > selected based on > > the url when dispatching calls using getDispatcher(). Is > that correct? > > Yes, this is the intended behavior. > > > Specifically when using Restlet embedded in a servlet > > container, how do we get > > access to the underlying Component created by the > > ServerServlet? And when should > > one add the client connectors to it? > > This is a tricky case here that will require you to extend > the default ServerServlet class. You can override the > createServer() method and do something like: > > @Override public HttpServerHelper > createServer(HttpServletRequest request) { > HttpServerHelper result = super.createServer(request); > > if(firstCall) { > Component comp = getComponent(); > comp.getClients().add(new > Client(comp.getContext(), Protocol.HTTP); > firstCall = false; > } > } > > You should of course declare a "firstCall" member variable. > > > Last question, related to dispatching calls to client > > connectors is about > > request, response and request headers: what if I want to > > dispatch N number of > > times before returning a response to the browser and for > > every dispatch there > > are, for instance, different headers I want to submit (maybe > > authentication > > headers, for instance, or a X-JSON header. Should I save the > > current state of > > the request, response and modify them for each dispatch, > > reverting to the saved > > one before returning the response? > > You should create a new set of Request/Response instances for > your client calls, separate from your current server call. > You can try reusing/modifying the client Request instances as > long as you ensure that any input entity/representation has > fresh content to submit if necessary (PUT/POST). > > Best regards, > Jerome

