Package org.apache.mina.proxy.session

Examples of org.apache.mina.proxy.session.ProxyIoSession


        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",
View Full Code Here


            }
        } 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);
View Full Code Here

     * the proxy.
     */
    @Override
    public void proxySessionOpened(IoSession session) throws Exception {
        logger.debug("CLIENT - Session opened: " + session);
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        if (proxyIoSession != null) {
            ProxyRequest req = proxyIoSession.getRequest();

            byte[] c = null;
            if (req instanceof SocksProxyRequest && cmd != null) {
                logger.debug("Sending request to a SOCKS SESSION ...");
                c = cmd.getBytes(proxyIoSession.getCharsetName());
            } else if (req instanceof HttpProxyRequest
                    && ((HttpProxyRequest) req).getHttpVerb() == HttpProxyConstants.CONNECT) {
                logger.debug("Sending request to a HTTP CONNECTED SESSION ...");
                c = (((HttpProxyRequest) req).toHttpString())
                        .getBytes(proxyIoSession.getCharsetName());
            }

            if (c != null) {
                IoBuffer buf = IoBuffer.allocate(c.length);
                buf.put(c);
View Full Code Here

     * @param nextFilter the next filter
     */
    @Override
    public void exceptionCaught(NextFilter nextFilter, IoSession session,
            Throwable cause) throws Exception {
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        proxyIoSession.setAuthenticationFailed(true);
        super.exceptionCaught(nextFilter, session, cause);
    }
View Full Code Here

     */
    @Override
    public void sessionCreated(NextFilter nextFilter, IoSession session)
            throws Exception {
        logger.debug("Session created: " + session);
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        logger.debug("  get proxyIoSession: " + proxyIoSession);
        proxyIoSession.setProxyFilter(this);

        // Create a HTTP proxy handler and start handshake.   
        ProxyLogicHandler handler = proxyIoSession.getHandler();

        // This test prevents from loosing handler conversationnal state when
        // reconnection occurs during an http handshake.
        if (handler == null) {
            ProxyRequest request = proxyIoSession.getRequest();

            if (request instanceof SocksProxyRequest) {
                SocksProxyRequest req = (SocksProxyRequest) request;
                if (req.getProtocolVersion() == SocksProxyConstants.SOCKS_VERSION_4) {
                    handler = new Socks4LogicHandler(proxyIoSession);
                } else {
                    handler = new Socks5LogicHandler(proxyIoSession);
                }
            } else {
                handler = new HttpSmartProxyHandler(proxyIoSession);
            }

            proxyIoSession.setHandler(handler);
            handler.doHandshake(nextFilter);
        }

        proxyIoSession.getEventQueue().enqueueEventIfNecessary(
                new IoSessionEvent(nextFilter, session,
                        IoSessionEventType.CREATED));
    }
View Full Code Here

     * @param session the session object
     */
    @Override
    public void sessionOpened(NextFilter nextFilter, IoSession session)
            throws Exception {
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        proxyIoSession.getEventQueue().enqueueEventIfNecessary(
                new IoSessionEvent(nextFilter, session,
                        IoSessionEventType.OPENED));
    }
View Full Code Here

     * @param session the session object
     */   
    @Override
    public void sessionIdle(NextFilter nextFilter, IoSession session,
            IdleStatus status) throws Exception {
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        proxyIoSession.getEventQueue().enqueueEventIfNecessary(
                new IoSessionEvent(nextFilter, session, status));
    }
View Full Code Here

     * @param session the session object
     */   
    @Override
    public void sessionClosed(NextFilter nextFilter, IoSession session)
            throws Exception {
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        proxyIoSession.getEventQueue().enqueueEventIfNecessary(
                new IoSessionEvent(nextFilter, session,
                        IoSessionEventType.CLOSED));
    }
View Full Code Here

    protected final void setHandshakeComplete() {
        synchronized (this) {
            handshakeComplete = true;
        }

        ProxyIoSession proxyIoSession = getProxyIoSession();
        proxyIoSession.getConnector()
                .fireConnected(proxyIoSession.getSession())
                .awaitUninterruptibly();

        logger.debug("  handshake completed");

        // Connected OK
        try {
            proxyIoSession.getEventQueue().flushPendingSessionEvents();
            flushPendingWriteRequests();
        } catch (Exception ex) {
            logger.error("Unable to flush pending write requests", ex);
        }
    }
View Full Code Here

     * the proxy.
     */
    @Override
    public void proxySessionOpened(IoSession session) throws Exception {
        logger.debug("CLIENT - Session opened: " + session);
        ProxyIoSession proxyIoSession = (ProxyIoSession) session
                .getAttribute(ProxyIoSession.PROXY_SESSION);
        if (proxyIoSession != null) {
            ProxyRequest req = proxyIoSession.getRequest();

            byte[] c = null;
            if (req instanceof SocksProxyRequest && cmd != null) {
                logger.debug("Sending request to a SOCKS SESSION ...");
                c = cmd.getBytes(proxyIoSession.getCharsetName());
            } else if (req instanceof HttpProxyRequest
                    && ((HttpProxyRequest) req).getHttpVerb() == HttpProxyConstants.CONNECT) {
                logger.debug("Sending request to a HTTP CONNECTED SESSION ...");
                c = (((HttpProxyRequest) req).toHttpString())
                        .getBytes(proxyIoSession.getCharsetName());
            }

            if (c != null) {
                IoBuffer buf = IoBuffer.allocate(c.length);
                buf.put(c);
View Full Code Here

TOP

Related Classes of org.apache.mina.proxy.session.ProxyIoSession

Copyright © 2018 www.massapicom. 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.