簡體   English   中英

如何使用JAX-WS / SOAP認證Web服務客戶端

[英]How to authenticate a Web Service Client with JAX-WS / SOAP

我是Web服務的新手,並嘗試了一些教程。 但是當我嘗試訪問HTTPS安全SOAP Web服務時,我偶然發現了巡邏。 我可以使用瀏覽器訪問WSDL ,並使用從提供程序中恢復過來的登錄名/密碼訪問Netbeans。

Netbeans生成服務/模式類(通過身份驗證),並且我在Glassfish 3.1.2上運行客戶端。 我添加了一個Servlet來訪問服務。 但是當嘗試訪問服務和WSDL時,我得到了HTTP響應代碼:401(= Unauthorized)。 該服務確實連接到HTTPS ,但是錯誤告訴HTTP

添加用戶名/密碼以訪問Web服務的正確方法是什么?

Servlet的服務提供者

private static LogicalModel pullpullEnterpriseService() {
    pullEnterpriseService service = new pullEnterpriseService();        
    ClientPullSoapBinding port = service.getClientPullSoapBinding();        

    BindingProvider prov = ((BindingProvider)port);
    prov.getRequestContext().put(BindingProvider.USERNAME_PROPERTY, "myuser");
    prov.getRequestContext().put(BindingProvider.PASSWORD_PROPERTY, "mypassword");

    return port.getDataModel();
}

我嘗試在SOAP標頭中提供用戶名/密碼,但結果相同

    ...
    Map<String, Object> req_ctx = ((BindingProvider)port).getRequestContext();        

    Map<String, List<String>> headers = new HashMap<String, List<String>>();
    headers.put("Username", Collections.singletonList("myuser"));
    headers.put("Password", Collections.singletonList("mypassword"));
    req_ctx.put(MessageContext.HTTP_REQUEST_HEADERS, headers);
    ...

我看了這些帖子,但它們不能解決我的問題:

如何使用Java JAX-WS添加SOAP標頭

http://www.mkyong.com/webservices/jax-ws/application-authentication-with-jax-ws/

您可以嘗試在項目中本地存儲WSDL。

請參閱使用Java 6和JAX-WS-Wiki-Confluence消耗Web服務中的示例。

然后,可以使用“ 指定端點地址和HTTP基本授權”部分中的方法,就像問題中的第一個代碼一樣。

希望對您有所幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM