ErrorResponsePayloadTestingServerConfig() { try { port = ComponentTestUtils.findFreePort(); } catch (IOException e) { throw new RuntimeException("Couldn't allocate port", e); } }
public static NettyHttpClientResponse executeRequest( FullHttpRequest request, int port, long incompleteCallTimeoutMillis, Consumer<ChannelPipeline> pipelineAdjuster ) throws InterruptedException, TimeoutException, ExecutionException { Bootstrap bootstrap = createNettyHttpClientBootstrap(); try { // Connect to the proxyServer. Channel ch = connectNettyHttpClientToLocalServer(bootstrap, port); try { return executeNettyHttpClientCall(ch, request, incompleteCallTimeoutMillis, pipelineAdjuster); } finally { ch.close(); } } finally { bootstrap.group().shutdownGracefully(); } }
@Test public void verify_compression_helper_methods_work_as_expected() { // given String orig = UUID.randomUUID().toString(); // when byte[] gzipped = gzipPayload(orig); String ungzipped = ungzipPayload(gzipped); byte[] deflated = deflatePayload(orig); String inflated = inflatePayload(deflated); // then assertThat(gzipped).isNotEqualTo(orig.getBytes(UTF_8)); assertThat(deflated).isNotEqualTo(orig.getBytes(UTF_8)); assertThat(ungzipped).isEqualTo(orig); assertThat(inflated).isEqualTo(orig); assertThat(gzipped).isNotEqualTo(deflated); }
public static NettyHttpClientResponse executeNettyHttpClientCall( Channel ch, FullHttpRequest request, long incompleteCallTimeoutMillis, Consumer<ChannelPipeline> pipelineAdjuster ) throws ExecutionException, InterruptedException, TimeoutException { CompletableFuture<NettyHttpClientResponse> responseFuture = setupNettyHttpClientResponseHandler(ch, pipelineAdjuster); // Send the request. ch.writeAndFlush(request); // Wait for the response to be received return responseFuture.get(incompleteCallTimeoutMillis, TimeUnit.MILLISECONDS); }
throws IOException, InterruptedException, TimeoutException, ExecutionException { Bootstrap bootstrap = createNettyHttpClientBootstrap(); Channel proxyServerChannel = connectNettyHttpClientToLocalServer(bootstrap, proxyServerConfig.endpointsPort()); request() .withMethod(HttpMethod.POST) .withUri(RouterEndpointForwardingToDelayEndpoint.MATCHING_PATH) verifyErrorReceived(response.payload, response.statusCode, INTENTIONAL_EXPLOSION_AFTER_LAST_CHUNK_API_ERROR); request() .withMethod(HttpMethod.POST) .withUri(RouterEndpointForwardingToLongerDelayEndpoint.MATCHING_PATH);
assertThat(response.asString()).isEqualTo(DeserializationEndpointWithDecompressionEnabled.RESPONSE_PAYLOAD); assertThat( base64Decode(response.header(RECEIVED_PAYLOAD_BYTES_AS_BASE64_RESPONSE_HEADER_KEY)) ).isEqualTo(origPayloadBytes); assertThat(response.header(SOME_OBJ_FIELD_VALUE_HEADER_KEY)).isEqualTo(origPayload.someField);
String rawBytesOnTheWireBody = extractBodyFromRawRequestOrResponse(rawBytesOnTheWireResponse); HttpHeaders headersFromRawResponse = extractHeadersFromRawRequestOrResponse(rawBytesOnTheWireResponse);
public static NettyHttpClientResponse executeRequest( FullHttpRequest request, int port, long incompleteCallTimeoutMillis ) throws InterruptedException, TimeoutException, ExecutionException { return executeRequest(request, port, incompleteCallTimeoutMillis, null); }
private void verifyRawRequestStuff(CallScenario scenario, String origRequestPayload) { verifyProxyAndDownstreamRequestHeaders(); String downstreamRawRequestBody = extractBodyFromRawRequestOrResponse(downstreamServerRawRequest.toString()); String proxyRawRequestBody = extractBodyFromRawRequestOrResponse(proxyServerRawRequest.toString()); if (scenario.isChunkedRequest) { // Verify that the request was sent in chunks verifyChunked(downstreamRawRequestBody); verifyChunked(proxyRawRequestBody); } else { // Verify that the request was NOT sent in chunks verifyNotChunked(downstreamRawRequestBody); verifyNotChunked(proxyRawRequestBody); } // Verify that request bodies are functionally equal by removing the chunk metadata (if any) and comparing. verifyBodyEqualityMinusChunkMetadata(downstreamRawRequestBody, origRequestPayload); verifyBodyEqualityMinusChunkMetadata(proxyRawRequestBody, origRequestPayload); verifyBodyEqualityMinusChunkMetadata(proxyRawRequestBody, downstreamRawRequestBody); }
private void verifyBodyEqualityMinusChunkMetadata(String body1, String body2) { String body1MinusChunkMeta = extractFullBodyFromChunks(body1); String body2MinusChunkMeta = extractFullBodyFromChunks(body2); assertThat(body1MinusChunkMeta).isEqualTo(body2MinusChunkMeta); }
public NettyHttpClientResponse execute(Channel ch, long incompleteCallTimeoutMillis) throws InterruptedException, ExecutionException, TimeoutException { return executeNettyHttpClientCall(ch, build(), incompleteCallTimeoutMillis, pipelineAdjuster); } }
private static HttpHeaders generateDefaultResponseHeaders(RequestInfo<?> request) { String base64EncodedPayload = base64Encode(request.getRawContentBytes()); return new DefaultHttpHeaders() .set(RECEIVED_PAYLOAD_BYTES_AS_BASE64_RESPONSE_HEADER_KEY, base64EncodedPayload) .set(RECEIVED_CONTENT_ENCODING_HEADER, String.valueOf(request.getHeaders().get(CONTENT_ENCODING))) .set(RECEIVED_CONTENT_LENGTH_HEADER, String.valueOf(request.getHeaders().get(CONTENT_LENGTH))) .set(RECEIVED_TRANSFER_ENCODING_HEADER, String.valueOf(request.getHeaders().get(TRANSFER_ENCODING))); }
assertThat(response.asString()).isEqualTo(BasicEndpointWithDecompressionDisabled.RESPONSE_PAYLOAD); assertThat( base64Decode(response.header(RECEIVED_PAYLOAD_BYTES_AS_BASE64_RESPONSE_HEADER_KEY)) ).isEqualTo(compressedPayload); verifyExpectedContentAndTransferHeaders(
public NettyHttpClientResponse execute(int port, long incompleteCallTimeoutMillis) throws Exception { return executeRequest(build(), port, incompleteCallTimeoutMillis, pipelineAdjuster); }
verifyProxyAndDownstreamResponseHeaders(expectProxyToRemoveTransferEncoding); String downstreamRawResponseBody = extractBodyFromRawRequestOrResponse(downstreamServerRawResponse.toString()); String proxyRawResponseBody = extractBodyFromRawRequestOrResponse(proxyServerRawResponse.toString());
public SSLTestConfig() { try { port = ComponentTestUtils.findFreePort(); } catch (IOException e) { throw new RuntimeException("Couldn't allocate port", e); } }
assertThat(response.asString()).isEqualTo(BasicEndpointWithDecompressionEnabled.RESPONSE_PAYLOAD); assertThat( base64Decode(response.header(RECEIVED_PAYLOAD_BYTES_AS_BASE64_RESPONSE_HEADER_KEY)) ).isEqualTo(origPayloadBytes); verifyExpectedContentAndTransferHeaders(response, "null", "null", CHUNKED);
public TimeoutsAndProxyTestServerConfig(long workerChannelIdleTimeoutMillis, long cfTimeoutMillis, long incompleteCallTimeoutMillis) { try { port = ComponentTestUtils.findFreePort(); } catch (IOException e) { throw new RuntimeException("Couldn't allocate port", e); } this.workerChannelIdleTimeoutMillis = workerChannelIdleTimeoutMillis; this.cfTimeoutMillis = cfTimeoutMillis; this.incompleteCallTimeoutMillis = incompleteCallTimeoutMillis; }
assertThat(response.asString()).isEqualTo(BasicEndpointWithDecompressionDisabled.RESPONSE_PAYLOAD); assertThat( base64Decode(response.header(RECEIVED_PAYLOAD_BYTES_AS_BASE64_RESPONSE_HEADER_KEY)) ).isEqualTo(origPayloadBytes); verifyExpectedContentAndTransferHeaders(response, "null", "null", CHUNKED);
public RequestAndResponseFilterTestConfig() { try { port = ComponentTestUtils.findFreePort(); } catch (IOException e) { throw new RuntimeException("Couldn't allocate port", e); } }