Package org.apache.cactus

Examples of org.apache.cactus.WebRequest


     * @exception Exception on error
     */
    public void testCreateHttpStateWhenNoCactusCookieDefined()
        throws Exception
    {
        WebRequest request = new WebRequest();
        HttpState state = CookieUtil.createHttpState(request,
            new URL("http://jakarta.apache.org"));
        assertEquals(0, state.getCookies().length);
    }
View Full Code Here


     * @exception Exception on error
     */
    public void testCreateHttpStateWhenSeveralCactusCookieExist()
        throws Exception
    {
        WebRequest request = new WebRequest();
        request.addCookie(new Cookie("domain1", "name1", "value1"));
        request.addCookie(new Cookie("domain2", "name2", "value2"));
       
        HttpState state = CookieUtil.createHttpState(request,
            new URL("http://jakarta.apache.org"));
        assertEquals(2, state.getCookies().length);
    }
View Full Code Here

     *            redirector servlet.
     */
    private WebTestResult callGetResult(WebRequest theOriginalRequest)
        throws Throwable
    {
        WebRequest resultsRequest = new WebRequest(this.configuration);
        RequestDirectives directives = new RequestDirectives(resultsRequest);
        directives.setService(ServiceEnumeration.GET_RESULTS_SERVICE);

        // Use the same redirector as was used by the original request
        resultsRequest.setRedirectorName(
            theOriginalRequest.getRedirectorName());
       
        // Add authentication details
        if (theOriginalRequest.getAuthentication() != null)
        {
            resultsRequest.setAuthentication(
                theOriginalRequest.getAuthentication());
        }

        // Open the second connection to get the test results
        ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(
View Full Code Here

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

     *            for the current test case.
     */
    protected void runGenericTest(DefaultHttpClient theHttpClient)
        throws Throwable
    {
        WebRequest request = new WebRequest(
            (WebConfiguration) getConfiguration());

        // Call the set up and begin methods to fill the request object
        callClientGlobalBegin(request);
        callBeginMethod(request);
View Full Code Here

     *                      redirector servlet.
     */
    private WebTestResult callGetResult(
        AbstractAuthentication theAuthentication) throws Throwable
    {
        WebRequest resultsRequest = new WebRequest();

        // Add authentication details
        resultsRequest.addParameter(HttpServiceDefinition.SERVICE_NAME_PARAM,
            ServiceEnumeration.GET_RESULTS_SERVICE.toString(),
            WebRequest.GET_METHOD);
        resultsRequest.setAuthentication(theAuthentication);

        // Open the second connection to get the test results
        ConnectionHelper helper = ConnectionHelperFactory.getConnectionHelper(
            getRedirectorURL(resultsRequest));

View Full Code Here

     * @exception Exception on error
     */
    public void testCreateHttpStateWhenNoCactusCookieDefined()
        throws Exception
    {
        WebRequest request = new WebRequest();
        HttpState state = CookieUtil.createHttpState(request,
            new URL("http://jakarta.apache.org"));
        assertEquals(0, state.getCookies().length);
    }
View Full Code Here

     * @exception Exception on error
     */
    public void testCreateHttpStateWhenSeveralCactusCookieExist()
        throws Exception
    {
        WebRequest request = new WebRequest();
        request.addCookie(new Cookie("domain1", "name1", "value1"));
        request.addCookie(new Cookie("domain2", "name2", "value2"));
       
        HttpState state = CookieUtil.createHttpState(request,
            new URL("http://jakarta.apache.org"));
        assertEquals(2, state.getCookies().length);
    }
View Full Code Here

     *            for the current test case.
     */
    protected void runGenericTest(DefaultHttpClient theHttpClient)
        throws Throwable
    {
        WebRequest request = new WebRequest(
            (WebConfiguration) getConfiguration());

        // Call the set up and begin methods to fill the request object
        callClientGlobalBegin(request);
        callBeginMethod(request);
View Full Code Here

     * @see ProtocolHandler#runTest(Test, Test, Request)
     */
    public ProtocolState runTest(Test theDelegatedTest, Test theWrappedTest,
        Request theRequest) throws Throwable
    {
        WebRequest request = (WebRequest) theRequest;

        // Run the web test
        HttpURLConnection connection = runWebTest(theDelegatedTest,
            theWrappedTest, request);

View Full Code Here

TOP

Related Classes of org.apache.cactus.WebRequest

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.