Announcement Announcement Module
Collapse
No announcement yet.
Remote SLSB + JBoss 4.0.2 NullPointer Exception Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Remote SLSB + JBoss 4.0.2 NullPointer Exception

    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!

  • #2
    Forgot to add the exception

    17:11:58,953 INFO [STDOUT] java.lang.NullPointerException
    17:11:58,953 INFO [STDOUT] at com.kbcomputersolutions.movieapp.presentation.acti on.RegisterNewUserAction.processStep1(Unknown Source)
    17:11:58,953 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke0(Nativ e Method)
    17:11:58,953 INFO [STDOUT] at sun.reflect.NativeMethodAccessorImpl.invoke(Unknow n Source)
    17:11:58,953 INFO [STDOUT] at sun.reflect.DelegatingMethodAccessorImpl.invoke(Un known Source)
    17:11:58,953 INFO [STDOUT] at java.lang.reflect.Method.invoke(Unknown Source)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.actions.DispatchAction.dispatchM ethod(DispatchAction.java:276)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.actions.LookupDispatchAction.exe cute(LookupDispatchAction.java:162)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.processA ctionPerform(RequestProcessor.java:421)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.action.RequestProcessor.process( RequestProcessor.java:226)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.action.ActionServlet.process(Act ionServlet.java:1164)
    17:11:58,953 INFO [STDOUT] at com.kbcomputersolutions.movieapp.presentation.acti on.OnLoadServlet.process(Unknown Source)
    17:11:58,953 INFO [STDOUT] at org.apache.struts.action.ActionServlet.doPost(Acti onServlet.java:415)
    17:11:58,953 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet .java:717)
    17:11:58,953 INFO [STDOUT] at javax.servlet.http.HttpServlet.service(HttpServlet .java:810)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:252)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    17:11:58,953 INFO [STDOUT] at org.jboss.web.tomcat.filters.ReplyHeaderFilter.doF ilter(ReplyHeaderFilter.java:81)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.in ternalDoFilter(ApplicationFilterChain.java:202)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.ApplicationFilterChain.do Filter(ApplicationFilterChain.java:173)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.StandardWrapperValve.invo ke(StandardWrapperValve.java:213)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.StandardContextValve.invo ke(StandardContextValve.java:178)
    17:11:58,953 INFO [STDOUT] at org.jboss.web.tomcat.security.CustomPrincipalValve .invoke(CustomPrincipalValve.java:39)
    17:11:58,953 INFO [STDOUT] at org.jboss.web.tomcat.security.SecurityAssociationV alve.invoke(SecurityAssociationValve.java:153)
    17:11:58,953 INFO [STDOUT] at org.jboss.web.tomcat.security.JaccContextValve.inv oke(JaccContextValve.java:59)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.StandardHostValve.invoke( StandardHostValve.java:126)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.valves.ErrorReportValve.invoke (ErrorReportValve.java:105)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.core.StandardEngineValve.invok e(StandardEngineValve.java:107)
    17:11:58,953 INFO [STDOUT] at org.apache.catalina.connector.CoyoteAdapter.servic e(CoyoteAdapter.java:148)
    17:11:58,953 INFO [STDOUT] at org.apache.coyote.http11.Http11Processor.process(H ttp11Processor.java:856)
    17:11:58,953 INFO [STDOUT] at org.apache.coyote.http11.Http11Protocol$Http11Conn ectionHandler.processConnection(Http11Protocol.jav a:744)
    17:11:58,953 INFO [STDOUT] at org.apache.tomcat.util.net.PoolTcpEndpoint.process Socket(PoolTcpEndpoint.java:527)
    17:11:58,953 INFO [STDOUT] at org.apache.tomcat.util.net.MasterSlaveWorkerThread .run(MasterSlaveWorkerThread.java:112)
    17:11:58,953 INFO [STDOUT] at java.lang.Thread.run(Unknown Source)

    Comment


    • #3
      You posted everything, except the code that actually throws the exception.

      Comment


      • #4
        Oopps

        /*
        * Created on Mar 31, 2005
        *
        * TODO To change the template for this generated file go to
        * Window - Preferences - Java - Code Style - Code Templates
        */
        package com.kbcomputersolutions.movieapp.presentation.acti on;

        import java.util.ArrayList;
        import java.util.Collection;
        import java.util.HashMap;
        import java.util.Map;

        import javax.servlet.http.HttpServletRequest;
        import javax.servlet.http.HttpServletResponse;

        import org.apache.struts.action.ActionForm;
        import org.apache.struts.action.ActionMapping;
        import org.apache.struts.action.ActionForward;
        import org.apache.struts.action.ActionMessage;
        import org.apache.struts.action.ActionMessages;
        import org.apache.struts.util.LabelValueBean;
        import org.springframework.web.context.WebApplicationCont ext;

        import com.kbcomputersolutions.movieapp.business.exceptio n.delegate.UserCreateException;
        import com.kbcomputersolutions.movieapp.business.services .AddressService;
        import com.kbcomputersolutions.movieapp.business.services .UserService;
        import com.kbcomputersolutions.movieapp.common.constants. SpringConstants;
        import com.kbcomputersolutions.movieapp.common.constants. TypeConstants;
        import com.kbcomputersolutions.movieapp.presentation.acti on.base.CVSLookupDispatchAction;
        import com.kbcomputersolutions.movieapp.presentation.form .RegisterNewUserForm;


        public class RegisterNewUserAction extends CVSLookupDispatchAction {

        /**
        * Get reference to the Application Context(Spring Bean Container) via WebApplicationContext
        */
        //private WebApplicationContext springCtx = getWebApplicationContext();

        /**
        * JSP Key constants & LookupDispatchAction forwards
        */
        public final static String REGISTER_NEW_USER_STEP_1 = "demo.page.register.new.user.next1";
        public final static String REGISTER_NEW_USER_STEP_2 = "demo.page.register.new.user.next2";
        public final static String REGISTER_NEW_USER_STEP_3 = "demo.page.register.new.user.next3";
        public final static String REGISTER_NEW_USER_PREVIOUS_STEP_1 = "demo.page.register.new.user.previous1";
        public final static String REGISTER_NEW_USER_PREVIOUS_STEP_2 = "demo.page.register.new.user.previous2";

        /**
        * Action(Message/Error) Message Resource Lookup Keys
        */
        private static final String REGISTER_NEW_USER_FAILURE_MESSAGE = "demo.page.register.page.failure.registrationFailu re";
        private static final String REGISTER_NEW_USER_SUCCESS_MESSAGE = "demo.page.register.page.success.newUserRegistrati onSuccessful";
        private static final String REGISTER_NEW_ADDRESSES_SUCCESS_MESSAGE = "demo.page.register.page.success.newAddressRegistr ationSuccessful";

        /**
        * Action Forward
        */
        public final static String REGISTER_NEW_USER_SUCCESS_FORWARD = "demo.page.register.new.user.success";
        public final static String REGISTER_NEW_USER_FAILURE_FORWARD = "demo.page.register.new.user.failure";

        /*
        * (non-Javadoc)
        * @see org.apache.struts.actions.LookupDispatchAction#get KeyMethodMap()
        */
        protected Map getKeyMethodMap() {
        Map keyMethodMap = new HashMap();
        //keyMethodMap.put(/*key*/, /*methodName*/);
        keyMethodMap.put(REGISTER_NEW_USER_STEP_1, "processStep1");
        keyMethodMap.put(REGISTER_NEW_USER_STEP_2, "processStep2");
        keyMethodMap.put(REGISTER_NEW_USER_STEP_3, "processStep3");
        keyMethodMap.put(REGISTER_NEW_USER_PREVIOUS_STEP_1 , "previousStep1");
        keyMethodMap.put(REGISTER_NEW_USER_PREVIOUS_STEP_2 , "previousStep2");
        return keyMethodMap;
        }

        /**
        * Process Step 1 :: Verify the the new user information and forward onto the next page of
        * the new user registration. If a form error is encountered forward to the apporpriate JSP
        * page and display the action messages. If an error is encountered forward control to
        * the application error page.
        *
        * @param mapping
        * @param form
        * @param request
        * @param response
        * @return ActionForward
        */
        public ActionForward processStep1(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {

        ActionForward forward = null;
        ActionMessages actionErrors = new ActionMessages();
        ActionMessages actionMessages = new ActionMessages();
        RegisterNewUserForm registerNewUserForm = (RegisterNewUserForm)form;

        try {
        // If process of step 1 is successful forward control to the next page in the user
        // registration process.

        System.out.println("ProcessStep1() Method");
        forward = mapping.findForward(REGISTER_NEW_USER_STEP_2);

        // Call the Bean Container to get reference to the AddressService

        WebApplicationContext springCtx = getWebApplicationContext();
        AddressService addressService = (AddressService)springCtx.getBean(SpringConstants. ADDRESS_SERVICE)
        ;

        Collection defaultAddresses = addressService.retrieveDefaultAddresses();

        Collection addressTypes = this.getAddressTypes();


        // Prepopulate the Collection of default/template addresses
        registerNewUserForm.setAddresses(defaultAddresses) ;
        registerNewUserForm.setAddressTypes(addressTypes);

        // If a form error is encountered in processing step one forward control to the step 1
        // error page
        // forward = mapping.findForward(DemoResourcesConstantKeys.REGI STER_NEW_USER_STEP_1);
        } catch(Exception e) {
        // If process of step one fails or errors out forward control to the application
        // global forward error page
        e.printStackTrace();
        forward = mapping.findForward(GLOBAL_FORWARD_ERROR);
        }

        return forward;
        }

        /**
        * Process Step 2 :: Verify the the new user address information and forward onto the next page of
        * the new user registration. If a form error is encountered forward to the apporpriate JSP
        * page and display the action messages. If an error is encountered forward control to
        * the application error page.
        *
        * @param mapping
        * @param form
        * @param request
        * @param response
        * @return ActionForward
        */
        public ActionForward processStep2(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {

        ActionForward forward = null;
        RegisterNewUserForm registerNewUserForm = (RegisterNewUserForm)form;

        try {
        // If process of step 2 is successful forward control to the next page in the user
        // registration process.
        System.out.println("ProcessStep2() Method");

        /*
        Iterator it = registerNewUserForm.getAddresses().iterator();
        AddressVO addressVO = null;

        while(it.hasNext()) {
        addressVO = (AddressVO)it.next();
        System.out.println("Address :: "+addressVO.toString());
        System.out.println("Address :: "+addressVO.getAddress1());
        }
        */

        forward = mapping.findForward(REGISTER_NEW_USER_STEP_3);

        // If a form error is encountered in processing step one forward control to the step 2
        // error page
        // forward = mapping.findForward(DemoResourcesConstantKeys.REGI STER_NEW_USER_STEP_2);
        } catch(Exception e) {
        // If process of step one fails or errors out forward control to the application
        // global forward error page
        forward = mapping.findForward(GLOBAL_FORWARD_ERROR);
        }

        return forward;
        }

        /**
        * Process Step 3 :: Verify the the new user and user address information and forward onto
        * the next page of the new user registration. If a form error is encountered forward to
        * the apporpriate JSP page and display the action messages. If an error is encountered
        * forward control to the application error page.
        *
        * @param mapping
        * @param form
        * @param request
        * @param response
        * @return ActionForward
        */
        public ActionForward processStep3(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {

        // If process of step 3 is successful forward control to the next page in the user
        // registration process.
        System.out.println("ProcessStep3() Method");

        ActionForward forward = null;
        ActionMessages actionErrors = new ActionMessages();
        ActionMessages actionMessages = new ActionMessages();
        RegisterNewUserForm registerNewUserForm = (RegisterNewUserForm)form;

        Long newUserId = null;
        Collection newAddressIds = new ArrayList();

        try {
        WebApplicationContext springCtx = getWebApplicationContext();
        UserService userService = (UserService)springCtx.getBean(SpringConstants.USE R_SERVICE);
        newUserId = userService.createUser(registerNewUserForm.getUser ());

        AddressService addressService = (AddressService)springCtx.getBean(SpringConstants. ADDRESS_SERVICE);
        addressService.createAddresses(registerNewUserForm .getAddresses());

        saveActionMessage(new ActionMessage(REGISTER_NEW_USER_SUCCESS_MESSAGE), actionMessages, request);
        saveActionMessage(new ActionMessage(REGISTER_NEW_ADDRESSES_SUCCESS_MESSA GE, Integer.toString(newAddressIds.size())),
        actionMessages, request);
        forward = mapping.findForward(REGISTER_NEW_USER_SUCCESS_FORW ARD);

        } catch(UserCreateException cue) {
        System.out.println("Could not save user due to error in business layer");
        saveErrorMessage(new ActionMessage(REGISTER_NEW_USER_FAILURE_MESSAGE), actionErrors, request);
        forward = mapping.findForward(REGISTER_NEW_USER_FAILURE_FORW ARD);

        // } catch(CreateAddressException sae) {
        // System.out.println("Could not save address due to error in business layer");
        // saveErrorMessage(new ActionMessage(REGISTER_NEW_USER_FAILURE_MESSAGE), actionErrors, request);
        // forward = mapping.findForward(REGISTER_NEW_USER_FAILURE_FORW ARD);

        } catch(Exception e) {

        // If process of step one fails or errors out forward control to the application
        // global forward error page
        e.printStackTrace();
        forward = mapping.findForward(GLOBAL_FORWARD_ERROR);
        }

        // Reset the RegisterNewUserForm since it is saved in session!!!
        System.out.println("Reseting the RegisterNewUserForm data.");
        registerNewUserForm.reset();

        return forward;
        }

        /**
        * Previous Step 1 :: Do any processing if needed before forwarding to the previous page in
        * the registration process.
        *
        * @param mapping
        * @param form
        * @param request
        * @param response
        * @return ActionForward
        */
        public ActionForward previousStep1(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {

        ActionForward forward = null;
        System.out.println("PreviousStep1() Method");
        forward = mapping.findForward(REGISTER_NEW_USER_STEP_1);

        return forward;
        }

        /**
        * Previous Step 2 :: Do any processing if needed before forwarding to the previous page in
        * the registration process.
        *
        * @param mapping
        * @param form
        * @param request
        * @param response
        * @return ActionForward
        */
        public ActionForward previousStep2(ActionMapping mapping,
        ActionForm form,
        HttpServletRequest request,
        HttpServletResponse response) {

        ActionForward forward = null;
        System.out.println("PreviousStep2() Method");
        forward = mapping.findForward(REGISTER_NEW_USER_STEP_2);

        return forward;
        }

        private Collection getAddressTypes() {
        Collection addressTypes = new ArrayList();
        LabelValueBean labelValueBean = new LabelValueBean();

        addressTypes.add(new LabelValueBean(TypeConstants.PRIMARY_ADDRESS_STRIN G, Integer.toString(TypeConstants.PRIMARY_ADDRESS_TYP E)));
        addressTypes.add(new LabelValueBean(TypeConstants.SECONDARY_ADDRESS_STR ING, Integer.toString(TypeConstants.SECONDARY_ADDRESS_T YPE)));
        addressTypes.add(new LabelValueBean(TypeConstants.MAILING_ADDRESS_STRIN G, Integer.toString(TypeConstants.MAILING_ADDRESS_TYP E)));
        addressTypes.add(new LabelValueBean(TypeConstants.WORK_ADDRESS_STRING, Integer.toString(TypeConstants.WORK_ADDRESS_TYPE)) );
        addressTypes.add(new LabelValueBean(TypeConstants.ANOTHER_ADDRESS_STRIN G, Integer.toString(TypeConstants.ANOTHER_ADDRESS_TYP E)));

        return addressTypes;
        }

        }

        Comment

        Working...
        X