[ 
http://issues.apache.org/jira/browse/DIRMINA-223?page=comments#action_12431838 
] 
            
Trustin Lee commented on DIRMINA-223:
-------------------------------------

It seems like java.net.Proxy is available since JDK 1.5.  The patch has to be 
integrated into the core code which is supposed to run with JDK 1.4.

Fortunately, JDK 1.4 provides javax.net.SocketFactory where you can insert your 
initialization code (new Socket(proxy)).  Allowing a user to specify the socket 
factory in the constructor of SocketConnector will work in this case.

WDYT?  Any better idea to support both 1.4 and 1.5?

> Addition of SocketConnector method to handle socks proxies.
> -----------------------------------------------------------
>
>                 Key: DIRMINA-223
>                 URL: http://issues.apache.org/jira/browse/DIRMINA-223
>             Project: Directory MINA
>          Issue Type: Improvement
>    Affects Versions: 0.9.4
>         Environment: All platforms
>            Reporter: John Preston
>
> When using MINA to to establish a SocketConnector behind a firewall it is 
> necessary to specify socks proxie to use. The SocketConnector can be ammended 
> as follows: (svn diff)
> Index: 
> core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java
> ===================================================================
> --- 
> core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java  
>     (revision 415629)
> +++ 
> core/src/main/java/org/apache/mina/transport/socket/nio/SocketConnector.java  
>     (working copy)
> @@ -21,6 +21,7 @@
>  import java.io.IOException;
>  import java.net.ConnectException;
>  import java.net.InetSocketAddress;
> +import java.net.Proxy;
>  import java.net.SocketAddress;
>  import java.nio.channels.SelectionKey;
>  import java.nio.channels.Selector;
> @@ -61,6 +62,7 @@
>      private final Set managedSessions = Collections.synchronizedSet( new 
> HashSet() );
>      private final SocketIoProcessor[] ioProcessors;
>      private final int processorCount;
> +    private final Proxy socketProxy;
>  
>      /**
>       * @noinspection FieldAccessedSynchronizedAndUnsynchronized
> @@ -73,9 +75,17 @@
>      /**
>       * Create a connector with a single processing thread
>       */
> +    public SocketConnector(Proxy proxy)
> +    {
> +        this( 1, proxy );
> +    }
> +
> +    /**
> +     * Create a connector with a single processing thread
> +     */
>      public SocketConnector()
>      {
> -        this( 1 );
> +        this( 1, Proxy.NO_PROXY );
>      }
>  
>      /**
> @@ -83,7 +93,7 @@
>       *
>       * @param processorCount Number of processing threads
>       */
> -    public SocketConnector( int processorCount )
> +    public SocketConnector( int processorCount, Proxy proxy )
>      {
>          if( processorCount < 1 )
>          {
> @@ -91,6 +101,7 @@
>          }
>  
>          this.processorCount = processorCount;
> +        this.socketProxy = proxy == null ? Proxy.NO_PROXY : proxy;
>          ioProcessors = new SocketIoProcessor[processorCount];
>  
>          for( int i = 0; i < processorCount; i++ )
> @@ -153,11 +164,12 @@
>          boolean success = false;
>          try
>          {
> -            ch = SocketChannel.open();
> -            ch.socket().setReuseAddress( true );
> +            Socket s = new Socket(socketProxy);
> +            s.setReuseAddress( true );
> +            ch = s.getChannel().open();
>              if( localAddress != null )
>              {
> -                ch.socket().bind( localAddress );
> +                s.bind( localAddress );
>              }
>  
>              ch.configureBlocking( false );
> @@ -475,4 +487,4 @@
>              this.config = config;
>          }
>      }
> -}
> \ No newline at end of file
> +}

-- 
This message is automatically generated by JIRA.
-
If you think it was sent incorrectly contact one of the administrators: 
http://issues.apache.org/jira/secure/Administrators.jspa
-
For more information on JIRA, see: http://www.atlassian.com/software/jira

        

Reply via email to