由于最近有客户需通过webservice接入我们这边的系统(Axis21.3),以前给接入包不行,问了客户那边的情况才知道他们那边是内网通过代理访问外网的。
以前的client是通过插件自动生成的,所以直接在生成的stub类里面加上配置代理的参数就ok
webservice是通过http端口走的,所以代理应该提供http端口,一开始客户提供了socks5端口,害的测试n久都没通过
以前的client是通过插件自动生成的,所以直接在生成的stub类里面加上配置代理的参数就ok
/**
* Constructor that takes in a configContext and useseperate listner
*/
public MessageTransportServiceStub(org.apache.axis2.context.ConfigurationContext configurationContext,
java.lang.String targetEndpoint, boolean useSeparateListener)
throws org.apache.axis2.AxisFault {
//To populate AxisService
populateAxisService();
populateFaults();
_serviceClient = new org.apache.axis2.client.ServiceClient(configurationContext,_service);
configurationContext = _serviceClient.getServiceContext().getConfigurationContext();
_serviceClient.getOptions().setTo(new org.apache.axis2.addressing.EndpointReference(
targetEndpoint));
_serviceClient.getOptions().setUseSeparateListener(useSeparateListener);
//以下为通过配置文件判断是否使用代理,有使用的话设置参数
Configuration config=new Configuration();
if (config.getValue("isproxy").equals("true")) {
ProxyProperties proxyProperties=new ProxyProperties();
proxyProperties.setProxyName(config.getValue("host"));
proxyProperties.setProxyPort(Integer.valueOf(config.getValue("port")));
proxyProperties.setDomain(config.getValue("domain"));
proxyProperties.setUserName(config.getValue("username"));
proxyProperties.setPassWord(config.getValue("userpassword"));
_serviceClient.getOptions().setProperty(HTTPConstants.PROXY, proxyProperties);
_serviceClient.getOptions().setProperty(HTTPConstants.HTTP_PROTOCOL_VERSION, HTTPConstants.HEADER_PROTOCOL_10);
}
}
webservice是通过http端口走的,所以代理应该提供http端口,一开始客户提供了socks5端口,害的测试n久都没通过
配置WebService代理访问
本文介绍了一种通过配置Axis2客户端来实现使用代理访问WebService的方法。针对内网环境中需通过代理服务器访问外部WebService的需求,文中详细展示了如何在自动生成的Stub类中设置代理参数。
1240

被折叠的 条评论
为什么被折叠?



