cxf-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "N. Tisserand (JIRA)" <j...@apache.org>
Subject [jira] Updated: (CXF-3171) http.proxyHost and http.proxyPort of System properties win when no proxy is required
Date Tue, 07 Dec 2010 12:10:10 GMT

     [ https://issues.apache.org/jira/browse/CXF-3171?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]

N. Tisserand updated CXF-3171:
------------------------------

    Description: 
When VM args "{{-Dhttp.proxyHost=xxxxxxxx -Dhttp.proxyPort=3128}}" are set, there is no way
to connect a webservice directly without passing throuh the proxy xxxxxxxx.

The client CXF is build as following :
{code:java|borderStyle=solid}JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  factory.setServiceClass(MyWs.class);
  factory.setAddress(bundle.getProperty("url.web.service"));

  MyWs instance = (MyWs) factory.create();
  Client client = ClientProxy.getClient(instance);
  HTTPConduit conduit = (HTTPConduit) client.getConduit();
  HTTPClientPolicy httpClientPolicy = conduit.getClient();
  httpClientPolicy.setAllowChunking(false);
  
  // Force NO proxy ?
  httpClientPolicy.setProxyServer(null);
  httpClientPolicy.setProxyServerPort(0);
  // httpClientPolicy.unsetProxyServerPort();  // tried without success
  conduit.setClient(httpClientPolicy);
{code}


When creating the instance with , CXF use HttpURLConnectionFactoryImpl (or HttpsURLConnectionFactory)
to open the url :
{code:java|borderStyle=solid}    if (proxy != null) {
      return (HttpURLConnection) url.openConnection(proxy);
    } else {
      return (HttpURLConnection) url.openConnection();
    }
{code}
When the variable "{{proxy}}" is null, {{url.openConnection()}} is used, and benifits of VM
args ({{http.proxyHost}} and {{http.proxyPort}}).

The only solution to bypass the proxy, while keeping existing VM args, is to add a System
property "{{http.nonProxyHosts}}" in order to exclude the host of the proxy. This can be done
with an other VM arg "{{-Dhttp.nonProxyHosts=xxxx}}" or programmatically : {{System.setProperty("http.nonProxyHosts",
"xxxx")}}

According to http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (chapter
3 Proxy class) when no proxy is required url.openConnection() should be used like this :
{code:java|borderStyle=solid}     url.openConnection(Proxy.NO_PROXY);{code}
The technote points out : ??"Now, this guarantees you that this specific URL will be retrieved
though a direct connection bypassing any other proxy settings, which can be convenient."??

I think that using {{url.openConnection(Proxy.NO_PROXY)}} could fix this problem in :
* org.apache.cxf.transport.http.HttpURLConnectionFactoryImpl.createConnection(Proxy proxy,
URL url)   > line #51  (release 2.3.1)
* org.apache.cxf.transport.https.HttpsURLConnectionFactory.createConnection(Proxy proxy, URL
url) > line #120 (release 2.3.1)


(!) WARNING (!) : this issue can conflicts with this other one : [CXF-2839|http://issues.apache.org/jira/browse/CXF-2839]
A lot of tests will be required.

  was:
When VM args "{{-Dhttp.proxyHost=xxxxxxxx -Dhttp.proxyPort=3128}}" are set, there is no way
to connect a webservice directly without passing throuh the proxy xxxxxxxx.

The client CXF is build as following :
{code:java|borderStyle=solid}JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
  factory.setServiceClass(MyWs.class);
  factory.setAddress(bundle.getProperty("url.web.service"));

  MyWs instance = (MyWs) factory.create();
  Client client = ClientProxy.getClient(instance);
  HTTPConduit conduit = (HTTPConduit) client.getConduit();
  HTTPClientPolicy httpClientPolicy = conduit.getClient();
  httpClientPolicy.setAllowChunking(false);
  
  try {
    String proxyHost = bundle.getProperty("web.service.proxy.host");
    String proxyPort = bundle.getProperty("web.service.proxy.port");

    if (proxyHost != null && !proxyHost.isEmpty()) {
      httpClientPolicy.setProxyServer(proxyHost);
      httpClientPolicy.setProxyServerPort(Integer.parseInt(proxyPort));
      conduit.setClient(httpClientPolicy);
    } else {
      // Force NO proxy ?
      httpClientPolicy.setProxyServer(null);
      httpClientPolicy.setProxyServerPort(0);
      // httpClientPolicy.unsetProxyServerPort();  // tried without success
      conduit.setClient(httpClientPolicy);
    }
  } catch (NumberFormatException nfe) {
    log.error("ClientWS.init: proxy initialization failed", nfe);
  }
{code}


When creating the instance with , CXF use HttpURLConnectionFactoryImpl (or HttpsURLConnectionFactory)
to open the url :
{code:java|borderStyle=solid}    if (proxy != null) {
      return (HttpURLConnection) url.openConnection(proxy);
    } else {
      return (HttpURLConnection) url.openConnection();
    }
{code}
When the variable "{{proxy}}" is null, {{url.openConnection()}} is used, and benifits of VM
args ({{http.proxyHost}} and {{http.proxyPort}}).

The only solution to bypass the proxy, while keeping existing VM args, is to add a System
property "{{http.nonProxyHosts}}" in order to exclude the host of the proxy. This can be done
with an other VM arg "{{-Dhttp.nonProxyHosts=xxxx}}" or programmatically : {{System.setProperty("http.nonProxyHosts",
"xxxx")}}

According to http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html (chapter
3 Proxy class) when no proxy is required url.openConnection() should be used like this :
{code:java|borderStyle=solid}     url.openConnection(Proxy.NO_PROXY);{code}
The technote points out : ??"Now, this guarantees you that this specific URL will be retrieved
though a direct connection bypassing any other proxy settings, which can be convenient."??

I think that using {{url.openConnection(Proxy.NO_PROXY)}} could fix this problem in :
* org.apache.cxf.transport.http.HttpURLConnectionFactoryImpl.createConnection(Proxy proxy,
URL url)   > line #51  (release 2.3.1)
* org.apache.cxf.transport.https.HttpsURLConnectionFactory.createConnection(Proxy proxy, URL
url) > line #120 (release 2.3.1)


(!) WARNING (!) : this issue can conflicts with this other one : [CXF-2839|http://issues.apache.org/jira/browse/CXF-2839]
A lot of tests will be required.


Code snippet simplification

> http.proxyHost and http.proxyPort of System properties win when no proxy is required
> ------------------------------------------------------------------------------------
>
>                 Key: CXF-3171
>                 URL: https://issues.apache.org/jira/browse/CXF-3171
>             Project: CXF
>          Issue Type: Bug
>          Components: Transports
>    Affects Versions: 2.2, 2.2.1, 2.2.2, 2.2.3, 2.2.4, 2.2.5, 2.2.6, 2.2.7, 2.2.8, 2.2.9,
2.1.10, 2.0.13, 2.2.10, 2.3.0, 2.2.11, 2.2.12, 2.3.1
>            Reporter: N. Tisserand
>   Original Estimate: 3h
>  Remaining Estimate: 3h
>
> When VM args "{{-Dhttp.proxyHost=xxxxxxxx -Dhttp.proxyPort=3128}}" are set, there is
no way to connect a webservice directly without passing throuh the proxy xxxxxxxx.
> The client CXF is build as following :
> {code:java|borderStyle=solid}JaxWsProxyFactoryBean factory = new JaxWsProxyFactoryBean();
>   factory.setServiceClass(MyWs.class);
>   factory.setAddress(bundle.getProperty("url.web.service"));
>   MyWs instance = (MyWs) factory.create();
>   Client client = ClientProxy.getClient(instance);
>   HTTPConduit conduit = (HTTPConduit) client.getConduit();
>   HTTPClientPolicy httpClientPolicy = conduit.getClient();
>   httpClientPolicy.setAllowChunking(false);
>   
>   // Force NO proxy ?
>   httpClientPolicy.setProxyServer(null);
>   httpClientPolicy.setProxyServerPort(0);
>   // httpClientPolicy.unsetProxyServerPort();  // tried without success
>   conduit.setClient(httpClientPolicy);
> {code}
> When creating the instance with , CXF use HttpURLConnectionFactoryImpl (or HttpsURLConnectionFactory)
to open the url :
> {code:java|borderStyle=solid}    if (proxy != null) {
>       return (HttpURLConnection) url.openConnection(proxy);
>     } else {
>       return (HttpURLConnection) url.openConnection();
>     }
> {code}
> When the variable "{{proxy}}" is null, {{url.openConnection()}} is used, and benifits
of VM args ({{http.proxyHost}} and {{http.proxyPort}}).
> The only solution to bypass the proxy, while keeping existing VM args, is to add a System
property "{{http.nonProxyHosts}}" in order to exclude the host of the proxy. This can be done
with an other VM arg "{{-Dhttp.nonProxyHosts=xxxx}}" or programmatically : {{System.setProperty("http.nonProxyHosts",
"xxxx")}}
> According to http://download.oracle.com/javase/6/docs/technotes/guides/net/proxies.html
(chapter 3 Proxy class) when no proxy is required url.openConnection() should be used like
this :
> {code:java|borderStyle=solid}     url.openConnection(Proxy.NO_PROXY);{code}
> The technote points out : ??"Now, this guarantees you that this specific URL will be
retrieved though a direct connection bypassing any other proxy settings, which can be convenient."??
> I think that using {{url.openConnection(Proxy.NO_PROXY)}} could fix this problem in :
> * org.apache.cxf.transport.http.HttpURLConnectionFactoryImpl.createConnection(Proxy proxy,
URL url)   > line #51  (release 2.3.1)
> * org.apache.cxf.transport.https.HttpsURLConnectionFactory.createConnection(Proxy proxy,
URL url) > line #120 (release 2.3.1)
> (!) WARNING (!) : this issue can conflicts with this other one : [CXF-2839|http://issues.apache.org/jira/browse/CXF-2839]
> A lot of tests will be required.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message