Example #1
0
  @Test
  public void httpRedirect() throws Exception {

    String uri =
        "http4://"
            + localServer.getInetAddress().getHostName()
            + ":"
            + localServer.getLocalPort()
            + "/test?httpClient.redirectsEnabled=false&httpClient.socketTimeout=60000&httpClient.connectTimeout=60000"
            + "&httpClient.staleConnectionCheckEnabled=false";
    Exchange out =
        template.request(
            uri,
            new Processor() {
              public void process(Exchange exchange) throws Exception {
                // no data
              }
            });

    assertNotNull(out);
    HttpOperationFailedException cause = out.getException(HttpOperationFailedException.class);
    assertNotNull(cause);
    assertEquals(HttpStatus.SC_MOVED_PERMANENTLY, cause.getStatusCode());
    assertEquals(
        "http4://"
            + localServer.getInetAddress().getHostName()
            + ":"
            + localServer.getLocalPort()
            + "/someplaceelse",
        cause.getRedirectLocation());
  }
Example #2
0
  @After
  @Override
  public void tearDown() throws Exception {
    super.tearDown();

    if (localServer != null) {
      localServer.stop();
    }
  }
Example #3
0
  @Test
  public void httpHandleRedirect() throws Exception {

    String uri =
        "http4://"
            + localServer.getInetAddress().getHostName()
            + ":"
            + localServer.getLocalPort()
            + "/test?httpClient.socketTimeout=60000&httpClient.connectTimeout=60000"
            + "&httpClient.staleConnectionCheckEnabled=false";
    Exchange out =
        template.request(
            uri,
            new Processor() {
              public void process(Exchange exchange) throws Exception {
                // no data
              }
            });

    assertNotNull(out);
    assertEquals(HttpStatus.SC_OK, out.getOut().getHeader(Exchange.HTTP_RESPONSE_CODE));
    assertEquals("Bye World", out.getOut().getBody(String.class));
  }
Example #4
0
  @Before
  @Override
  public void setUp() throws Exception {
    localServer =
        ServerBootstrap.bootstrap()
            .setHttpProcessor(getBasicHttpProcessor())
            .setConnectionReuseStrategy(getConnectionReuseStrategy())
            .setResponseFactory(getHttpResponseFactory())
            .setExpectationVerifier(getHttpExpectationVerifier())
            .setSslContext(getSSLContext())
            .registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY))
            .registerHandler(
                "/someplaceelse", new BasicValidationHandler("GET", null, null, "Bye World"))
            .registerHandler("/test", new RedirectHandler(HttpStatus.SC_MOVED_PERMANENTLY))
            .create();
    localServer.start();

    super.setUp();
  }