I am trying, using Jersey & Google Guice 3.0, to map 2 different URL
patterns to the same servlet and each of these URL patterns to be applied
to a different package in my project.
To be clear I am pasting part of the code below and I will also explain.
*web.xml*
<listener>
<listener-class>com.abc.web.listeners.GuiceContextListener</listener-class>
</listener>
<filter>
<filter-name>guiceFilter</filter-name>
<filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>guiceFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
*GuiceContextListener*
public final class GuiceContextListener extends GuiceServletContextListener
{
...
private JerseyServletModule getJerseyServletModule() {
JerseyServletModule jerseyModule = new JerseyServletModule() {
@Override
protected void configureServlets() {
filter("/*").through(WebServerStateFilter.class);
final Map<String, String> params = new HashMap<String,
String>();
StringBuilder sb = new StringBuilder();
sb.append(*"com.abc.web.stats.services"*);
params.put(PackagesResourceConfig.PROPERTY_PACKAGES,
sb.toString());
serve(*"/api/v1/*"*).with(GuiceContainer.class, params);
final Map<String, String> params1 = new HashMap<String,
String>();
StringBuilder sb1 = new StringBuilder();
sb1.append(*"com.abc.web.stats.otherservices"*);
params1.put(PackagesResourceConfig.PROPERTY_PACKAGES,
sb1.toString());
serve(*"/api/*"*).with(GuiceContainer.class, params1);
}
}
}
...
}
So basically I want:
URLs starting with *"/api/v1/*"* to be handled through servlet
GuiceContainer by services in package *"com.abc.web.stats.services"*
URLs starting with *"/api/*"* to be handled through same servlet
GuiceContainer by services in package *"com.abc.web.stats.otherservices"*
I used the code above but it does not seem to work, it seems that only the
first "serve" call is taken into consideration so in this case only URLs
matching "/api/v1/*" are served. I do not want to hardcode "v1" in my
services since the version might change (to "v2") in the future.
Can somebody help me out?
Thanks, Paul
--
You received this message because you are subscribed to the Google Groups
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/google-guice?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.