我可以在Java SDK 0.9.0中为Azure服务总线连接设置代理吗?

我正在与第三方集成,后者为我们提供了一个Azure服务总线队列来接收消息。 (我们使用https://azure.microsoft.com/en-us/documentation/articles/java-download-azure-sdk/上的下载链接中的0.9.0 Azure jar)

我设置了这样的连接:

Configuration config = new Configuration(); config = ServiceBusConfiguration.configureWithConnectionString(null, config, connectionString); ServiceBusContract azureService = ServiceBusService.create(config); 

并接收如下消息:

 ReceiveQueueMessageResult resultQM = azureService.receiveQueueMessage(queueName, receiveMessageOptions); 

这在正常情况下工作正常。 但是,在办公室,我必须通过代理,连接失败并出现此错误:

 com.microsoft.windowsazure.exception.ServiceException: com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor.receiveQueueMessage(ServiceBusExceptionProcessor.java:141) at com.mycompany.dr.theircompany.TheirCompanyDataListener.receiveMessage(TheirCompanyDataListener.java:127) at com.mycompany.dr.theircompany.TheirCompanyDataListener.lambda$0(TheirCompanyDataListener.java:75) at java.lang.Thread.run(Unknown Source) Caused by: com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection timed out: connect at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:151) at com.microsoft.windowsazure.services.servicebus.implementation.AuthorizationFilter.handle(AuthorizationFilter.java:39) at com.microsoft.windowsazure.core.pipeline.jersey.ClientFilterRequestAdapter.handle(ClientFilterRequestAdapter.java:35) at com.sun.jersey.api.client.Client.handle(Client.java:648) at com.sun.jersey.api.client.WebResource.handle(WebResource.java:680) at com.sun.jersey.api.client.WebResource.post(WebResource.java:251) at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveMessage(ServiceBusRestProxy.java:248) at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusRestProxy.receiveQueueMessage(ServiceBusRestProxy.java:216) at com.microsoft.windowsazure.services.servicebus.implementation.ServiceBusExceptionProcessor.receiveQueueMessage(ServiceBusExceptionProcessor.java:137) ... 3 more Caused by: java.net.ConnectException: Connection timed out: connect at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) at java.net.DualStackPlainSocketImpl.socketConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.doConnect(Unknown Source) at java.net.AbstractPlainSocketImpl.connectToAddress(Unknown Source) at java.net.AbstractPlainSocketImpl.connect(Unknown Source) at java.net.PlainSocketImpl.connect(Unknown Source) at java.net.SocksSocketImpl.connect(Unknown Source) at java.net.Socket.connect(Unknown Source) at sun.security.ssl.SSLSocketImpl.connect(Unknown Source) at sun.net.NetworkClient.doConnect(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.http.HttpClient.openServer(Unknown Source) at sun.net.www.protocol.https.HttpsClient.(Unknown Source) at sun.net.www.protocol.https.HttpsClient.New(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.getNewHttpClient(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.plainConnect(Unknown Source) at sun.net.www.protocol.https.AbstractDelegateHttpsURLConnection.connect(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream0(Unknown Source) at sun.net.www.protocol.http.HttpURLConnection.getOutputStream(Unknown Source) at sun.net.www.protocol.https.HttpsURLConnectionImpl.getOutputStream(Unknown Source) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler$1$1.getOutputStream(URLConnectionClientHandler.java:234) at com.sun.jersey.api.client.CommittingOutputStream.commitWrite(CommittingOutputStream.java:117) at com.sun.jersey.api.client.CommittingOutputStream.flush(CommittingOutputStream.java:100) at sun.nio.cs.StreamEncoder.implFlush(Unknown Source) at sun.nio.cs.StreamEncoder.flush(Unknown Source) at java.io.OutputStreamWriter.flush(Unknown Source) at java.io.BufferedWriter.flush(Unknown Source) at com.sun.jersey.core.util.ReaderWriter.writeToAsString(ReaderWriter.java:191) at com.sun.jersey.core.provider.AbstractMessageReaderWriterProvider.writeToAsString(AbstractMessageReaderWriterProvider.java:128) at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:88) at com.sun.jersey.core.impl.provider.entity.StringProvider.writeTo(StringProvider.java:58) at com.sun.jersey.api.client.RequestWriter.writeRequestEntity(RequestWriter.java:300) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler._invoke(URLConnectionClientHandler.java:213) at com.sun.jersey.client.urlconnection.URLConnectionClientHandler.handle(URLConnectionClientHandler.java:149) ... 11 more 

现在,当我查看com.microsoft.windowsazure.Configuration的文档时 ,它显示了两个属性的常量:

  • PROPERTY_HTTP_PROXY_HOST(字符串值“http.proxyHost”)
  • PROPERTY_HTTP_PROXY_PORT(字符串值“http.proxyPort”)

但是,这些常量似乎不存在于0.9.0中。 我尝试使用字符串文字将属性添加到配置中,

 config.setProperty("http.proxyHost", "proxy.mycompany.com"); config.setProperty("http.proxyPort", 8080); 

但这没有明显的效果。

我甚至在这里正确的轨道? 有没有办法在0.9.0中设置服务总线合同的代理?

根据类Configuration的源代码,属性PROPERTY_HTTP_PROXY_HOSTPROPERTY_HTTP_PROXY_PORT被定义为静态最终变量。 因此,您无法通过方法setProperty更改其值。

众所周知,支持Java代理的方法有两种,可以在当前场景中使用。

  1. 命令行JVM设置:代理设置通过命令行参数提供给JVM:

    java -Dhttp.proxyHost = proxyhostURL -Dhttp.proxyPort = proxyPortNumber -Dhttp.proxyUser = someUserName -Dhttp.proxyPassword = somePassword

  2. 在代码中设置系统属性在Java代码中添加以下行,以便JVM使用代理进行HTTP调用。 当然,这需要您重新编译Java源代码。 (其他方法不需要任何重新编译):

    System.setProperty(“http.proxyPort”,“someProxyPort”); System.setProperty(“http.proxyUser”,“someUserName”); System.setProperty(“http.proxyPassword”,“somePassword”); System.setProperty(“http.proxyHost”,“someProxyURL”);

有关Java中的网络和代理和属性的更多信息,请参阅http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html和http://docs.oracle.com/ javase / 7 / docs / technotes / guides / net / properties.html 。