Package org.apache.commons.httpclient.server

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


    // ----------------------------------------------------------- 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


    }

    // ------------------------------------------------------- TestCase Methods
    public void testNoClaimsBasedAuthentication() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new NoClaimsService());
       
        // 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 {
            assertEquals(403, client.executeMethod(httpget));
        } catch (Exception e) {
            fail("Exception caught: " + e.getMessage());
        }
        finally {
            httpget.releaseConnection();
        }
        server.destroy();
    }
View Full Code Here

        server.destroy();
    }
   
    public void testClaimsBasedAuthn() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new ClaimsService(
            "http://" + server.getLocalAddress() + ":" + server.getLocalPort()
        ));
     
        // 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"));
       
        GetMethod httpget = new GetMethod(
            "http://" + server.getLocalAddress() + ":" + server.getLocalPort() + "/");
        try {
            assertEquals(200, client.executeMethod(httpget));
        }
        finally {
            httpget.releaseConnection();
        }
        server.destroy();
    }
View Full Code Here

        server.destroy();
    }
   
    public void testClaimsBasedAuthnInvalidCredentials() throws Exception {
        // configure the server
        SimpleHttpServer server = new SimpleHttpServer(); // use arbitrary port
        server.setTestname(getName());
        server.setHttpService(new ClaimsService(
            "http://" + server.getLocalAddress() + ":" + server.getLocalPort()
        ));
   
        // configure the client
        HttpClient client = new HttpClient();
        client.getHostConfiguration().setHost(
                server.getLocalAddress(), server.getLocalPort(),
                Protocol.getProtocol("http"));
   
        client.getState().setCredentials(AuthScope.ANY,
            new NTCredentials("nonexisting", "wrongpassword", "host", "domain"));
     
        GetMethod httpget = new GetMethod(
            "http://" + server.getLocalAddress() + ":" + server.getLocalPort() + "/");
        try {
            assertEquals(401, client.executeMethod(httpget));
        }
        finally {
            httpget.releaseConnection();
        }
        server.destroy();     
    }
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

   */
  protected void setUp() throws Exception {
    super.setUp();
    tmpFile = File.createTempFile("ECFTest", "");
    server = new SimpleServer(getName());
    SimpleHttpServer simple = server.getSimpleHttpServer();
    simple.setRequestHandler(new HttpRequestHandler() {

      public boolean processRequest(SimpleHttpServerConnection conn,
          SimpleRequest request) throws IOException {
        trace("Responding to request "
            + request.getRequestLine());
View Full Code Here

    service.shutdown();
  }
 
  public void testServerCreation() {
    assertNotNull( service );
    SimpleHttpServer server = service.getServer();
    assertNotNull( server );
    assertTrue( server.isRunning() );
  }
View Full Code Here

    assertNotNull( server );
    assertTrue( server.isRunning() );
  }
 
  public void testStart() {
    SimpleHttpServer server = service.getServer();
    assertNotNull( server );
    service.run();
    assertTrue( server.isRunning() );   
  }
View Full Code Here

    service.run();
    assertTrue( server.isRunning() );   
  }
 
  public void testStop() {
    SimpleHttpServer server = service.getServer();
    assertNotNull( server );
    service.shutdown();
    server = service.getServer();
    assertNull( server );
  }
View Full Code Here

    }
  }

  private void createServer() {
    try {
      server = new SimpleHttpServer();
      server.setRequestHandler(reqHandler);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }
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.