EJB Services Sample Guide

Introduction

EJB Services feature in WSO2 Application Server to expose an externally deployed J2EE compliant Enterprise Java Beans (EJB) application as a web service. So an existing EJB service can be exposed as a SOA web service and this service will also be eligible for the fill advantages of WSO2 carbon features such as security, throttling, caching, etc. In the sample EJB library system is implemented. Its build as a java enterprise archive (ear) ans needs to be deployed in an external J2EE compliant application server. Then the library system cam be exposed as a WS via WSO2 Application Server. The sample is based on EJB 3.x.

Building the Sample

Sample contains the following items.

            |-- build.xml ant build file
            |-- ejb/ module for creating the EJB jar archive and java sources bundle
            `-- ear/ module for creating the enterprise application archive
        

If you are using windows get a command line shell,

go to, CARBON_HOME\samples\EJBLibrary\
            then run, \EJBLibrary\> ant

If in linux from console,

go to CARBON_HOME/samples/EJBLibrary/
            and run, /EJBLibrary$ ant

Now all the resources for the sample are built. Required resources for the sample are following,

  • EJBLibrary/ejb/target/library.jar - jar archive containing ejb sources
  • EJBLibrary/ear/target/library.ear - enterprise application archive

Running the sample

To deploy and run the sample follow the instruction below.

Deploy the Enterprise Application Archive

Deploy the ear archive (library.ear) in a J2EE compliant application server.

eg: jboss, glassfish, bea weblogic, apache gerenimo

Exposing the deployed EJB application as a web service

This needs to be configured via the WSO2 Application Server's ejb-services UI.

  1. Adding the clients jars of the external application server into WSO2 Application Server. Client jar(s) should be copied into CARBON_HOME/repository/components/lib

    eg: If the EJB is deployed in,

    • jboss application server -> copy jbossall-client.jar into,
      CARBON_HOME/repository/components/lib
    • glassfish application server -> copy the gf-client.jar into,
      CARBON_HOME/repository/components/lib

    Also add EJBLibrary/ejb/target/library.jar into CARBON_HOME/lib

  2. create the ejb-service via WSO2 Application Server console
    • go to Manage > WebServices > EJB Service
    • Add a new application server type or use an existing if you have already defined.
    • Click next
    • upload the library.jar and click next
    • Provide the EJB details.
                              Remote Interface : org.wso2.appserver.samples.ejb.LibraryManager
                              Bean JNDI Name : LibraryManager (Please use the correct JNDI name is
                              its different from the given value)
    • Click "Deploy Service"

Now the ejb-service would be created and deployed. For more information on using the ejb-services UI, please refer to ejb-services userguide.

Testing the created ejb-service

If the created ejb-service is successfully deployed it will be shown under web services listing in the WSO2 Application Server.

go to Manage > Web Services > List and you will be able to see the deployed ejb-service (library). Click on the service and it will show the service dashboard. Now click try-it and the try-it page for the service open. This can be used to invoke the ejb-service and hence EJB service deployed in the external application server.

Important

  • For some application servers their client jar is a empty jar wchich is referring to a collection of jars through manifest references. Since these references are relative and we need to copy the client jars in to WSO2 Application Server, just copying these empty client jars wouldn't work. [1] describes a way how you can bundle all these referred jars into one bundle.
  • Some of the packages in external application server's client jar(s) may clash with the existing packages in WSO2 Application Server's classpath. This might lead to class loading issues. So users may need to remove those conflicting packages from client jars for the ejb-service to function properly.