@Override protected ListenableFuture<Response> go(Request request) { results.put( request.getUrl(), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(2)
@Override public ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals("http://example.com/test", request.getUrl()); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals("http://example.com/val1/val2", request.getUrl()); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(counter.getAndIncrement())), jsonMapper.writeValueAsString(events.get(counter.getAndIncrement())) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(3)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws IOException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( HttpHeaders.Values.GZIP, request.getHeaders().get(HttpHeaders.Names.CONTENT_ENCODING) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteBuffer data = request.getByteBufferData().slice(); byte[] dataArray = new byte[data.remaining()]; data.get(dataArray); CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos); Assert.assertEquals( StringUtils.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), baos.toString(StandardCharsets.UTF_8.name()) ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( "Basic " + StringUtils.encodeBase64String(StringUtils.toUtf8("foo:bar")), request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION) ); Assert.assertEquals( StringUtils.format( "%s\n%s\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), StandardCharsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.byteBufferData = prototype.getByteBufferData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator();
else if (request.getByteData() != null) requestBuilder.setBody(request.getByteData()); else if (request.getByteBufferData() != null) requestBuilder.setBody(request.getByteBufferData()); else if (request.getBodyGenerator() != null) requestBuilder.setBody(request.getBodyGenerator());
nettyBody = new NettyByteBufferBody(StringUtils.charSequence2ByteBuffer(request.getStringData(), bodyCharset)); } else if (request.getByteBufferData() != null) { nettyBody = new NettyByteBufferBody(request.getByteBufferData());
@Override protected ListenableFuture<Response> go(Request request) { results.put( request.getUrl().toString(), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(2)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals("http://example.com/val1/val2", request.getUrl()); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override public ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals("http://example.com/test", request.getUrl()); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(counter.getAndIncrement())), jsonMapper.writeValueAsString(events.get(counter.getAndIncrement())) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(3)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws JsonProcessingException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( "Basic " + BaseEncoding.base64().encode("foo:bar".getBytes()), request.getHeaders().get(HttpHeaders.Names.AUTHORIZATION) ); Assert.assertEquals( String.format( "%s\n%s\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), Charsets.UTF_8.decode(request.getByteBufferData().slice()).toString() ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
@Override protected ListenableFuture<Response> go(Request request) throws IOException { Assert.assertEquals(TARGET_URL, request.getUrl()); Assert.assertEquals( "application/json", request.getHeaders().get(HttpHeaders.Names.CONTENT_TYPE) ); Assert.assertEquals( HttpHeaders.Values.GZIP, request.getHeaders().get(HttpHeaders.Names.CONTENT_ENCODING) ); ByteArrayOutputStream baos = new ByteArrayOutputStream(); ByteBuffer data = request.getByteBufferData().slice(); byte[] dataArray = new byte[data.remaining()]; data.get(dataArray); CompressionUtils.gunzip(new ByteArrayInputStream(dataArray), baos); Assert.assertEquals( String.format( "[%s,%s]\n", jsonMapper.writeValueAsString(events.get(0)), jsonMapper.writeValueAsString(events.get(1)) ), baos.toString(Charsets.UTF_8.name()) ); return GoHandlers.immediateFuture(okResponse()); } }.times(1)
public RequestImpl(Request prototype) { if (prototype != null) { this.method = prototype.getMethod(); this.uri = prototype.getUri(); this.address = prototype.getInetAddress(); this.localAddress = prototype.getLocalAddress(); this.headers = new FluentCaseInsensitiveStringsMap(prototype.getHeaders()); this.cookies = new ArrayList<>(prototype.getCookies()); this.byteData = prototype.getByteData(); this.compositeByteData = prototype.getCompositeByteData(); this.stringData = prototype.getStringData(); this.byteBufferData = prototype.getByteBufferData(); this.streamData = prototype.getStreamData(); this.bodyGenerator = prototype.getBodyGenerator(); this.formParams = prototype.getFormParams() == null ? null : new ArrayList<>(prototype.getFormParams()); this.parts = prototype.getParts() == null ? null : new ArrayList<>(prototype.getParts()); this.virtualHost = prototype.getVirtualHost(); this.length = prototype.getContentLength(); this.proxyServer = prototype.getProxyServer(); this.realm = prototype.getRealm(); this.file = prototype.getFile(); this.followRedirect = prototype.getFollowRedirect(); this.requestTimeout = prototype.getRequestTimeout(); this.rangeOffset = prototype.getRangeOffset(); this.charset = prototype.getBodyCharset(); this.connectionPoolPartitioning = prototype.getConnectionPoolPartitioning(); this.nameResolver = prototype.getNameResolver(); } }