title: Spring WS/boot: How to set WebServiceTemplate property in client interceptor?
body: <p>My application is both SOAP server and Client, i,e it acts like a proxy server in between the clients and webservice provider. So i get different client requests and i will do validation and route them to the destination soap service by setting up appropriate SSL/TS configurations. I am using Spring WS to make a SOAP web service call. Below code is working fine:</p>
  
  <pre><code>     try {
              webServiceTemplate.setMessageSender(certManager.setKeystores());
              // perform the transaction
              SOAPResponse =  (JAXBElement&lt;Response&gt;) webServiceTemplate
                      .marshalSendAndReceive(SoapRequest);
          } catch(Exception e) {
              // catching a broad exception here because many things can go wrong,
              //but any exception means total failure
              throw new ServiceException(e);
          }
  </code></pre>
  
  <p>But i am trying a different approach where i set the SSL configuration in client interceptor:</p>
  
  <pre><code>public class AppClientInterceptor implements ClientInterceptor{
  
      private static final Logger LOGGER = LoggerFactory
              .getLogger(AppClientInterceptor.class);
      @Autowired
      WebServiceTemplate webServiceTemplate;
      @Autowired
      CertManager certManager;
  
      @Override
      public boolean handleRequest(MessageContext messageContext) throws WebServiceClientException {
          // pull out the request from the current thread
  
          try {
              LOGGER.info("before setting message sender");
              if(webServiceTemplate!=null)
              webServiceTemplate.setMessageSender(certManager.setKeystores());
              else
              System.out.println("web service tempate is null");  
              return false;
          } catch (GeneralSecurityException | IOException e) {
              // TODO Auto-generated catch block
              LOGGER.info("In catch block unable to set keystores");
              e.printStackTrace();
          }
  
          return false;
      }
  </code></pre>
  
  <p>The client interceptor is getting invoked when i make the webservice call, but its failing as the webservicetemplate is null. I wired the web service template, but not able to understand why its null. The webservice template which i used is below:</p>
  
  <pre><code>@Bean
      public WebServiceTemplate webServiceTemplate() {
  
          WebServiceTemplate webServiceTemplate = new WebServiceTemplate();
          webServiceTemplate.setMarshaller(jaxb2Marshaller());
          webServiceTemplate.setUnmarshaller(jaxb2Marshaller());
          ClientInterceptor[] interceptors = {new AppClientInterceptor()};
          webServiceTemplate.setInterceptors(interceptors);
          webServiceTemplate.setDefaultUri(
                  "https://destinationserver.com:10072");
  
          return webServiceTemplate;
      }
  </code></pre>
  
  <p>Can i set the SSL configuration in my interceptor in the above way? Is it a right approach?</p>
  
  <p>Thanks in advance</p>