axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Younsoo" <shaka...@tmax.co.kr>
Subject an expedient way to make a webservice using EJB
Date Thu, 09 May 2002 01:28:20 GMT
  I solved this problem easily. This is my old EJB webservice config.

--------------------------------------------- Old Config --------------------------------------------------
 <service name="MyAccount" provider="java:EJB">
  <parameter name="allowedMethods" value="*"/>
  <parameter name="jndiURL" value="localhost"/>
  <parameter name="scope" value="request"/>
  <parameter name="beanJndiName" value="TestAccount"/>
  <parameter name="homeInterfaceName" value="testaccount.TestAccountHome"/>
 </service>
----------------------------------------------------------------------------------------------------------------

  The beta2 axis can't resolve methods in EJB. so I add "allowedMethods" and "className" parameters.

--------------------------------------------- New Config --------------------------------------------------
 <service name="MyAccount" provider="java:EJB">
  <parameter name="allowedMethods" value="deposit withdraw getBalance getFormattedBalance"/>
  <parameter name="jndiURL" value="localhost"/>
  <parameter name="scope" value="application"/>
  <parameter name="beanJndiName" value="TestAccount"/>
  <parameter name="homeInterfaceName" value="testaccount.TestAccountHome"/>
  <parameter name="className" value="testaccount.TestAccount"/>
 </service>
----------------------------------------------------------------------------------------------------------------

  These are my EJB source code.

----------------------------------------- TestAccount.java -------------------------------------
package testaccount;

import javax.ejb.EJBObject;
import java.rmi.RemoteException;

public interface TestAccount extends EJBObject {
    int deposit (int amount) throws RemoteException;
    int withdraw (int amount) throws RemoteException;
    int getBalance() throws RemoteException;
    String getFormattedBalance() throws RemoteException;
}

----------------------------------------- TestAccountHome.java -------------------------------------
package testaccount;

import java.rmi.RemoteException;
import javax.ejb.CreateException;
import javax.ejb.EJBHome;

public interface TestAccountHome extends EJBHome {
    TestAccount create() throws RemoteException, CreateException;
    TestAccount create(int startingBalance) throws RemoteException, CreateException;
}

----------------------------------------- TestAccountEJB.java -------------------------------------
package testaccount;

import java.rmi.RemoteException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;


public class TestAccountEJB implements SessionBean {

    private int balance = 0;

    public TestAccountEJB() {
    }

    public int deposit (int amount) throws RemoteException {
    balance += amount;   
    return balance;     
    } 

    public int withdraw (int amount) throws RemoteException {
    int withdrawn;  
    
    if (balance >= amount) {
            withdrawn = amount;
    } else {
       withdrawn = balance;
    }
    
    balance -= withdrawn;
    return withdrawn;      
    }

    public int getBalance() throws RemoteException {
    return balance;        
    }

    public String getFormattedBalance() throws RemoteException {
    int wholeBalance = balance/100;  
    int cents = balance % 100 ;  
    
    if (balance >= 0) {
        return new String ("$" + wholeBalance + "." + cents);
    } else {
        return new String ("$" + "(" + wholeBalance + "." + cents + ")");
    }
    }


    public void ejbCreate() throws RemoteException {
    balance = 0;
    }

    public void ejbCreate(int starting) throws RemoteException {
    balance = starting;
    }

    public void setSessionContext(SessionContext sc) {
    }

    public void ejbRemove() throws RemoteException {
    }

    public void ejbActivate() {
    }

    public void ejbPassivate() {
    }
}
Mime
View raw message