簡體   English   中英

為 WebSphere Spring 引導應用程序設置超時

[英]set timeout for a WebSphere Spring boot application

我正在使用在 LibertyCode 服務器上運行的 spring 啟動應用程序,

我有一個配置了超時的 web 服務器:

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();

它在我的本地機器上完美運行(基於沒有 websphere 的 tomcat)但是當我在 WebSphere 服務器上運行戰爭時,超時被忽略了! 這就是我的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>

請提供任何幫助

您可以嘗試將<feature>restConnector-1.0</feature>更改為<feature>restConnector-2.0</feature>嗎? 我認為 1.0 連接器會泄漏 JAX-RS - 基本上包括它用於應用程序 - 即使您 package 您自己的 JAX-RS 和 CXF 版本等。發生這種情況時,您會得到 Liberty 的 JAX-RS 版本(基於CXF,但不允許用戶為 API 甚至某些實現類加載特定於 CXF 的實現類。 此外,我認為 restConnector-1.0 功能使用可能不支持連接和讀取超時的舊版本的 JAX-RS。

如果遷移到 restConnector-2.0 不起作用,那么我建議顯式添加jaxrs-2.1功能,然后使用 JAX-RS API 而不是特定於實現的 API。 它看起來像:

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();

希望這可以幫助!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM