openwebbeans-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rmannibu...@apache.org
Subject [openwebbeans-meecrowave] branch master updated: MEECROWAVE-228 ensure proxy dont fail on cookies with a null domain
Date Fri, 20 Dec 2019 16:49:22 GMT
This is an automated email from the ASF dual-hosted git repository.

rmannibucau pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/openwebbeans-meecrowave.git


The following commit(s) were added to refs/heads/master by this push:
     new f8628ca  MEECROWAVE-228 ensure proxy dont fail on cookies with a null domain
f8628ca is described below

commit f8628ca8dc95558052050f685f2465873f166aa4
Author: Romain Manni-Bucau <rmannibucau@gmail.com>
AuthorDate: Fri Dec 20 17:49:17 2019 +0100

    MEECROWAVE-228 ensure proxy dont fail on cookies with a null domain
---
 .../proxy/servlet/front/ProxyServlet.java          | 43 +++++++++++-----------
 1 file changed, 21 insertions(+), 22 deletions(-)

diff --git a/meecrowave-proxy/src/main/java/org/apache/meecrowave/proxy/servlet/front/ProxyServlet.java
b/meecrowave-proxy/src/main/java/org/apache/meecrowave/proxy/servlet/front/ProxyServlet.java
index eb4fbc1..c18b5b4 100644
--- a/meecrowave-proxy/src/main/java/org/apache/meecrowave/proxy/servlet/front/ProxyServlet.java
+++ b/meecrowave-proxy/src/main/java/org/apache/meecrowave/proxy/servlet/front/ProxyServlet.java
@@ -82,24 +82,15 @@ public class ProxyServlet extends HttpServlet {
         final AsyncContext asyncContext = req.startAsync();
         asyncContext.setTimeout(route.clientConfiguration.timeouts.execution);
 
-        return doRequest(route, req, resp, prefix).handle((response, error) -> {
-            try {
-                if (error != null) {
-                    onError(route, req, resp, error);
-                } else {
+        return doRequest(route, req, resp, prefix)
+                .thenAccept(response -> {
                     try {
                         forwardResponse(route, response, req, resp, identity());
                     } catch (final IOException e) {
                         onError(route, req, resp, e);
                     }
-                }
-            } catch (final IOException ioe) {
-                getServletContext().log("Error Proxying " + req.getMethod() + " " + req.getRequestURI()
+ ": " + ioe.getMessage(), ioe);
-            } finally {
-                asyncContext.complete();
-            }
-            return resp;
-        });
+        }).exceptionally(error -> onError(route, req, resp, error)).whenComplete((a, b)
-> asyncContext.complete())
+                .thenApply(i -> resp);
     }
 
     protected CompletionStage<Response> doRequest(final Routes.Route route,
@@ -168,17 +159,23 @@ public class ProxyServlet extends HttpServlet {
         return !HttpMethod.HEAD.equalsIgnoreCase(req.getMethod()) && !HttpMethod.GET.equalsIgnoreCase(req.getMethod());
     }
 
-    protected void onError(final Routes.Route route,
+    protected Void onError(final Routes.Route route,
                            final HttpServletRequest request, final HttpServletResponse resp,
-                           final Throwable error) throws IOException {
-        if (WebApplicationException.class.isInstance(error)) {
-            final WebApplicationException wae = WebApplicationException.class.cast(error);
-            if (wae.getResponse() != null) {
-                forwardResponse(route, wae.getResponse(), request, resp, identity());
-                return;
+                           final Throwable error) {
+        try {
+            if (WebApplicationException.class.isInstance(error)) {
+                final WebApplicationException wae = WebApplicationException.class.cast(error);
+                if (wae.getResponse() != null) {
+                    forwardResponse(route, wae.getResponse(), request, resp, identity());
+                    return null;
+                }
             }
+            onDefaultError(resp, error);
+        } catch (final IOException ioe) {
+            getServletContext().log(ioe.getMessage(), ioe);
+            throw new IllegalStateException(ioe);
         }
-        onDefaultError(resp, error);
+        return null;
     }
 
     protected void onDefaultError(HttpServletResponse resp, Throwable error) throws IOException
{
@@ -209,7 +206,9 @@ public class ProxyServlet extends HttpServlet {
         final NewCookie nc = cookie.getValue();
         final Cookie servletCookie = new Cookie(cookie.getKey(), nc.getValue());
         servletCookie.setComment(nc.getComment());
-        servletCookie.setDomain(nc.getDomain());
+        if (nc.getDomain() != null) {
+            servletCookie.setDomain(nc.getDomain());
+        }
         servletCookie.setHttpOnly(nc.isHttpOnly());
         servletCookie.setSecure(nc.isSecure());
         servletCookie.setMaxAge(nc.getMaxAge());


Mime
View raw message