Reputation: 831
I have a problem deploying a RESTful web application (JAX-RS) on JBoss 7.1 This is the web.xml
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
id="WebApp_ID" version="3.0">
<display-name>HEODWS</display-name>
<servlet>
<servlet-name>Resteasy</servlet-name>
<servlet-class>org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Resteasy</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>it.heod.ws.WSApplication</param-value>
</context-param>
<listener>
<listener-class>org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap</listener-class>
</listener>
While the class implementing the web service is:
@Path("/")
public class LoginService {
public LoginService() {
}
@GET
@Path("helloworld")
@Produces(MediaType.TEXT_PLAIN)
public Response helloWorld() {
Utils utils = Utils.getInstance();
utils.logExecutingMethod();
ResponseBuilder responseBuilder = null;
Response response = null;
responseBuilder = Response.ok();
responseBuilder.entity("Hello, world!");
response = utils.completeResponse(responseBuilder);
return (response);
}
}
The class WSApplication is:
public class WSApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
public WSApplication(){
singletons.add(new LoginService());
}
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
Now, if I deploy the WAR file on my local copy of JBoss 7.1 and I go to
http://localhost:8080/HEODWS/helloworld
the service behaves correctly and I get the desired response, while if I deploy it on another server, running JBoss 7.1, and I go to
http://anotherhost:8080/HEODWS/helloworld
I get a 404 not found.
Can anybody understand why, i.e. what is the difference between the two servers? Maybe I have configured (in the past) my local server in such a way that I can't recall now?
Thanks a lot in advance, Gianluca
Upvotes: 0
Views: 1342
Reputation: 831
I actually didn't know what happened, but by copying and pasting all the classes and the web.xml in a new project and deploying, it worked. I suppose it was just Eclipse that went crazy. Thanks everyone for the answers.
Upvotes: 0
Reputation: 1600
JBoss AS 7.1 provides you with Java EE 6 support, so you don't need to use the servlet dispatcher provided by RESTEasy (it's only necessary if you deploy on Tomcat or Jetty).
Then, you can remove the content from web.xml and declare your JAX-RS Activator in a pure Java form like this:
@ApplicationPath("/")
public class WSApplication extends Application {
private Set<Object> singletons = new HashSet<Object>();
private Set<Class<?>> empty = new HashSet<Class<?>>();
public WSApplication(){
singletons.add(new LoginService());
}
@Override
public Set<Class<?>> getClasses() {
return empty;
}
@Override
public Set<Object> getSingletons() {
return singletons;
}
}
You can even remove all the methods and fields in your WSApplication
class (ie, just have an empty subclass of javax.ws.rs.core.Application
) and annotate your LoginService
class with @RequestScoped
(or @Stateless
).
HTH. Xavier
Upvotes: 1