You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by dk...@apache.org on 2023/04/25 16:50:22 UTC

[cxf] 18/39: Update the ServletRequest adapters to implement getContentLengthLong instead of throw exception

This is an automated email from the ASF dual-hosted git repository.

dkulp pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git

commit 1bfb87f1c028a36b617435ae19b15aaedcb8b0ba
Author: Daniel Kulp <da...@kulp.com>
AuthorDate: Wed Mar 15 14:21:16 2023 -0400

    Update the ServletRequest adapters to implement getContentLengthLong instead of throw exception
    
    (cherry picked from commit 365932977e4c97b34ca6de47425fd60054d91511)
    
    # Conflicts:
    #       rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java
---
 .../http_jaxws_spi/HttpServletRequestAdapter.java  | 12 +++-
 .../server/servlet/NettyHttpServletRequest.java    | 77 ++++++++++++++++++++++
 .../transport/http/AbstractHTTPDestination.java    |  4 +-
 .../jetty/WebSocketVirtualServletRequest.java      |  4 +-
 .../undertow/WebSocketUndertowServletRequest.java  |  4 +-
 5 files changed, 94 insertions(+), 7 deletions(-)

diff --git a/rt/frontend/jaxws/src/main/java/org/apache/cxf/transport/http_jaxws_spi/HttpServletRequestAdapter.java b/rt/frontend/jaxws/src/main/java/org/apache/cxf/transport/http_jaxws_spi/HttpServletRequestAdapter.java
index 20b631e316..889d12777b 100644
--- a/rt/frontend/jaxws/src/main/java/org/apache/cxf/transport/http_jaxws_spi/HttpServletRequestAdapter.java
+++ b/rt/frontend/jaxws/src/main/java/org/apache/cxf/transport/http_jaxws_spi/HttpServletRequestAdapter.java
@@ -89,7 +89,11 @@ class HttpServletRequestAdapter implements HttpServletRequest {
     }
 
     public int getContentLength() {
-        return 0;
+        String s = getHeader("Content-Length");
+        if (s != null) {
+            return Integer.parseInt(s);
+        }
+        return -1;
     }
 
     public String getContentType() {
@@ -432,7 +436,11 @@ class HttpServletRequestAdapter implements HttpServletRequest {
 
     @Override
     public long getContentLengthLong() {
-        throw new UnsupportedOperationException();
+        String s = getHeader("Content-Length");
+        if (s != null) {
+            return Long.parseLong(s);
+        }
+        return -1;
     }
 
     @Override
diff --git a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java
index a535512cb6..c3444fc3a0 100644
--- a/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java
+++ b/rt/transports/http-netty/netty-server/src/main/java/org/apache/cxf/transport/http/netty/server/servlet/NettyHttpServletRequest.java
@@ -469,4 +469,81 @@ public class NettyHttpServletRequest implements HttpServletRequest {
         throw new IllegalStateException(
                 "Method 'getRequestDispatcher' not yet implemented!");
     }
+
+    @Override
+    public long getContentLengthLong() {
+        return getContentLength();
+    }
+
+    @Override
+    public ServletContext getServletContext() {
+        throw new IllegalStateException("Method 'getServletContext' not yet implemented!");
+    }
+
+    @Override
+    public AsyncContext startAsync() throws IllegalStateException {
+        throw new IllegalStateException("Method 'startAsync' not yet implemented!");
+    }
+
+    @Override
+    public AsyncContext startAsync(ServletRequest servletRequest,
+            ServletResponse servletResponse) throws IllegalStateException {
+        throw new IllegalStateException("Method 'startAsync' not yet implemented!");
+    }
+
+    @Override
+    public boolean isAsyncStarted() {
+        throw new IllegalStateException("Method 'isAsyncStarted' not yet implemented!");
+    }
+
+    @Override
+    public boolean isAsyncSupported() {
+        throw new IllegalStateException("Method 'isAsyncSupported' not yet implemented!");
+    }
+
+    @Override
+    public AsyncContext getAsyncContext() {
+        throw new IllegalStateException("Method 'getAsyncContext' not yet implemented!");
+    }
+
+    @Override
+    public DispatcherType getDispatcherType() {
+        throw new IllegalStateException("Method 'getDispatcherType' not yet implemented!");
+    }
+
+    @Override
+    public String changeSessionId() {
+        throw new IllegalStateException("Method 'changeSessionId' not yet implemented!");
+    }
+
+    @Override
+    public boolean authenticate(HttpServletResponse response) throws IOException, ServletException {
+        throw new IllegalStateException("Method 'authenticate' not yet implemented!");
+    }
+
+    @Override
+    public void login(String username, String password) throws ServletException {
+        throw new IllegalStateException("Method 'login' not yet implemented!");
+    }
+
+    @Override
+    public void logout() throws ServletException {
+        throw new IllegalStateException("Method 'logout' not yet implemented!");
+    }
+
+    @Override
+    public Collection<Part> getParts() throws IOException, ServletException {
+        throw new IllegalStateException("Method 'getParts' not yet implemented!");
+    }
+
+    @Override
+    public Part getPart(String name) throws IOException, ServletException {
+        throw new IllegalStateException("Method 'getPart' not yet implemented!");
+    }
+
+    @Override
+    public <T extends HttpUpgradeHandler> T upgrade(Class<T> handlerClass)
+            throws IOException, ServletException {
+        throw new IllegalStateException("Method 'upgrade' not yet implemented!");
+    }
 }
diff --git a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
index 29f93b81fc..098c96df26 100644
--- a/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
+++ b/rt/transports/http/src/main/java/org/apache/cxf/transport/http/AbstractHTTPDestination.java
@@ -318,7 +318,9 @@ public abstract class AbstractHTTPDestination
                     //Please note, exchange used to always get the "current" message
                     exchange.getInMessage().put(HTTP_REQUEST, new HttpServletRequestSnapshot(req));
                 }
-                super.cacheInput();
+                if (req.getContentLengthLong() != 0) {
+                    super.cacheInput();
+                }
             }
             private boolean isWSAddressingReplyToSpecified(Exchange ex) {
                 AddressingProperties map = ContextUtils.retrieveMAPs(ex.getInMessage(), false, false, false);
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/WebSocketVirtualServletRequest.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/WebSocketVirtualServletRequest.java
index 90f8ef6829..44b403e321 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/WebSocketVirtualServletRequest.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/jetty/WebSocketVirtualServletRequest.java
@@ -123,7 +123,7 @@ public class WebSocketVirtualServletRequest implements HttpServletRequest {
     @Override
     public int getContentLength() {
         LOG.log(Level.FINE, "getContentLength()");
-        return 0;
+        return -1;
     }
 
     @Override
@@ -545,7 +545,7 @@ public class WebSocketVirtualServletRequest implements HttpServletRequest {
 
     @Override
     public long getContentLengthLong() {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     @Override
diff --git a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java
index b7749d1936..f1a51d5ff6 100644
--- a/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java
+++ b/rt/transports/websocket/src/main/java/org/apache/cxf/transport/websocket/undertow/WebSocketUndertowServletRequest.java
@@ -126,7 +126,7 @@ public class WebSocketUndertowServletRequest implements HttpServletRequest {
     @Override
     public int getContentLength() {
         LOG.log(Level.FINE, "getContentLength()");
-        return 0;
+        return -1;
     }
 
     @Override
@@ -570,7 +570,7 @@ public class WebSocketUndertowServletRequest implements HttpServletRequest {
 
     @Override
     public long getContentLengthLong() {
-        throw new UnsupportedOperationException();
+        return -1;
     }
 
     @Override