2014-02-05 82 views
0

我想通過代理調用webservice(SOAP)。 假設,代理用戶名:XYZ和密碼:XYZ如何調用SOAP webserivce以及如何設置代理設置?

Webservice的網址https://xyz.com/pqr

服務名稱:uploadData

我用

System.getProperties().put("http.proxyHost", "some host"); 
    System.getProperties().put("http.proxyPort", "some port"); 
    System.getProperties().put("http.proxyUser", "username"); 
    System.getProperties().put("http.proxyPassword", "password"); // I have also tried base64 password. 

但將需要驗證例外。

基本上我需要用一些參數調用這個webservice並從中得到響應。

謝謝。

+0

你使用的是什麼庫或只是簡單的HttpConnection認證者? –

+0

@DhanaKrishnasamy我使用QName,Service,SOAPMessage等調用webservice –

+0

考慮使用純HTTP客戶端來發送創建的SOAP消息或其他具有代理支持的套件,並且可以根據每個連接設置身份驗證。 – vzamanillo

回答

0

你將不得不使用像

final PasswordAuthentication AUTHENTICATOR = new PasswordAuthentication(proxyUser, proxyPassword.toCharArray()); 
       Authenticator.setDefault(new Authenticator() 
       { 
        @Override 
        protected PasswordAuthentication getPasswordAuthentication() 
        { 
         if(ObjectUtil.equals(getRequestorType(), Authenticator.RequestorType.PROXY)) { 
          return AUTHENTICATOR; 
         } 
         return null; 
        } 
       }); 
+0

JVM中的Authenticator對象注意,java.net.Authenticator不能在每個連接的基礎上進行設置,因此如果您將Application Server與其他應用程序一起使用自己的身份驗證器,那麼您的「Authenticator.setDefault()」方法應用程序將重寫先前定義的身份驗證器,其他應用程序將失敗。有關於此行爲的一些已解決的錯誤http://bugs.java.com/bugdatabase/view_bug.do?bug_id=4941958 – vzamanillo