Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incompatibility with Apache's Async HTTP Client #124

Closed
whiskeysierra opened this issue Jul 25, 2016 · 1 comment
Closed

Incompatibility with Apache's Async HTTP Client #124

whiskeysierra opened this issue Jul 25, 2016 · 1 comment
Assignees
Labels

Comments

@whiskeysierra
Copy link
Collaborator

When using the async http client, as zalando/riptide is now doing as of version 2.x, we're failing with an exception when logging responses:

java.lang.IllegalStateException: Content has not been provided​

I found this post from an old mailing list (2013, not sure if it still applies) and it states:

HTTP messages passed to async message consumers contain full message
head (status line or request line plus all headers) and an HttpEntity
which is not attached to any data stream and is merely a descriptor.

It doesn't directly refer to interceptors, but it makes sense that it also applies.

After reading the docs of HttpResponseInterceptor it should be possible to delay the logging until someone provides the content:

Interceptors can also manipulate content entities enclosed with messages.
Usually this is accomplished by using the 'Decorator' pattern where a wrapper
entity class is used to decorate the original entity.

Unfortunately the method interface is not making it obvious how to do that:

 void process(HttpResponse response, HttpContext context)
    throws HttpException, IOException;

I guess this one could do the trick, although we need to be careful not to consume the underlying stream:

/**
 * Associates a response entity with this response.
 * <p>
 * Please note that if an entity has already been set for this response and it depends on
 * an input stream ({@link HttpEntity#isStreaming()} returns {@code true}),
 * it must be fully consumed in order to ensure release of resources.
 *
 * @param entity    the entity to associate with this response, or
 *                  {@code null} to unset
 *
 * @see HttpEntity#isStreaming()
 * @see org.apache.http.util.EntityUtils#updateEntity(HttpResponse, HttpEntity)
 */
void setEntity(HttpEntity entity);
@whiskeysierra
Copy link
Collaborator Author

I can set a custom entity but there is a buffer being applied around it, so I'm missing a good point at which I can intercept the content.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants