Package org.apache.commons.httpclient.server

Examples of org.apache.commons.httpclient.server.SimpleHttpServer


        } else {
            serversocketfactory = new SimplePlainSocketFactory();
            testhttp = Protocol.getProtocol("http");
        }

        this.server = new SimpleHttpServer(serversocketfactory, 0); // use arbitrary port
        this.server.setTestname(getName());

        this.client = new HttpClient();

        this.client.getHostConfiguration().setHost(
View Full Code Here


    // ----------------------------------------------------------- Test Methods

    public void setUp() throws IOException {
        client = new HttpClient();
        server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setRequestHandler(new MyHttpRequestHandler());
    }
View Full Code Here

    }

   
    public void testDigestAuthenticationWithStaleNonce() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new StaleNonceService());

        // configure the client
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(
                server.getLocalAddress(), server.getLocalPort(),
                Protocol.getProtocol("http"));
       
        client.getState().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("username","password"));
       
        FakeHttpMethod httpget = new FakeHttpMethod("/");
        try {
            client.executeMethod(httpget);
        } finally {
            httpget.releaseConnection();
        }
        assertNotNull(httpget.getStatusLine());
        assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
        Map table = AuthChallengeParser.extractParams(
                httpget.getRequestHeader("Authorization").getValue());
        assertEquals("username", table.get("username"));
        assertEquals("realm1", table.get("realm"));
        assertEquals("/", table.get("uri"));
        assertEquals("321CBA", table.get("nonce"));
        assertEquals("7f5948eefa115296e9279225041527b3", table.get("response"));
        server.destroy();
    }
View Full Code Here

    public void testCrossSiteRedirect() throws IOException {
        String host = this.server.getLocalAddress();
        int port = this.server.getLocalPort();
       
        SimpleHttpServer thatserver = new SimpleHttpServer();
        this.server.setHttpService(new BasicRedirectService(host, port));
        thatserver.setHttpService(new BasicRedirectService(host, port));
        thatserver.setTestname(getName());
       
        HostConfiguration hostconfig = new HostConfiguration();
        hostconfig.setHost(
                thatserver.getLocalAddress(),
                thatserver.getLocalPort(),
                Protocol.getProtocol("http"));

        GetMethod httpget = new GetMethod("/oldlocation/");
        httpget.setFollowRedirects(true);
        try {
            this.client.executeMethod(hostconfig, httpget);
            assertEquals(HttpStatus.SC_OK, httpget.getStatusCode());
            assertEquals("/newlocation/", httpget.getPath());
            assertEquals(host, httpget.getURI().getHost());
            assertEquals(port, httpget.getURI().getPort());
            assertEquals(new URI("http://" + host + ":" + port + "/newlocation/", false),
                    httpget.getURI());
        } finally {
            httpget.releaseConnection();
        }
        thatserver.destroy();
    }
View Full Code Here

    // ------------------------------------------------- TestCase setup/shutdown

    public void setUp() throws IOException {
        // configure the server
        this.server = new SimpleHttpServer(); // use arbitrary port

        // configure the client
        this.client = new HttpClient();
        this.client.getHostConfiguration().setHost(
            this.server.getLocalAddress(),
View Full Code Here

    // ----------------------------------------------------------- Test Methods

    public void setUp() throws IOException {
        client = new HttpClient();
        server = new SimpleHttpServer(); // use arbitrary port
        server.setRequestHandler(new MyHttpRequestHandler());
    }
View Full Code Here

    }

   
    public void testDigestAuthenticationWithStaleNonce() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new StaleNonceService());

        // configure the client
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(
                server.getLocalAddress(), server.getLocalPort(),
                Protocol.getProtocol("http"));
       
        client.getState().setCredentials(AuthScope.ANY,
                new UsernamePasswordCredentials("username","password"));
       
        FakeHttpMethod httpget = new FakeHttpMethod("/");
        try {
            client.executeMethod(httpget);
        } finally {
            httpget.releaseConnection();
        }
        assertNotNull(httpget.getStatusLine());
        assertEquals(HttpStatus.SC_OK, httpget.getStatusLine().getStatusCode());
        Map table = AuthChallengeParser.extractParams(
                httpget.getRequestHeader("Authorization").getValue());
        assertEquals("username", table.get("username"));
        assertEquals("realm1", table.get("realm"));
        assertEquals("/", table.get("uri"));
        assertEquals("321CBA", table.get("nonce"));
        assertEquals("7f5948eefa115296e9279225041527b3", table.get("response"));
        server.destroy();
    }
View Full Code Here

    }
   
    // ------------------------------------------------- TestCase setup/shutdown

    public void setUp() throws IOException {
        this.server = new SimpleHttpServer(); // use arbitrary port
        this.server.setTestname(getName());

        this.client = new HttpClient();
        this.client.getHostConfiguration().setHost(
            this.server.getLocalAddress(),
View Full Code Here

    }

   
    public void testNTLMAuthenticationRetry() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new NTLMAuthService());

        // configure the client
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(
                server.getLocalAddress(), server.getLocalPort(),
                Protocol.getProtocol("http"));
       
        client.getState().setCredentials(AuthScope.ANY,
                new NTCredentials("username", "password", "host", "domain"));
       
        FakeHttpMethod httpget = new FakeHttpMethod("/");
        try {
            client.executeMethod(httpget);
        } finally {
            httpget.releaseConnection();
        }
        assertNull(httpget.getResponseHeader("WWW-Authenticate"));
        assertEquals(200, httpget.getStatusCode());
        server.destroy();
    }
View Full Code Here

                    (ProtocolSocketFactory)new SimpleSSLTestProtocolSocketFactory(), 443);
        } else {
            serversocketfactory = new SimplePlainSocketFactory();
            testhttp = Protocol.getProtocol("http");
        }
        this.httpserver = new SimpleHttpServer(serversocketfactory, 0);
        this.httpclient.getHostConfiguration().setHost(
                this.httpserver.getLocalAddress(),
                this.httpserver.getLocalPort(),
                testhttp);
    }
View Full Code Here

TOP

Related Classes of org.apache.commons.httpclient.server.SimpleHttpServer

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.