From 77a651406384ff191a3fe0cee0ad4019c2cd3708 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 31 Mar 2016 18:22:49 +1100 Subject: [PATCH 1/3] Issue #469 Update to Apache Jasper 8.0.33 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 6c5b11c8bce..85840aaaab5 100644 --- a/pom.xml +++ b/pom.xml @@ -17,7 +17,7 @@ 1.6.6 1.2 1.1.2.v20150522 - 8.0.27 + 8.0.33 undefined From a97d29f54b5ee410a8115a791af1bf9233e6746e Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 31 Mar 2016 12:58:50 +0200 Subject: [PATCH 2/3] Removed usages of deprecated Callback.Adapter. --- .../java/org/eclipse/jetty/client/ResponseNotifier.java | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java b/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java index 0f27789f677..206ca84d3fc 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/ResponseNotifier.java @@ -209,8 +209,7 @@ public class ResponseNotifier } notifyHeaders(listeners, response); if (response instanceof ContentResponse) - // TODO: handle callback - notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), new Callback.Adapter()); + notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), Callback.NOOP); notifySuccess(listeners, response); } @@ -231,8 +230,7 @@ public class ResponseNotifier } notifyHeaders(listeners, response); if (response instanceof ContentResponse) - // TODO: handle callback - notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), new Callback.Adapter()); + notifyContent(listeners, response, ByteBuffer.wrap(((ContentResponse)response).getContent()), Callback.NOOP); notifyFailure(listeners, response, failure); } From c8fea46e8f3a81bba2a98abc00a34f30d97c5e46 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Fri, 1 Apr 2016 12:46:04 +0200 Subject: [PATCH 3/3] Issue #450 - Client AuthenticationProtocolHandler sends request failures to response failure listener. Fixed by properly forwarding response success in case only the request failed. --- .../client/AuthenticationProtocolHandler.java | 10 +++-- .../client/HttpClientAuthenticationTest.java | 41 +++++++++++++++++++ 2 files changed, 48 insertions(+), 3 deletions(-) diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java index e39888d1e11..6709f951200 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AuthenticationProtocolHandler.java @@ -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 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 parseAuthenticateHeader(Response response, HttpHeader header) diff --git a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java index 5814508a512..07cc0cde850 100644 --- a/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java +++ b/jetty-client/src/test/java/org/eclipse/jetty/client/HttpClientAuthenticationTest.java @@ -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)); + } }