I am having an issue with obtaining a reference to a Remote SLSB using the org.springframework.ejb.access.SimpleRemoteStatele ssSessionProxyFactoryBean.
Everytime my Action class attempts to create an instance of the Proxy Bean I recieve a Null Pointer exception... When I use a MockObject in place of the Proxy Bean all works fine so the setup is correct and obtaining the Bean Container is not the issue. Also wondering if this could be an issue with the way JBoss's Class Loading is configured. Pretty sure it is setup to have a Class Loader for both the Servlet and EJB containers (Independent of each other) Included is the following code and XML ::
applicationContext.xml
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans
PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<!-- Spring Proxy Beans to communicate to the EJB container -->
<bean id="userService" class="org.springframework.ejb.access.SimpleRemote StatelessSessionProxyFactoryBean" >
<property name="jndiName" value="ejb/session/User" />
<property name="businessInterface" value="com.kbcomputersolutions.movieapp.business.s ervices.UserService" />
</bean>
<bean id="addressService"
class="org.springframework.ejb.access.SimpleRemote StatelessSessionProxyFactoryBean" >
<property name="jndiName" value="ejb/session/Address" />
<property name="businessInterface" value="com.kbcomputersolutions.movieapp.business.s ervices.AddressService" />
</bean>
<!-- Spring Mock object beans to be used for testing -->
<!--
<bean id="userService" class="com.kbcomputersolutions.movieapp.business.m ock.MockUser" >
</bean>
<bean id="addressService"
class="com.kbcomputersolutions.movieapp.business.m ock.MockAddress" >
</bean>
-->
</beans>
POJI Local and Remote ::
LOCAL ::
/*
* Created on Sep 15, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.kbcomputersolutions.movieapp.business.services ;
import java.util.Collection;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserCreateException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserDeleteException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserRetrieveException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserUpdateException;
import com.kbcomputersolutions.movieapp.business.vo.UserV O;
/**
* @author ksbober
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public interface UserService {
/**
* Create User
* @param users Collection of UserVO objects
* @return ArrayList of Long objects that contain the unique userId primary key(s)
* @throws UserCreateException
*/
public Collection createUsers(Collection users) throws UserCreateException;
/**
* Create a User
* @param user UserVO object
* @return Long object that contains the unique userId primary key
* @throws UserCreateException
*/
public Long createUser(UserVO user) throws UserCreateException;
/**
* Delete the User
* @param userId
* @return
* @throws
*/
public Long deleteUser(Long userId) throws UserDeleteException;
/**
* Retrieve the User
* @param userId
* @return
* @throws UserRetrieveException
*/
public UserVO retrieveUser(Long userId) throws UserRetrieveException;
/**
* Retrieve User Template
* @return
* @throws UserRetrieveException
*/
public Collection retrieveDefaultUsers() throws UserRetrieveException;
/**
* Update the User
* @param oldUser
* @param newUSer
* @return
* @throws UserUpdateException
*/
public UserVO updateUser(UserVO oldUser, UserVO newUser) throws UserUpdateException;
}
REMOTE::
/*
* Created on Sep 15, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.kbcomputersolutions.movieapp.business.services ;
import java.rmi.RemoteException;
import java.util.Collection;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserCreateException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserDeleteException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserRetrieveException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserUpdateException;
import com.kbcomputersolutions.movieapp.business.vo.UserV O;
/**
* @author ksbober
*
* TODO To change the template for this generated type comment go to
* Window - Preferences - Java - Code Style - Code Templates
*/
public interface UserServiceRemote extends java.rmi.Remote {
/**
* Create User
* @param users Collection of UserVO objects
* @return ArrayList of Long objects that contain the unique userId primary key(s)
* @throws UserCreateException
*/
public Collection createUsers(Collection users) throws UserCreateException, RemoteException;
/**
* Create a User
* @param user UserVO object
* @return Long object that contains the unique userId primary key
* @throws UserCreateException
*/
public Long createUser(UserVO user) throws UserCreateException, RemoteException;
/**
* Delete the User
* @param userId
* @return
* @throws
*/
public Long deleteUser(Long userId) throws UserDeleteException, RemoteException;
/**
* Retrieve the User
* @param userId
* @return
* @throws UserRetrieveException
*/
public UserVO retrieveUser(Long userId) throws UserRetrieveException, RemoteException;
/**
* Retrieve User Template
* @return
* @throws UserRetrieveException
*/
public Collection retrieveDefaultUsers() throws UserRetrieveException, RemoteException;
/**
* Update the User
* @param oldUser
* @param newUSer
* @return
* @throws UserUpdateException
*/
public UserVO updateUser(UserVO oldUser, UserVO newUser) throws UserUpdateException, RemoteException;
}
EJB REMOTE INTERFACE ::
/*
* Generated by XDoclet - Do not edit!
*/
package com.kbcomputersolutions.movieapp.business.ejb.inte rfaces;
import com.kbcomputersolutions.movieapp.business.services .UserServiceRemote;
import com.kbcomputersolutions.movieapp.business.vo.UserV O;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserCreateException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserDeleteException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserRetrieveException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserUpdateException;
import java.rmi.RemoteException;
import java.util.Collection;
/**
* Remote interface for User.
*/
public interface User extends javax.ejb.EJBObject, UserServiceRemote {
/**
* Create User
* @param users Collection of UserVO objects
* @return ArrayList of Long objects that contain the unique userId primary key(s)
* @throws RemoteException
*/
public Collection createUsers(Collection users) throws UserCreateException, RemoteException;
/**
* Create a User
* @param user UserVO object
* @return Long object that contains the unique userId primary key
* @throws RemoteException
*/
public Long createUser(UserVO user) throws UserCreateException, RemoteException;
/**
* Delete the User
* @param userId
* @return
* @throws RemoteException
*/
public Long deleteUser(Long userId) throws UserDeleteException, RemoteException;
/**
* Retrieve the User
* @param userId
* @return
* @throws RemoteException
*/
public UserVO retrieveUser(Long userId) throws UserRetrieveException, RemoteException;
/**
* Retrieve User Template
* @return
* @throws RemoteException
*/
public Collection retrieveDefaultUsers() throws UserRetrieveException, RemoteException;
/**
* Update the User
* @param oldUser
* @param newUSer
* @return
* @throws RemoteException
*/
public UserVO updateUser(UserVO oldUser, UserVO newUser) throws UserUpdateException, RemoteException;
}
EJB HOME INTERFACE::
/*
* Generated by XDoclet - Do not edit!
*/
package com.kbcomputersolutions.movieapp.business.ejb.inte rfaces;
import java.rmi.RemoteException;
import javax.ejb.CreateException;
/**
* Home interface for User.
*/
public interface UserHome extends javax.ejb.EJBHome {
public static final String COMP_NAME = "java:comp/env/ejb/session/User";
public static final String JNDI_NAME = "ejb/session/User";
public User create() throws CreateException, RemoteException;
}
EJB BEAN ::
/*
* Created on May 16, 2005
*
* TODO To change the template for this generated file go to
* Window - Preferences - Java - Code Style - Code Templates
*/
package com.kbcomputersolutions.movieapp.business.ejb.bean s;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import javax.ejb.CreateException;
import org.hibernate.Session;
import org.hibernate.Transaction;
import org.springframework.ejb.support.AbstractStatelessS essionBean;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserCreateException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserDeleteException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserRetrieveException;
import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserUpdateException;
import com.kbcomputersolutions.movieapp.business.services .UserService;
import com.kbcomputersolutions.movieapp.business.vo.UserV O;
import com.kbcomputersolutions.movieapp.common.constants. SpringConstants;
import com.kbcomputersolutions.movieapp.common.constants. TypeConstants;
import com.kbcomputersolutions.movieapp.common.util.hiber nate.HibernateUtil;
/**
* @ejb.bean name="User"
* display-name="Name for User"
* description="Description for User"
* jndi-name="ejb/session/User"
* type="Stateless"
* view-type="remote"
*/
public class UserBean extends AbstractStatelessSessionBean implements UserService {
/**
*
*/
private static final long serialVersionUID = 158742166273912459L;
private UserService user;
/**
* Obtain our POJO service object from the BeanFactory/ApplicationContext
*/
protected void onEjbCreate() throws CreateException {
user = (UserService) getBeanFactory().getBean(
SpringConstants.USER_BEAN);
}
/**
* Create the Users
*
*/
public Collection createUsers(Collection users) throws UserCreateException {
UserVO user = null;
Collection userIds = new ArrayList();
System.out.println("Inside createUsers(Collection users) method");
System.out.println("Creating a total of ["+users.size()+"] users");
Iterator it = users.iterator();
Session session = HibernateUtil.currentSession();
Transaction tx = tx = session.beginTransaction();
while(it.hasNext()) {
user = (UserVO)it.next();
System.out.println(user.toString());
session.save(user);
userIds.add((Long)session.getIdentifier(user));
}
tx.commit();
HibernateUtil.closeSession();
return userIds;
}
/**
* Create the User
*
*/
public Long createUser(UserVO user) throws UserCreateException {
Long userId = null;
System.out.println("Inside createAddress(AddressVO address) method");
System.out.println(user.toString());
Session session = HibernateUtil.currentSession();
Transaction tx = session.beginTransaction();
session.save(user);
tx.commit();
userId = (Long)session.getIdentifier(user);
HibernateUtil.closeSession();
return userId;
}
/**
* Delete the User
*/
public Long deleteUser(Long userId) throws UserDeleteException {
System.out.println("Inside deleteUser(Long userId) method");
return userId;
}
/**
* Retrieve the User
*
*/
public UserVO retrieveUser(Long UserId) throws UserRetrieveException {
System.out.println("Inside retrieveUser(Long userId) method");
UserVO user = new UserVO();
return user;
}
/**
* Retrieve User Template
*
*/
public Collection retrieveDefaultUsers() throws UserRetrieveException {
System.out.println("Inside retrieveDefaultUsers() method");
Collection usersCollection = new ArrayList();
Collection userTypes = this.getUserTypes();
UserVO user = null;
Iterator it = userTypes.iterator();
Integer userType = null;
while(it.hasNext()) {
userType = (Integer)it.next();
}
System.out.println("Populated User Collection :: "+usersCollection.toString());
return usersCollection;
}
/**
* Update User
*/
public UserVO updateUser(UserVO oldUser, UserVO newUser) throws UserUpdateException {
System.out.println("Inside updateUser(UserVO oldUser, UserVO newUser) method");
return newUser;
}
/**
* Retrieve the user types
* @return User Types in a HashMap
*/
private Collection getUserTypes() {
Collection userTypes = new ArrayList();
userTypes.add(new Integer(TypeConstants.PRIMARY_USER_TYPE));
userTypes.add(new Integer(TypeConstants.SECONDARY_USER_TYPE));
userTypes.add(new Integer(TypeConstants.ANOTHER_USER_TYPE));
return userTypes;
}
/**
* Default create method
*
* @throws CreateException
* @ejb.create-method
*/
public void ejbCreate() throws CreateException {
// TODO Auto-generated method stub
}
}
Code to call the Bean Container and obtain the bean instance::
private final WebApplicationContext springCtx = getWebApplicationContext();
UserService userService = (UserService)springCtx.getBean(SpringConstants.USE R_SERVICE);
newUserId = userService.createUser(registerNewUserForm.getUser ());
JBOSS.XML
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss
PUBLIC "-//JBoss//DTD JBOSS 3.0//EN"
"http://www.jboss.org/j2ee/dtd/jboss_4_0.dtd" >
<jboss>
<enterprise-beans>
<!--
To add beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called jboss-beans.xml that contains
the <session></session>, <entity></entity> and <message-driven></message-driven>
markup for those beans.
-->
<session>
<ejb-name>User</ejb-name>
<jndi-name>ejb/session/User</jndi-name>
</session>
<session>
<ejb-name>Address</ejb-name>
<jndi-name>ejb/session/Address</jndi-name>
</session>
</enterprise-beans>
<resource-managers>
</resource-managers>
</jboss>
EJB_JAR.XML ::
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar
PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN"
"http://java.sun.com/dtd/ejb-jar_2_0.dtd" >
<ejb-jar >
<description><![CDATA[No Description.]]></description>
<display-name>Generated by XDoclet</display-name>
<enterprise-beans>
<!-- Session Beans -->
<!-- User Session Bean -->
<session >
<description><![CDATA[Description for User]]></description>
<display-name>Name for User</display-name>
<ejb-name>User</ejb-name>
<home>com.kbcomputersolutions.movieapp.business.ej b.interfaces.UserHome</home>
<remote>com.kbcomputersolutions.movieapp.business. ejb.interfaces.User</remote>
<ejb-class>com.kbcomputersolutions.movieapp.business.ej b.beans.UserBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>com/kbcomputersolutions/movieapp/common/applicationContext.xml</env-entry-value>
</env-entry>
</session>
<!-- Address Session Bean -->
<session >
<description><![CDATA[Description for Address]]></description>
<display-name>Name for Address</display-name>
<ejb-name>Address</ejb-name>
<home>com.kbcomputersolutions.movieapp.business.ej b.interfaces.AddressHome</home>
<remote>com.kbcomputersolutions.movieapp.business. ejb.interfaces.Address</remote>
<ejb-class>com.kbcomputersolutions.movieapp.business.ej b.beans.AddressBean</ejb-class>
<session-type>Stateless</session-type>
<transaction-type>Container</transaction-type>
<env-entry>
<env-entry-name>ejb/BeanFactoryPath</env-entry-name>
<env-entry-type>java.lang.String</env-entry-type>
<env-entry-value>com/kbcomputersolutions/movieapp/common/applicationContext.xml</env-entry-value>
</env-entry>
</session>
<!--
To add session beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called session-beans.xml that contains
the <session></session> markup for those beans.
-->
<!-- Entity Beans -->
<!--
To add entity beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called entity-beans.xml that contains
the <entity></entity> markup for those beans.
-->
<!-- Message Driven Beans -->
<!--
To add message driven beans that you have deployment descriptor info for, add
a file to your XDoclet merge directory called message-driven-beans.xml that contains
the <message-driven></message-driven> markup for those beans.
-->
</enterprise-beans>
<!-- Relationships -->
<!-- Assembly Descriptor -->
<assembly-descriptor >
<!--
To add additional assembly descriptor info here, add a file to your
XDoclet merge directory called assembly-descriptor.xml that contains
the <assembly-descriptor></assembly-descriptor> markup.
-->
<!-- finder permissions -->
<!-- transactions -->
<!-- finder transactions -->
</assembly-descriptor>
</ejb-jar>
Any help would be appreciated. Thanks in advance!


Reply With Quote
