title: Java bypass proxy programmatically apache
body: <p><strong>Background</strong></p>
  
  <p>I am using <a href="http://docs.aws.amazon.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/sqs/AmazonSQSClient.html" rel="nofollow noreferrer">AWS Java SDK for SQS</a> to read a message from a local queue. I am using <a href="https://github.com/adamw/elasticmq" rel="nofollow noreferrer">ElasticMQ</a> for my local queue.</p>
  
  <pre><code>@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&lt;Message&gt; sqsMessages = receiveMessageResult.getMessages();
  
  }
  </code></pre>
  
  <p>This works perfectly until I am connected to my internet via proxy (at work)</p>
  
  <p>I then get a <code>504</code> as it tries to route my localhost via my proxy.</p>
  
  <p><strong>Question</strong></p>
  
  <p>How do I bypass my proxy for my localhost programmatically in Java?</p>
  
  <p>I have tried the following to no avail </p>
  
  <pre><code>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");
  </code></pre>
  
  <p>The only thing that works is adding <code>127.0.0.1</code> to bypass proxy in Mac Network Settings.</p>
  
  <p><a href="https://i.stack.imgur.com/iO5Cn.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/iO5Cn.png" alt="localhost in bypass proxy"></a></p>
  
  <p>I have also tried <code>localhost</code> (oppose to <code>127.0.0.1</code>)</p>
  
  <p>Any Ideas?</p>