示例#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());
  }
示例#2
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));
  }