I'm trying to expose some EJBs as REST web service using JAX-RS annotations. When I deploy war
file containing EJB Jar in WEB-INF/lib
to Wildfly 8, I can see in web admin panel EJB Jar as deployed, But I cannot reach REST endpoints and get 404.
This is content of web.xml
:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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-mapping>
<servlet-name>javax.ws.rs.core.Application</servlet-name>
<url-pattern>/separated/*</url-pattern>
</servlet-mapping>
</web-app>
This is a sample session bean I'm trying to serve as web service and put in jar
file:
@Stateless(name = "TestSessionEJB")
@LocalBean
public class TestSessionBean {
@PersistenceContext(unitName = "TestPU")
private EntityManager em;
public AuthenticationSessionBean() {
}
@GET
@Path("ep")
public String testEP() {
return "Hello from testEP()";
}
}
I cannot reach testEP
through /<war_file_name>/separated/ep
. Added ejb-jar.xml
descriptor to WEB-INF/
, still no success. I made another service with classes compiled and deployed directly in war
file's WEB-INF/classes
:
@ApplicationPath("/integrated")
public class TestRestApp extends Application {
}
@Path("/ep")
public class TestRestEp {
@GET
public String doGet() {
return "success";
}
}
Here I can reach doGet()
through /<war_file_name>/integrated/ep
.
Am I missing something? Can I deploy EJBs as separated jar
files and expose them as REST web services with no wrapper?
UPDATE:
I annotated TestSessionBean
with ApplicationPath("separated")
and made it extending from javax.ws.rs.Application
. Still getting 404 but this time It's different; 404 without "Not Found" body. If I make an endpoint path same as an endpoint in TestRestApp
, e.g @Path("ep")
It maps to endpoint in TestRestApp
and I get "success" instead of "Hello from testEP()" by navigating to /<war_file_name>/separated/ep
. If I annotate a method in TestSessionBean
with a path not defined in TestRestApp
result is 404. I cleared my web.xml
out of servlet definitions and still same result.