0

I created a sample web application for POC. This application running in Amazon EC2 liberty 17.0.0.2. When we send get request to servlet as below it has to send message to AWS SQS.

http://localhost:8080/TestSqsWeb/SqsServlet?message=Hello333

Our EC2 is coorporate EC2, it needs proxy to connect to internet. So I provided proxy configuration in jvm.options file in liberty.

-Dhttps.nonProxyHosts=169.254.169.254|localhost|127.0.0.1
-Dhttp.nonProxyHosts=169.254.169.254|localhost|127.0.0.1
-Dhttp.proxyHost=proxy.ebiz.abc.com
-Dhttp.proxyPort=80
-Dhttps.proxyHost=proxy.ebiz.abc.com
-Dhttps.proxyPort=80 

It is keep giving below exception.

org.apache.http.conn.ConnectTimeoutException: Connect to sqs.us-west-2.amazonaws.com:443 [sqs.us-west-2.amazonaws.com/52.119.168.22] failed: connect timed out

After further analysis I found it is not taking proxy system properties while making connection. I did printing of all system property in code using System.getProperty. It prints my system properties, it means configuration is correct.

For further analysis I deployed same app in tomcat-8 in same EC2 with same proxy configuration , it is working. It is able to make connection and send my message to AWS SQS queue.

After this analysis I concluded that there is some issue in liberty.

[Libraries in my sample app][1]

  [1]: https://i.stack.imgur.com/K2gbj.png

In one of post I found, it can happen due to old version of http-client but I am using latest httpclient-4.5.2.jar and httpcore-4.4.4.jar as you can see in above link.

Has any one encountered same issue with Liberty 17.0.0.2/17.0.0.3 ? I am using IBM JAVA SDK-8.

1 Answers1

0

As I understand it, those proxy system properties work for HTTP connection classes provided by the JDK - like HttpUrlConnection. Depending on you use Apache HTTP Client, it may not use those APIs.

Instead of using the JDK-supplied system properties, you may want to modify your code like this:

    public static void main(String[] args)throws Exception {
        CloseableHttpClient httpclient = HttpClients.createDefault();
        try {
            HttpHost target = new HttpHost("httpbin.org", 443, "https");
            HttpHost proxy = new HttpHost("127.0.0.1", 8080, "http");

            RequestConfig config = RequestConfig.custom()
                .setProxy(proxy)
                .build();
            HttpGet request = new HttpGet("/");
            request.setConfig(config);
            ...

This code sample was taken from the Apache HTTP Client examples page.

There are other samples (including proxy authentication) here: https://hc.apache.org/httpcomponents-client-ga/examples.html

Hope this helps, Andy

Andy McCright
  • 1,273
  • 6
  • 8
  • I am using JMS api with AWS library. I dont have direct access to http client level. AWS Liberary internally using http client. – Manoj Kumar Dewangan Nov 16 '17 at 17:59
  • I am using JMS api with AWS library. AWS SQS is JMS provider. I dont have direct access to http client level. AWS Liberary internally using http client. Please see some code snippet – Manoj Kumar Dewangan Nov 16 '17 at 18:00
  • I am using JMS api with AWS library. AWS SQS is JMS provider. I dont have direct access to http client level. AWS Liberary internally using http client. Please see my imports ////////////////////////////////////////// import javax.jms.Queue; import javax.jms.Session; import com.amazon.sqs.javamessaging.ProviderConfiguration; import com.amazon.sqs.javamessaging.SQSConnection; import com.amazon.sqs.javamessaging.SQSConnectionFactory; import com.amazonaws.auth.InstanceProfileCredentialsProvider; import com.amazonaws.services.sqs.AmazonSQSClientBuilder; – Manoj Kumar Dewangan Nov 16 '17 at 18:14
  • I don’t know how these AWS APIs work - it’s possible that they may need to make a change in order to resolve this issue. Can you also try adding this to your jvm.options files: -Djava.net.useSystemProxies=true From reading https://stackoverflow.com/questions/30630330/what-java-properties-to-pass-to-a-java-app-to-authenticate-with-a-http-proxy it seems like this might tell Apache Http Client to use the other system properties. – Andy McCright Nov 17 '17 at 03:03
  • I put this -Djava.net.useSystemProxies=true in jvm.options but no gain. Any way thanks a lot for your suggestions. I raised this question in liberty forum as well but no reply yet. – Manoj Kumar Dewangan Nov 18 '17 at 01:26