📄 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);
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -