Why Tomcat/Jetty can not find my web app services?

73 views
Skip to first unread message

Haitao

unread,
Jul 29, 2011, 6:26:57 PM7/29/11
to google-guice
Hi,

I am very new to Guice, so please help me out on this one. I developed
a web app with Guice injection, and deploy the war file to a Tomcat 6
server (tried Jetty as well,same error). The WAR file is called
myservice.war.

For some reasons,

http://<tomcat/jetty host>:8080/myservice/

works, but

http://<tomcat/jetty host>:8080/myservice/user-service/test

gave me 404 error. I checked my web.xml etc., could not identify any
obvious problem. Hope I can get some help here.

-------------- Web.xml---------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:sch
emaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>myservice</display-name>

<listener>
<listener-class>myservice.ServletListener</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>

</web-app>
-------------------------------------

My code looks like
--------------------ServiceResource------------
public class ServiceResource {
/**
* @return hardcoded string
*/
@GET
@Produces("text/plain")
public final String toString() {
return "Service";
}
}
-------------------- UserService------------
@Path("/user-service")
public class UserService
{
protected static Injector injector;

@GET
@Path("/test")
public final String toString()
{
return "My service - user service";
}
}
--------------------------

My bindings looks like
-------------------------
public static class RestModule extends JerseyServletModule {

@Override
protected void configureServlets() {
/*
* REST Stuff
*/
bind(ServiceResource.class);
:
bind(UserService.class);

/*
* Override Jersey Settings here
*/
final Map<String, String> params = new HashMap<String,
String>();
// ensure WADL generation
params.put("com.sun.jersey.config.feature.DisableWADL",
"false");

serve("/*").with(GuiceContainer.class,params);
}
}
---------------------------

Any help or pointer would be highly appreciated!

Thanks

Haitao

transmeta01

unread,
Nov 7, 2012, 9:48:10 AM11/7/12
to google...@googlegroups.com
try: serve("/rest/*").with(GuiceContainer.class,params); 
Reply all
Reply to author
Forward
0 new messages