use of org.apache.hc.core5.util.Timeout in project feign by OpenFeign.
the class AsyncApacheHttp5ClientTest method throwsFeignExceptionIncludingBody.
@Test
public void throwsFeignExceptionIncludingBody() throws Throwable {
server.enqueue(new MockResponse().setBody("success!"));
final TestInterfaceAsync api = AsyncFeign.asyncBuilder().decoder((response, type) -> {
throw new IOException("timeout");
}).target(TestInterfaceAsync.class, "http://localhost:" + server.getPort());
final CompletableFuture<?> cf = api.body("Request body");
server.takeRequest();
try {
unwrap(cf);
} catch (final FeignException e) {
assertThat(e.getMessage()).isEqualTo("timeout reading POST http://localhost:" + server.getPort() + "/");
assertThat(e.contentUTF8()).isEqualTo("Request body");
return;
}
fail();
}
use of org.apache.hc.core5.util.Timeout in project rest.li by linkedin.
the class HttpNettyClient method sendRequest.
/**
* Sends the request to the {@link ChannelPipeline}.
*/
private void sendRequest(Request request, RequestContext requestContext, Map<String, String> wireAttrs, TransportCallback<StreamResponse> callback) {
final TransportCallback<StreamResponse> decoratedCallback = decorateUserCallback(request, callback);
final NettyClientState state = _state.get();
if (state != NettyClientState.RUNNING) {
decoratedCallback.onResponse(TransportResponseImpl.error(new IllegalStateException("Client is not running")));
return;
}
final long resolvedRequestTimeout = resolveRequestTimeout(requestContext, _requestTimeout);
// Timeout ensures the request callback is always invoked and is cancelled before the
// responsibility of invoking the callback is handed over to the pipeline.
final Timeout<None> timeout = new Timeout<>(_scheduler, resolvedRequestTimeout, TimeUnit.MILLISECONDS, None.none());
timeout.addTimeoutTask(() -> decoratedCallback.onResponse(TransportResponseImpl.error(new TimeoutException("Exceeded request timeout of " + resolvedRequestTimeout + "ms"))));
// resolve address
final SocketAddress address;
try {
TimingContextUtil.markTiming(requestContext, TIMING_KEY);
address = resolveAddress(request, requestContext);
TimingContextUtil.markTiming(requestContext, TIMING_KEY);
} catch (Exception e) {
decoratedCallback.onResponse(TransportResponseImpl.error(e));
return;
}
// Serialize wire attributes
final Request requestWithWireAttrHeaders;
if (request instanceof StreamRequest) {
requestWithWireAttrHeaders = buildRequestWithWireAttributes((StreamRequest) request, wireAttrs);
} else {
MessageType.setMessageType(MessageType.Type.REST, wireAttrs);
requestWithWireAttrHeaders = buildRequestWithWireAttributes((RestRequest) request, wireAttrs);
}
// Gets channel pool
final AsyncPool<Channel> pool;
try {
pool = getChannelPoolManagerPerRequest(requestWithWireAttrHeaders).getPoolForAddress(address);
} catch (IllegalStateException e) {
decoratedCallback.onResponse(TransportResponseImpl.error(e));
return;
}
// Saves protocol version in request context
requestContext.putLocalAttr(R2Constants.HTTP_PROTOCOL_VERSION, _protocolVersion);
final Cancellable pendingGet = pool.get(new ChannelPoolGetCallback(pool, requestWithWireAttrHeaders, requestContext, decoratedCallback, timeout, resolvedRequestTimeout, _streamingTimeout));
if (pendingGet != null) {
timeout.addTimeoutTask(pendingGet::cancel);
}
}
use of org.apache.hc.core5.util.Timeout in project feign by OpenFeign.
the class AsyncApacheHttp5ClientTest method throwsFeignExceptionWithoutBody.
@Test
public void throwsFeignExceptionWithoutBody() {
server.enqueue(new MockResponse().setBody("success!"));
final TestInterfaceAsync api = AsyncFeign.asyncBuilder().decoder((response, type) -> {
throw new IOException("timeout");
}).target(TestInterfaceAsync.class, "http://localhost:" + server.getPort());
try {
api.noContent();
} catch (final FeignException e) {
assertThat(e.getMessage()).isEqualTo("timeout reading POST http://localhost:" + server.getPort() + "/");
assertThat(e.contentUTF8()).isEqualTo("");
}
}
use of org.apache.hc.core5.util.Timeout in project feign by OpenFeign.
the class AsyncApacheHttp5ClientTest method doesntRetryAfterResponseIsSent.
@Test
public void doesntRetryAfterResponseIsSent() throws Throwable {
server.enqueue(new MockResponse().setBody("success!"));
thrown.expect(FeignException.class);
thrown.expectMessage("timeout reading POST http://");
final TestInterfaceAsync api = new TestInterfaceAsyncBuilder().decoder((response, type) -> {
throw new IOException("timeout");
}).target("http://localhost:" + server.getPort());
final CompletableFuture<?> cf = api.post();
server.takeRequest();
unwrap(cf);
}
Aggregations