现备份一下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
*/
public void ejbActivate()
...{
}

/** *//**
* ejbPassivate
*/
public void ejbPassivate()
...{
}


/** *//**
* The factory mothed for ServiceInterface
* @param request xml request
* @return the instance which in charge of sending and receive message
* @throws IProxyException
*/
private ServiceInterface getService(String request) throws IProxyException
...{
MessageInfo msgInfo = new MessageInfo(request);
String serviceType = msgInfo.getServiceType();
System.out.println("the service type is: " + serviceType);
String myClass = (String)this.services.get(serviceType);
System.out.println("myClass = " + myClass);
ServiceInterface service = null;
if (myClass == null)
...{
throw new ParamInvalidIProxyException(serviceType + " service can not be provided");
}
try
...{
service = (ServiceInterface)Class.forName(myClass).newInstance();
}
catch (Exception e)
...{
try
...{
service = (ServiceInterface)Class.forName(myClass).newInstance();
}
catch (Exception e1)
...{
throw new IProxyException(serviceType + " service Exception:" + e1.toString());
}
}
return service;
}

/** *//**
* Send the message and return the status
* @param xml request
* @return the status of response
*/
public String request(String request)
...{
ServiceInterface service = null;
String result = null;
try
...{
service = this.getService(request);
result = service.request(request);
}
catch (Exception e)
...{
// TODO Auto-generated catch block
result = this.getStatus(e.toString());
e.printStackTrace();
}
finally
...{
if (service != null)
...{
service.clear();
service = null;
}
return result;
}
}

/** *//**
* Send the message and return the response
*
* @param request xml request
* @return the response
*/
public String syncRequest(String request)
...{
ServiceInterface service = null;
String result = null;
try
...{
service = this.getService(request);
result = service.syncRequest(request);
}
catch (Exception e)
...{
// TODO Auto-generated catch block
result = this.getStatus(e.toString());
e.printStackTrace();
}
finally
...{
if (service != null)
...{
service.clear();
service = null;
}
return result;
}
}

/** *//**
* ejbRemove
*/
public void ejbRemove()
...{
}

/**//*
* Generate a response status
*
* @param s the content of status
* @return xml string for status
*/
private String getStatus(String s)
...{
StringBuffer sb = new StringBuffer();
sb.append("<iproxy><status value=failed />").append(s).append("</iproxy>");
return sb.toString();
}
}一个MDB: 负责监听message queue,并且调用其它ejb:
package co.iproxy.mdb;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Enumeration;
import