AWS API Gateway - Connection timeout on accessing API using Spring RestTemplate in Java where it works fine using PostmanSpring RestTemplate timeoutAppium: Getting connection error when trying to launch Android serverFirefox web browser 50.1.0 is not opening with Selenium webdriver 3.0.1 and Java 1.8Spring RestTemplate Connection Timeout is not workingNo valid certificate for website under test produbile? (using HTMLUnit / Java)NoHttpResponseException when certificate can't be verifiedSimple POST request to API Gateway from jdk1.6.0_45 using Apache Http Client 4.5.3Internet Explorer is not opening from selenium 2.48 for JavaJavafx SSL client configuration to consume my Spring boot ssl secured Rest ApiGetting exception is java.net.SocketException: Connection reset

Alternatives to Network Backup

Term used to describe a person who predicts future outcomes

To what extent should we fear giving offense?

Can I get a PhD for developing educational software?

What ways are there to "PEEK" memory sections in (different) BASIC(s)

Journal published a paper, ignoring my objections as a referee

Template factorial function without template specialization

Get contents before a colon

Is this position a forced win for Black after move 14?

STM32 cannot reach individual registers and pins as PIC

What is the sound/audio equivalent of "unsightly"?

Printing a list as "a, b, c." using Python

How does attacking during a conversation affect initiative?

Is there a better way to use C# dictionaries than TryGetValue?

Why nature prefers simultaneous events?

Why is there not a willingness from the world to step in between Pakistan and India?

Did ancient peoples ever hide their treasure behind puzzles?

Why does this London Underground poster from 1924 have a Star of David atop a Christmas tree?

What should be done with the carbon when using magic to get oxygen from carbon dioxide?

How do you say "half the time …, the other half …" in German?

How to reply to people who accuse me of putting people out of work?

How do Barton (Hawkeye/Ronin) and Romanov (Black Widow) end up on the Benatar on Morag in 2014?

Did the Apollo Guidance Computer really use 60% of the world's ICs in 1963?

Looking for a plural noun related to ‘fulcrum’ or ‘pivot’ that denotes multiple things as crucial to success



AWS API Gateway - Connection timeout on accessing API using Spring RestTemplate in Java where it works fine using Postman


Spring RestTemplate timeoutAppium: Getting connection error when trying to launch Android serverFirefox web browser 50.1.0 is not opening with Selenium webdriver 3.0.1 and Java 1.8Spring RestTemplate Connection Timeout is not workingNo valid certificate for website under test produbile? (using HTMLUnit / Java)NoHttpResponseException when certificate can't be verifiedSimple POST request to API Gateway from jdk1.6.0_45 using Apache Http Client 4.5.3Internet Explorer is not opening from selenium 2.48 for JavaJavafx SSL client configuration to consume my Spring boot ssl secured Rest ApiGetting exception is java.net.SocketException: Connection reset






.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;








0















I have created an API on AWS API Gateway. When I access this using postman it works fine but when I am trying to access this in java using Spring RestTemplate, it gives me connection time out error. I tried with below different rest client approaches. But no luck. Not sure what mistake I am doing in code below.



Please note, I changed URI and IPs in below code/exception as I don't want to disclose actual URl and IPs.



Approach-1



final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Approach-2



CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);

RestTemplate restTemplate = new RestTemplate(requestFactory);

final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Getting below exception when I call API using above java/spring code.



Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://xyz.execute-api.us-east-1.amazonaws.com/dev/dynamodb/users/55": Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:310)
at com.adp.taxcredits.connector.icims.services.CachingServiceImpl.main(CachingServiceImpl.java:46)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)
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: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:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734)
... 3 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 16 more









share|improve this question
























  • As a test can you try using the OkHttp3ClientHttpRequestFactory?

    – Darren Forsythe
    Mar 27 at 22:30

















0















I have created an API on AWS API Gateway. When I access this using postman it works fine but when I am trying to access this in java using Spring RestTemplate, it gives me connection time out error. I tried with below different rest client approaches. But no luck. Not sure what mistake I am doing in code below.



Please note, I changed URI and IPs in below code/exception as I don't want to disclose actual URl and IPs.



Approach-1



final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Approach-2



CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);

RestTemplate restTemplate = new RestTemplate(requestFactory);

final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Getting below exception when I call API using above java/spring code.



Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://xyz.execute-api.us-east-1.amazonaws.com/dev/dynamodb/users/55": Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:310)
at com.adp.taxcredits.connector.icims.services.CachingServiceImpl.main(CachingServiceImpl.java:46)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)
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: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:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734)
... 3 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 16 more









share|improve this question
























  • As a test can you try using the OkHttp3ClientHttpRequestFactory?

    – Darren Forsythe
    Mar 27 at 22:30













0












0








0


1






I have created an API on AWS API Gateway. When I access this using postman it works fine but when I am trying to access this in java using Spring RestTemplate, it gives me connection time out error. I tried with below different rest client approaches. But no luck. Not sure what mistake I am doing in code below.



Please note, I changed URI and IPs in below code/exception as I don't want to disclose actual URl and IPs.



Approach-1



final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Approach-2



CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);

RestTemplate restTemplate = new RestTemplate(requestFactory);

final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Getting below exception when I call API using above java/spring code.



Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://xyz.execute-api.us-east-1.amazonaws.com/dev/dynamodb/users/55": Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:310)
at com.adp.taxcredits.connector.icims.services.CachingServiceImpl.main(CachingServiceImpl.java:46)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)
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: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:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734)
... 3 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 16 more









share|improve this question














I have created an API on AWS API Gateway. When I access this using postman it works fine but when I am trying to access this in java using Spring RestTemplate, it gives me connection time out error. I tried with below different rest client approaches. But no luck. Not sure what mistake I am doing in code below.



Please note, I changed URI and IPs in below code/exception as I don't want to disclose actual URl and IPs.



Approach-1



final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

RestTemplate restTemplate = new RestTemplate();
String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Approach-2



CloseableHttpClient httpClient = HttpClients.custom().setSSLHostnameVerifier(new NoopHostnameVerifier()).build();

HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();
requestFactory.setHttpClient(httpClient);

RestTemplate restTemplate = new RestTemplate(requestFactory);

final String uri = "https://xyz.execute-api.us-east-2.amazonaws.com/dev/dynamodb/users/55";

String result = restTemplate.getForObject(uri, String.class);

System.out.println(result);


Getting below exception when I call API using above java/spring code.



Exception in thread "main" org.springframework.web.client.ResourceAccessException: I/O error on GET request for "https://xyz.execute-api.us-east-1.amazonaws.com/dev/dynamodb/users/55": Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect; nested exception is org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743)
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669)
at org.springframework.web.client.RestTemplate.getForObject(RestTemplate.java:310)
at com.adp.taxcredits.connector.icims.services.CachingServiceImpl.main(CachingServiceImpl.java:46)
Caused by: org.apache.http.conn.HttpHostConnectException: Connect to xyz.execute-api.us-east-1.amazonaws.com:443 [xyz.execute-api.us-east-1.amazonaws.com/11.11.232.11, xyz.execute-api.us-east-1.amazonaws.com/52.200.98.93, xyz.execute-api.us-east-1.amazonaws.com/11.81.200.210] failed: Connection timed out: connect
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:159)
at org.apache.http.impl.conn.PoolingHttpClientConnectionManager.connect(PoolingHttpClientConnectionManager.java:373)
at org.apache.http.impl.execchain.MainClientExec.establishRoute(MainClientExec.java:394)
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: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:56)
at org.springframework.http.client.HttpComponentsClientHttpRequest.executeInternal(HttpComponentsClientHttpRequest.java:87)
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48)
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734)
... 3 more
Caused by: java.net.ConnectException: Connection timed out: connect
at java.net.DualStackPlainSocketImpl.connect0(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:79)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.ssl.SSLConnectionSocketFactory.connectSocket(SSLConnectionSocketFactory.java:339)
at org.apache.http.impl.conn.DefaultHttpClientConnectionOperator.connect(DefaultHttpClientConnectionOperator.java:142)
... 16 more






java amazon-web-services aws-api-gateway resttemplate






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Mar 27 at 21:21









Narendra VermaNarendra Verma

1,2764 gold badges22 silver badges53 bronze badges




1,2764 gold badges22 silver badges53 bronze badges















  • As a test can you try using the OkHttp3ClientHttpRequestFactory?

    – Darren Forsythe
    Mar 27 at 22:30

















  • As a test can you try using the OkHttp3ClientHttpRequestFactory?

    – Darren Forsythe
    Mar 27 at 22:30
















As a test can you try using the OkHttp3ClientHttpRequestFactory?

– Darren Forsythe
Mar 27 at 22:30





As a test can you try using the OkHttp3ClientHttpRequestFactory?

– Darren Forsythe
Mar 27 at 22:30












1 Answer
1






active

oldest

votes


















0















Finally, I got this working with below code.



import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil

public static RestTemplate restTemplate;

public static RestTemplate getRestTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException

if(restTemplate != null)
return restTemplate;


TrustStrategy acceptingTrustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
return true;

;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder builder = HttpClients.custom();
builder.setSSLSocketFactory(csf);
builder.setProxy(new HttpHost("youproxy.com", 8080, "http"));
CloseableHttpClient httpClient = builder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
return restTemplate;








share|improve this answer

























  • Can you explain what exactly is "fixing" the issue?

    – Christian Fries
    Jun 8 at 10:14










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386643%2faws-api-gateway-connection-timeout-on-accessing-api-using-spring-resttemplate%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0















Finally, I got this working with below code.



import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil

public static RestTemplate restTemplate;

public static RestTemplate getRestTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException

if(restTemplate != null)
return restTemplate;


TrustStrategy acceptingTrustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
return true;

;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder builder = HttpClients.custom();
builder.setSSLSocketFactory(csf);
builder.setProxy(new HttpHost("youproxy.com", 8080, "http"));
CloseableHttpClient httpClient = builder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
return restTemplate;








share|improve this answer

























  • Can you explain what exactly is "fixing" the issue?

    – Christian Fries
    Jun 8 at 10:14















0















Finally, I got this working with below code.



import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil

public static RestTemplate restTemplate;

public static RestTemplate getRestTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException

if(restTemplate != null)
return restTemplate;


TrustStrategy acceptingTrustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
return true;

;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder builder = HttpClients.custom();
builder.setSSLSocketFactory(csf);
builder.setProxy(new HttpHost("youproxy.com", 8080, "http"));
CloseableHttpClient httpClient = builder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
return restTemplate;








share|improve this answer

























  • Can you explain what exactly is "fixing" the issue?

    – Christian Fries
    Jun 8 at 10:14













0














0










0









Finally, I got this working with below code.



import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil

public static RestTemplate restTemplate;

public static RestTemplate getRestTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException

if(restTemplate != null)
return restTemplate;


TrustStrategy acceptingTrustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
return true;

;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder builder = HttpClients.custom();
builder.setSSLSocketFactory(csf);
builder.setProxy(new HttpHost("youproxy.com", 8080, "http"));
CloseableHttpClient httpClient = builder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
return restTemplate;








share|improve this answer













Finally, I got this working with below code.



import java.security.KeyManagementException;
import java.security.KeyStoreException;
import java.security.NoSuchAlgorithmException;
import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;

import javax.net.ssl.SSLContext;

import org.apache.http.HttpHost;
import org.apache.http.conn.ssl.NoopHostnameVerifier;
import org.apache.http.conn.ssl.SSLConnectionSocketFactory;
import org.apache.http.conn.ssl.TrustStrategy;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.impl.client.HttpClients;
import org.springframework.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.web.client.RestTemplate;

public class RestTemplateUtil

public static RestTemplate restTemplate;

public static RestTemplate getRestTemplate()
throws KeyStoreException, NoSuchAlgorithmException, KeyManagementException

if(restTemplate != null)
return restTemplate;


TrustStrategy acceptingTrustStrategy = new TrustStrategy()
@Override
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException
return true;

;
SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();
SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext, new NoopHostnameVerifier());
HttpClientBuilder builder = HttpClients.custom();
builder.setSSLSocketFactory(csf);
builder.setProxy(new HttpHost("youproxy.com", 8080, "http"));
CloseableHttpClient httpClient = builder.build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
restTemplate = new RestTemplate(requestFactory);
return restTemplate;









share|improve this answer












share|improve this answer



share|improve this answer










answered Mar 29 at 18:08









Narendra VermaNarendra Verma

1,2764 gold badges22 silver badges53 bronze badges




1,2764 gold badges22 silver badges53 bronze badges















  • Can you explain what exactly is "fixing" the issue?

    – Christian Fries
    Jun 8 at 10:14

















  • Can you explain what exactly is "fixing" the issue?

    – Christian Fries
    Jun 8 at 10:14
















Can you explain what exactly is "fixing" the issue?

– Christian Fries
Jun 8 at 10:14





Can you explain what exactly is "fixing" the issue?

– Christian Fries
Jun 8 at 10:14








Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.







Got a question that you can’t ask on public Stack Overflow? Learn more about sharing private information with Stack Overflow for Teams.



















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55386643%2faws-api-gateway-connection-timeout-on-accessing-api-using-spring-resttemplate%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript