"segment" router or subrouter

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

"segment" router or subrouter

koma
Hi

My Restlet application is now mapped in the web.xml to "/app" and "/app/*". I have a whole bunch of routes setup underneath this base URL in a function called setupApp(router).

Now, I plan to refactor things a bit and I want to change my web.xml so *every* call is intercepted by Restlet so "/*".

The existing routings like "/app/user/{userId}" must keep on working.

**Now I can manually add the first segment "app" to my existing routings so they keep on working. **

But there must be an easier way to do this. I expect something like this to work :

public synchronized Restlet createInboundRoot() {

  Router router = new Router(this.getContext());

  Router subRouter = new Router(this.getContext());
  router.add("/app/*", subRouter);
  setupApp(subRouter);
 
  // add new stuff to the router
  router.add("index.html", IndexRouter.class);

}


// existing code but now with first segment /app added ?
// in the original code, the main router is passed in
public void setupApp(Router subRouter) {

  subRouter.add("/user/{userId}", UserResource.class);
  subRouter.add("/user/{userId}", UserResource.class);

}

thx for the pointers ...

Koen

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3091593
Reply | Threaded
Open this post in threaded view
|

RE: "segment" router or subrouter

koma
Ok, I guess I better create a second Application and map that under /*

Correct?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3091601
Reply | Threaded
Open this post in threaded view
|

Re: "segment" router or subrouter

Tim Peierls
I think you can do better. Here's an old conversation that might have some hints:


Not all of this is relevant to you. Concentrate on the autowire part.

--tim

On Thu, Nov 20, 2014 at 11:01 AM, Koen Maes <[hidden email]> wrote:
Ok, I guess I better create a second Application and map that under /*

Correct?

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3091601

Reply | Threaded
Open this post in threaded view
|

RE: Re: "segment" router or subrouter

koma
I have been reading the javadocs for documentation ServerServlet (http://restlet.com/technical-resources/restlet-framework/javadocs/snapshot/gae/ext/org/restlet/ext/servlet/ServerServlet.html)

In deployment mode 3, the context path of the servlet is automatically added. That's what we call the auto-wire feature. This is the default case, and is equivalent to setting the value "true" for the "org.restlet.autoWire" parameter as described above. In modes 1 or 2, if you want to manually control the URI wiring, you can disable the auto-wiring by setting the property to "false".

Finally, an "org.restlet.ext.servlet.offsetPath" attribute, containing the computed offset path used to attach applications when (and only when) the auto-wiring feature is set, is added to the component's context.

Both autowire and offsetPath should do the trick... i am trying to figure out how exactly.

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=3091619