Using: Jersey 1.19, TomEE Plus 1.74 I can access the same controller method via two different urls.
http://localhost:8080/hello
http://localhost:8080/rest/hello
web.xml:
<init-param>
<param-name>
com.sun.jersey.config.property.packages
</param-name>
<paramvalue>
mif.ubermensch.labanorogiraite.presentation.controllers
</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>LabanoroGiraite</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
Controller:
@Path("/hello")
public class HelloController {
@GET
@Produces("text/plain")
public String Hello(){
return "Hello, Restful world!";
}
}
Additions were made to TomEE system.properties based on result found on stackoverfow
openejb.api.javax.ws.rs.Path.validation=false
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
Without these two, accessing a url with the /rest/ prefix would cause an excepion:
javax.naming.NameNotFoundException: Name [com] is not bound in this Context. Unable to find [com].
How to restrict the access only through the /api/* url-pattern ?
you don't mention which flavor of tomee you are using but if a distribution providing jaxrs (-jaxrs or -plus) you will need to add disabled=true in conf/conf.d/cxf-rs.properties.