1

I am facing the issues while hitting the API from the JAVA code

Below are the logs for this

    18:01:02.039 [main] INFO dk.danskebank.dw.datasourcing.sbl.application.SkatConfig - Creation of RestTemplate for skat is started
18:01:02.045 [main] INFO dk.danskebank.dw.datasourcing.sbl.application.SkatConfig - Loading of Certificate file started.. 
18:01:02.813 [main] DEBUG dk.danskebank.dw.datasourcing.sbl.application.SkatConfig - Loading of certificate file is in process
18:01:03.112 [main] INFO dk.danskebank.dw.datasourcing.sbl.application.SkatConfig - Loading of certificate file is completed successfully
18:01:03.811 [main] INFO dk.danskebank.dw.datasourcing.sbl.application.SkatConfig - Creation of RestTemplate for Skat is Completed
18:01:03.867 [main] DEBUG org.springframework.web.client.RestTemplate - HTTP GET https://api-at.sits.no/api/innrapportert/inntektsmottaker/sbl/01029413157/oppgave/inntekt?fraOgMed=2018-05&tilOgMed=2018-07
18:01:03.891 [main] DEBUG org.springframework.web.client.RestTemplate - Accept=[text/plain, application/json, application/*+json, */*]
18:01:03.932 [main] DEBUG org.apache.http.client.protocol.RequestAddCookies - CookieSpec selected: default
18:01:03.948 [main] DEBUG org.apache.http.client.protocol.RequestAuthCache - Auth cache not set in the context
18:01:03.950 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection request: [route: {tls}->http://DK1ISPRDEVP.danskenet.net:8080->https://api-at.sits.no:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
18:01:03.970 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection leased: [id: 0][route: {tls}->http://DK1ISPRDEVP.danskenet.net:8080->https://api-at.sits.no:443][total kept alive: 0; route allocated: 1 of 2; total allocated: 1 of 20]
18:01:03.973 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Opening connection {tls}->http://DK1ISPRDEVP.danskenet.net:8080->https://api-at.sits.no:443
18:01:03.996 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connecting to DK1ISPRDEVP.danskenet.net/10.111.1.18:8080
18:01:04.002 [main] DEBUG org.apache.http.impl.conn.DefaultHttpClientConnectionOperator - Connection established 10.132.21.124:51274<->10.111.1.18:8080
18:01:04.006 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> CONNECT api-at.sits.no:443 HTTP/1.1
18:01:04.007 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> Host: api-at.sits.no
18:01:04.007 [main] DEBUG org.apache.http.headers - http-outgoing-0 >> User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_201)
18:01:04.007 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "CONNECT api-at.sits.no:443 HTTP/1.1[\r][\n]"
18:01:04.011 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "Host: api-at.sits.no[\r][\n]"
18:01:04.012 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "User-Agent: Apache-HttpClient/4.5.7 (Java/1.8.0_201)[\r][\n]"
18:01:04.012 [main] DEBUG org.apache.http.wire - http-outgoing-0 >> "[\r][\n]"
18:01:04.013 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "HTTP/1.1 200 Connection established[\r][\n]"
18:01:04.013 [main] DEBUG org.apache.http.wire - http-outgoing-0 << "[\r][\n]"
18:01:04.016 [main] DEBUG org.apache.http.headers - http-outgoing-0 << HTTP/1.1 200 Connection established
18:01:04.018 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Tunnel to target created.
18:01:04.055 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled protocols: [TLSv1, TLSv1.1, TLSv1.2]
18:01:04.055 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Enabled cipher suites:[TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384, TLS_RSA_WITH_AES_256_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA384, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA384, TLS_DHE_RSA_WITH_AES_256_CBC_SHA256, TLS_DHE_DSS_WITH_AES_256_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA, TLS_RSA_WITH_AES_256_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_256_CBC_SHA, TLS_ECDH_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_RSA_WITH_AES_256_CBC_SHA, TLS_DHE_DSS_WITH_AES_256_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256, TLS_RSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_RSA_WITH_AES_128_CBC_SHA256, TLS_DHE_DSS_WITH_AES_128_CBC_SHA256, TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA, TLS_RSA_WITH_AES_128_CBC_SHA, TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA, TLS_ECDH_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_RSA_WITH_AES_128_CBC_SHA, TLS_DHE_DSS_WITH_AES_128_CBC_SHA, TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384, TLS_RSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_ECDSA_WITH_AES_256_GCM_SHA384, TLS_ECDH_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_RSA_WITH_AES_256_GCM_SHA384, TLS_DHE_DSS_WITH_AES_256_GCM_SHA384, TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256, TLS_RSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_ECDSA_WITH_AES_128_GCM_SHA256, TLS_ECDH_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_RSA_WITH_AES_128_GCM_SHA256, TLS_DHE_DSS_WITH_AES_128_GCM_SHA256]
18:01:04.056 [main] DEBUG org.apache.http.conn.ssl.SSLConnectionSocketFactory - Starting handshake
18:01:04.199 [main] DEBUG org.apache.http.impl.conn.DefaultManagedHttpClientConnection - http-outgoing-0: Shutdown connection
18:01:04.200 [main] DEBUG org.apache.http.impl.execchain.MainClientExec - Connection discarded
18:01:04.200 [main] DEBUG org.apache.http.impl.conn.PoolingHttpClientConnectionManager - Connection released: [id: 0][route: {tls}->http://DK1ISPRDEVP.danskenet.net:8080->https://api-at.sits.no:443][total kept alive: 0; route allocated: 0 of 2; total allocated: 0 of 20]
Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://api-at.sits.no/api/innrapportert/inntektsmottaker/sbl/01029413157/oppgave/inntekt": Received fatal alert: handshake_failure; nested exception is javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:744)
    at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:670)
    at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:579)
    at dk.danskebank.dw.datasourcing.sbl.application.SkatConfig.getResponsefromSkat(SkatConfig.java:99)
    at dk.danskebank.dw.datasourcing.sbl.application.TestSkat.main(TestSkat.java:15)
Caused by: javax.net.ssl.SSLHandshakeException: Received fatal alert: handshake_failure
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.Alerts.getSSLException(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.recvAlert(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.performInitialHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at sun.security.ssl.SSLSocketImpl.startHandshake(Unknown Source)
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.createLayeredSocket(SSLConnectionSocketFactory.java:404)

I am able to consume the API through POSTMAN but am facing issues while consuming through java code.

user207421
  • 305,947
  • 44
  • 307
  • 483
  • Below are the logs after enable : – Raju Sharma Apr 15 '19 at 12:35
  • 3
    Possible duplicate of [Received fatal alert: handshake\_failure through SSLHandshakeException](https://stackoverflow.com/questions/6353849/received-fatal-alert-handshake-failure-through-sslhandshakeexception) – user2340612 Apr 15 '19 at 12:35
  • Hi User , I have fixed this issue now by configuring the proxy HttpClient httpClient = HttpClients.custom().setSSLSocketFactory(socketFactory).setProxy(new HttpHost("proxyserver", 8080, "http")).build(); **in the HttpClients** and pass this httpClient to ClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory(httpClient); And again I can pass requestFactory Object to RestTemplate RestTemplate restTemplate = new RestTemplate(requestFactory); – Raju Sharma Apr 16 '19 at 11:26
  • but when I am configuring it by this way HttpComponentsClientHttpRequestFactory clientHttpRequestFactory = new HttpComponentsClientHttpRequestFactory( HttpClientBuilder.create() .setProxy(new HttpHost("proxyserver", 8080, "http")) .build()); And passing this (clientHttpRequestFactory) Object to RestTemplate restTemplate = new RestTemplate(requestFactory); is not working – Raju Sharma Apr 16 '19 at 11:27

0 Answers0