Examples of ProxyConnector


Examples of org.apache.mina.proxy.ProxyConnector

     */
    public ProxyTelnetTestClient() throws Exception {
        // Create proxy connector.
        NioSocketConnector targetConnector = new NioSocketConnector(Runtime
                .getRuntime().availableProcessors() + 1);
        ProxyConnector connector = new ProxyConnector(targetConnector);

        /*
        // Example of socks v5 proxy use
        SocksProxyRequest req = new SocksProxyRequest(
                SocksProxyConstants.SOCKS_VERSION_5,
                SocksProxyConstants.ESTABLISH_TCPIP_STREAM, serverAddress, USER);
        req.setPassword(PWD);
        */

        HttpProxyRequest req = new HttpProxyRequest(serverAddress);
        HashMap<String, String> props = new HashMap<String, String>();
        props.put(HttpProxyConstants.USER_PROPERTY, USER);
        props.put(HttpProxyConstants.PWD_PROPERTY, PWD);
        req.setProperties(props);       

        ProxyIoSession proxyIoSession = new ProxyIoSession(proxyAddress, req);
        connector.setProxyIoSession(proxyIoSession);

        LineDelimiter delim = new LineDelimiter("\r\n");
        targetConnector.getFilterChain().addLast(
                "codec",
                new ProtocolCodecFilter(new TextLineCodecFactory(Charset
                        .forName("UTF-8"), delim, delim)));

        connector.setHandler(new TelnetSessionHandler());

        IoSession session;
        for (;;) {
            try {
                ConnectFuture future = connector.connect();
                future.awaitUninterruptibly();
                session = future.getSession();
                break;
            } catch (RuntimeIoException e) {
                System.err.println("Failed to connect. Retrying in 5 secs ...");
                Thread.sleep(5000);
            }
        }

        // Wait until done
        if (session != null) {
            session.getCloseFuture().awaitUninterruptibly();
        }
        connector.dispose();
        System.exit(0);
    }
View Full Code Here

Examples of org.apache.mina.proxy.ProxyConnector

        // Create proxy connector.
        NioSocketConnector socketConnector = new NioSocketConnector(Runtime
                .getRuntime().availableProcessors() + 1);

        ProxyConnector connector = new ProxyConnector(socketConnector);

        // Set connect timeout.
        connector.setConnectTimeoutMillis(5000);

        URL url = new URL(args[2]);
        int port = url.getPort() == -1 ? url.getDefaultPort() : url.getPort();

        ProxyRequest req = null;

        if (args.length == 4) {
            if ("SOCKS4".equals(args[3])) {
                req = new SocksProxyRequest(
                        SocksProxyConstants.SOCKS_VERSION_4,
                        SocksProxyConstants.ESTABLISH_TCPIP_STREAM,
                        new InetSocketAddress(url.getHost(), port), USER);
            } else if ("SOCKS4a".equals(args[3])) {
                req = new SocksProxyRequest(
                        SocksProxyConstants.ESTABLISH_TCPIP_STREAM, url
                                .getHost(), port, USER);
            } else if ("SOCKS5".equals(args[3])) {
                req = new SocksProxyRequest(
                        SocksProxyConstants.SOCKS_VERSION_5,
                        SocksProxyConstants.ESTABLISH_TCPIP_STREAM,
                        new InetSocketAddress(url.getHost(), port), USER);
                ((SocksProxyRequest) req).setPassword(PWD);
                ((SocksProxyRequest) req)
                        .setServiceKerberosName(Socks5GSSAPITestServer.SERVICE_NAME);
            } else {
                req = createHttpProxyRequest(args[2]);
            }
        } else {
            req = createHttpProxyRequest(args[2]);
        }

        ProxyIoSession proxyIoSession = new ProxyIoSession(
                new InetSocketAddress(args[0], Integer.parseInt(args[1])), req);

        // Tests modifying authentication order preferences. First algorithm in list available on server
        // will be used for authentication.
        List<HttpAuthenticationMethods> l = new ArrayList<HttpAuthenticationMethods>();
        l.add(HttpAuthenticationMethods.DIGEST);
        l.add(HttpAuthenticationMethods.BASIC);
        proxyIoSession.setPreferedOrder(l);

        connector.setProxyIoSession(proxyIoSession);

        socketConnector.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, 5);

        connector.getFilterChain().addLast("logger", new LoggingFilter());

        // This command is sent when using a socks proxy to request a page from the web server.
        String cmd = "GET " + url.toExternalForm() + " HTTP/1.0"
                + HttpProxyConstants.CRLF + HttpProxyConstants.CRLF;

        connector.setHandler(new ClientSessionHandler(cmd));

        IoSession session;
        for (;;) {
            try {
                ConnectFuture future = connector.connect();
                future.awaitUninterruptibly();
                session = future.getSession();
                break;
            } catch (RuntimeIoException e) {
                System.err.println("Failed to connect. Retrying in 5 secs ...");
                Thread.sleep(5000);
            }
        }

        // Wait until done
        if (session != null) {
            session.getCloseFuture().awaitUninterruptibly();
        }
        connector.dispose();
        System.exit(0);
    }
View Full Code Here

Examples of org.openengsb.core.services.internal.virtual.ProxyConnector

    @Before
    public void setUp() {
        router = mock(OutgoingPortUtilService.class);
        registryImpl = new ProxyConnectorRegistryImpl();
        ProxyRegistration registration = registryImpl.create("foo");
        proxy = new ProxyConnector("foo", null, registration);
        proxy.setOutgoingPortUtilService(router);
        proxy.setPortId("id");
        proxy.setDestination("test");
        proxy.addMetadata("key", "value");
        registryImpl.registerConnector("foo", "jms-json", "tcp://localhost");
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.