[jboss-svn-commits] JBL Code SVN: r26909 - in labs/jbossesb/trunk/product/rosetta/src/org/jboss: soa/esb/listeners/gateway and 1 other directory.

jboss-svn-commits at lists.jboss.org jboss-svn-commits at lists.jboss.org
Wed Jun 10 12:26:49 EDT 2009


Author: tfennelly
Date: 2009-06-10 12:26:48 -0400 (Wed, 10 Jun 2009)
New Revision: 26909

Added:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java
Modified:
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java
   labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2616
JBoss Remoting HttpMarshaller class handling of InvocationResponses is invalid

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java	2009-06-10 16:22:55 UTC (rev 26908)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java	2009-06-10 16:26:48 UTC (rev 26909)
@@ -22,9 +22,13 @@
 import org.jboss.remoting.marshal.Marshaller;
 import org.jboss.remoting.marshal.http.HTTPMarshaller;
 import org.jboss.remoting.InvocationResponse;
+import org.jboss.remoting.InvocationRequest;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+import org.jboss.soa.esb.listeners.gateway.JBossRemotingGatewayListener;
 
 import java.io.IOException;
 import java.io.OutputStream;
+import java.util.Map;
 
 /**
  * Extended version of the JBossRemoting HTTPMarshaller.
@@ -36,19 +40,50 @@
 public class HttpMarshaller extends HTTPMarshaller {
 
     public void write(Object object, OutputStream outputStream, int version) throws IOException {
-        if(object instanceof byte[]) {
-            outputStream.write((byte[])object);
-            outputStream.flush();
-        } else if(object instanceof InvocationResponse) {
+        if(object instanceof InvocationResponse) {
             Object result = ((InvocationResponse)object).getResult();
-            if(result instanceof String) {
-                super.write(result, outputStream, version);
-            } else if(result instanceof byte[]) {
-                outputStream.write((byte[])result);
+            InvocationRequest currentRequest = JBossRemotingGatewayListener.getCurrentRequest();
+            boolean isRemotingClient = false;
+            boolean isBinaryResponse = false;
+
+            if(result != null && currentRequest != null) {
+                Map requestMetadata = currentRequest.getRequestPayload();
+                Map responseMetadata = currentRequest.getReturnPayload();
+                Object userAgentObj = requestMetadata.get(HTTPMetadataConstants.REMOTING_USER_AGENT);
+
+                if(userAgentObj != null) {
+                    isRemotingClient = ((String)userAgentObj).startsWith("JBossRemoting");
+
+                    // In this case, assume non binary if the content type has not been set.
+                    // Will only kick in if the object is an InvocationResponse.
+                    if(JBossRemotingUtil.getContentType(responseMetadata) == null) {
+                        isBinaryResponse = true;
+                    } else {
+                        isBinaryResponse = JBossRemotingUtil.isBinaryPayload(responseMetadata);
+                    }
+                }
+            }
+            
+            if(isRemotingClient && !isBinaryResponse) {
+                // This block of code tries to work around a bug in JBoss Remoting, while at the same time
+                // providing backward compatibility for earlier versions of the ESB.  This code should not
+                // have been present.  See https://jira.jboss.org/jira/browse/JBESB-2611
+                if(result instanceof byte[]) {
+                    outputStream.write((byte[])result);
+                    outputStream.flush();
+                } else {
+                    super.write(result, outputStream, version);
+                }
+            } else {
+                super.write(object, outputStream, version);
+            }
+        } else {
+            if(object instanceof byte[]) {
+                outputStream.write((byte[])object);
                 outputStream.flush();
+            } else {
+                super.write(object, outputStream, version);
             }
-        } else {
-            super.write(object, outputStream, version);
         }
     }
 

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java	2009-06-10 16:22:55 UTC (rev 26908)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java	2009-06-10 16:26:48 UTC (rev 26909)
@@ -23,7 +23,6 @@
 import org.jboss.remoting.marshal.UnMarshaller;
 import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
 import org.jboss.remoting.transport.http.HTTPMetadataConstants;
-import org.jboss.remoting.transport.web.WebUtil;
 
 import java.io.*;
 import java.util.List;
@@ -56,7 +55,7 @@
      * @throws ClassNotFoundException
      */
     public Object read(InputStream inputStream, Map metadata, int version) throws IOException, ClassNotFoundException {
-        if (isBinaryData(metadata)) {
+        if (JBossRemotingUtil.isBinaryPayload(metadata)) {
             try {
                 return super.read(inputStream, metadata, version);
             }
@@ -178,26 +177,4 @@
         }
         return isError;
     }
-
-    private boolean isBinaryData(Map metadata) throws IOException {
-        boolean isBinary = false;
-
-        if (metadata != null) {
-            // need to get the content type
-            Object value = metadata.get("Content-Type");
-            if (value == null) {
-                value = metadata.get("content-type");
-            }
-            if (value != null) {
-                if (value instanceof List) {
-                    List valueList = (List) value;
-                    if (valueList != null && valueList.size() > 0) {
-                        value = valueList.get(0);
-                    }
-                }
-                isBinary = WebUtil.isBinary((String) value);
-            }
-        }
-        return isBinary;
-    }
 }

Copied: labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java (from rev 26898, labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java)
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java	                        (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java	2009-06-10 16:26:48 UTC (rev 26909)
@@ -0,0 +1,81 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.internal.soa.esb.remoting;
+
+import org.jboss.remoting.transport.web.WebUtil;
+
+import java.util.Map;
+import java.util.List;
+import java.io.IOException;
+
+/**
+ * JBoss Remoting utility methods.
+ * 
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public class JBossRemotingUtil {
+
+    /**
+     * Check the request/response metadata and determine whether or not the
+     * message payload is a binary payload type.
+     * 
+     * @param metadata Request/Response metadata.
+     * @return True of the Content-Type indicates a binary payload, otherwise false.
+     */
+    public static boolean isBinaryPayload(Map metadata) {
+        boolean isBinary = false;
+
+        if (metadata != null) {
+            String value = getContentType(metadata);
+
+            if (value != null) {
+                isBinary = WebUtil.isBinary(value);
+            }
+        }
+        
+        return isBinary;
+    }
+
+    /**
+     * Get the content type from the supplied metadata.
+     * @param metadata The request/response metadata.
+     * @return The content type if set, otherwise null.
+     */
+    public static String getContentType(Map metadata) {
+        Object value = metadata.get("Content-Type");
+
+        if (value == null) {
+            value = metadata.get("content-type");
+        }
+
+        if (value != null) {
+            if (value instanceof List) {
+                List valueList = (List) value;
+                if (valueList != null && valueList.size() > 0) {
+                    value = valueList.get(0);
+                }
+            }
+        }
+        
+        return (String) value;
+    }
+}

Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java	2009-06-10 16:22:55 UTC (rev 26908)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java	2009-06-10 16:26:48 UTC (rev 26909)
@@ -111,6 +111,10 @@
      */
     public static final String JBR_SERVER_PORT = JBR_PREFIX + ServerInvoker.SERVER_BIND_PORT_KEY;
     /**
+     * JBoss Remoting request for the current thread.
+     */
+    private static ThreadLocal<InvocationRequest> currentRequest = new ThreadLocal<InvocationRequest>();
+    /**
      * Class Logger instance.
      */
     private static Logger logger = Logger.getLogger(JBossRemotingGatewayListener.class);
@@ -193,6 +197,10 @@
         }
     }
 
+    public static InvocationRequest getCurrentRequest() {
+        return currentRequest.get();
+    }
+
     /**
      * Is this listener instance initialised.
      *
@@ -347,6 +355,10 @@
      * @throws Throwable Message processing failure.
      */
     public Object invoke(InvocationRequest invocationRequest) throws Throwable {
+        // Set the request object on the thread so as to make it available
+        // to the HttpMarshaller...
+        currentRequest.set(invocationRequest);
+
         try {
             if (synchronous) {
                 Object response = messageDeliveryAdapter.deliverSync(invocationRequest, serviceInvokerTimeout);




More information about the jboss-svn-commits mailing list