Я использую асинхронную клиентскую библиотеку Apache http для параллельных HTTP-вызовов и получения ответа на обратный вызов.Я получаю следующую ошибку после запроса, когда код развернут на сервере.
java.io.IOException: Connection reset by peer
at sun.nio.ch.FileDispatcherImpl.read0(Native Method)
at sun.nio.ch.SocketDispatcher.read(SocketDispatcher.java:39)
at sun.nio.ch.IOUtil.readIntoNativeBuffer(IOUtil.java:223)
at sun.nio.ch.IOUtil.read(IOUtil.java:197)
at sun.nio.ch.SocketChannelImpl.read(SocketChannelImpl.java:384)
at org.apache.http.nio.reactor.ssl.SSLIOSession.receiveEncryptedData(SSLIOSession.java:450)
at org.apache.http.nio.reactor.ssl.SSLIOSession.isAppInputReady(SSLIOSession.java:504)
at org.apache.http.impl.nio.reactor.AbstractIODispatch.inputReady(AbstractIODispatch.java:120)
at org.apache.http.impl.nio.reactor.BaseIOReactor.readable(BaseIOReactor.java:162)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvent(AbstractIOReactor.java:337)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.processEvents(AbstractIOReactor.java:315)
at org.apache.http.impl.nio.reactor.AbstractIOReactor.execute(AbstractIOReactor.java:276)
at org.apache.http.impl.nio.reactor.BaseIOReactor.execute(BaseIOReactor.java:104)
at org.apache.http.impl.nio.reactor.AbstractMultiworkerIOReactor$Worker.run(AbstractMultiworkerIOReactor.java:588)
at java.lang.Thread.run(Thread.java:745)
Вот мои зависимости
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpasyncclient</artifactId>
<version>4.1.3</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpclient</artifactId>
<version>4.5.5</version>
</dependency>
<dependency>
<groupId>org.apache.httpcomponents</groupId>
<artifactId>httpcore</artifactId>
<version>4.4</version>
</dependency>
как мне решить эту проблему?Заранее спасибо.
Добавление моего кода для справки
CloseableHttpAsyncClient httpclient = HttpAsyncClients.custom().build();
try {
httpclient.start();
final HttpGet[] requests = new HttpGet[] {new HttpGet("https://www.api.com/api/api1"),
new HttpGet("https://www.api.com/api/api2"),
new HttpGet("https://www.api.com/api/api3")};
final CountDownLatch latch = new CountDownLatch(requests.length);
final LocationData location= new LocationData();
for (final HttpGet request: requests) {
request.addHeader("Authorization", "Bearer "+token);
httpclient.execute(request, new FutureCallback<HttpResponse>() {
@Override
public void completed(final HttpResponse response) {
latch.countDown();
BufferedReader in = null;
in = new BufferedReader(new InputStreamReader(response.getEntity().getContent()));
String data = null;
while((data =in.readLine())!= null)
{
//process the data
}
}
@Override
public void failed(final Exception ex) {
latch.countDown();
System.out.println(request.getRequestLine() + "->" + ex);
ex.printStackTrace();
}
@Override
public void cancelled() {
latch.countDown();
System.out.println(request.getRequestLine() + " cancelled");
}
});
}
try {
latch.await();
} catch (InterruptedException e) {
e.printStackTrace();
}
//some more processinng here
} catch (Exception e) {
e.printStackTrace();
}
}
}
Любая помощь будет оценена.Кто-нибудь?