Here is the source code for the AllTypes bean. It's actually supposed to be
the same as the one that jboss distribution is bundled with.

package org.jboss.zol.testbean2.bean;

import java.rmi.*;
import javax.ejb.*;
import java.util.Collection;
import java.util.ArrayList;

import org.jboss.zol.testbean.interfaces.StatefulSession;
import org.jboss.zol.testbean.interfaces.StatefulSessionHome;
import org.jboss.zol.testbean.interfaces.StatelessSession;
import org.jboss.zol.testbean.interfaces.StatelessSessionHome;
import org.jboss.zol.testbean.interfaces.EnterpriseEntity;
import org.jboss.zol.testbean.interfaces.EnterpriseEntityHome;
import javax.naming.Context;
import javax.naming.InitialContext;
import java.sql.Date;
import java.sql.Timestamp;
import org.jboss.zol.testbean2.interfaces.MyObject;


public class AllTypesBean implements EntityBean {
    public boolean aBoolean;
 public byte aByte;
 public short aShort;
    public int anInt;
    public long aLong;
 public float aFloat;
 public double aDouble;
//    public char aChar;
    public String aString;
    public Date aDate;
 public Timestamp aTimestamp;

 public MyObject anObject;

    public StatefulSession statefulSession;
    public StatelessSession statelessSession;
    public EnterpriseEntity enterpriseEntity;

 public Collection aList;

 private EntityContext entityContext;


    public String ejbCreate(String pk) throws RemoteException,
CreateException {
  return ejbCreate(true, (byte)1, (short)2, (int)3, (long)4, (float)5.6,
   (double)7.8, /*'9',*/ pk, new Date(System.currentTimeMillis()),
      new Timestamp(System.currentTimeMillis()), new MyObject());
 }

    public void ejbPostCreate(String pk)
  throws RemoteException, CreateException {}


    public String ejbCreate(boolean aBoolean, byte aByte, short aShort, int
anInt,
  long aLong, float aFloat, double aDouble, /*char aChar,*/ String aString,
  Date aDate, Timestamp aTimestamp, MyObject anObject )

  throws RemoteException, CreateException {

        this.aBoolean = aBoolean;
  this.aByte = aByte;
  this.aShort = aShort;
     this.anInt = anInt;
  this.aLong = aLong;
  this.aFloat = aFloat;
  this.aDouble = aDouble;
  this.aChar = aChar;
        this.aString = aString;
  this.aDate = aDate;
  this.aTimestamp = aTimestamp;
  this.anObject = anObject;

  try {
   Context ctx = new InitialContext();

   StatefulSessionHome sfHome =
(StatefulSessionHome)ctx.lookup("java:comp/env/ejb/stateful");
   statefulSession = sfHome.create();

   StatelessSessionHome slHome =
(StatelessSessionHome)ctx.lookup("java:comp/env/ejb/stateless");
   statelessSession = slHome.create();

   EnterpriseEntityHome eeHome =
(EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
   try {
    enterpriseEntity = eeHome.findByPrimaryKey(aString);
   } catch (FinderException e) {
    enterpriseEntity = eeHome.create(aString);
   }

  } catch (Exception e) {
   throw new CreateException(e.getMessage());
  }

  aList = new ArrayList();

        return null;
    }


    public void ejbPostCreate(boolean aBoolean, byte aByte, short aShort,
int anInt,
  long aLong, float aFloat, double aDouble, /*char aChar,*/ String aString,
  Date aDate, Timestamp aTimestamp, MyObject anObject )

  throws RemoteException, CreateException {}

    public void ejbActivate() throws RemoteException {}

    public void ejbLoad() throws RemoteException {}

    public void ejbPassivate() throws RemoteException {}

    public void ejbRemove() throws RemoteException, RemoveException {}

    public void ejbStore() throws RemoteException {}


    public void setEntityContext(EntityContext context) throws
RemoteException {
        entityContext = context;
    }

    public void unsetEntityContext() throws RemoteException {
        entityContext = null;
    }


 public String callBusinessMethodA() throws RemoteException {
  // test external ejb-ref in testbeans.jar
  return statefulSession.callBusinessMethodA();
 }



    public void updateAllValues(boolean aBoolean, byte aByte, short aShort,
int anInt,
  long aLong, float aFloat, double aDouble, /*char aChar,*/ String aString,
  Date aDate, Timestamp aTimestamp, MyObject anObject ) {

        this.aBoolean = aBoolean;
  this.aByte = aByte;
  this.aShort = aShort;
     this.anInt = anInt;
  this.aLong = aLong;
  this.aFloat = aFloat;
  this.aDouble = aDouble;
  file://this.aChar = aChar;
        this.aString = aString;
  this.aDate = aDate;
  this.aTimestamp = aTimestamp;
  this.anObject = anObject;

  try {
   Context ctx = new InitialContext();

   EnterpriseEntityHome eeHome =
(EnterpriseEntityHome)ctx.lookup("java:comp/env/ejb/entity");
   try {
    enterpriseEntity = eeHome.findByPrimaryKey(aString);
   } catch (FinderException e) {
    enterpriseEntity = eeHome.create(aString);
   }

  } catch (Exception e) {
         // ignore
  }

    }

 public void addObjectToList(Object anObject) throws RemoteException {
  aList.add(anObject);
 }

 public void removeObjectFromList(Object anObject) throws RemoteException {
  aList.remove(anObject);
 }

    public Collection getObjectList() throws RemoteException { return
aList; }

 public boolean getBoolean() throws RemoteException { return aBoolean; }
    public byte getByte() throws RemoteException { return aByte; }
 public short getShort() throws RemoteException { return aShort; }
 public int getInt() throws RemoteException { return anInt; }
 public long getLong() throws RemoteException { return aLong; }
 public float getFloat() throws RemoteException { return aFloat; }
 public double getDouble() throws RemoteException { return aDouble; }
 public char getChar() throws RemoteException { return aChar; }
 public String getString() throws RemoteException { return aString; }
 public Date getDate() throws RemoteException { return aDate; }
 public Timestamp getTimestamp() throws RemoteException { return
aTimestamp; }

 public MyObject getObject() throws RemoteException { return anObject; }

 public Handle getStateful() throws RemoteException

  return statefulSession.getHandle();
 }

 public Handle getStateless() throws RemoteException {
  return statelessSession.getHandle();
 }

 public Handle getEntity() throws RemoteException {
  return enterpriseEntity.getHandle();
 }


}

Another piece of code that doesn't work for the same reason I suppose is:
package org.jboss.zol.accountmanager.bean;

/*
 * Class org.jboss.zol.accountmanager.bean.AccountManagerBean;
 * Copyright (C) 2000  Juha Lindfors
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
USA.
 *
 * This package and its source code is available at www.jboss.org
 * $Id: AccountManagerBean.java,v 1.1.1.1 2000/04/27 19:45:34 juha Exp $
 *
 * You can reach the author by sending email to [EMAIL PROTECTED].
 */

// standard imports
import javax.ejb.*;
import javax.rmi.*;
import java.rmi.*;
import javax.naming.*;
import java.util.*;

// non-standard class dependencies
import org.jboss.zol.account.interfaces.AccountHome;
import org.jboss.zol.account.interfaces.Account;
import org.jboss.zol.account.interfaces.InvalidLoginException;


/**
 * AccountManager stateless session bean implementation. This bean acts
 * as a mediator between the client and the Account entity bean.
 *
 * For more detailed documentation, refer to the
 * <a href=""> << INSERT DOC LINK HERE >> </a>
 *
 * @see     << OTHER RELATED CLASSES >>
 *
 * @author  Juha Lindfors
 * @version $Revision: 1.1.1.1 $
 * @since   JDK 1.2
 */
public class AccountManagerBean implements SessionBean {

    private final static String ACCOUNT_REF =
            "Account";


    public void login(String name, String passwd) throws
InvalidLoginException {

        try {
            AccountHome home = getAccountHome();
            Account account  = home.findByPrimaryKey(name);
            account.validateLogin(name, passwd);
        }
        catch (FinderException e) {
            throw new InvalidLoginException("Account not found: " +
e.getMessage());
        }
        catch (NamingException e) {
            throw new InvalidLoginException("Account bean not found: " +
e.getMessage());
        }
        catch (RemoteException e) {
            throw new InvalidLoginException("Yeah this was it, Juha you
dumbass" + e.getMessage());
        }
    }

    public void createAccount(String name, String passwd) throws
                                                          CreateException {

        try {
            AccountHome home = getAccountHome();
            home.create(name, passwd);
        }
        catch (NamingException e) {
            throw new CreateException("Account bean not found: " +
e.getMessage());
        }
        catch (RemoteException e) {
            throw new CreateException("Yeah I need EJB for dummies edition:
" + e.getMessage());
        }

    }

    private AccountHome getAccountHome() throws NamingException {
 System.out.println("Trying to get account home...");
        Context root = new InitialContext();
 System.out.println("Got initial context!");

file://***************** please note -it did not work neither this::*************
       file://Object  obj  = root.lookup("java:comp/env/" + ACCOUNT_REF);
// ***************** nor this way :
        Object  obj  = root.lookup(ACCOUNT_REF);
        System.out.println("Got an object reference...");
        Object  ref  = PortableRemoteObject.narrow(obj,
AccountHome.class);// an exception is thrown here - see the server trace
below
     System.out.println("Object reference narrowed successfully!");
        /*
         * [TODO] handle ClassCastException of narrow
         */
        return (AccountHome)ref;
    }

    public void ejbCreate() throws CreateException {};
    public void ejbRemove() {}
    public void ejbActivate() {}
    public void ejbPassivate() {}
    public void setSessionContext(SessionContext sc) {}
}

As you know at some point in it's business life the AccountManager bean is
trying to 'talk' to the 'Account' bean for which reason it's trying to get
the AccountHome and it's using the private AccountHome getAccountHome()
throws NamingException
function for this.
As you've probably noticed I added some comments in this function, except
this everything else is untouched from the original source code (including
the client source code).
I managed to deploy the AccountManager and the Account home and remote
interfaces as well as the beans themselves.
The server output is as follows:

[Container factory] Deploying:file:/S:/Program
Files/jboss/jBoss20/deploy/seb.ja
r
[Container factory] S:\Program Files\jboss\jBoss20\tmp\deploy
[Container factory] Loading ejb-jar.xml : jar:file:/S:/Program
Files/jboss/jBoss
20/tmp/deploy/tmpejbjar30889.jar!/META-INF/ejb-jar.xml
[Container factory] Loading standardjboss.xml : jar:file:/S:/Program
Files/jboss
/jBoss20/lib/ext/jboss.jar!/org/jboss/metadata/standardjboss.xml
[Verifier] Verifying file:/S:/Program
Files/jboss/jBoss20/tmp/deploy/tmpejbjar30
889.jar
[Verifier] Account: Verified.
[Verifier] AccountManager: Verified.
[Container factory] Deploying Account
[Container factory] Container Invoker Optimize='false'
[Container factory] Deploying AccountManager
[Container factory] Container Invoker Optimize='false'
[Container factory] Binding an EJBReference Account
[Container factory] Binding Account to internal JNDI source: Account
[JAWS] Initializing JAWS plugin for Account
[JAWS] Loading standardjaws.xml : jar:file:/S:/Program
Files/jboss/jBoss20/lib/e
xt/jboss.jar!/org/jboss/ejb/plugins/jaws/metadata/standardjaws.xml
[Container factory] Table 'Account' already exists!
[Container factory] Bound AccountManager to AccountManager
[Container factory] Bound Account to Account
[Container factory] Deployed application: file:/S:/Program
Files/jboss/jBoss20/d
eploy/seb.jar
[Default] JRMPCI:invokeHome create
[Default] Tx is null
[AccountManager] TX_REQUIRED for create
[AccountManager] begin tx
[AccountManager] commit tx 0
[AccountManager] TX_REQUIRED for login
[AccountManager] begin tx
[AccountManager] Trying to get account home...
[AccountManager] Got initial context!
[AccountManager] commit tx 1
[AccountManager] Account bean not found: null

If you need some more information please let me now :)
Regards,
Kamen.

----- Original Message -----
From: "Aaron Mulder" <[EMAIL PROTECTED]>
To: "Kamen" <[EMAIL PROTECTED]>
Sent: Monday, September 25, 2000 12:43 PM
Subject: Re: EJB-ref problem


> On Mon, 25 Sep 2000, Kamen wrote:
> > Ok - sorry for skipping the mailing list - I'm new to the 'mailing lists
> > system'.
> > Please accept my appologies :)
> > I'll send you the bean source code ASAP.
> > Best regards,
> > Kamen
>
> No problem.  It's just that it doesn't help anyone else if we talk
> about it privately, and then we have to do it again if anyone else has the
> same issue.
>
> Aaron
>
>

Reply via email to