Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

567
Views
Spring WS/boot: How to set WebServiceTemplate property in client interceptor?

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:

     try {
            webServiceTemplate.setMessageSender(certManager.setKeystores());
            // perform the transaction
            SOAPResponse =  (JAXBElement<Response>) 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);
        }

But i am trying a different approach where i set the SSL configuration in client interceptor:

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

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:

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

Can i set the SSL configuration in my interceptor in the above way? Is it a right approach?

Thanks in advance

about 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Did you tried @Configurable annotation before the class definition?

@Configurable
public class AppClientInterceptor implements ClientInterceptor{
    ...
}
about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!