aspose file tools*
The moose likes Web Services and the fly likes Exposing EJB as Webservice... Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Exposing EJB as Webservice..." Watch "Exposing EJB as Webservice..." New topic
Author

Exposing EJB as Webservice...

Bala Gangadhar
Ranch Hand

Joined: Oct 07, 2008
Posts: 87
    
    1
Hi All,
I am going through a online tutorial for exposing stateless session bean as a webservice. It simply deployed a ejb and write a client program which has a method called callEJB() and exposed that method as webservice.

It is very similar to exposing a normal java bean method as webservice. Is not it?. Is this correct way to expose our EJB as webservice (just exposing ejb client code).

Regards,
Bala
Vinod K Singh
Ranch Hand

Joined: Sep 30, 2008
Posts: 198
If you use EJB Client to invoke your EJB method, which is exposed as web service then communication between client and server will be using RMI not SOAP over HTTP.


My Blog
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Bala Gangadhar:
It simply deployed a ejb and write a client program which has a method called callEJB() and exposed that method as webservice.


The way you describe it here sounds like the EJB client is the web service - in effect it is transforming the web service method call to an EJB call. The indirection is not always necessary. An application server (starting with J2EE 1.4) should be capable exposing a stateless session bean directly to a web service client (not an EJB client).

SLSB--(WSDL) <-- web service client (1)

That being said there are situations where the "intermediate client scenario" can bring an advantage

SLSB--(EJB) <-- ejb client--(WSDL) <-- web service client (2)

In scenario (1) the web service contract (WSDL) is autogenerated by the application server from the interface of the SLSB. Though most servers will offer some features to coerce the service contract characteristics in some way, sometimes the resulting auto-generated contract could exhibit characteristics that make it difficult for non-Java web service clients to consume the resulting web service. In that case the intermediate [ejb client--(WSDL)] gives you full control over the web service contract. So scenario (2) has to be used if you need to build the web service contract first. The intermediate client then has characteristics of a Proxy and a Fa�ade.


EJB 2.1 Web Services (Part 1): JAX-RPC and the endpoint interface
Developing web services using EJB 3.0
Bala Gangadhar
Ranch Hand

Joined: Oct 07, 2008
Posts: 87
    
    1
Thanks a lot Reynders.
Eventhough I could not frame the question correctly, you have given the correct explanation.

SLSB--(WSDL) <-- web service client (1)

I have used AXIS to expose a simple java bean method as webservice.
Can we implment the above scenario(1) using AXIS?
[ December 15, 2008: Message edited by: Bala Gangadhar ]
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
Originally posted by Bala Gangadhar:
Can we implement the above scenario(1) using AXIS?


No.

Axis is a SOAP web service statck that is implemented as a servlet to be run in a servlet container like Tomcat or Jetty - for the EJB you also need an EJB container. In the early days Axis was sometimes used in combination JBoss (to supply the EJB container). Nowadays there is JBossWS for web service integration on JBoss.

Netbeans 5.5: JAX-WS Web Service Tutorial for JBoss
[ December 16, 2008: Message edited by: Peer Reynders ]
Gautam Tiwari
Greenhorn

Joined: Dec 11, 2008
Posts: 3
Originally posted by Bala Gangadhar:
Thanks a lot Reynders.
Eventhough I could not frame the question correctly, you have given the correct explanation.


I have used AXIS to expose a simple java bean method as webservice.
Can we implment the above scenario(1) using AXIS?

[ December 15, 2008: Message edited by: Bala Gangadhar ]


Well it is quite possible to deploy your ejb as a webservice. All you will need in addition is a web module, say a web project in an IDE. The web module will not contain anything else but a ejb link to the ejb you want to expose as a web service. This is also taken care of, usually, by the IDE like those provided by IBM.
what actually happens in this case is that the web module actually acts as webservice or better so a Router which routes the SOAP request to ejb.
However the actual development of this web service will depend on the IDE and the runtime being used.

If any one has any idea how we can incorporate this without an IDE, as I have been doing this since long using RAD or WSAD with both AXIS and Websphere runtimes, please do update me too... thanks in advance


Gautam
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2922
    
    5
If any one has any idea how we can incorporate this without an IDE.


The specifications are pretty clear on what has to be done to make all the pieces fit together. However there are always gaps in the specifications for the vendors left to fill which is where the tools come in. However in many cases those tools are also available via command line, Ant tasks, etc, so it becomes a matter of where to look. Here we're talking about Axis 1.x which uses JAX-RPC (as does WS 5 & 6). According to the specs you need:

  • An endpoint interface which extends java.rmi.Remote. This interface lists all the java methods that are supposed to be exposed as web methods
  • A SLSB implementing javax.ejb.SessionBean. The SLSB has to have methods that match those in the endpoint interface - but it doesn't actually extend the endpoint interface.
  • In the ejb-jar.xml you have to set up the stateless session bean's "ejb-name", "service-endpoint" (endpoint interface), and "ejb-class" (implementing SLSB)
  • In the webservices.xml you set up the SLSB in the "port-component" element where you specify its "port-component-name" element. You map the SLSB to a port definition in the WSDL (which could require a JAX-RPC mapping file for data type coercion). You repeat the endpoint interface in "service-endpoint-interface" and finally link this "port-component" to the SLSB inside the "service-impl-bean" element through a "ejb-link" to the "ejb-name" that was specified in the ejb-jar.xml.


  • (service provider) ejb-jar.xml excerpt


    (service provider) webservices.xml excerpt


    Apparently in WebSphere an SLSB can be exposed as a web service without the IDE through the EJB2WebService command line tool (in Version 5 this was included in Java2WSDL).

    (Because of the lack of an EJB container none of this will work in plain Axis).
    [ December 17, 2008: Message edited by: Peer Reynders ]
     
    I agree. Here's the link: http://aspose.com/file-tools
     
    subject: Exposing EJB as Webservice...