0

I use Java and Spring Boot. I implemented the correct termination of the application when receiving the SIGTERM command.

Set the settings for SpringBoot:

server:
  shutdown: graceful

spring.task.execution:
  pool:
    allow-core-thread-timeout: true
    keep-alive: 3m
  shutdown:
    await-termination: true
    await-termination-period: 3m

And I also tried it with ThreadPoolTaskExecutor:

ThreadPoolTaskExecutor defaultExecutor = new ThreadPoolTaskExecutor();
defaultExecutor.setKeepAliveSeconds(180);
defaultExecutor.setWaitForTasksToCompleteOnShutdown(true);
defaultExecutor.setAwaitTerminationSeconds(180);

But I ran into a problem. In an asynchronous thread, the SOAP method is called and it crashes with an error:

ERROR [iso20022.app.FCR,3b58933b54e5e47c,1eb7da1d0650e9d9] 2808 --- [     h2h-async1] r.a.h.c.RepeaterInvocationHandler        : error on calling jdk.proxy6.$Proxy236.wsAccountBaseInfoGet
java.lang.ExceptionInInitializerError: null
    at com.sun.xml.ws.transport.http.client.HttpTransportPipe.getTransport(HttpTransportPipe.java:154) ~[jaxws-rt-2.3.1.jar:2.3.1]
…
Caused by: java.lang.IllegalStateException: Illegal access: this web application instance has been stopped already. Could not load [META-INF/services/javax.xml.bind.JAXBContext]. The following stack trace is thrown for debugging purposes as well as to attempt to terminate the thread which caused the illegal access.
    at org.apache.catalina.loader.WebappClassLoaderBase.checkStateForResourceLoading(WebappClassLoaderBase.java:1432) ~[tomcat-embed-core-9.0.76.jar:9.0.76]
    at org.apache.catalina.loader.WebappClassLoaderBase.getResourceAsStream(WebappClassLoaderBase.java:1140) ~[tomcat-embed-core-9.0.76.jar:9.0.76]
    at javax.xml.bind.ContextFinder.firstByServiceLoaderDeprecated(ContextFinder.java:611) ~[jaxb-api-2.4.0-b180830.0359.jar:2.3.0]

Please, help. What do I need to do?

Miss Skooter
  • 803
  • 10
  • 22

2 Answers2

0

The problem was in the libraries.

Was:

implementation group: 'org.glassfish.main.javaee-api', name: 'javax.jws', version: '3.1.2.2'
implementation group: 'javax.xml.ws', name: 'jaxws-api', version: '2.3.1'
implementation group: 'com.sun.xml.ws', name: 'jaxws-rt', version: '2.3.1'

Need to do:

implementation 'jakarta.xml.bind:jakarta.xml.bind-api:4.0.0'
implementation 'jakarta.xml.ws:jakarta.xml.ws-api:4.0.0'
implementation 'jakarta.activation:jakarta.activation-api:2.1.2'
implementation 'com.sun.xml.ws:jaxws-rt:4.0.1'
implementation 'com.sun.xml.bind:jaxb-impl:2.3.1'
implementation 'org.glassfish.jaxb:jaxb-runtime:4.0.2'
runtimeOnly 'jakarta.xml.soap:jakarta.xml.soap-api:3.0.0'
runtime Only 'com.sun.xml.messaging.saaj:saaj-impl:3.0.2'

And accordingly, fix the imports in the classes from javax to jakarta

-2

The error message indicates that the SOAP client is throwing an exception because it's trying to access a resource (META-INF/services/javax.xml.bind.JAXBContext) that is not available due to the web application being stopped.

This issue can occur when the application is shutting down and the SOAP client is still trying to make requests. To handle this gracefully, you can catch the exception and handle it appropriately. Here's an example of how you can do this:

import javax.xml.ws.WebServiceException;

// ...

try {
    // Call the SOAP method
    // Your SOAP method invocation code here
} catch (WebServiceException ex) {
    if (ex.getCause() instanceof IllegalStateException) {
        IllegalStateException illegalStateException = (IllegalStateException) ex.getCause();
        if (illegalStateException.getMessage().startsWith("Illegal access: this web application instance has been stopped")) {
            // Handle the case where the web application is stopping
            // You can choose to log the error or perform any necessary cleanup
            // Example: logger.error("SOAP client error: Web application is stopping", ex);
        } else {
            // Handle other WebServiceException cases
        }
    } else {
        // Handle other WebServiceException cases
    }
}

In the code above, we catch the WebServiceException and check if the cause of the exception is an IllegalStateException with the specific error message indicating that the web application is stopping. If it matches, you can handle the situation accordingly (e.g., logging an error message or performing cleanup operations).

By handling the exception, you can prevent the application from crashing when the SOAP client is invoked during the shutdown process.

  • Thanks! Probably I will have to do this, but this type of error can be caught using Error, since it is not an exception that occurs, but an error – Systemoteh Aug 18 '23 at 06:48