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
Did you tried @Configurable annotation before the class definition?
@Configurable
public class AppClientInterceptor implements ClientInterceptor{
...
}