Я использую Jackson ObjectMapper
и следующий код для чтения JSON информации из URL-адреса HTTPS:
CurrencyDto[] currencyDtos = objectMapper.readValue(new URL("https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json"), CurrencyDto[].class);
, что вызывает следующее исключение:
2020-05-27 10:00:00.271 ERROR 30514 --- [schedulerFactoryBean_Worker-1] c.b.d.s.job.CurrencyExchangeJob : Exception occurred
javax.net.ssl.SSLException: Connection reset
at java.base/sun.security.ssl.Alert.createSSLException(Alert.java:127) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:320) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:263) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:258) ~[na:na]
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:137) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.decode(SSLSocketImpl.java:1152) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.readHandshakeRecord(SSLSocketImpl.java:1063) ~[na:na]
at java.base/sun.security.ssl.SSLSocketImpl.startHandshake(SSLSocketImpl.java:402) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsClient.afterConnect(HttpsClient.java:567) ~[na:na]
at java.base/sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(AbstractDelegateHttpsURLConnection.java:185) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream0(HttpURLConnection.java:1587) ~[na:na]
at java.base/sun.net.www.protocol.http.HttpURLConnection.getInputStream(HttpURLConnection.java:1515) ~[na:na]
at java.base/sun.net.www.protocol.https.HttpsURLConnectionImpl.getInputStream(HttpsURLConnectionImpl.java:250) ~[na:na]
at java.base/java.net.URL.openStream(URL.java:1139) ~[na:na]
at com.fasterxml.jackson.core.TokenStreamFactory._optimizedStreamFromURL(TokenStreamFactory.java:185) ~[jackson-core-2.10.3.jar!/:2.10.3]
at com.fasterxml.jackson.core.JsonFactory.createParser(JsonFactory.java:944) ~[jackson-core-2.10.3.jar!/:2.10.3]
at com.fasterxml.jackson.databind.ObjectMapper.readValue(ObjectMapper.java:3145) ~[jackson-databind-2.10.3.jar!/:2.10.3]
at com.example.domain.scheduling.job.CurrencyExchangeJob.updateCurrencies(CurrencyExchangeJob.java:48) ~[classes!/:0.0.1]
at com.example.domain.scheduling.job.CurrencyExchangeJob.executeInternal(CurrencyExchangeJob.java:39) ~[classes!/:0.0.1]
at org.springframework.scheduling.quartz.QuartzJobBean.execute(QuartzJobBean.java:75) ~[spring-context-support-5.2.5.RELEASE.jar!/:5.2.5.RELEASE]
at org.quartz.core.JobRunShell.run(JobRunShell.java:202) ~[quartz-2.3.2.jar!/:na]
at org.quartz.simpl.SimpleThreadPool$WorkerThread.run(SimpleThreadPool.java:573) ~[quartz-2.3.2.jar!/:na]
Suppressed: java.net.SocketException: Broken pipe (Write failed)
at java.base/java.net.SocketOutputStream.socketWrite0(Native Method) ~[na:na]
at java.base/java.net.SocketOutputStream.socketWrite(SocketOutputStream.java:110) ~[na:na]
at java.base/java.net.SocketOutputStream.write(SocketOutputStream.java:150) ~[na:na]
at java.base/sun.security.ssl.SSLSocketOutputRecord.encodeAlert(SSLSocketOutputRecord.java:81) ~[na:na]
at java.base/sun.security.ssl.TransportContext.fatal(TransportContext.java:351) ~[na:na]
... 20 common frames omitted
Caused by: java.net.SocketException: Connection reset
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:186) ~[na:na]
at java.base/java.net.SocketInputStream.read(SocketInputStream.java:140) ~[na:na]
at java.base/sun.security.ssl.SSLSocketInputRecord.read(SSLSocketInputRecord.java:448) ~[na:na]
at java.base/sun.security.ssl.SSLSocketInputRecord.decode(SSLSocketInputRecord.java:165) ~[na:na]
at java.base/sun.security.ssl.SSLTransport.decode(SSLTransport.java:108) ~[na:na]
... 17 common frames omitted
Тем не менее, Я могу получить доступ к указанному URL из curl с помощью следующей команды:
curl -i -H "Accept: application/json" https://bank.gov.ua/NBUStatService/v1/statdirectory/exchange?json
В чем может быть причина этой проблемы и как ее исправить?
ОБНОВЛЕНО
Еще одно примечание: я выполняю код упоминания Java из Quartz job org.springframework.scheduling.quartz.QuartzJobBean#executeInternal
method