【Java开源代码栏目提醒】:网学会员为需要Java开源代码的朋友们搜集整理了WebEndServiceLocator.java相关资料,希望对各位网友有所帮助!
package com.cownew.PIS.framework.web.helper;
import java.net.MalformedURLException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.springframework.remoting.httpinvoker.CommonsHttpInvokerRequestExecutor;
import org.springframework.remoting.httpinvoker.HttpInvokerProxyFactoryBean;
import com.cownew.PIS.framework.client.RemoteServerException;
import com.cownew.PIS.framework.common.SysConstants;
import com.cownew.ctk.common.StringUtils;
public class WebEndServiceLocator
{
public static Object getService(HttpServletRequest request,
Class serviceIntfClass)
{
HttpSession webSession = request.getSession();
String sessionId = (String)
webSession
.getAttribute(WebConstant.SESSIONID);
return getService(sessionId, serviceIntfClass);
}
public static Object getService(String sessionId,
Class serviceIntfClass)
{
WebConfig webConfig = WebConfig.getInstance();
HttpInvokerProxyFactoryBean proxyFactory = new HttpInvokerProxyFactoryBean();
CommonsHttpInvokerRequestExecutor reqExecutor = new CommonsHttpInvokerRequestExecutor();
proxyFactory.setHttpInvokerRequestExecutor(reqExecutor);
try
{
String serviceIntfName = serviceIntfClass.getName();
String serviceURL = webConfig.getServerURL().toString()
+ serviceIntfName;
if (!StringUtils.isEmpty(sessionId))
{
StringBuffer sb = new StringBuffer();
sb.append(serviceURL).append("?")
.append(SysConstants.SESSIONID).append("=").append(
sessionId);
proxyFactory.setServiceUrl(sb.toString());
} else
{
proxyFactory.setServiceUrl(serviceURL);
}
proxyFactory.setServiceInterface(serviceIntfClass);
proxyFactory.afterPropertiesSet();
Object service = proxyFactory.getObject();
return service;
} catch (MalformedURLException e)
{
throw new RemoteServerException(
RemoteServerException.CONNECTSERVERERROR, e);
}
}
}