Package org.apache.cactus.client.connector.http

Examples of org.apache.cactus.client.connector.http.ConnectionHelper


            // Create a helper that will connect to a restricted resource.

            String resource = ((WebConfiguration) theConfiguration).
                getRedirectorURL(theRequest);
   
            ConnectionHelper helper =
                ConnectionHelperFactory.getConnectionHelper(resource,
                theConfiguration);

            // Make the connection using a default web request.
            HttpURLConnection connection = helper.connect(
                new WebRequest((WebConfiguration) theConfiguration),
                theConfiguration);

            // Clean any existing session ID.
            sessionId = null;
           
            // Check (possible multiple) cookies for a JSESSIONID.
            int i = 1;
            String key = connection.getHeaderFieldKey(i);
            while (key != null)
            {
                if (key.equalsIgnoreCase("set-cookie"))
                {
                    // Cookie is in the form:
                    // "NAME=VALUE; expires=DATE; path=PATH;
                    //  domain=DOMAIN_NAME; secure"
                    // The only thing we care about is finding a cookie with
                    // the name "JSESSIONID" and caching the value.
                   
                    String cookiestr = connection.getHeaderField(i);
                    String nameValue = cookiestr.substring(0,
                        cookiestr.indexOf(";"));
                    int equalsChar = nameValue.indexOf("=");
                    String name = nameValue.substring(0, equalsChar);

                    if (name.equalsIgnoreCase("JSESSIONID"))
                    {
                        // We must set a cookie with the exact same name as the
                        // one given to us, so to preserve any capitalization
                        // issues, cache the exact cookie name.
                        sessionIdCookieName = name;
                        sessionId = nameValue.substring(equalsChar + 1);
                        break;
                    }
                }
                key = connection.getHeaderFieldKey(++i);
            }

            // Create a helper that will connect to the security check URL.
            helper = ConnectionHelperFactory.getConnectionHelper(
                getSecurityCheckURL(theConfiguration).toString(),
                (WebConfiguration) theConfiguration);
               
            // Configure a web request with the JSESSIONID cookie,
            // the username and the password.         
            WebRequest request = getSecurityRequest();
            request.setConfiguration(theConfiguration);
            request.addCookie(sessionIdCookieName, sessionId);
            request.addParameter("j_username", getName(),
                WebRequest.POST_METHOD);
            request.addParameter("j_password", getPassword(),
                WebRequest.POST_METHOD);
           
            // Make the connection using the configured web request.
            connection = helper.connect(request, theConfiguration);
       
            // If we get back a response code of 302, it means we were
            // redirected to the context root after successfully logging in.
            // If we receive anything else, we didn't log in correctly.
            if (connection.getResponseCode() != 302)
View Full Code Here


        {
            throw new ChainedRuntimeException("setConfiguration() should have "
                + "been called prior to calling getSessionCookie()");
        }
       
        ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(
            ((WebConfiguration) getConfiguration()).getRedirectorURL(this),
            getConfiguration());

        WebRequest obtainSessionIdRequest = new WebRequest(
            (WebConfiguration) getConfiguration());
           
       
        //Not sure whether I should be adding the service parameter to
        //this request (this) or to the obtainSessionIdRequest
        //seems obvious that it should be the obtainSessionIdRequest
        RequestDirectives directives =
            new RequestDirectives(obtainSessionIdRequest);
        directives.setService(ServiceEnumeration.CREATE_SESSION_SERVICE);

        HttpURLConnection resultConnection;
        try
        {
            resultConnection =
                helper.connect(obtainSessionIdRequest, getConfiguration());
        }
        catch (Throwable e)
        {
            throw new ChainedRuntimeException("Failed to connect to ["
                + ((WebConfiguration) getConfiguration()).getRedirectorURL(this)
View Full Code Here

        {
            throw new ChainedRuntimeException("setConfiguration() should have "
                + "been called prior to calling getSessionCookie()");
        }
       
        ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(
            ((WebConfiguration) getConfiguration()).getRedirectorURL(this),
            getConfiguration());

        WebRequest obtainSessionIdRequest = new WebRequest(
            (WebConfiguration) getConfiguration());
           
       
        //Not sure whether I should be adding the service parameter to
        //this request (this) or to the obtainSessionIdRequest
        //seems obvious that it should be the obtainSessionIdRequest
        RequestDirectives directives =
            new RequestDirectives(obtainSessionIdRequest);
        directives.setService(ServiceEnumeration.CREATE_SESSION_SERVICE);

        HttpURLConnection resultConnection;
        try
        {
            resultConnection =
                helper.connect(obtainSessionIdRequest, getConfiguration());
        }
        catch (Throwable e)
        {
            throw new ChainedRuntimeException("Failed to connect to ["
                + ((WebConfiguration) getConfiguration()).getRedirectorURL(this)
View Full Code Here

TOP

Related Classes of org.apache.cactus.client.connector.http.ConnectionHelper

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.