0

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

maksim2112
  • 381
  • 7
  • 21

1 Answers1

0

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.

maksim2112
  • 381
  • 7
  • 21