Server Log in java using Unirest

4.1k Views Asked by At

I use unirest for call method from API. But after implement it in my code and see in server log, it always call closing expired connections.

This my code:

public static JSONArray getJsonArray(String url, Map<String, Object> filter){
    GetRequest request = null;
    jArr= null;  
    try {
        Unirest.setTimeouts(10000, 10000);
        request = Unirest.get(url).header("accept", "application/json");

        if (filter != null){
            request.queryString(filter);
        }

        jArr = request.asJson().getBody().getArray();
    } catch (Exception ex){
        logger.debug(ex);
    }finally{
        //Unirest.shutdow();
    }
    return jArr;
}

Server log:

 14:05:25,954 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:25,954 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,529 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,529 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,826 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,826 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS
 14:05:26,835 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing expired connections
 14:05:26,835 INFO  [STDOUT] [PoolingHttpClientConnectionManager] : Closing connections idle longer than 30 SECONDS

I had tried using Unirest.shutdown() in my code. The log became normal but i cannot use Unirest code again after it. I found it was stop.

Is a way to start it after call Unirest.shutdow() or fix the log?

1

There are 1 best solutions below

0
On

You may use com.mashape.unirest.http.options.Options.refresh(); to enable Unirest again or just modify log4j to change the log level of org.apache.http.impl.conn.PoolingHttpClientConnectionManager from DEBUG.

<logger name="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
    <level value="WARN"/>
    <appender-ref ref="MyLogFile"/>
</logger>