knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [knox] branch master updated: KNOX-1864 - Knox returns HTTP 405 Method Not Allowed error with HTTP PATCH method (#91)
Date Wed, 22 May 2019 18:51:28 GMT
This is an automated email from the ASF dual-hosted git repository.

krisden pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/knox.git


The following commit(s) were added to refs/heads/master by this push:
     new c80ad98  KNOX-1864 - Knox returns HTTP 405 Method Not Allowed error with HTTP PATCH
method (#91)
c80ad98 is described below

commit c80ad98e324b63a0aa4f88f77b7c310e54a9ff21
Author: bvanhaute2 <50864036+bvanhaute2@users.noreply.github.com>
AuthorDate: Wed May 22 19:15:05 2019 +0200

    KNOX-1864 - Knox returns HTTP 405 Method Not Allowed error with HTTP PATCH method (#91)
---
 .../apache/knox/gateway/dispatch/AbstractGatewayDispatch.java |  6 ++++++
 .../org/apache/knox/gateway/dispatch/DefaultDispatch.java     | 11 +++++++++++
 .../main/java/org/apache/knox/gateway/dispatch/Dispatch.java  |  3 +++
 .../apache/knox/gateway/dispatch/GatewayDispatchFilter.java   |  9 +++++++++
 4 files changed, 29 insertions(+)

diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
index 0214255..3c63f2b 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/AbstractGatewayDispatch.java
@@ -95,6 +95,12 @@ public abstract class AbstractGatewayDispatch implements Dispatch {
   }
 
   @Override
+  public void doPatch(URI url, HttpServletRequest request, HttpServletResponse response )
+      throws IOException, URISyntaxException {
+    response.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
+  }
+
+  @Override
   public void doDelete(URI url, HttpServletRequest request, HttpServletResponse response
)
       throws IOException, URISyntaxException {
     response.sendError( HttpServletResponse.SC_METHOD_NOT_ALLOWED );
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultDispatch.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultDispatch.java
index 5f0b3e4..77d38a1 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultDispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/DefaultDispatch.java
@@ -26,6 +26,7 @@ import org.apache.http.client.methods.HttpHead;
 import org.apache.http.client.methods.HttpOptions;
 import org.apache.http.client.methods.HttpPost;
 import org.apache.http.client.methods.HttpPut;
+import org.apache.http.client.methods.HttpPatch;
 import org.apache.http.client.methods.HttpUriRequest;
 import org.apache.http.entity.ContentType;
 import org.apache.knox.gateway.SpiGatewayMessages;
@@ -273,6 +274,16 @@ public class DefaultDispatch extends AbstractGatewayDispatch {
    }
 
    @Override
+   public void doPatch(URI url, HttpServletRequest request, HttpServletResponse response)
+         throws IOException, URISyntaxException {
+      HttpPatch method = new HttpPatch(url);
+      HttpEntity entity = createRequestEntity(request);
+      method.setEntity(entity);
+      copyRequestHeaderFields(method, request);
+      executeRequest(method, request, response);
+   }
+
+   @Override
    public void doPost(URI url, HttpServletRequest request, HttpServletResponse response)
          throws IOException, URISyntaxException {
       HttpPost method = new HttpPost(url);
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/Dispatch.java b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/Dispatch.java
index 32f985d..cca8064 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/Dispatch.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/Dispatch.java
@@ -47,6 +47,9 @@ public interface Dispatch {
   void doPut( URI url, HttpServletRequest request, HttpServletResponse response )
       throws IOException, ServletException, URISyntaxException;
 
+  void doPatch( URI url, HttpServletRequest request, HttpServletResponse response )
+      throws IOException, ServletException, URISyntaxException;
+
   void doDelete( URI url, HttpServletRequest request, HttpServletResponse response )
       throws IOException, ServletException, URISyntaxException;
 
diff --git a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java
b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java
index 79442db..044c32c 100644
--- a/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java
+++ b/gateway-spi/src/main/java/org/apache/knox/gateway/dispatch/GatewayDispatchFilter.java
@@ -60,6 +60,7 @@ public class GatewayDispatchFilter extends AbstractGatewayFilter {
     map.put("GET", new GetAdapter());
     map.put("POST", new PostAdapter());
     map.put("PUT", new PutAdapter());
+    map.put("PATCH", new PatchAdapter());
     map.put("DELETE", new DeleteAdapter());
     map.put("OPTIONS", new OptionsAdapter());
     map.put("HEAD", new HeadAdapter());
@@ -190,6 +191,14 @@ public class GatewayDispatchFilter extends AbstractGatewayFilter {
     }
   }
 
+  private static class PatchAdapter implements Adapter {
+    @Override
+    public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse
response)
+        throws IOException, ServletException, URISyntaxException {
+      dispatch.doPatch( dispatch.getDispatchUrl(request), request, response);
+    }
+  }
+
   private static class DeleteAdapter implements Adapter {
     @Override
     public void doMethod(Dispatch dispatch, HttpServletRequest request, HttpServletResponse
response)


Mime
View raw message