0

I'm able to execute below sample code locally (output: 200 OK) but unable to execute (output: timeout) the same code in AWS ec2 server. This code used to work perfectly fine in AWS ec2 until last week, but stoped working since last few days.

public class CheckURL {
public static void main(String[] args) {
    HttpClient httpClient = HttpClients.custom().setUserAgent("Java Agent").build();
    String urlString = "https://www.nseindia.com/content/historical/EQUITIES/2019/DEC/cm26DEC2019bhav.csv.zip";

    try {
        HttpGet request = new HttpGet(urlString);
        HttpResponse response = httpClient.execute(request);

        System.out.println("Status code: " + response.getStatusLine().getStatusCode());
    } catch (Exception ex) {
        ex.printStackTrace();
    }
}

}

Note: ec2 server connected to Internet Gateway and Inbound/Outbound both are set to All traffic. Interestingly, the above code works perfectly fine with https://google.com as URL in ec2 server. Is this something issue with nseindia.com site?

Any help would be greatly appreciated.


Stacktrace:

java.net.SocketTimeoutException: Read timed out
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:171)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at sun.security.ssl.InputRecord.readFully(InputRecord.java:465)
at sun.security.ssl.InputRecord.read(InputRecord.java:503)
at sun.security.ssl.SSLSocketImpl.readRecord(SSLSocketImpl.java:975)
at sun.security.ssl.SSLSocketImpl.readDataRecord(SSLSocketImpl.java:933)
at sun.security.ssl.AppInputStream.read(AppInputStream.java:105)
at org.apache.http.impl.io.SessionInputBufferImpl.streamRead(SessionInputBufferImpl.java:137)
at org.apache.http.impl.io.SessionInputBufferImpl.fillBuffer(SessionInputBufferImpl.java:153)
at org.apache.http.impl.io.SessionInputBufferImpl.readLine(SessionInputBufferImpl.java:280)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:138)
at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
at org.apache.http.impl.DefaultBHttpClientConnection.receiveResponseHeader(DefaultBHttpClientConnection.java:163)
at org.apache.http.impl.conn.CPoolProxy.receiveResponseHeader(CPoolProxy.java:157)
at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
at org.apache.http.impl.execchain.MainClientExec.execute(MainClientExec.java:272)
at org.apache.http.impl.execchain.ProtocolExec.execute(ProtocolExec.java:186)
at org.apache.http.impl.execchain.RetryExec.execute(RetryExec.java:89)
at org.apache.http.impl.execchain.RedirectExec.execute(RedirectExec.java:110)
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 org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
10
  • You might need to increase timeout values of HttpClient as well as the server. Commented Dec 28, 2019 at 5:07
  • Have you tried SSHing to the server and trying to ping this host from there? Commented Dec 28, 2019 at 5:09
  • @TomazFernandes the URL h specified in the example is accessible and zip is downloaded. means the machine is accessible over the http. Commented Dec 28, 2019 at 5:11
  • @Susovon Pal, I tried your code and its giving me 200 only. Commented Dec 28, 2019 at 5:14
  • Yep, but if he can’t ping this host from the EC2 server it means it’s a AWS configuration problem, rather than a java problem... Commented Dec 28, 2019 at 5:15

1 Answer 1

1

Timing out as well when trying this from the command line with curl:

$ curl -iv https://www.nseindia.com/content/historical/EQUITIES/2019/DEC/cm26DEC2019bhav.csv.zip
*   Trying 104.90.192.157:443...
* TCP_NODELAY set
* Connected to www.nseindia.com (104.90.192.157) port 443 (#0)
* ALPN, offering http/1.1
* successfully set certificate verify locations:
*   CAfile: /opt/local/share/curl/curl-ca-bundle.crt
CApath: none
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.2 (IN), TLS handshake, Certificate (11):
* TLSv1.2 (IN), TLS handshake, Server key exchange (12):
* TLSv1.2 (IN), TLS handshake, Server finished (14):
* TLSv1.2 (OUT), TLS handshake, Client key exchange (16):
* TLSv1.2 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.2 (OUT), TLS handshake, Finished (20):
* TLSv1.2 (IN), TLS handshake, Finished (20):
* SSL connection using TLSv1.2 / ECDHE-RSA-AES128-GCM-SHA256
* ALPN, server accepted to use http/1.1
* Server certificate:
*  subject: C=IN; ST=Maharashtra; L=Mumbai; O=National Stock Exchange of India Ltd.; OU=IT; CN=www.nseindia.com
*  start date: Dec  6 00:00:00 2019 GMT
*  expire date: Dec 12 12:00:00 2020 GMT
*  subjectAltName: host "www.nseindia.com" matched cert's "www.nseindia.com"
*  issuer: C=US; O=DigiCert Inc; OU=www.digicert.com; CN=GeoTrust RSA CA 2018
*  SSL certificate verify ok.
> GET /content/historical/EQUITIES/2019/DEC/cm26DEC2019bhav.csv.zip HTTP/1.1
> Host: www.nseindia.com
> User-Agent: curl/7.67.0
> Accept: */*
>
* OpenSSL SSL_read: Operation timed out
* Closing connection 0

So there's no problem on your side.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.