public HttpForward buildObject() { return new HttpForward() .withHost(host) .withPort(port != null ? port : 80) .withScheme((scheme != null ? scheme : HttpForward.Scheme.HTTP)); }
@Test(enabled = false) public void mustDownloadLargeFiles() throws Exception { mockServer.when(HttpRequest.request().withMethod("CONNECT").withPath("www.us.apache.org:80")) .respond(HttpResponse.response().withStatusCode(200)); mockServer.when(HttpRequest.request().withMethod("GET") .withPath("/dist//httpcomponents/httpclient/binary/httpcomponents-client-4.5.1-bin.tar.gz")) .forward(HttpForward.forward().withHost("www.us.apache.org").withPort(80)); Tunnel tunnel = Tunnel.build("www.us.apache.org", 80, "localhost", PORT); try { IOUtils.copyLarge((InputStream) new URL("http://localhost:" + tunnel.getPort() + "/dist//httpcomponents/httpclient/binary/httpcomponents-client-4.5.1-bin.tar.gz") .getContent(new Class[]{InputStream.class}), new FileOutputStream(File.createTempFile("httpcomponents-client-4.5.1-bin", "tar.gz"))); } finally { tunnel.close(); } }
forward() .withHost("127.0.0.1") .withPort(secureEchoServer.getPort()) .withScheme(HttpForward.Scheme.HTTPS) );
.respond(response().withBody("some_other_body")); mockServerClient.when(request().withPath(calculatePath("some_forward_path"))) .forward(forward()); .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward()) ))) ); .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward()) ))) );
/** * Static builder to create a callback. */ public static HttpForward forward() { return new HttpForward(); }
public void doForward(ForwardChainExpectation fce, EndPoint ep){ LOG.debug("forward host: " + ep.getForwardHost()); fce.forward(forward().withHost(ep.getForwardHost()) .withPort(ep.getForwardPort()) .withScheme(ep.getForwardScheme())); } }
.respond(response().withBody("some_other_body")); mockServerClient.when(request().withPath(calculatePath("some_forward_path"))) .forward(forward()); .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward()) ))) ); .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward()) ))) );
/** * Static builder to create a callback. */ public static HttpForward forward() { return new HttpForward(); }
public HttpForward buildObject() { return new HttpForward() .withHost(host) .withPort(port != null ? port : 80) .withScheme((scheme != null ? scheme : HttpForward.Scheme.HTTP)); }
@Override public String serialize(int numberOfSpacesToIndent, HttpForward httpForward) { StringBuffer output = new StringBuffer(); if (httpForward != null) { appendNewLineAndIndent(numberOfSpacesToIndent * INDENT_SIZE, output).append("forward()"); if (httpForward.getHost() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withHost(\"").append(httpForward.getHost()).append("\")"); } if (httpForward.getPort() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withPort(").append(httpForward.getPort()).append(")"); } if (httpForward.getScheme() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withScheme(HttpForward.Scheme.").append(httpForward.getScheme()).append(")"); } } return output.toString(); }
.respond(response().withBody("some_other_body")); mockServerClient.when(request().withPath(calculatePath("some_forward_path"))) .forward(forward()); .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward()) .thenRespond(response().withBody("some_other_body")), new Expectation(request().withPath(calculatePath("some_forward_path"))) .thenForward(forward())
public HttpForwardActionResult handle(HttpForward httpForward, HttpRequest httpRequest) { if (httpForward.getScheme().equals(HttpForward.Scheme.HTTPS)) { httpRequest.withSecure(true); } else { httpRequest.withSecure(false); } return sendRequest(httpRequest, new InetSocketAddress(httpForward.getHost(), httpForward.getPort())); }
@Override public String serialize(int numberOfSpacesToIndent, HttpForward httpForward) { StringBuffer output = new StringBuffer(); if (httpForward != null) { appendNewLineAndIndent(numberOfSpacesToIndent * INDENT_SIZE, output).append("forward()"); if (httpForward.getHost() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withHost(\"").append(httpForward.getHost()).append("\")"); } if (httpForward.getPort() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withPort(").append(httpForward.getPort()).append(")"); } if (httpForward.getScheme() != null) { appendNewLineAndIndent((numberOfSpacesToIndent + 1) * INDENT_SIZE, output).append(".withScheme(HttpForward.Scheme.").append(httpForward.getScheme()).append(")"); } } return output.toString(); }
public HttpForwardActionResult handle(HttpForward httpForward, HttpRequest httpRequest) { if (httpForward.getScheme().equals(HttpForward.Scheme.HTTPS)) { httpRequest.withSecure(true); } else { httpRequest.withSecure(false); } return sendRequest(httpRequest, new InetSocketAddress(httpForward.getHost(), httpForward.getPort())); }