我可以在Java SDK 0.9.0中为Azure服务总线连接设置代理吗? [英] Can I set a proxy for Azure service bus connections in Java SDK 0.9.0?

查看:58
本文介绍了我可以在Java SDK 0.9.0中为Azure服务总线连接设置代理吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在与第三方集成,该第三方已提供Azure服务总线队列供我们接收消息. (我们正在通过 https://azure.microsoft.com/en-us/documentation/articles/java-download-azure-sdk/)

I am integrating with a third party, who has provided an Azure service bus queue for us to receive messages. (We're using the 0.9.0 Azure jars from the download link at https://azure.microsoft.com/en-us/documentation/articles/java-download-azure-sdk/)

我这样建立连接:

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

并像这样接收消息:

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

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

This works fine under normal circumstances. However, at the office, I have to go through a proxy, and the connection fails with this error:

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.<init>(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,它显示两个属性的常量:

Now, when I look at the documentation for com.microsoft.windowsazure.Configuration, it shows constants for two properties:

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

但是,这些常数在0.9.0中似乎不存在.我尝试使用字符串文字

However, these constants don't seem to exist in 0.9.0. I've tried adding the properties to the Configuration using the string literals,

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

但这没有明显的作用.

我在这里甚至在正确的轨道上吗?有什么办法可以在0.9.0中为服务总线合同设置代理?

Am I even on the right track here? Is there any way to set a proxy for the service bus contract in 0.9.0?

推荐答案

根据类

According to the source code of Class Configuration, the properties PROPERTY_HTTP_PROXY_HOST & PROPERTY_HTTP_PROXY_PORT are defined as static final variables. So you can't change their values via the method setProperty.

我知道,有两种方法可以支持Java代理,可以在当前情况下使用.

As I known, there are two ways support proxy for Java which can be used in your current scenario.

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

  1. Command Line JVM Settings: The proxy settings are given to the JVM via command line arguments:

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

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

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

Setting System Properties in Code Add the following lines in your Java code so that JVM uses the proxy to make HTTP calls. This would, of course, require you to recompile your Java source. (The other methods do not require any recompilation):

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

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

More information for Networking & Proxies & Properties in Java, Please refer to http://docs.oracle.com/javase/7/docs/technotes/guides/net/proxies.html and http://docs.oracle.com/javase/7/docs/technotes/guides/net/properties.html.

这篇关于我可以在Java SDK 0.9.0中为Azure服务总线连接设置代理吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆