How to remove soapAction

此生再无相见时 提交于 2019-12-25 00:19:51

问题


I need to remove the soapAction from this header:

Headers: {Accept=[*/*], SOAPAction ["http://www.ya.ru/mybank/method/getDollars"]}

My configuration looks like this:

@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();
}

In the class of service I make such a request:

@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);
    }
}

I found this code, but I do not know how to apply it:

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()");
    }
}

This code can remove the required header


回答1:


It was necessary to create an interceptor:

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");
        }
    }
}

And apply it this way:

@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);
}

If you judge by logs, then the SOAPAction header is gone.



来源:https://stackoverflow.com/questions/52326792/how-to-remove-soapaction

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!