commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From d...@multitask.com.au
Subject RE: [httpclient] Need support for selecting the local interface f or socket construction
Date Tue, 23 Jul 2002 04:40:01 GMT
Hi Dennis,

just to let you know I haven't forgotten about this one...I'l try to get 
to it tonight....

For future stuff, if you could post the patch as an attachment, rather 
than inline text, that would help me.

Thanks for the patch!
--
dIon Gillard, Multitask Consulting
Work:      http://www.multitask.com.au
Developers: http://adslgateway.multitask.com.au/developers


Dennis Cook <dennis@cook-mail.net> wrote on 07/20/2002 07:15:13 AM:

> Here are the patches for the use of an alternate interface.  Three 
classes
> are effected:
> HttpConnection.java, HttpMultiClient.java and HttpClient.java.  I hope 
they
> pass approval.
> 
> 
> 
> Index: HttpConnection.java
> ===================================================================
> RCS file:
> 
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpc
> lient/HttpConnection.java,v
> retrieving revision 1.10
> diff -u -r1.10 HttpConnection.java
> --- HttpConnection.java   14 Jul 2002 05:16:06 -0000   1.10
> +++ HttpConnection.java   19 Jul 2002 20:02:16 -0000
> @@ -144,6 +144,19 @@
>      // ------------------------------------------ Attribute Setters and
> Getters
> 
>      /**
> +     * Set the network interface to which the local socket is bound 
when it
> is created.
> +     * Useful for multihomed hosts.
> +     * @param intf InetAddress of the local interface. A null value 
will
> use the default
> +     * interface of the local host.
> +     * @throws IllegalStateException if I am already connected
> +     */
> +    public void setInterface(java.net.InetAddress intf) throws
> IllegalStateException {
> +        assertNotOpen();
> +        _bindAddr = intf;
> +    }
> +
> +
> +    /**
>       * Return my host.
>       *
>       * @return my host.
> @@ -304,9 +317,9 @@
>                  String host = (null == _proxyHost) ? _host : 
_proxyHost;
>                  int port = (null == _proxyHost) ? _port : _proxyPort;
>                  if (_ssl) {
> -                    _socket =
> SSLSocketFactory.getDefault().createSocket(host,port);
> +                   _socket =
> SSLSocketFactory.getDefault().createSocket(host,port,_bindAddr,0);
>                  } else {
> -                    _socket = new Socket(host,port);
> +                    _socket = new Socket(host,port,_bindAddr,0);
>                  }
>              }
>              _socket.setSoTimeout(_so_timeout);
> @@ -648,5 +661,7 @@
>      private static final byte[] CRLF = "\r\n".getBytes();
>      /** SO_TIMEOUT value */
>      private int _so_timeout = 0;
> +    /** Local Interface to which socket is to bind */
> +    private java.net.InetAddress _bindAddr;
> 
>  }
> 
> 
> 
> 
> 
> 
> 
> Index: HttpClient.java
> ===================================================================
> RCS file:
> 
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpc
> lient/HttpClient.java,v
> retrieving revision 1.48
> diff -u -r1.48 HttpClient.java
> --- HttpClient.java   14 Jul 2002 04:40:00 -0000   1.48
> +++ HttpClient.java   19 Jul 2002 20:14:26 -0000
> @@ -108,6 +108,7 @@
>       */
>      private HttpState state;
> 
> +    private java.net.InetAddress bindAddr;
>      // -------------------------------------------------------------
> Properties
> 
>      /**
> @@ -133,6 +134,18 @@
>          this.state = state;
>      }
> 
> +
> +    /**
> +     * Set the network interface to which the local socket is bound 
when it
> is created.
> +     * Useful for multihomed hosts.
> +     * @param intf InetAddress of the local interface. A null value 
will
> use the default
> +     * interface of the local host.
> +     * @throws IllegalStateException if I am already connected
> +     */
> +    public void setInterface(java.net.InetAddress intf){
> +        bindAddr = intf;
> +    }
> +
>      // --------------------------------------------------------- Public
> Methods
> 
>      /**
> @@ -163,6 +176,7 @@
>                        host + " Port:" + port + " HTTPS:" + https);
>          }
>          connection = new HttpConnection(host,port,https);
> +        connection.setInterface(bindAddr);
>      }
> 
>      /**
> @@ -201,6 +215,7 @@
>          }
>          getState().setCredentials(null,creds);
>          connection = new HttpConnection(host,port,https);
> +        connection.setInterface(bindAddr);
>      }
> 
>      /**
> @@ -285,6 +300,7 @@
>                               String proxyhost, int proxyport,
>                               boolean secure) {
>          connection = new
> HttpConnection(proxyhost,proxyport,host,port,secure);
> +        connection.setInterface(bindAddr);
>      }
> 
>      /**
> 
> 
> 
> 
> 
> 
> 
> Index: HttpMultiClient.java
> ===================================================================
> RCS file:
> 
/home/cvspublic/jakarta-commons/httpclient/src/java/org/apache/commons/httpc
> lient/HttpMultiClient.java,v
> retrieving revision 1.5
> diff -u -r1.5 HttpMultiClient.java
> --- HttpMultiClient.java   5 Jul 2002 07:13:46 -0000   1.5
> +++ HttpMultiClient.java   19 Jul 2002 21:00:25 -0000
> @@ -89,6 +89,7 @@
>      private boolean strictMode = true;
>      private int timeoutConnection = 0;
>      private int timeoutRequest = 0;
> +    private java.net.InetAddress bindAddr;
> 
>      // -----------------------------------------------------------
> Constructors
> 
> @@ -105,6 +106,37 @@
>      /**
>       * Constructor that uses proxy host and port. Strict mode is 
enabled by
> 
>       * default.
> +     * when the client is constructed, but a different one can be
> provided externally
> +     *
> +     * @param The {@link HttpConnectionManager} to be used.
> +     *
> +     */
> +    public void setConnectionManager(HttpConnectionManager mgr)
> +    {
> +       if (mgr == null)
> +       {
> +          this.mgr = new HttpConnectionManager();
> +       } else
> +       {
> +          this.mgr = mgr;
> +       }
> +    }
> +    /**
> +     * Get the {@link HttpConnectionManager} used by this client
> +     *
> +     * @return the {@link HttpConnectionManager} used by this client
> +     *
> +     */
> +    public HttpConnectionManager getConnectionManager()
> +    {
> +       return mgr;
> +    }
> +
> +    /**
> +     * Get the {@link HttpConnectionManager} used by this client
> +     *
> +     * @return the {@link HttpConnectionManager} used by this client
> +     *
>       */
>      public HttpMultiClient(String proxyHost, int proxyPort)
>      {
> @@ -265,6 +297,29 @@
>          return mgr.getProxyPort();
>      }
> 
> +
> +
> +    /**
> +     * Set the network interface to which the local socket is bound 
when it
> is created.
> +     * Useful for multihomed hosts.
> +     * @param intf InetAddress of the local interface. A null value 
will
> use the default
> +     * interface of the local host.
> +     * @throws IllegalStateException if I am already connected
> +     */
> +    public void setInterface(java.net.InetAddress intf){
> +       bindAddr = intf;
> +    }
> +
> +    /**
> +     * Returns the address of the network interface used to bind local
> socket for connection
> +     * 
> +     * @return the address of the network interface used to bind local
> socket for connection
> +     */
> +    public java.net.InetAddress getInterface()
> +    {
> +        return bindAddr;
> +    }
> + 
>      /**
>       *
>       * Execute the given {@link HttpUrlMethod} using my current
> @@ -286,6 +341,7 @@
>          }
> 
>          HttpConnection connection = mgr.getConnection(method.getUrl(),
> timeoutConnection);
> +        connection.setInterface(bindAddr);
>          connection.setSoTimeout(timeoutRequest);
> 
>          int status = 0;
> 
> 
> 
> 
> 
> 
> 
> 
> -----Original Message-----
> From: dion@multitask.com.au [mailto:dion@multitask.com.au]
> Sent: Thursday, July 11, 2002 9:24 PM
> To: Jakarta Commons Developers List
> Subject: Re: [httpclient] Need support for selecting the local interface
> for s ocket construction
> 
> 
> Dennis Cook <dennis@cook-mail.net> wrote on 07/12/2002 12:25:31 PM:
> 
> > I brought this subject up several weeks back, but it did not seem to
> > generate much interest then, but with the renewed activity in this 
> project
> > maybe this issue could be addressed now.
> > 
> > In short, both the Socket constructor and the 
> SocketFactory.createSocket()
> > methods have signature options to provide an InetAddress to which the 
> local
> > side of the socket is bound.  However, the HttpConnecction class does 
> not
> > support this method of socket construction.
> > 
> > I have made my own modification to the last released version to 
support 
> this
> > feature, but I would like to see it folded back into the next release. 

> Is
> > any there any interest at this time for including this feature?
> Sure....pop up a patch and we can review it...
> 
> --
> dIon Gillard, Multitask Consulting
> Work:      http://www.multitask.com.au
> Developers: http://adslgateway.multitask.com.au/developers
> 
> --
> To unsubscribe, e-mail: 
<mailto:commons-dev-unsubscribe@jakarta.apache.org>
> For additional commands, e-mail: 
<mailto:commons-dev-help@jakarta.apache.org>
> 

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message