您的位置:首页 > 其它

webservice如何设置代理服务

2016-05-13 13:54 447 查看
由于最近有客户需通过webservice接入我们这边的系统(Axis21.3),以前给接入包不行,问了客户那边的情况才知道他们那边是内网通过代理访问外网的。 
以前的client是通过插件自动生成的,所以直接在生成的stub类里面加上配置代理的参数就ok 

Java代码  


/** 

     * 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久都没通过

转载自:http://jophy.iteye.com/blog/441372
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  webservice 代理