最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

jboss7.x - Migration of GlassFish 3.1.1 to Jboss 7.4 - Stack Overflow

programmeradmin1浏览0评论

Glass Fish Server Configurations: Glass Fish Version - 3.1.1, EJB Version - 2.0, Derby Version - 10.6, JDK - 7

Migrating to Jboss Jboss eap Version - 7.4, EJB Version - 3.0, Derby version - 10.14, JDK - 8

Issues Faced: EJB connectivity is not working—Is there a straightforward approach to ensuring compatibility with EJB 2.0 in JBoss 7.4 while making minimal modifications?

Class Name: ComDelegate.java

package com.lsi.delegate;

import javax.ejb.CreateException;
import java.rmi.RemoteException;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.Map;
import java.util.Set;

import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;

import com.lsi.sesfacade.interfaces.ComSesFacade;
import com.lsi.sesfacade.interfaces.ComSesFacadeHome;
import com.lsi.utils.DTObject;
import com.lsi.utils.HTMLInputFilter;
public  class ComDelegate{
public  DTObject callMethod(DTObject formDTO ) {
    DTObject resultDTO =new DTObject();
    ComSesFacadeHome  comSesFacadeHome = null;
    ComSesFacade  comSesFacade = null;
    try{
        InitialContext initialContext = new InitialContext();
        comSesFacadeHome  = (ComSesFacadeHome) initialContext.lookup("ejb/ComSesFacade");
        comSesFacade =(ComSesFacade) comSesFacadeHome.create();
        resultDTO  =(DTObject) comSesFacade.callMethod(formDTO) ;
    }catch(NamingException e){
            resultDTO.setValue("result",e.getLocalizedMessage());
            return resultDTO ;
    }catch (CreateException e) {
        resultDTO.setValue("result",e.getLocalizedMessage());
        return resultDTO ;
    }catch(RemoteException e) {
        resultDTO.setValue("result",e.getLocalizedMessage());
        return resultDTO ;
    }
    return resultDTO;
}

Class Name: ComSesFacadeHome.java

package com.lsi.sesfacade.interfaces;

public interface ComSesFacadeHome
   extends javax.ejb.EJBHome
{
   public static final String COMP_NAME="java:comp/env/ejb/ComSesFacade";
   public static final String JNDI_NAME="ejb/ComSesFacade";

   public com.lsi.sesfacade.interfaces.ComSesFacade create()
      throws javax.ejb.CreateException,java.rmi.RemoteException;

}

Class Name: ComSesFacadeBean.java

package com.lsi.sesfacade.ejb;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.rmi.RemoteException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import javax.ejb.CreateException;
import javax.transaction.HeuristicMixedException;
import javax.transaction.HeuristicRollbackException;
import javax.transaction.NotSupportedException;
import javax.transaction.RollbackException;
import javax.transaction.SystemException;

import com.lsi.utils.DTObject;

public class ComSesFacadeBean implements SessionBean {

    private SessionContext context;

    public ComSesFacadeBean() {
        super();
    }

    public void setSessionContext(SessionContext newContext)
        throws EJBException {
        context = newContext;
    }

    public void ejbRemove() throws EJBException, RemoteException {}
    public void ejbActivate() throws EJBException, RemoteException {}
    public void ejbPassivate() throws EJBException, RemoteException {}
    public void ejbCreate() throws CreateException {}
    
     public  Object  callMethod(Object FormDTO ) {
            DTObject formDTO = (DTObject) FormDTO;
            DTObject resultDTO = new DTObject() ;
            Class       boClass = null;                                     
            Object      businessObject = null;                              
            Method      invokeMethod = null;
            String      strMaxDaysl=null;
            Class[]     parameterTypes = new Class[] {DTObject.class};
            Object[]    params = new Object[] {formDTO};
            boClass = null;                                     
            businessObject = null;                              
            invokeMethod = null;
            UserTransaction userTran = null;
            try {
                boClass = Class.forName(formDTO.getValue("Class").toString());
                businessObject = boClass.newInstance();
                invokeMethod = boClass.getMethod(formDTO.getValue("Method").toString(), parameterTypes);
                
                if (formDTO.getValue("Method").toString().indexOf("update")> -1){
                    userTran = context.getUserTransaction();
                    try {                       
                        if((formDTO.getValue("Class").toString().equals("com.lsi.bo.eofcordempds")|| formDTO.getValue("Class").toString().equals("com.lsi.bo.Eofcordiempds"))&& formDTO.getValue("cboUserOption").equals("A")){
                            invokeMethod = boClass.getMethod("getMaxSerial", parameterTypes);
                            userTran.begin();
                            strMaxDaysl = (String) invokeMethod.invoke(businessObject, params);
                            userTranmit();
                            invokeMethod = boClass.getMethod(formDTO.getValue("Method").toString(), parameterTypes);
                        }
                        
                    }catch (Exception e) {
                        resultDTO.setValue("errMsg",e.getLocalizedMessage());
                        resultDTO.setValue("sucFlg","0");
                        return resultDTO ;
                    }
                }
                resultDTO = (DTObject) invokeMethod.invoke(businessObject, params);
                }
                boClass = null;                                     
                businessObject = null;                              
                invokeMethod = null;    
                return resultDTO;
            } catch (ClassNotFoundException e) {
                resultDTO.setValue("errMsg",e.getLocalizedMessage());
                resultDTO.setValue("sucFlg","0");
                return resultDTO ;
            } catch (InstantiationException e) {
                resultDTO.setValue("errMsg",e.getLocalizedMessage());
                resultDTO.setValue("sucFlg","0");
                return resultDTO ;
            } catch (IllegalAccessException e) {
                resultDTO.setValue("errMsg",e.getLocalizedMessage());
                resultDTO.setValue("sucFlg","0");
                return resultDTO ;
            }catch (NoSuchMethodException e) {
                resultDTO.setValue("errMsg",e.getLocalizedMessage());
                resultDTO.setValue("sucFlg","0");
                return resultDTO ;
            }catch (InvocationTargetException e) {
                resultDTO.setValue("errMsg",e.getLocalizedMessage());
                resultDTO.setValue("sucFlg","0");
                return resultDTO ;
            }
     }
}

ejb-jar.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE ejb-jar PUBLIC "-//Sun Microsystems, Inc.//DTD Enterprise JavaBeans 2.0//EN" ".dtd">
<ejb-jar >
   <description><![CDATA[No Description.]]></description>
   <display-name>Generated by XDoclet</display-name>
   <enterprise-beans>
      <session >
         <description><![CDATA[Description for ComSesFacade]]></description>
         <display-name>Name for ComSesFacade</display-name>
         <ejb-name>ComSesFacade</ejb-name>
         <home>com.lsi.sesfacade.interfaces.ComSesFacadeHome</home>
         <remote>com.lsi.sesfacade.interfaces.ComSesFacade</remote>
         <ejb-class>com.lsi.sesfacade.ejb.ComSesFacadeBean</ejb-class>
         <session-type>Stateless</session-type>
         <transaction-type>Bean</transaction-type>
      </session>
   </enterprise-beans>
</ejb-jar>

jboss.xml

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE jboss PUBLIC "-//JBoss//DTD JBOSS 3.2//EN" ".dtd">
<jboss>
   <enterprise-beans>
      <session>
         <ejb-name>ComSesFacade</ejb-name>
         <jndi-name>ejb/ComSesFacade</jndi-name>
        <method-attributes>
        </method-attributes>
      </session>
   </enterprise-beans>
   <resource-managers>
   </resource-managers>
</jboss>

Please assist me in modifying the code to ensure proper EJB connectivity within the JBoss 7.4 server environment?

发布评论

评论列表(0)

  1. 暂无评论