Search code examples
spring-integrationspring-integration-dslspring-integration-http

MarshallingWebServiceOutboundGateway takes too much for the first request


We have lot of soap services that we use to connect to and every time the first to the same service takes lot of time to initiate from integration and subsequent requests are fast cutting down by 60% of response time.

Analyzed on the JAXB bindings initialization

@Configuration
public interface WSCommons {
Jaxb2Marshaller marshaller = new Jaxb2Marshaller();
    @Bean
      static Jaxb2Marshaller jaxb2Marshaller() {
            marshaller.setPackagesToScan("com.abc");
        return marshaller;
      }
}

This takes significant amount of for the first request to scan every thing and create the marshaller.

But,

Once the Bean is initialized it works fast for few requests. When the service flow is idle for some time and requests starts flowing again, MarshallingWebServiceOutboundGateway lags really bad.

Jaxb2Marshaller is static and it should die down to re-initialize in this case.

Any input is appreciated, may be doing things wrong in the initialization.

Thanks


Solution

  • I don't believe it is going to work with the @Configuration on the interface. Therefore your @Bean for the Jaxb2Marshaller is not visible.

    You need to consider to make your @Configuration as a class and remove that static from the bean definition.

    The Jaxb2Marshaller has an option like:

    /**
     * Set whether to lazily initialize the {@link JAXBContext} for this marshaller.
     * Default is {@code false} to initialize on startup; can be switched to {@code true}.
     * <p>Early initialization just applies if {@link #afterPropertiesSet()} is called.
     */
    public void setLazyInit(boolean lazyInit) {
    

    Which is false by default and therefore an afterPropertiesSet() is called during normal bean initialization phase. All the packages is scanned here and a fully blown JAXBContext is cached in the Jaxb2Marshaller bean.