@Override public void produce(final DataStreamChannel channel) throws IOException { final AsyncEntityProducer producer = entityProducerRef.get(); Asserts.notNull(producer, "Entity producer"); producer.produce(channel); }
@Override public void releaseResources() { final AsyncEntityProducer producer = entityProducerRef.getAndSet(null); if (producer != null) { producer.releaseResources(); } }
@Override public int available() { final AsyncEntityProducer producer = entityProducerRef.get(); Asserts.notNull(producer, "Entity producer"); return producer.available(); }
@Test public void testTextContentRepeatable() throws Exception { final AsyncEntityProducer producer = new FileEntityProducer(tempFile, ContentType.TEXT_PLAIN); Assert.assertEquals(6, producer.getContentLength()); Assert.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType()); Assert.assertEquals(null, producer.getContentEncoding()); for (int i = 0; i < 3; i++) { final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024); final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel); producer.produce(streamChannel); producer.produce(streamChannel); Assert.assertFalse(byteChannel.isOpen()); Assert.assertEquals("abcdef", byteChannel.dump(StandardCharsets.US_ASCII)); producer.releaseResources(); } }
@Override public void completed(final Map<String, Variant> variants) { if (variants != null && !variants.isEmpty() && (entityProducer == null || entityProducer.isRepeatable())) { negotiateResponseFromVariants(target, request, entityProducer, scope, chain, asyncExecCallback, variants); } else { callBackend(target, request, entityProducer, scope, chain, asyncExecCallback); } }
final HttpRoute route = scope.route; final HttpClientContext clientContext = scope.clientContext; if (entityProducer != null && !entityProducer.isRepeatable()) { log.debug("Cannot retry non-repeatable request"); } else if (retryHandler.retryRequest(request, (IOException) cause, execCount, clientContext)) { scope.execRuntime.discardEndpoint(); if (entityProducer != null) { entityProducer.releaseResources();
@Override public long getContentLength() { return wrapped.getContentLength(); }
@Override public String getContentType() { return wrapped.getContentType(); }
@Override public String getContentEncoding() { return wrapped.getContentEncoding(); }
@Test public void testTextContent() throws Exception { final AsyncEntityProducer producer = new FileEntityProducer(tempFile, ContentType.TEXT_PLAIN); Assert.assertEquals(6, producer.getContentLength()); Assert.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType()); Assert.assertEquals(null, producer.getContentEncoding()); final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024); final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel); producer.produce(streamChannel); producer.produce(streamChannel); Assert.assertFalse(byteChannel.isOpen()); Assert.assertEquals("abcdef", byteChannel.dump(StandardCharsets.US_ASCII)); }
&& (entityProducer == null || entityProducer.isRepeatable())) {
if (entityProducer != null && !entityProducer.isRepeatable()) { log.debug("Cannot retry non-repeatable request"); asyncExecCallback.completed(); entityProducer.releaseResources();
@Override public long getContentLength() { return wrapped.getContentLength(); }
@Override public String getContentType() { return wrapped.getContentType(); }
@Override public String getContentEncoding() { return wrapped.getContentEncoding(); }
@Test public void testTextContentRepeatable() throws Exception { final AsyncEntityProducer producer = new BasicAsyncEntityProducer( "abc", ContentType.TEXT_PLAIN); Assert.assertEquals(3, producer.getContentLength()); Assert.assertEquals(ContentType.TEXT_PLAIN.toString(), producer.getContentType()); Assert.assertEquals(null, producer.getContentEncoding()); for (int i = 0; i < 3; i++) { final WritableByteChannelMock byteChannel = new WritableByteChannelMock(1024); final DataStreamChannel streamChannel = new BasicDataStreamChannel(byteChannel); producer.produce(streamChannel); Assert.assertFalse(byteChannel.isOpen()); Assert.assertEquals("abc", byteChannel.dump(StandardCharsets.US_ASCII)); producer.releaseResources(); } }
@Override public void produce(final DataStreamChannel channel) throws IOException { final AsyncEntityProducer producer = entityProducerRef.get(); Asserts.notNull(producer, "Entity producer"); producer.produce(channel); }
@Override public void releaseResources() { entityConsumer.releaseResources(); final AsyncEntityProducer producer = entityProducerRef.getAndSet(null); if (producer != null) { producer.releaseResources(); } }
@Override public int available() { final AsyncEntityProducer producer = entityProducerRef.get(); Asserts.notNull(producer, "Entity producer"); return producer.available(); }
@Override public boolean isRepeatable() { return entityProducer == null || entityProducer.isRepeatable(); }