@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()); }
@After @Override public void tearDown() throws Exception { super.tearDown(); if (localServer != null) { localServer.stop(); } }
@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)); }
@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(); }