Java旁路代理以编程方式apache

时间:2016-08-23 19:41:47

标签: java apache amazon-web-services proxy

背景

我正在使用AWS Java SDK for SQS从本地队列中读取消息。我正在使用ElasticMQ作为我的本地队列。

@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();

}

这完全有效,直到我通过代理(在工作中)连接到我的互联网

然后我尝试通过我的代理路由我的localhost时获得504

问题

如何在Java中以编程方式绕过我的localhost代理?

我尝试过以下无效

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");

唯一有效的方法是在Mac网络设置中添加127.0.0.1以绕过代理。

localhost in bypass proxy

我也试过localhost(反对127.0.0.1

任何想法?

1 个答案:

答案 0 :(得分:3)

您是否尝试过设置 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);