-
Notifications
You must be signed in to change notification settings - Fork 30
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How enable WSA-Addresing for client? #63
Comments
I think you need to use an out interceptor and modify the header in the interceptor. Here is some pseudo code for one I have done in the past. package com.foo.bar
import org.apache.cxf.message.Message;
import org.apache.cxf.phase.AbstractPhaseInterceptor;
import org.apache.cxf.phase.Phase;
import org.springframework.beans.factory.annotation.Autowired;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class SmartApiMetaOutInterceptor extends AbstractPhaseInterceptor<Message> {
@Autowired
EndpointConfiguration endpointConfiguration;
public SmartApiMetaOutInterceptor() {
super(Phase.PREPARE_SEND);
}
@Override
public void handleMessage(Message message) {
if(message != null) {
Map<String, List<String>> headers = (Map<String, List<String>>) message.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
headers = new HashMap<>();
message.put(Message.PROTOCOL_HEADERS, headers);
}
headers.put("X-Cache-Enabled", Collections.singletonList(endpointConfiguration.isCacheEnabled().toString()));
headers.put("X-Cache-Remote-Url", Collections.singletonList(endpointConfiguration.getFopBaseServiceUrl()));
headers.put("X-Cache-Prefix", Collections.singletonList(endpointConfiguration.getCachePrefix()));
}
}
} |
@michmzr Did the out interceptor work for you? |
Thanks for help, but interceptor only injected HTTP headers. I need to modify SOAP Request do add xml with soap header |
Still possible via SoapPreProtocolOutInterceptor |
Thank you for help :) Finally, I found the solution. My interceptor public class BirSoapHeaderInterceptor extends AbstractSoapInterceptor { public BirSoapHeaderInterceptor() { super(Phase.PRE_PROTOCOL); } @Override public void handleMessage(SoapMessage message) throws Fault { List list = message.getHeaders() //----------------- copy values from old header String wsaAction = "" String wsaTo = "" list.each{tag -> System.out.println("${tag.name} ${tag.dataBinding}") String tagName = (tag.name as String) def objectValue = tag.object?.value if(!wsaAction && tagName.contains("Action")) wsaAction = objectValue?.value if(!wsaTo && tagName.contains("To")) wsaTo = objectValue?.value } list.clear() //-----------------wsa:To Header headTo = new Header(new QName("", "wsa:To"), wsaTo, new JAXBDataBinding(String.class)) list.add(headTo) //-----------------wsa:Action Header headAction = new Header(new QName("", "wsa:Action"), wsaAction, new JAXBDataBinding(String.class)) list.add(headAction) message.put(Header.HEADER_LIST, list) } } |
:) |
I imported classes from xsd file with configuration, but server require WSA-Attributes in soap header("wsa:action", "wsa:to"). Unfortunettly client service dont inject these attributes and server return http code 400. How could I repair my code?
Configuration in Config.groovy
Main xsd file: https://wyszukiwarkaregontest.stat.gov.pl/wsBIR/wsdl/UslugaBIRzewnPubl.xsd
I use grails 2.5.0
Update:
I used annotation javax.xml.ws.soap.Addressing for actions and soap request header included WS-Addresing, but was wrong for webserver.
The text was updated successfully, but these errors were encountered: