Search code examples
spring-bootspring-3webservicetemplatespring-boot-2

WebServiceTemplate performance issue with spring boot


I am consuming soap web services using WebServiceTemplate its working fine with good performance in spring3+ .

spring :- 3.2.4.RELEASE
spring-ws-core :- 2.1.4.RELEASE
spring-ws-support :- 2.1.4.RELEASE
spring-ws-security :-2.1.4.RELEASE

Class for calling soap service

SaajSoapMessageFactory messageFactory = new SaajSoapMessageFactory(MessageFactory.newInstance());
messageFactory.afterPropertiesSet();

WebServiceTemplate webServiceTemplate = new WebServiceTemplate(messageFactory);

Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
marshaller.setContextPath("some package");
marshaller.afterPropertiesSet();

webServiceTemplate.setMarshaller(marshaller);
webServiceTemplate.setUnmarshaller(marshaller);
webServiceTemplate.afterPropertiesSet();
webServiceTemplate.setInterceptors(clientInterceptors);
webServiceTemplate.setMessageSender(webServiceMessageSenderWithAuth);
webServiceTemplate.setDefaultUri(url);
Output result= ((JAXBElement<Output >) webServiceTemplate.marshalSendAndReceive(jaxbRequest)).getValue();

Configuration File

@Configuration
public class WebServiceConfiguration {

    @Autowired
    private SaajSoapMessageFactory messageFactory;

    @Autowired
    private WebServiceMessageSenderWithAuth webServiceMessageSenderWithAuth;

    @Bean
    public Wss4jSecurityInterceptor getWss4jSecurityInterceptor(@Value("${WSDL.UserName}") String userName,
            @Value("${WSDL.Password}") String password) {
        Wss4jSecurityInterceptor wss4jSecurityInterceptor = new Wss4jSecurityInterceptor();
        wss4jSecurityInterceptor.setSecurementActions("UsernameToken");
        wss4jSecurityInterceptor.setSecurementPasswordType("PasswordText");
        wss4jSecurityInterceptor.setSecurementUsername(userName);
        wss4jSecurityInterceptor.setSecurementPassword(password);
        return wss4jSecurityInterceptor;
    }

    @Bean
    public SaajSoapMessageFactory getSaajSoapMessageFactory() {
        return new SaajSoapMessageFactory();
    }

    @Bean
    public ClientInterceptor[] clientInterceptors(Wss4jSecurityInterceptor wsSecurityInterceptor) {
        return new ClientInterceptor[] { wsSecurityInterceptor };
    }
}

Performance result Timings -- around 500ms average time , max time :- 1 sec

Spring Boot 1.5.20.RELEASE and 2.2.2.RELEASE

With spring boot same code without any change takes around 4sec for first call and if continue hitting the same then takes around 2sec for

Performance result with spring boot

First Call :- 4 sec

Subsequent calls without interval (1-10 sec gap) :- 2 sec to 800 ms

Its keep on decreasing while keep hitting the same call again and again with less interval and goes down to spring mvc 3 like result but if tried again after some interval like 5 min then again follow the same pattern If same tried after 5 mins then again the result is same for first and further calls.

Note:- With spring boot i have tried wss4j as well instead of wss4j2 Also tried AxiomSoapMessageFactory but no luck

  • i have tried connection keep alive etc etc but still no luck

Solution

  • So the issue is not with code. I finally deployed it on jboss Wildfly and bang.. It just start performing really well without a single line change.

    Now its taking around 300ms to 500ms. So the problem is with embedded tomcat and embedded jetty is not good