Java login using Unirest
I am using unirest for a call method from an API. But after implementing it in my code and viewing it in the server log, it always causes expired connections to close.
This code of mine:
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've tried using Unirest.shutdown () in my code. The log has become normal, but after it I cannot use the Unirest code. I found it was a stop.
Is it possible to run it after calling Unirest.shutdow () or fix the log?
+3
source to share
1 answer
You can use com.mashape.unirest.http.options.Options.refresh();
to re-enable Unirest or just change log4j to change the log level org.apache.http.impl.conn.PoolingHttpClientConnectionManager from DEBUG.
<logger name="org.apache.http.impl.conn.PoolingHttpClientConnectionManager">
<level value="WARN"/>
<appender-ref ref="MyLogFile"/>
</logger>
+1
source to share