2014-12-05 55 views
0

我想使用的用戶名/密碼使用下面的客戶端調用web服務,但我沒有看到用戶名/密碼的頭被設置無法傳遞JAXWS用戶名和密碼

客戶端代碼

AttachmentWSImplService service = new AttachmentWSImplService(); 
     AttachmentWS aws = service.getAttachmentWS(); 
     BindingProvider bindingProvider = (BindingProvider) aws; 
     SOAPBinding sopadBinding = (SOAPBinding) bindingProvider.getBinding(); 
     sopadBinding.setMTOMEnabled(true); 

     bindingProvider.getRequestContext().put(bindingProvider.USERNAME_PROPERTY,"p3xferdt"); 
     bindingProvider.getRequestContext().put(bindingProvider.PASSWORD_PROPERTY,"92mnGg1Cb14D9hVhG1W5fZra4UI="); 

Server代碼

SOAPMessageContext ctx = (SOAPMessageContext) wsCtx 
      .getMessageContext(); 
    java.util.Map<java.lang.String, java.util.List<java.lang.String>> headers = (Map<String, List<String>>) ctx 
      .get(MessageContext.HTTP_REQUEST_HEADERS); 
    if (headers.keySet() != null && !headers.keySet().isEmpty()) { 
     Iterator<String> keys = headers.keySet().iterator(); 
     while (keys.hasNext()) { 
      String key = (String) keys.next(); 
      logger.info("HeaderKey->" + key); 
      logger.info("Header values->" + headers.get(key)); 
      // getting Basic Authentication 
      String tmpusername = getUsernameFromAuthentication(key, 
        headers.get(key).toString()); 

回答

0

代碼看起來不錯對我來說,應該很好地工作。

不管怎麼說嘗試通過

Headers headers = ex.getRequestHeaders(); 
List<String> ulist = headers.get(BindingProvider.USERNAME_PROPERTY); 
List<String> plist = headers.get(BindingProvider.PASSWORD_PROPERTY); 

PS訪問請求頭:還記得USERNAME_PROPERTY從BindingProvider接口的靜態字符串,可以在靜態的方式進行訪問。 (編碼標準:))

相關問題