1

Background

I am using AWS Java SDK for SQS to read a message from a local queue. I am using ElasticMQ for my local queue.

@Test
public void readMessageFromQueue() {

    AWSCredentialsProviderChain credentialsProvider = new AWSCredentialsProviderChain(new DefaultAWSCredentialsProviderChain());
    ClientConfiguration clientConfiguration = new ClientConfiguration();

    AmazonSQSClient sqsClient = new AmazonSQSClient(credentialsProvider, clientConfiguration);
    sqsClient.setEndpoint("http://127.0.0.1:9324/queue");
    ReceiveMessageRequest receiveMessageRequest = new ReceiveMessageRequest("queue1").withMaxNumberOfMessages(10);

    ReceiveMessageResult receiveMessageResult = sqsClient.receiveMessage(receiveMessageRequest);
    List<Message> sqsMessages = receiveMessageResult.getMessages();

}

This works perfectly until I am connected to my internet via proxy (at work)

I then get a 504 as it tries to route my localhost via my proxy.

Question

How do I bypass my proxy for my localhost programmatically in Java?

I have tried the following to no avail

System.setProperty("NO_PROXY", "127.0.0.1");
System.setProperty("proxySet", "false");
System.setProperty("proxyHost", "");
System.setProperty("proxyPort", "");
System.setProperty("no_proxy", "127.0.0.1");
System.setProperty("http.no_proxy", "127.0.0.1");
System.setProperty("http.proxySet", "false");

The only thing that works is adding 127.0.0.1 to bypass proxy in Mac Network Settings.

localhost in bypass proxy

I have also tried localhost (oppose to 127.0.0.1)

Any Ideas?

1 Answer 1

3

Have you tried setting http.nonProxyHosts?

String nonProxyHosts = System.getProperty("http.nonProxyHosts");
nonProxyHosts = nonProxyHosts == null ? "127.0.0.1" : nonProxyHosts + "|127.0.0.1";
System.setProperty("http.nonProxyHosts", nonProxyHosts);
Sign up to request clarification or add additional context in comments.

1 Comment

I very much appreciate your accept, resulted in two badges for me. Unfortunately, you dont have much content I could show my gratitude at. But whenever you have another great question, just drop me a note ;-)

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.