WS-Security および WS-Adressing ヘッダーを SOAPHeaders として期待する SOAP Web サービスを使用しようとしています。Java SOAP-WS クライアント ホラーと同様に、リクエストでこれらすべてのヘッダーを取得できませんでした。
私は CXF を使用しており、cxf-codegen プラグインを使用して Web サービス スタブを生成しました。WSSA4J インターセプターを使用して WSS ヘッダーを追加しようとしました (ここの cxf ドキュメントに基づく):
//WS-Security
org.apache.cxf.endpoint.Endpoint cxfEndpoint = client.getEndpoint();
Map<String,Object> outProps = new HashMap<String,Object>();
outProps.put(WSHandlerConstants.ACTION, WSHandlerConstants.USERNAME_TOKEN);
// Specify our username
outProps.put(WSHandlerConstants.USER, user.getUsername());
// Password type : plain text
outProps.put(WSHandlerConstants.PASSWORD_TYPE, WSConstants.PW_TEXT);
outProps.put("password", user.getPassword());
//Add the interceptor
WSS4JOutInterceptor wssOut = new WSS4JOutInterceptor(outProps);
cxfEndpoint.getOutInterceptors().add(wssOut);
ただし、要求には WS-Security ヘッダーが含まれていません。
WS-A ヘッダーを追加する際にも同じ問題があります。これに基づいて、 < To > および < ReplyTo > タグを追加したいと思いました。
//WS-A
Map<String, Object> reqCtx = client.getRequestContext();
AddressingProperties addrProperties = new AddressingProperties();
EndpointReferenceType endpointRef = new EndpointReferenceType();
AttributedURIType address = new AttributedURIType();
address.setValue("http://www.w3.org/2005/08/addressing/anonymous");
endpointRef.setAddress(address);
ReferenceParametersType refParams = new ReferenceParametersType();
refParams.getAny().add(new JAXBElement<String>(new QName("ServiceGroupId"), String.class, sessionId));
endpointRef.setReferenceParameters(refParams);
addrProperties.setReplyTo(endpointRef);
endpointRef = new EndpointReferenceType();
address.setValue(endpointUrl);
endpointRef.setAddress(address);
addrProperties.setTo(endpointRef);
reqCtx.put("javax.xml.ws.addressing.context", addrProperties);
私は次のようなものを期待していました:
<h:ReplyTo xmlns:h="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">
<Address>http://www.w3.org/2005/08/addressing/anonymous</Address>
<ReferenceParameters>
<ServiceGroupId>urn:uuid:8f27332c08854fb09989b2d</ServiceGroupId>
</ReferenceParameters>
</h:ReplyTo>
<h:To xmlns:h="http://schemas.xmlsoap.org/ws/2004/08/addressing" xmlns="http://schemas.xmlsoap.org/ws/2004/08/addressing">
http://...
</h:To>
しかし、SOAP リクエストには何もありませんでした。私は何が欠けていますか/間違っていますか?
この時点で、SOAP ヘッダーを直接変更して手動で追加できれば幸いです。メッセージがインターセプターを使用して送信される前に、ヘッダーを変更できますか?
CXF 3.1.2、wss4j 2.1.2、Java 1.8、および Spring Boot 1.2.5 を使用しています。
ありがとうございました!