I have this web.xml
, don't want a suffix for the url-pattern
so I'm using a /*
pattern:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<servlet>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
This is my RestVersion.java
class that I want to manage the root requests:
import javax.ejb.EJB;
import javax.ws.rs.Path;
@Path("/")
public class RestVersion implements IRestVersion{
@EJB
private VersionBean versionBean;
@Override
public VersionInfo version() {
return versionBean.getVersion();
}
}
Where IRestVersion.java
is the following:
import javax.ejb.Local;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
@Local
public interface IRestVersion {
@GET
@Path("/")
@Produces(MediaType.APPLICATION_JSON)
public VersionInfo version();
}
The problem is that any other path is intercepted by this RestVersion class, like this:
http://localhost:8080/
---> it answers correctly with the RestVersion.version() jsonhttp://localhost:8080/asd
---> it is intercepted always by RestVersion but I would like to manage this on another class which will have a@Path("/asd")
on top (but in this moment I cannot with this configuration)
How can I intercept just the project root without compromising all the other paths?