ptimson ptimson - 1 year ago 164
Apache Configuration Question

Java bypass proxy programmatically apache


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

public void readMessageFromQueue() {

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

AmazonSQSClient sqsClient = new AmazonSQSClient(credentialsProvider, clientConfiguration);
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
as it tries to route my localhost via my proxy.


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

I have tried the following to no avail

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

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

localhost in bypass proxy

I have also tried
(oppose to

Any Ideas?

Answer Source

Have you tried setting http.nonProxyHosts?

String nonProxyHosts = System.getProperty("http.nonProxyHosts");
nonProxyHosts = nonProxyHosts == null ? "" : nonProxyHosts + "|";
System.setProperty("http.nonProxyHosts", nonProxyHosts);
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download