Adding soap header for each service request

Rachel :

First I will explain the project. It is an integration Web Service, that listens for requests and internally consumes another web Service and handles its reponses in order to get the desired answer. I need to add a custom header to each request to the "internal" Web Service. I have checked that using the next configuration, the handler is a singleton class. I need that every new request to the "internal Service" creates a new instance. I have checked that sometimes the headers for request "A" are using the values for request "B". I am initializing the values of the header before the first "internal" request (I need to make a call to a method of the "internal" web service without any soap header, and then set it up using a value contained in the first response). Any ideas how can I make this work?

Thanks

//ConfigurationClass

@Bean(name = "internalService")
         @Scope(scopeName="prototype")


            public JaxWsPortProxyFactoryBean internalService() {
                JaxWsPortProxyFactoryBean bean = new JaxWsPortProxyFactoryBean();

                try {
                    bean.setServiceInterface(internalService.class);
                    bean.setWsdlDocumentUrl(new URL("https://localhost/internalService.svc?wsdl" ));
                    bean.setNamespaceUri( "http://schemas.internalService.com/2019/04/");
                    bean.setServiceName("InternalService");
                    bean.setPortName("InternalServicePort");
                    bean.setEndpointAddress("https://localhost/internalService.svc");
                    bean.setHandlerResolver(wsHandlerResolver());

                } catch (MalformedURLException e) {

                    e.printStackTrace();

                }

                return bean;

            }
@Bean(name = "wsHandlerResolver")

            public WebServiceHandlerResolver wsHandlerResolver() {
             WebServiceHandlerResolver wshandlerResolver = new WebServiceHandlerResolver();
             List handlers = new ArrayList();
             handlers.add(webServiceHandler());
             wshandlerResolver.setHandlers(handlers);
                return wshandlerResolver;

            }

 @Bean(name = "webServiceHandler")
            public WebServiceHandler webServiceHandler() {
             WebServiceHandler webServiceHandler = new WebServiceHandler();
                return webServiceHandler;

            }
//HandlerResolver class
public class WebServiceHandlerResolver implements HandlerResolver {

    private List<Handler> handlers;

    public List<Handler> getHandlerChain(PortInfo portInfo) {
        return handlers;
    }

    public void setHandlers(List<Handler> handlers) {
        this.handlers = handlers;
    }
}
//Handler class
public class WebServiceHandler implements SOAPHandler<SOAPMessageContext> {

    private String user;
    private String pass;
    private String source;

    @Override
    public boolean handleMessage(SOAPMessageContext context)  {
             //THIS IS WHERE I ADD THE VALUES
        }

}
Rachel :

Finally I was able to do it. It was just a problem with the scope request in the Handler class, I was missing the proxyMode option.

@Scope(value = WebApplicationContext.SCOPE_REQUEST, proxyMode = ScopedProxyMode.TARGET_CLASS)

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=157942&siteId=1