Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

573
Vistas
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

over 4 years ago · Santiago Trujillo
1 Respuestas
Responde la pregunta

0

Did you tried @Configurable annotation before the class definition?

@Configurable
public class AppClientInterceptor implements ClientInterceptor{
    ...
}
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda