Differences between revisions 1 and 2
Revision 1 as of 2005-01-12 02:44:18
Size: 6806
Editor: proxy35
Comment: Importing old wiki ...
Revision 2 as of 2009-09-20 22:48:40
Size: 6806
Editor: localhost
Comment: converted to 1.6 markup
No differences found!

How to deploy a EJB as a Web Service on Axis by John Mammen (john_mammen@yahoo.com)

In this `how to', there are four classes involved, three EJB related classes and one details class.

Lets call this bean Rates Bean. In brief, the functionality of this bean is to obtain rate details of a currency when an three digit currency code is passed.

The four Classes are Rates.java, the remote bean, RatesBean.java, implementation bean, RatesHome.java home and RatesDetails return class for rate details.

Below are excerpts of xml deployment descriptors and Java code for Rates bean for Weblogic deployment, which can used for reference.

Note: None of the below excerpts are complete. Only required details are shown.

Rates.java ( This is the EJB Remote class )

  public interface Rates extends EJBObject {

  public RatesDetails getRateDetails(String currencyCode) throws

RateDetails.java (This is the class returned by remote EJB Call)


  public class RatesDetails implements Serializable{

  private String isoCode;
  private String vaildFrom;
  private String vaildTo;
  private double retailBuy;
  private double retailMid;
  private double retailSell;
  private double wholesaleBuy;
  private double wholesaleMid;
  private double wholesaleSell;
  private int rateType;
  public RatesDetails() {
  // setters and getters are defined but left out here


      <description>Datasource for Rates DB</description>



Assuming similar classes as described above and successfully deployed to your container, we can start the deployment of web services.

1. First make sure you have successfully deployed your EJB to your EJB Container.

2. Then install and configure Axis 1.0 with your J2EE application server.

3. Test the Axis deployment by clicking on the validate of Axis installation page.

4. Create a rates.wsdd in notepad as shown below. The below example corresponds to the above beans described. Please make note of the bolded text. Also make sure your class names should include the packages if in packages. For example: if your RatesHome was in package com.mycompany, then your home interface name is com.mycompany.RatesHome

  <?xml version="1.0" encoding="UTF-8"?>
  <deployment xmlns="http://xml.apache.org/axis/wsdd/"
    <service name="RateDetails" provider="java:EJB">
      <parameter name="beanJndiName" value="jndi.Rates" />
      <parameter name="homeInterfaceName" value="RatesHome" />
      <parameter name="remoteInterfaceName" value="Rates" />
      <parameter name="allowedMethods" value="getRateDetails" />
      <parameter name="className" value="RatesBean" />
      <parameter name="jndiURL" value="t3://localhost:7001" />
      <parameter name="jndiContextClass" value="weblogic.jndi.WLInitialContextFactory" />
      <typeMapping xmlns:ns="http://soapinterop.org/xsd" qname="ns:RatesDetails"
         type="java:RatesDetails" serializer="org.apache.axis.encoding.ser.BeanSerializerFactory"

5. Now deploy your rates.wsdd by issuing the command:

java org.apache.axis.client.AdminClient -lhttp://localhost:7001/axis/services/ejbservice rates.wsdd

6. If successfully deployed, you will not get any error message. If there are any errors, the console will display the errors. Also take a look at your EJB Container's console for any errors.

7. Now test your web service in the browser url: http://localhost:7001/axis/services/RateDetails?method=getRateDetails&value=USD

If deployment was successful, you should get something like this.

Axis Reply XML

  <?xml version="1.0" encoding="UTF-8"?>
  <soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
        <geRateDetailsReturn href="#id0"/>
      <multiRef id="id0" soapenc:root="0"
        <rateType xsi:type="xsd:int">0</rateType>
        <wholesaleSell xsi:type="xsd:double">1.0</wholesaleSell>
        <retailSell xsi:type="xsd:double">1.0</retailSell>
        <retailMid xsi:type="xsd:double">1.0</retailMid>
        <wholesaleMid xsi:type="xsd:double">1.0</wholesaleMid>
        <validTo xsi:type="xsd:string" xsi:nil="true"/>
        <validFrom xsi:type="xsd:string" xsi:nil="true"/>
        <isoCode xsi:type="xsd:string" xsi:nil="true"/>
        <retailBuy xsi:type="xsd:double">1.0</retailBuy>
        <wholesaleBuy xsi:type="xsd:double">1.0</wholesaleBuy>

--- Question 01.16.03 07:02p EST Can the EJBProvider be asked to connect using a given SECURITY_PRINCIPAL? That is, if the web service caller provides a security user/pwd pair, what's recommended for placing this into the EJBContext on the server side?

FrontPage/Axis/EJBinAxis (last edited 2009-09-20 22:48:40 by localhost)