我需要从此标头中删除soapAction:
Headers: {Accept=[*/*], SOAPAction ["http://www.ya.ru/mybank/method/getDollars"]}
我的配置如下:
@PostConstruct
public void initialization(){
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyClass.class);
factory.setAddress(myWsdlUrl);
service = (MyClass) factory.create();
Client client = ClientProxy.getClient(service);
}
@Bean
public SAAJMetaFactory messageFactory(){
return new SAAJMetaFactoryImpl();
}
在服务类别中,我提出了这样的要求:
@Service
public class MyIntegrationImpl implements MyIntegration {
private MyClass service;
public MyIntegrationImpl(MyClass service) {
this.service = service;
}
@Override
public Info getVpc(ReqClass req, String clientPhone) {
return service.getInfo(req, clientPhone);
}
}
我找到了此代码,但是我不知道如何应用它:
public class RemoveActionHandler implements SOAPHandler<SOAPMessageContext> {
@Override
public Set<QName> getHeaders() {
System.out.println("Server : getHeaders()");
return null;
}
@Override
public boolean handleMessage(SOAPMessageContext context) {
if ("".equals(context.get(BindingProvider.SOAPACTION_URI_PROPERTY)))
context.put(BindingProvider.SOAPACTION_URI_PROPERTY, null);
return true;
}
@Override
public boolean handleFault(SOAPMessageContext context) {
System.out.println("Server : handleFault()");
return true;
}
@Override
public void close(MessageContext context) {
System.out.println("Server : close()");
}
}
此代码可以删除所需的标头
答案 0 :(得分:0)
有必要创建一个拦截器:
public class ServiceMyInterceptor extends AbstractSoapInterceptor {
private static final Logger LOGGER = LoggerFactory.getLogger(ServiceMyInterceptor.class);
public ServiceMyInterceptor() {
super(Phase.USER_PROTOCOL);
addAfter(ReadHeadersInterceptor.class.getName());
addAfter(EndpointSelectionInterceptor.class.getName());
}
@Override
public void handleMessage(SoapMessage message) throws Fault {
Map<String, List<String>> headers = CastUtils.cast((Map)message.get(Message.PROTOCOL_HEADERS));
if (headers != null) {
List<String> sa = headers.get("SOAPAction");
String action = null;
if (sa != null && sa.size() > 0) {
action = sa.get(0);
}
LOGGER.info("Remove SOAPAction who equals {}", action);
headers.remove("SOAPAction");
}
}
}
并以这种方式应用它:
@PostConstruct
public void initialization(){
JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
factory.setServiceClass(MyClass.class);
factory.setAddress(myWsdlUrl);
service = (MyClass) factory.create();
Client client = ClientProxy.getClient(service);
ServiceMyInterceptor interceptor = new ServiceMyInterceptor();
client.getEndpoint().getOutInterceptors().add(interceptor);
}
如果通过日志判断,则SOAPAction标头不见了。