Uploaded image for project: 'CXF'
  1. CXF
  2. CXF-3171

http.proxyHost and http.proxyPort of System properties win when no proxy is required

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Fixed
    • 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, 2.2.11, 2.2.12, 2.3.1
    • 2.3.4
    • Transports
    • None
    • Moderate

    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 :

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

      When creating the instance with , CXF use HttpURLConnectionFactoryImpl (or HttpsURLConnectionFactory) to open the url :

          if (proxy != null) {
            return (HttpURLConnection) url.openConnection(proxy);
          } else {
            return (HttpURLConnection) url.openConnection();
          }
      

      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 :

           url.openConnection(Proxy.NO_PROXY);

      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
      A lot of tests will be required.

      Attachments

        Activity

          People

            dkulp Daniel Kulp
            iltud N. Tisserand
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Time Tracking

                Estimated:
                Original Estimate - 3h
                3h
                Remaining:
                Remaining Estimate - 3h
                3h
                Logged:
                Time Spent - Not Specified
                Not Specified