Android Open Source - Orlib My Default Client Connection Operator






From Project

Back to project page Orlib.

License

The source code is released under:

GNU Lesser General Public License

If you think the Android project Orlib listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package info.guardianproject.net.http;
//from   w  w  w.  j  a v a  2s  . com
import java.io.IOException;
import java.net.ConnectException;
import java.net.InetAddress;
import java.net.Socket;

import org.apache.http.HttpHost;
import org.apache.http.conn.HttpHostConnectException;
import org.apache.http.conn.OperatedClientConnection;
import org.apache.http.conn.scheme.Scheme;
import org.apache.http.conn.scheme.SchemeRegistry;
import org.apache.http.conn.scheme.SocketFactory;
import org.apache.http.impl.conn.DefaultClientConnectionOperator;
import org.apache.http.params.HttpParams;
import org.apache.http.protocol.HttpContext;

public class MyDefaultClientConnectionOperator extends
    DefaultClientConnectionOperator {

  public MyDefaultClientConnectionOperator(SchemeRegistry schemes) {
    super(schemes);
  }
  
  @Override
  public void openConnection(OperatedClientConnection conn, HttpHost target,
      InetAddress local, HttpContext context, HttpParams params)
      throws IOException {
    if (conn == null) {
            throw new IllegalArgumentException
                ("Connection must not be null.");
        }
        if (target == null) {
            throw new IllegalArgumentException
                ("Target host must not be null.");
        }
        // local address may be null
        //@@@ is context allowed to be null?
        if (params == null) {
            throw new IllegalArgumentException
                ("Parameters must not be null.");
        }
        if (conn.isOpen()) {
            throw new IllegalArgumentException
                ("Connection must not be open.");
        }

        final Scheme schm = schemeRegistry.getScheme(target.getSchemeName());
        final SocketFactory sf = schm.getSocketFactory();

        Socket sock = sf.createSocket();
        conn.opening(sock, target);

        try {
          Socket connsock = sf.connectSocket(sock, target.getHostName(),
                    schm.resolvePort(target.getPort()),
                    local, 0, params);
          
              if (sock != connsock) {
                    sock = connsock;
                    conn.opening(sock, target);
                }
        } catch (ConnectException ex) {
            throw new HttpHostConnectException(target, ex);
        }
        prepareSocket(sock, context, params);
        conn.openCompleted(sf.isSecure(sock), params);
  }

}




Java Source Code List

info.guardianproject.net.SocksSocketFactory.java
info.guardianproject.net.http.HttpManager.java
info.guardianproject.net.http.ModSSLSocketFactory.java
info.guardianproject.net.http.MyDefaultClientConnectionOperator.java
info.guardianproject.net.http.MyThreadSafeClientConnManager.java
info.guardianproject.net.http.SocksHttpClient.java
net.sourceforge.jsocks.SOCKS.java
net.sourceforge.jsocks.SocksServerException.java
net.sourceforge.jsocks.socks.AuthenticationException.java
net.sourceforge.jsocks.socks.AuthenticationNone.java
net.sourceforge.jsocks.socks.Authentication.java
net.sourceforge.jsocks.socks.InetRange.java
net.sourceforge.jsocks.socks.ProxyMessage.java
net.sourceforge.jsocks.socks.ProxyServer.java
net.sourceforge.jsocks.socks.Proxy.java
net.sourceforge.jsocks.socks.Socks4Message.java
net.sourceforge.jsocks.socks.Socks4Proxy.java
net.sourceforge.jsocks.socks.Socks5DatagramSocket.java
net.sourceforge.jsocks.socks.Socks5Message.java
net.sourceforge.jsocks.socks.Socks5Proxy.java
net.sourceforge.jsocks.socks.SocksException.java
net.sourceforge.jsocks.socks.SocksServerSocket.java
net.sourceforge.jsocks.socks.SocksSocket.java
net.sourceforge.jsocks.socks.UDPEncapsulation.java
net.sourceforge.jsocks.socks.UDPRelayServer.java
net.sourceforge.jsocks.socks.UserPasswordAuthentication.java
net.sourceforge.jsocks.socks.server.IdentAuthenticator.java
net.sourceforge.jsocks.socks.server.Ident.java
net.sourceforge.jsocks.socks.server.ServerAuthenticatorNone.java
net.sourceforge.jsocks.socks.server.ServerAuthenticator.java
net.sourceforge.jsocks.socks.server.UserPasswordAuthenticator.java
net.sourceforge.jsocks.socks.server.UserValidation.java
orlib.sample.OrlibMainActivity.java