Package org.apache.mina.proxy.session

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


        sb.append(':');
        sb.append(StringUtilities.getDirectiveValue(map, "uri", false));

        String qop = StringUtilities.getDirectiveValue(map, "qop", false);
        if ("auth-int".equalsIgnoreCase(qop)) {
            ProxyIoSession proxyIoSession = (ProxyIoSession) session
                    .getAttribute(ProxyIoSession.PROXY_SESSION);
            byte[] hEntity;

            synchronized (md5) {
                md5.reset();
                hEntity = md5.digest(body.getBytes(proxyIoSession
                        .getCharsetName()));
            }
            sb.append(':').append(hEntity);
        }
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

     */
    private void autoSelectAuthHandler(final HttpProxyResponse response)
            throws ProxyAuthException {
        // Get the Proxy-Authenticate header
        List<String> values = response.getHeaders().get("Proxy-Authenticate");
        ProxyIoSession proxyIoSession = getProxyIoSession();

        if (values == null || values.size() == 0) {
            authHandler = HttpAuthenticationMethods.NO_AUTH
                    .getNewHandler(proxyIoSession);

        } else if (getProxyIoSession().getPreferedOrder() == null) {
            // No preference order set for auth mechanisms
            int method = -1;

            // Test which auth mechanism to use. First found is the first used
            // that's why we test in a decreasing security quality order.
            for (String proxyAuthHeader : values) {
                proxyAuthHeader = proxyAuthHeader.toLowerCase();

                if (proxyAuthHeader.contains("ntlm")) {
                    method = HttpAuthenticationMethods.NTLM.getId();
                    break;
                } else if (proxyAuthHeader.contains("digest")
                        && method != HttpAuthenticationMethods.NTLM.getId()) {
                    method = HttpAuthenticationMethods.DIGEST.getId();
                } else if (proxyAuthHeader.contains("basic") && method == -1) {
                    method = HttpAuthenticationMethods.BASIC.getId();
                }
            }

            if (method != -1) {
                try {
                    authHandler = HttpAuthenticationMethods.getNewHandler(
                            method, proxyIoSession);
                } catch (Exception ex) {
                    logger.debug("Following exception occured:", ex);
                }
            }

            if (authHandler == null) {
                authHandler = HttpAuthenticationMethods.NO_AUTH
                        .getNewHandler(proxyIoSession);
            }

        } else {
            for (HttpAuthenticationMethods method : proxyIoSession
                    .getPreferedOrder()) {
                if (authHandler != null) {
                    break;
                }

View Full Code Here

     * @param nextFilter the next filter
     * @param request the http request
     */
    public void writeRequest(final NextFilter nextFilter,
            final HttpProxyRequest request) {
        ProxyIoSession proxyIoSession = getProxyIoSession();

        if (proxyIoSession.isReconnectionNeeded()) {
            reconnect(nextFilter, request);
        } else {
            writeRequest0(nextFilter, request);
        }
    }
View Full Code Here

     */
    private void reconnect(final NextFilter nextFilter,
            final HttpProxyRequest request) {
        LOGGER.debug("Reconnecting to proxy ...");

        final ProxyIoSession proxyIoSession = getProxyIoSession();

        // Fires reconnection
        proxyIoSession.getConnector().connect(
                new IoSessionInitializer<ConnectFuture>() {
                    public void initializeSession(final IoSession session,
                            ConnectFuture future) {
                        LOGGER.debug("Initializing new session: {}", session);
                        session.setAttribute(ProxyIoSession.PROXY_SESSION,
                                proxyIoSession);
                        proxyIoSession.setSession(session);
                        LOGGER.debug("  setting up proxyIoSession: {}", proxyIoSession);
                        future
                                .addListener(new IoFutureListener<ConnectFuture>() {
                                    public void operationComplete(
                                            ConnectFuture future) {
                                        // Reconnection is done so we send the
                                        // request to the proxy
                                        proxyIoSession
                                                .setReconnectionNeeded(false);
                                        writeRequest0(nextFilter, request);
                                    }
                                });
                    }
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

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.