• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Exposing EJB as Webservice...

 
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 198
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 Tilak
Ranch Hand
Posts: 157
2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Peer Reynders
Bartender
Posts: 2968
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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 ]
     
    Well THAT's new! Comfort me, reliable tiny ad:
    Gift giving made easy with the permaculture playing cards
    https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
    reply
      Bookmark Topic Watch Topic
    • New Topic