Исключение сброса соединения (разорванный канал) при использовании httpclient для чтения файла

#java #file #httpclient

Вопрос:

Я рассмотрел некоторые вопросы StackOverflow о сбросе соединения и сломанной трубе. Это объясняет проблему. но решения не помогают.

При чтении файлов с помощью HttpClient из API. Я получаю сообщение об ошибке восстановления соединения, указывающее на ошибку сломанной трубы.

 public HttpResponse get(String url, String token) throws Exception {

    try (CloseableHttpClient client = HttpClients.custom()
            .setConnectionManager(getConnectionManager())
            .setConnectionManagerShared(true).
            setConnectionTimeToLive(1, TimeUnit.MILLISECONDS).setMaxConnPerRoute(10000).build()) {

        // configure the timeouts (socket and connection) for the request
        RequestConfig.Builder config = RequestConfig.copy(RequestConfig.DEFAULT);
        // 5 minutes
        config.setConnectionRequestTimeout(5 * 60 * 1000);
        config.setSocketTimeout(5 * 60 * 1000);
        config.setConnectTimeout(5 * 60 * 1000);

        HttpGet request = new HttpGet(url);
        request.setConfig(config.build());
        if (token != null) {
            String bearerHeaderValue = "Bearer "   token;
            request.addHeader("Authorization", bearerHeaderValue);
        }
        HttpResponse response = client.execute(request);
        return response;
    } catch (Exception e) {
        log.error(e.getMessage());
        throw new Exception(e);
    }
}
 

Я устанавливаю входной поток в классе POJO, имеющем свойства файла, и передаю класс модели и чтение в других проектах зависимостей.

 There I am getting the below error.

    javax.net.ssl.SSLException: Connection reset
    at sun.security.ssl.Alert.createSSLException(Alert.java:127) ~[?:1.8.0_292]
    at sun.security.ssl.TransportContext.fatal(TransportContext.java:324) ~[?:1.8.0_292]
    at sun.security.ssl.TransportContext.fatal(TransportContext.java:267) ~[?:1.8.0_292]
    at sun.security.ssl.TransportContext.fatal(TransportContext.java:262) ~[?:1.8.0_292]
    at sun.security.ssl.SSLTransport.decode(SSLTransport.java:138) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1386) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1354) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketImpl.access$300(SSLSocketImpl.java:73) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:948) ~[?:1.8.0_292]
    at okio.Okio$2.read(Okio.java:140) ~[okio-1.17.2.jar:?]
    at okio.AsyncTimeout$2.read(AsyncTimeout.java:237) ~[okio-1.17.2.jar:?]
    at okio.RealBufferedSource.read(RealBufferedSource.java:51) ~[okio-1.17.2.jar:?]
    at okhttp3.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389) ~[okhttp-3.14.6.jar:?]
    at okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.java:427) ~[okhttp-3.14.6.jar:?]
    at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286) ~[okhttp-3.14.6.jar:?]
    at okio.RealBufferedSource$1.read(RealBufferedSource.java:447) ~[okio-1.17.2.jar:?]
    at com.exterro.edrm.commons.utils.RereadableInputStream.downloadFileInputStream(RereadableInputStream.java:450) [commons-internal.5.18.1.1.jar:internal.5.18.1.1]
    at com.exterro.edrm.commons.utils.RereadableInputStream.<init>(RereadableInputStream.java:105) [commons-internal.5.18.1.1.jar:internal.5.18.1.1]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.getAttachments(SlackCollectorService.java:1109) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.executeDocumentInfo(SlackCollectorService.java:1063) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.downloadAndProcessSlackFiles(SlackCollectorService.java:1015) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.processSingleItem(SlackCollectorService.java:941) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.parseDirectory(SlackCollectorService.java:807) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.processChannels(SlackCollectorService.java:747) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.getChannels(SlackCollectorService.java:666) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.processDirectory(SlackCollectorService.java:608) [slack-collector-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.slack.SlackCollectorService.start(SlackCollectorService.java:549) [slack-collector-internal.5.18.1.1.jar:?]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292]
    at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292]
    at com.exterro.edrm.collector.events.handler.MasterEventHandler.processEventRequest(MasterEventHandler.java:106) [exterro-connector-driver-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.events.handler.MasterEventHandler.start(MasterEventHandler.java:59) [exterro-connector-driver-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.events.handler.StartEventHandler.performEventAction(StartEventHandler.java:20) [exterro-connector-driver-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.events.handler.manager.ListernerManager.performEventAction(ListernerManager.java:114) [exterro-connector-driver-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.custom.connector.framework.ExterroCollectorCrawlHandler.start(ExterroCollectorCrawlHandler.java:229) [exterro-collector-core-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.services.custom.connector.framework.ExterroCollectorCrawler.startCrawl(ExterroCollectorCrawler.java:73) [exterro-collector-core-internal.5.18.1.1.jar:?]
    at com.exterro.edrm.collector.core.service.CollectorService.run(CollectorService.java:105) [collector-core-internal.5.18.1.1.jar:internal.5.19]
    at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
    Suppressed: java.net.SocketException: Broken pipe (Write failed)
        at java.net.SocketOutputStream.socketWrite0(Native Method) ~[?:1.8.0_292]
        at java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:111) ~[?:1.8.0_292]
        at java.net.SocketOutputStream.write(SocketOutputStream.java:155) ~[?:1.8.0_292]
        at sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81) ~[?:1.8.0_292]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:355) ~[?:1.8.0_292]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:267) ~[?:1.8.0_292]
        at sun.security.ssl.TransportContext.fatal(TransportContext.java:262) ~[?:1.8.0_292]
        at sun.security.ssl.SSLTransport.decode(SSLTransport.java:138) ~[?:1.8.0_292]
        at sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1386) ~[?:1.8.0_292]
        at sun.security.ssl.SSLSocketImpl.readApplicationRecord(SSLSocketImpl.java:1354) ~[?:1.8.0_292]
        at sun.security.ssl.SSLSocketImpl.access$300(SSLSocketImpl.java:73) ~[?:1.8.0_292]
        at sun.security.ssl.SSLSocketImpl$AppInputStream.read(SSLSocketImpl.java:948) ~[?:1.8.0_292]
        at okio.Okio$2.read(Okio.java:140) ~[okio-1.17.2.jar:?]
        at okio.AsyncTimeout$2.read(AsyncTimeout.java:237) ~[okio-1.17.2.jar:?]
        at okio.RealBufferedSource.read(RealBufferedSource.java:51) ~[okio-1.17.2.jar:?]
        at okhttp3.internal.http1.Http1ExchangeCodec$AbstractSource.read(Http1ExchangeCodec.java:389) ~[okhttp-3.14.6.jar:?]
        at okhttp3.internal.http1.Http1ExchangeCodec$FixedLengthSource.read(Http1ExchangeCodec.java:427) ~[okhttp-3.14.6.jar:?]
        at okhttp3.internal.connection.Exchange$ResponseBodySource.read(Exchange.java:286) ~[okhttp-3.14.6.jar:?]
        at okio.RealBufferedSource$1.read(RealBufferedSource.java:447) ~[okio-1.17.2.jar:?]
        at com.exterro.edrm.commons.utils.RereadableInputStream.downloadFileInputStream(RereadableInputStream.java:450) [commons-internal.5.18.1.1.jar:internal.5.18.1.1]
        at com.exterro.edrm.commons.utils.RereadableInputStream.<init>(RereadableInputStream.java:105) [commons-internal.5.18.1.1.jar:internal.5.18.1.1]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.getAttachments(SlackCollectorService.java:1109) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.executeDocumentInfo(SlackCollectorService.java:1063) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.downloadAndProcessSlackFiles(SlackCollectorService.java:1015) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.processSingleItem(SlackCollectorService.java:941) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.parseDirectory(SlackCollectorService.java:807) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.processChannels(SlackCollectorService.java:747) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.getChannels(SlackCollectorService.java:666) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.processDirectory(SlackCollectorService.java:608) [slack-collector-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.slack.SlackCollectorService.start(SlackCollectorService.java:549) [slack-collector-internal.5.18.1.1.jar:?]
        at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.8.0_292]
        at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[?:1.8.0_292]
        at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.8.0_292]
        at java.lang.reflect.Method.invoke(Method.java:498) ~[?:1.8.0_292]
        at com.exterro.edrm.collector.events.handler.MasterEventHandler.processEventRequest(MasterEventHandler.java:106) [exterro-connector-driver-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.events.handler.MasterEventHandler.start(MasterEventHandler.java:59) [exterro-connector-driver-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.events.handler.StartEventHandler.performEventAction(StartEventHandler.java:20) [exterro-connector-driver-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.events.handler.manager.ListernerManager.performEventAction(ListernerManager.java:114) [exterro-connector-driver-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.custom.connector.framework.ExterroCollectorCrawlHandler.start(ExterroCollectorCrawlHandler.java:229) [exterro-collector-core-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.services.custom.connector.framework.ExterroCollectorCrawler.startCrawl(ExterroCollectorCrawler.java:73) [exterro-collector-core-internal.5.18.1.1.jar:?]
        at com.exterro.edrm.collector.core.service.CollectorService.run(CollectorService.java:105) [collector-core-internal.5.18.1.1.jar:internal.5.19]
        at java.lang.Thread.run(Thread.java:748) [?:1.8.0_292]
Caused by: java.net.SocketException: Connection reset
    at java.net.SocketInputStream.read(SocketInputStream.java:210) ~[?:1.8.0_292]
    at java.net.SocketInputStream.read(SocketInputStream.java:141) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:457) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketInputRecord.decodeInputRecord(SSLSocketInputRecord.java:237) ~[?:1.8.0_292]
    at sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:190) ~[?:1.8.0_292]
    at sun.security.ssl.SSLTransport.decode(SSLTransport.java:109) ~[?:1.8.0_292]
    ... 34 more