As far I know, there isn't no such a default behavior in JEE. This is how I would solve this issue.
Adapt your restful endpoint URL(s) to: (You will need this since the usage of regular exprssion for the
<url-pattern>
tags is very limmited!)@Path( "/user/{site}")
@Path( "/group/{site}")
Create a User and a Group request filter sth. like: (Just pseudo source!!!)
public class UserFilter implements Filter { @Override public void init(FilterConfig filterConfig) throws ServletException { } @Override public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { HttpServletRequest req = null; boolean valid = false; PrintWriter out = null; if (request instanceof HttpServletRequest) { req = (HttpServletRequest) request; // TODO extract site info from url ... // TODO perform check ... // valid = ... } if (valid) { chain.doFilter(request, response); } else { response.setContentType("text/html"); out = response.getWriter(); out.println("<html><head><title>Your specific response</title></head><body>"); out.println("<h2>Sorry, Unknown URL!</h2>"); out.println("</body></html>"); out.close(); } } @Override public void destroy() { }
}
Add your filter in web.xml:
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> ... <filter> <filter-name>User validation fiter</filter-name> <filter-class>path.to.your.UserFilter</filter-class> </filter> <filter-mapping> <filter-name>User validation fiter</filter-name> <url-pattern>/services/user/*</url-pattern> </filter-mapping> <filter> <filter-name>Group validation fiter</filter-name> <filter-class>path.to.your.GroupFilter</filter-class> </filter> <filter-mapping> <filter-name>Group validation fiter</filter-name> <url-pattern>/services/group/*</url-pattern> </filter-mapping> ... </web-app>