【问题标题】:How to set timeout to RestServiceAdapter in Oracle MAF?如何在 Oracle MAF 中为 RestServiceAdapter 设置超时?
【发布时间】:2016-10-14 13:59:45
【问题描述】:

我在 Oracle MAF 中使用 RestServiceAdapter 来调用 Restfull 服务,我想为服务设置超时,因为我在存在网络连接时遇到问题(例如:信号低、接入点连接错误等),所以应用程序变得很奇怪,它尝试执行请求,然后以奇怪的行为挂出。

这是我的代码,运行良好,但如果花费的时间超过 X 秒,我会抛出异常。

public String getJSONResponse(String baseUrlService) throws Exception {
    try {
        RestServiceAdapter restServiceAdapter = RestServiceAdapterFactory.newFactory().createMcsRestServiceAdapter();  
        restServiceAdapter.clearRequestProperties();  
        restServiceAdapter.setConnectionName(REST_STORE_CONNECTION);  
        restServiceAdapter.setRequestURI(baseUrlService);       
        restServiceAdapter.setRequestMethod("GET");

        //Base 64 de Autenticacion de Weblogic real usuario 'Basic store-rest-user:password'
        restServiceAdapter.addRequestProperty("Authorization", "Basic " + loginBase64);
        //restServiceAdapter.setRequestType(RestServiceAdapter.REQUEST_TYPE_GET);  
        String response = restServiceAdapter.send(""); 
        return response;
    } catch(Exception e) {
        throw new Exception("Error: problema de conexión o problema en servidor");
    }
}

【问题讨论】:

    标签: oracle-adf oracle-maf maf


    【解决方案1】:

    据我所知,RestServiceAdapter 中没有选项可以使连接超时。但是您可以配置重试连接的频率。所以最好的做法似乎是将重试限制设置为 1,然后使用 RestServiceAdapter 从后台线程访问远程服务。

    【讨论】:

    • 谢谢,实际上我试图发送后台服务并使用 Executors 超时,我想我取得了一些成就,但是做一些本以为很容易的事情变得越来越复杂。我会试试你说的。
    • 如果您认为正确,请为答案投票。对其他人有用
    • 我认为它很有用,但它不能解决请求超时的需要
    • 如果你想使用 setTimedOut 使用 HttpURLConnection
    猜你喜欢
    • 2014-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-09-02
    • 1970-01-01
    • 1970-01-01
    • 2021-03-28
    • 2016-06-29
    相关资源
    最近更新 更多