reta commented on a change in pull request #697:
URL: https://github.com/apache/cxf/pull/697#discussion_r494622436



##########
File path: 
rt/frontend/jaxrs/src/main/java/org/apache/cxf/jaxrs/impl/ResponseImpl.java
##########
@@ -137,22 +143,70 @@ public Object getActualEntity() {
         return lastEntity != null ? lastEntity : entity;
     }
 
+    @Override
     public Object getEntity() {
         return InjectionUtils.getEntity(getActualEntity());
     }
 
+    @Override
     public boolean hasEntity() {
-        return getActualEntity() != null;
+        // per spec, need to check if the stream exists and if it has data.
+        Object actualEntity = getActualEntity();
+        if (actualEntity == null) {
+            return false;
+        } else if (actualEntity instanceof InputStream) {
+            final InputStream is = (InputStream) actualEntity;
+            try {
+                if (is.markSupported()) {
+                    is.mark(1);
+                    int i = is.read();
+                    is.reset();
+                    return i != -1;
+                } else {
+                    try {
+                        if (is.available() > 0) {
+                            return true;
+                        }
+                    } catch (IOException ioe) {
+                        //Do nothing
+                    }
+                    int b = is.read();
+                    if (b == -1) {
+                        return false;
+                    }
+                    PushbackInputStream pbis;
+                    if (is instanceof PushbackInputStream) {
+                        pbis = (PushbackInputStream) is;
+                    } else {
+                        pbis = new PushbackInputStream(is, 1);
+                        if (lastEntity != null) {

Review comment:
       👍 thank you




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to