users@jersey.java.net

[Jersey] Multi-tenancy implementation with Jersey

From: Maciek <studio.mave_at_gmail.com>
Date: Mon, 20 Jun 2011 21:43:18 +0200

Hi,

we are developing a web application that uses Jersey as a JAX-RS
implementation. At the moment one of our requirements is to introduce
a multi-tenancy into the application. Since we don't have full control
over the domain we have decided to "namespace" the application. Just
as an example: assuming that to this point some page is reachable at
"http://domain.com/search.html", after the introduction of the
multi-tenancy the same page is going to be at
"http://domain.com/{namespace}/search.html".

We have created the javax.servlet.Filter that wraps the
javax.servlet.http.HttpServletRequest and strips the first "directory"
in the path - the namespace. Both getServletPath() and getRequestURI()
methods return the modified values. We thought that this way the whole
application should work correctly without changes and only few DAOs
will have to honor the namespace of the request.

With such a filter the static content is served correctly, JAX-RS
resource matching also works without problems. The problem is with the
URIs that the services generate inside theirs outputs using
javax.ws.rs.core.UriInfo - they don't contain the namespace part. Of
course we could have modify all our root resource classes, so that
they ignore the namespace in the path, but we prefer a more generic
solution. Do you have any hints how to solve the above problem?

Thanks