title: Exception while getting data from Service Now using Rest API (Table API)
body: <p>I am using ServiceNow Table API - JAVA to fetch data (GET request). I am following the example provided in the below service now wiki link:</p>
  
  <p>URL: <a href="http://wiki.servicenow.com/index.php?title=Table_API_Java_Examples#gsc.tab=0" rel="nofollow noreferrer">http://wiki.servicenow.com/index.php?title=Table_API_Java_Examples#gsc.tab=0</a></p>
  
  <p>I am getting " java.net.SocketException: Connection reset"</p>
  
  <pre><code>Exception in thread "main" java.net.SocketException: Connection reset  
    at java.net.SocketInputStream.read(Unknown Source)  
    at java.net.SocketInputStream.read(Unknown Source)  
    at sun.security.ssl.InputRecord.readFully(Unknown Source)  
    at sun.security.ssl.InputRecord.read(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.waitForClose(Unknown Source)  
    at sun.security.ssl.HandshakeOutStream.flush(Unknown Source)  
    at sun.security.ssl.Handshaker.kickstart(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.kickstartHandshake(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:396)  
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)  
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)  
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)  
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)  
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)  
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)  
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)  
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)  
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)  
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)  
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)  
    at com.ucas.reports.volumetric.Demo.go(Demo.java:64)  
    at com.ucas.reports.volumetric.Demo.main(Demo.java:31)  
  </code></pre>
  
  <p>I am using maven to handle the dependency and using apache httpclient (4.5.3). Below is my code for reference:</p>
  
  <pre><code>package com.reports.volumetric;  
  import java.io.IOException;  
  import org.apache.http.HttpHost;  
  import org.apache.http.auth.AuthScope;  
  import org.apache.http.auth.UsernamePasswordCredentials;  
  import org.apache.http.client.CredentialsProvider;  
  import org.apache.http.client.methods.CloseableHttpResponse;  
  import org.apache.http.client.methods.HttpGet;  
  import org.apache.http.impl.client.BasicCredentialsProvider;  
  import org.apache.http.impl.client.CloseableHttpClient;  
  import org.apache.http.impl.client.HttpClients;  
  import org.apache.http.util.EntityUtils;  
  
  
  import com.reports.util.AppConstants;  
  
  public class Demo {  
  
    public static void main(String args[]) throws IOException {  
    go();  
    }  
  
  
    private static void go() throws IOException {  
        CredentialsProvider credsProvider = new BasicCredentialsProvider();  
        credsProvider.setCredentials(  
        new AuthScope(new HttpHost(new HttpHost(AppConstants.SNOW_HOST))),  
        new UsernamePasswordCredentials("WebServiceUser", "WebServiceUserPassword"));  
        CloseableHttpClient httpclient = null;  
        try {  
            httpclient = HttpClients.custom()  
                        .setDefaultCredentialsProvider(credsProvider)  
                        .build();  
            HttpGet httpget = new HttpGet("https://instance.service-
                              now.com/api/now/table/incident");  
            httpget.setHeader("Accept", "application/json");  
            System.out.println("Executing request " + httpget.getRequestLine());  
            CloseableHttpResponse response = httpclient.execute(httpget);  
        try {  
            System.out.println("----------------------------------------");  
            System.out.println(response.getStatusLine());  
            System.out.println(EntityUtils.toString(response.getEntity()));  
          } finally {  
            response.close();  
          }  
    }  finally {  
        httpclient.close();  
     }  
    }  
  }  
  </code></pre>
  
  <p>I am able to get the data if i open the URL from the browser with the web service credentials. But when i run my java code it throws java.net.SocketException: Connection reset</p>
  
  <blockquote>
    <p>UPDATE</p>
  </blockquote>
  
  <p>I was using Java 1.8 (jdk1.8.0_121). I changed the version to 1.6 (jdk1.6.0_24) and re-ran the above program and I was getting the json output as expected. I am not sure why it is failing in Java 1.8 version.</p>
  
  <p>Below is the ssl debug logs while running in Java 1.8</p>
  
  <pre><code>*** ClientHello, TLSv1.2  
  RandomCookie:  GMT: 1498393794 bytes = { 12, 120, 234, 134, 188, 168, 18, 119, 116, 190, 203, 67, 203, 117, 140, 58, 11, 37, 238, 63, 195, 158, 126, 45, 223, 152, 145, 239 }  
  Session ID:  {}  
  Cipher Suites: [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_128_GCM_SHA256, 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, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]  
  Compression Methods:  { 0 }  
  Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1, sect283k1, sect283r1, sect409k1, sect409r1, sect571k1, sect571r1, secp256k1}  
  Extension ec_point_formats, formats: [uncompressed]  
  Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA  
  Extension server_name, server_name: [type=host_name (0), value=instance.service-now.com]  
  ***  
  main, WRITE: TLSv1.2 Handshake, length = 194  
  main, waiting for close_notify or alert: state 1  
  main, Exception while waiting for close java.net.SocketException: Connection reset  
  main, handling exception: java.net.SocketException: Connection reset  
  main, SEND TLSv1.2 ALERT:  fatal, description = unexpected_message  
  main, WRITE: TLSv1.2 Alert, length = 2  
  main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error  
  main, called closeSocket()  
  Allow unsafe renegotiation: false  
  Allow legacy hello messages: true  
  Is initial handshake: true  
  Is secure renegotiation: false  
  Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  %% No cached client session  
  *** ClientHello, TLSv1.2  
  RandomCookie:  GMT: 1498393854 bytes = { 85, 197, 18, 247, 65, 37, 118, 123, 184, 222, 135, 136, 206, 199, 231, 124, 208, 237, 123, 64, 244, 31, 61, 23, 131, 135, 41, 99 }  
  Session ID:  {}  
  Cipher Suites: [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_128_GCM_SHA256, 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, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]  
  Compression Methods:  { 0 }  
  Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1, sect283k1, sect283r1, sect409k1, sect409r1, sect571k1, sect571r1, secp256k1}  
  Extension ec_point_formats, formats: [uncompressed]  
  Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA  
  Extension server_name, server_name: [type=host_name (0), value=instance.service-now.com]  
  ***  
  main, WRITE: TLSv1.2 Handshake, length = 194  
  main, waiting for close_notify or alert: state 1  
  main, Exception while waiting for close java.net.SocketException: Connection reset  
  main, handling exception: java.net.SocketException: Connection reset  
  main, SEND TLSv1.2 ALERT:  fatal, description = unexpected_message  
  main, WRITE: TLSv1.2 Alert, length = 2  
  main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error  
  main, called closeSocket()  
  Allow unsafe renegotiation: false  
  Allow legacy hello messages: true  
  Is initial handshake: true  
  Is secure renegotiation: false  
  Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1  
  Ignoring unsupported cipher suite: TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDH_ECDSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_ECDH_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_DHE_RSA_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  Ignoring unsupported cipher suite: TLS_DHE_DSS_WITH_AES_128_CBC_SHA256 for TLSv1.1  
  %% No cached client session  
  *** ClientHello, TLSv1.2  
  RandomCookie:  GMT: 1498394170 bytes = { 217, 71, 119, 16, 216, 43, 85, 204, 44, 23, 245, 62, 134, 87, 162, 228, 248, 194, 9, 10, 45, 170, 236, 196, 114, 95, 34, 181 }  
  Session ID:  {}  
  Cipher Suites: [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_128_GCM_SHA256, 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, TLS_ECDHE_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_RSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_ECDSA_WITH_3DES_EDE_CBC_SHA, TLS_ECDH_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_RSA_WITH_3DES_EDE_CBC_SHA, SSL_DHE_DSS_WITH_3DES_EDE_CBC_SHA, TLS_EMPTY_RENEGOTIATION_INFO_SCSV]  
  Compression Methods:  { 0 }  
  Extension elliptic_curves, curve names: {secp256r1, secp384r1, secp521r1, sect283k1, sect283r1, sect409k1, sect409r1, sect571k1, sect571r1, secp256k1}  
  Extension ec_point_formats, formats: [uncompressed]  
  Extension signature_algorithms, signature_algorithms: SHA512withECDSA, SHA512withRSA, SHA384withECDSA, SHA384withRSA, SHA256withECDSA, SHA256withRSA, SHA256withDSA, SHA1withECDSA, SHA1withRSA, SHA1withDSA  
  Extension server_name, server_name: [type=host_name (0), value=instance.service-now.com]  
  ***  
  main, WRITE: TLSv1.2 Handshake, length = 194  
  main, waiting for close_notify or alert: state 1  
  Exception in thread "main" main, Exception while waiting for close java.net.SocketException: Connection reset  
  main, handling exception: java.net.SocketException: Connection reset  
  main, SEND TLSv1.2 ALERT:  fatal, description = unexpected_message  
  main, WRITE: TLSv1.2 Alert, length = 2  
  main, Exception sending alert: java.net.SocketException: Connection reset by peer: socket write error  
  main, called closeSocket()  
  java.net.SocketException: Connection reset  
    at java.net.SocketInputStream.read(Unknown Source)  
    at java.net.SocketInputStream.read(Unknown Source)  
    at sun.security.ssl.InputRecord.readFully(Unknown Source)  
    at sun.security.ssl.InputRecord.read(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.readRecord(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.waitForClose(Unknown Source)  
    at sun.security.ssl.HandshakeOutStream.flush(Unknown Source)  
    at sun.security.ssl.Handshaker.kickstart(Unknown Source)  
    at sun.security.ssl.SSLSocketImpl.kickstartHandshake(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:396)  
    at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:355)  
    at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)  
    at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:359)  
    at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:381)  
    at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:237)  
    at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:185)  
    at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)  
    at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:111)  
    at org.apache.http.impl.client.InternalHttpClient.doExecute(InternalHttpClient.java:185)  
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)  
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:108)  
    at com.reports.volumetric.Demo.go(Demo.java:67)  
    at com.reports.volumetric.Demo.main(Demo.java:33)
  </code></pre>