Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Exposing EJB method as REST service

Tags:

rest

ejb

In J2EE 6 you can expose your EJB session bean as a REST web service as below

@Stateless
@Path("/test")
public class TestSessionBean {
  @GET
  @Produces("application/xml")
  public String getTest() {
    return "<?xml version='1.0' encoding='UTF-8'?><val>test session bean</val>";
  }
}

This works when I packaged the EJB in the .war, however, when I try to package my project into separate web and ejb modules inside an EAR I get an HTML 404 not found error.

Can someone please explain?

I'm using Glassfish v3

Here is my web.xml

<servlet>
    <servlet-name>TaskRestService</servlet-name>
    <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
  <load-on-startup>1</load-on-startup>


</servlet>
<servlet-mapping>
  <servlet-name>TaskRestService</servlet-name>
<url-pattern>/services/*</url-pattern>
</servlet-mapping>
like image 429
duvo Avatar asked Dec 07 '10 00:12

duvo


People also ask

Is EJB still used 2020?

EJB is still there and growing up. There are many new features (SOAP/RESTful webservice, JPA entities, JAXB...)

Is EJB an API?

WebNMS SNMP for EJB has been designed to support EJB applications, and conform to the EJB standards. The EJB standard restricts the Enterprise Java Bean from performing certain functions, such as socket access.


1 Answers

JAX-RS annotated enterprise beans in a stand-alone or in a separate ejb-jar file that is included in an EAR is not supported.

See below

http://pic.dhe.ibm.com/infocenter/wasinfo/v8r0/index.jsp?topic=%2Fcom.ibm.websphere.nd.iseries.doc%2Finfo%2Fiseriesnd%2Fae%2Ftwbs_jaxrs_ejb_localinterface.html

like image 113
duvo Avatar answered Oct 10 '22 15:10

duvo