0

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

kiran reddy
  • 135
  • 17

1 Answers1

0

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.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I actually had that question, if the context is getting created every time a request is created and the gateway is opened. Had a debug point on : `private JAXBContext createJaxbContextFromPackages() throws JAXBException` it only stops once for the first request and subsequent it is not. – kiran reddy Oct 08 '18 at 23:38
  • by the code works , it is just slow on the SOAP flow.. i am checking on if the JAXB context is not getting created or retrieved correctly. – kiran reddy Oct 09 '18 at 00:21
  • I’m not sure what you are talking about. Only what I see with config you provide, that you use Spring wrong way. Everything rest is missed in your question. So, this might be just a speculation – Artem Bilan Oct 09 '18 at 00:23
  • Too much not related information. I’m intended to close your question as `Not clear what you’re asking ` – Artem Bilan Oct 09 '18 at 12:00
  • will post a new question – kiran reddy Oct 09 '18 at 16:46