【问题标题】:How to send a SOAP message through a proxy that needs authentication?如何通过需要身份验证的代理发送 SOAP 消息?
【发布时间】:2015-08-06 12:34:32
【问题描述】:

我正在编写托管在 Apache Tomcat 7 中的 java 1.7 中的 servlet,并且我正在尝试将 SOAP 1.2 消息发送到 Web 服务。不是一个很有挑战性的功能,所以我写了一点代码来完成它:

    SOAPConnectionFactory soapConnectionFactory = SOAPConnectionFactory.newInstance();
    SOAPConnection soapConnection = soapConnectionFactory.createConnection();

    String url = petition.getUrl();
    SOAPMessage soapResponse = soapConnection.call(createSOAPRequest(xml), url);

问题是我的公司代理正在停止通话,而我总是收到超时异常。我发现我可以像这样设置代理设置,但它不包括引入完成调用所需的代理身份验证的方法。

//Set the http proxy to webcache.example.com:8080
System.setProperty("http.proxyHost", "webcache.example.com");
System.setProperty("http.proxyPort", "8080");

有没有办法让我登录代理而无需使用 URLConnection 发送 SOAP 消息?

【问题讨论】:

    标签: java soap proxy


    【解决方案1】:

    我推荐你使用带有基本认证的 Jax-ws 客户端,下面的代码设置认证配置而不使用 URLConnection:

    Service s = new Service();
    Port port = s.getPort();
    
    BindingProvider prov = (BindingProvider)port;
    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "myusername");
    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mypassword");
    
    port.call();
    

    【讨论】:

    • 这是怎么回事,能否举个例子
    猜你喜欢
    • 1970-01-01
    • 2021-03-29
    • 1970-01-01
    • 2012-11-10
    • 2018-07-25
    • 2018-09-29
    • 1970-01-01
    • 2021-10-10
    • 1970-01-01
    相关资源
    最近更新 更多