Mirlo
Mirlo

Reputation: 674

set timeout for a WebSphere Spring boot application

i'm using a spring boot application which running on a LibertyCode server,

I have a web server configured with a timeout :

ClientConfig configuration = new ClientConfig();
        configuration.property(ClientProperties.CONNECT_TIMEOUT, connecTimeout);
        configuration.property(ClientProperties.READ_TIMEOUT, readTimeout);
        apiClient = ClientBuilder.newClient(configuration);
        WebTarget target = apiClient.target(uri);
        Response response = target.request(MediaType.APPLICATION_JSON_VALUE).header("accept", "application/json")
                .header("Content-Type", "application/json").get();

it works perfectly on my local machine ( based on tomcat without websphere) but when i run the war on a WebSphere server the timeout was ignored ! that's the features using in my server.xml :

   <feature>localConnector-1.0</feature>
        <feature>restConnector-1.0</feature>
        <feature>beanValidation-1.1</feature>
        <feature>adminCenter-1.0</feature>
        <feature>transportSecurity-1.0</feature>

Any help please

Upvotes: 0

Views: 261

Answers (1)

Andy McCright
Andy McCright

Reputation: 1283

Can you try changing <feature>restConnector-1.0</feature> to <feature>restConnector-2.0</feature>? I think that the 1.0 connector leaks JAX-RS - basically including it for the application - even if you package your own version of JAX-RS and CXF, etc. When that happens you get Liberty's version of JAX-RS (which is based on CXF but doesn't allow users to load the CXF-specific implementation classes) for the APIs and possibly even some implementation classes. Further, I think the restConnector-1.0 feature uses an older version of JAX-RS that may not support the connect and read timeouts.

If moving to restConnector-2.0 doesn't work, then I would suggest explicitly adding the jaxrs-2.1 feature and then using the JAX-RS APIs instead of the implementation-specific APIs. It would look something like:

Client apiClient = ClientBuilder.newBuilder()
                                .connectTimeout(connecTimeout)
                                .readTimeout(readTimeout)
                                .build();
WebTarget target = apiClient.target(uri);
Response response = target.request(MediaType.APPLICATION_JSON)
                          .header("Content-Type", MediaType.APPLICATION_JSON)
                          .get();

Hope this helps!

Upvotes: 2

Related Questions