现备份一下IProxy模块代码:包含:
1:一个无状态SessionBean:负责JMS和http服务 
2:一个MDB:负责监听一个message queue,并调用其它模块ejb.
其它辅助类我就不备份了,纯属个人备份,如果有人对sessionbean,mdb感兴趣,可以参考.


一:负责JMS服务的实现类为JmsService,负责http服务的实现类为:HttpService,为了调用方便,它们都实现ServiceInterface接口:

package co.iproxy.service;

/**
 * 
@author lichunlei
 *
 * To change the template for this generated type comment go to
 * Window>Preferences>Java>Code Generation>Code and Comments
 
*/

public interface ServiceInterface 
{
    
/**
     * Send message and receive the response content
     * 
@param   request  xml request
     * 
@return  the response
     * 
@throws Exception
     
*/

    
public String syncRequest(String request) throws Exception;
    
    
    
/**
     * Send message and receive the response status
     * 
@param request xml request
     * 
@return  the response status
     * 
@throws Exception
     
*/

    
public String request(String request) throws Exception;
    
    
/**
     * Release the used resourses
     *
     
*/

    
public void clear();
}

 SessionBean的实现类(home,local和remote接口没有备份) 

package co.iproxy.sb;

import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

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

import co.iproxy.exception.IProxyException;
import co.iproxy.exception.ParamInvalidIProxyException;
import co.iproxy.jms.JmsService;
import co.iproxy.service.IProxyConfig;
import co.iproxy.service.IProxyConstants;
import co.iproxy.service.MessageInfo;
import co.iproxy.service.ServiceInterface;

/**
 * Bean implementation class for Enterprise Bean: IProxyServiceSession
 
*/

public class IProxyServiceSessionBean implements javax.ejb.SessionBean
{
    
private javax.ejb.SessionContext mySessionCtx;
    
    
private InitialContext context = null;
    
    
/**The map which contains the services for sending and receiving message*/
    
private Map services = new HashMap();
    
//    private ServiceInterface service = null;
    
    
/**
     * getSessionContext
     
*/

    
public javax.ejb.SessionContext getSessionContext()
    
{
        
return mySessionCtx;
    }

    
/**
     * setSessionContext
     
*/

    
public void setSessionContext(javax.ejb.SessionContext ctx)
    
{
        mySessionCtx 
= ctx;
    }

    
    
/**
     * ejbCreate
     
*/

    
public void ejbCreate() throws javax.ejb.CreateException
    
{
        
this.getContext();
                
        
//cache the environment variable name: sb/JmsServiceSessionBean_Cfg_File
        String cfgVarName = new StringBuffer().append(IProxyConstants.LOOKUP_PATH).append("/")
                                              .append(IProxyConstants.ENV_JMS_CFG_NAEM)
                                              .toString();
            
        
//Cache the configration file name from the environment variable.                                      
        String file;
        
try
        
{
            file 
= (String) context.lookup(cfgVarName);
            
this.setupInit(file);
        }

        
catch (NamingException e)
        
{
            
// TODO Auto-generated catch block
            e.printStackTrace();
        }
            
            
    }

    
    
/**
     * Get the context of the container
     *
     
*/

    
private void getContext()
    
{
        
try
        
{
            
this.context = new InitialContext();
        }

        
catch (NamingException e)
        
{
            
try
            
{
                
this.context = new InitialContext();
            }

            
catch (NamingException e1)
            
{
                
// TODO Auto-generated catch block
                e1.printStackTrace();
            }

        }

    }

    
    
/**
     * Initialize the param for IProxy
     * 
@param   filepath  the path of configuration file     
     
*/

    
private void setupInit(String filepath)
    
{
        
//Initalize JMS params for request 
        IProxyConfig config = new IProxyConfig(filepath);
        IProxyConstants.DEF_REP_QCF 
= config.getResponseQcfactory();
        IProxyConstants.DEF_REP_Q 
= config.getResponseDestination();
        IProxyConstants.DEF_REP_TIMEOUT 
= config.getResponseTimeout();
        
        
//Initalize JMS params for response
        IProxyConstants.DEF_REQ_QCF = config.getRequestQcfactory();
        IProxyConstants.DEF_REQ_Q 
= config.getRequestDestination();
        IProxyConstants.msgProperties 
= config.getMessageProperties();
        
        
//Initalize http params for http service 
        IProxyConstants.DEF_SERVLET_URL = config.getServletUrl();
        IProxyConstants.DEF_SERVLET_PORT 
= config.getServletPort();
        IProxyConstants.DEF_SERVLET_HOST 
= config.getServletHost();
        IProxyConstants.DEF_PROXY_URL 
= config.getProxyUrl();
        IProxyConstants.DEF_PROXY_PORT 
= config.getProxyPort();
        
        System.out.println(
"in init: " + IProxyConstants.msgProperties);
        
        services 
= config.getServices();
        

    }

    
    
/**
     * ejbActivate
     
*/

img
评论
发表评论

您还没有登录,请登录后发表评论

lcllcl987
搜索本博客
博客分类
最近加入圈子
存档
最新评论