Re: [servlex] install servlex in root context

On Sun, 2015-02-22 at 19:47 +0100, Florent Georges wrote:
> On 20 February 2015 at 20:06, Paul Tyson wrote:
> 
>   Hi,
> 
> > Is it possible to install servlex in the root context of tomcat?
> 
>   Yes.
> 
> > I have configured a tomcat context "/" to go to servlex.
> 
>   So it is the root webapp?  So it is in [tomcat]/webapps/ROOT/?
> 
> > My webapps.xml has a single <webapp> with @root="/". The servlex
> > WebappsParser complains this is not valid.
> 
> > My goal is to make "servlex" disappear from the url, and only respond to
> > urls defined by my webapp. That is, "http://myhost.com/myapp" instead of
> > "http://myhost.com/servlex/myapp" (or any alias for "servlex").
> 
>   I think there is a bit of confusion here.  Servlex is a Java web
> application, that you can deploy on Tomcat (for instance).  It is
> itself a web container for the EXPath webapp spec.  Meaning that you
> can deploy such EXPath webapps in Servlex.
> 
>   Since you have deployed Servlex at the root of your Tomcat instance,
> Servlex itself is available at http://myhost.com/ (and everything
> underneath...)  If you want the webapps you deploy in Servlex to be
> available as http://myhost.com/myapp/, then ou can deploy them as
> usual.  @root="/" is not what you want, rather root="myapp".
> 
>   There are 2 levels of context roots: those of Tomcat (one is
> assigned to Servlex, here the special "root" one).  And those of
> Servlex itself, one being assigned to your webapp (in this case, it
> should be "myapp").
> 
>   Does that solve your problem?

I didn't state my problem quite right.

I am implementing something like a linked data platform, which will
resolve all urls under a particular authority. So, for instance, I want
servlex to handle all urls under http://myhost.com.

Some urls in this space are distinguished by their initial path part.
They need to be associated with a particular expath component.

So I might have urls like these:
  http://myhost.com/some/special/url
  http://myhost.com/some-other/special/url
  http://myhost.com/any/ordinary/url

I could have dedicated expath webapps named "some" and "some-other".
(I've done this for the time being, just to make progress.) Then within
each of these webapps, there is a servlet association to the desired
component, using a pattern match relative to the webapp root.

But I still want to handle urls with initial path parts like "any",
"any1", "any-other", etc. In other words, the rest of the url space
under http://myhost.com, which, even if I could enumerate it today,
might change tomorrow. These could all be handled by a default component
(until perhaps a need arises to implement some special processing).

It would be cleaner and more flexible in this case to have a single
expath webapp rooted at "", and use servlets to dispatch "special" urls
to specialized components, and let a default url pattern handle the rest
with a generic component.

I can make tomcat use servlex as its default servlet by adding a
Host/Context element in server.xml like so:

  <Context path="" docBase="servlex.war"/>

and adjusting the Host attributes regarding auto-deployment and
unpacking.

But servlex doesn't like a webapp with @root="". It complains that it
doesn't match the WebappsParser.ROOT_RE of "^[-a-zA-Z0-9]+$". I don't
know if this is required by the spec, or if it is a servlex
implementation detail. I can't find the schema definition for
webapps/webapp/@root.

It would be nice if servlex allowed @root="", with the same effect as
tomcat's Context/@path="". Then I could have in .expath-web/webapps.xml:

  <webapp root=""...>

And then in the root application's expath-web.xml:

  <servlet name="some-other-servlet">
    <!-- associate to some-other component -->
    <match url="/some-other/"/>
  </servlet>
  <servlet name="some-servlet">
    <!-- associate to some component -->
    <match url= "/some/"/>
  </servlet>
  <servlet name="default">
    <!-- associate to a default component -->
    <match url="/">
  </servlet>

I am going to try to compile and run servlex with a modified
WebappsParser.ROOT_RE (to change "+" to "*") and see if it works. I
haven't looked into the code far enough to see if it will cause any
other problems. Worst case, maybe some urls with "//" to start the path
part.

Thanks for your attention to this.

Regards,
--Paul

> 
>   Regards,
> 

Received on Sunday, 22 February 2015 20:40:21 UTC