2015-11-20 77 views
1

我在NetBeans中爲SOAP Web服務創建了一組代理類。如何將HTTP標頭添加到JAXWS創建的代理類

我想爲傳出的請求添加一個HTTP標頭。

Map<String, Object> requestHeaders = new HashMap<>(); 
requestHeaders.put("X-Header", header); 
AccountManagementService service = new AccountManagementService(); 
AccountManagementServiceSoap soap = service.getAccountManagementServiceSoap(); 
GetMembershipSummaryResponse.GetMembershipSummaryResult membershipSummary = soap.getMembershipSummary("[email protected]"); 

我看到一堆JAX-WS頭部示例,用於從服務中獲取單個端口。有更容易的方法嗎?我可以將標題添加到服務或肥皂對象上的某個集合嗎?

回答

0

後一些挖我發現這個職位:jax-ws change Content-type to Content-Type because server is hyper sensitive

這是不是一個真正的完整的答案,所以我會發布完整的答案在這裏:

AccountManagementService service = new AccountManagementService(); 
    AccountManagementServiceSoap soap = service.getAccountManagementServiceSoap(); 

    ((BindingProvider)soap).getRequestContext().put(MessageContext.HTTP_REQUEST_HEADERS, 
    Collections.singletonMap("X-Header",Collections.singletonList(header))); 
    GetMembershipSummaryResponse.GetMembershipSummaryResult membershipSummary = soap.getMembershipSummary("[email protected]"); 
相關問題