Merged branch 'jetty-9.3.x' into 'master'.

This commit is contained in:
Simone Bordet 2016-04-01 12:48:09 +02:00
commit 650587ec0a
3 changed files with 48 additions and 5 deletions

View File

@ -88,9 +88,8 @@ public abstract class AuthenticationProtocolHandler implements ProtocolHandler
ContentResponse response = new HttpContentResponse(result.getResponse(), getContent(), getMediaType(), getEncoding());
if (result.isFailed())
{
Throwable failure = result.getFailure();
if (LOG.isDebugEnabled())
LOG.debug("Authentication challenge failed {}", failure);
LOG.debug("Authentication challenge failed {}", result.getFailure());
forwardFailureComplete(request, result.getRequestFailure(), response, result.getResponseFailure());
return;
}
@ -206,7 +205,12 @@ public abstract class AuthenticationProtocolHandler implements ProtocolHandler
{
HttpConversation conversation = request.getConversation();
conversation.updateResponseListeners(null);
notifier.forwardFailureComplete(conversation.getResponseListeners(), request, requestFailure, response, responseFailure);
List<Response.ResponseListener> responseListeners = conversation.getResponseListeners();
if (responseFailure == null)
notifier.forwardSuccess(responseListeners, response);
else
notifier.forwardFailure(responseListeners, response, responseFailure);
notifier.notifyComplete(responseListeners, new Result(request, requestFailure, response, responseFailure));
}
private List<Authentication.HeaderInfo> parseAuthenticateHeader(Response response, HttpHeader header)

View File

@ -209,7 +209,6 @@ public class ResponseNotifier
}
notifyHeaders(listeners, response);
if (response instanceof ContentResponse)
// TODO: handle callback
notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), Callback.NOOP);
notifySuccess(listeners, response);
}
@ -231,7 +230,6 @@ public class ResponseNotifier
}
notifyHeaders(listeners, response);
if (response instanceof ContentResponse)
// TODO: handle callback
notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), Callback.NOOP);
notifyFailure(listeners, response, failure);
}

View File

@ -21,6 +21,8 @@ package org.eclipse.jetty.client;
import java.io.File;
import java.io.IOException;
import java.net.URI;
import java.nio.ByteBuffer;
import java.nio.charset.StandardCharsets;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
@ -37,6 +39,7 @@ import org.eclipse.jetty.client.api.Request;
import org.eclipse.jetty.client.api.Response;
import org.eclipse.jetty.client.api.Result;
import org.eclipse.jetty.client.util.BasicAuthentication;
import org.eclipse.jetty.client.util.DeferredContentProvider;
import org.eclipse.jetty.client.util.DigestAuthentication;
import org.eclipse.jetty.security.Authenticator;
import org.eclipse.jetty.security.ConstraintMapping;
@ -395,4 +398,42 @@ public class HttpClientAuthenticationTest extends AbstractHttpClientServerTest
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(1, requests.get());
}
@Test
public void test_RequestFailsAfterResponse() throws Exception
{
startBasic(new EmptyServerHandler());
AuthenticationStore authenticationStore = client.getAuthenticationStore();
URI uri = URI.create(scheme + "://localhost:" + connector.getLocalPort());
BasicAuthentication authentication = new BasicAuthentication(uri, realm, "basic", "basic");
authenticationStore.addAuthentication(authentication);
CountDownLatch successLatch = new CountDownLatch(1);
CountDownLatch resultLatch = new CountDownLatch(1);
DeferredContentProvider content = new DeferredContentProvider();
client.newRequest("localhost", connector.getLocalPort())
.scheme(scheme)
.path("/secure")
.onRequestContent((request, buffer) -> request.abort(new Exception()))
.content(content)
.onResponseSuccess(response -> successLatch.countDown())
.send(result ->
{
if (result.isFailed() && result.getResponseFailure() == null)
resultLatch.countDown();
});
// Wait for the response to arrive to
// the authentication protocol handler.
Thread.sleep(1000);
// Send some content to trigger request failure.
content.offer(ByteBuffer.wrap("test".getBytes(StandardCharsets.UTF_8)));
content.close();
// Verify that the response was successful, it's the request that failed.
Assert.assertTrue(successLatch.await(5, TimeUnit.SECONDS));
Assert.assertTrue(resultLatch.await(5, TimeUnit.SECONDS));
}
}