[jboss-svn-commits] JBL Code SVN: r26898 - in labs/jbossesb/branches/JBESB_4_4_GA_CP/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 07:37:58 EDT 2009
Author: tfennelly
Date: 2009-06-10 07:37:58 -0400 (Wed, 10 Jun 2009)
New Revision: 26898
Added:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java
Modified:
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java
labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2611
Rework to make it backward compatible.
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java 2009-06-10 11:15:33 UTC (rev 26897)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java 2009-06-10 11:37:58 UTC (rev 26898)
@@ -22,10 +22,16 @@
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;
+import com.sun.java_cup.internal.version;
+
/**
* Extended version of the JBossRemoting HTTPMarshaller.
* <p/>
@@ -36,11 +42,45 @@
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();
+ InvocationRequest currentRequest = JBossRemotingGatewayListener.getCurrentRequest();
+ Map requestMetadata = currentRequest.getRequestPayload();
+ Map responseMetadata = currentRequest.getReturnPayload();
+ Object userAgentObj = requestMetadata.get(HTTPMetadataConstants.REMOTING_USER_AGENT);
+ boolean isRemotingClient = false;
+ boolean isBinaryResponse = false;
+
+ 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 && object instanceof InvocationResponse) {
+ // 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
+
+ Object result = ((InvocationResponse)object).getResult();
+
+ if(result instanceof byte[]) {
+ outputStream.write((byte[])result);
+ outputStream.flush();
+ } else {
+ super.write(result, outputStream, version);
+ }
} else {
- super.write(object, outputStream, version);
+ if(object instanceof byte[]) {
+ outputStream.write((byte[])object);
+ outputStream.flush();
+ } else {
+ super.write(object, outputStream, version);
+ }
}
}
Modified: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java 2009-06-10 11:15:33 UTC (rev 26897)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java 2009-06-10 11:37:58 UTC (rev 26898)
@@ -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);
}
@@ -168,26 +167,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;
- }
}
Added: labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java (rev 0)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java 2009-06-10 11:37:58 UTC (rev 26898)
@@ -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/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java
===================================================================
--- labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2009-06-10 11:15:33 UTC (rev 26897)
+++ labs/jbossesb/branches/JBESB_4_4_GA_CP/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/JBossRemotingGatewayListener.java 2009-06-10 11:37:58 UTC (rev 26898)
@@ -111,6 +111,10 @@
* Server port config attribute name.
*/
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.
@@ -187,6 +191,10 @@
}
}
+ public static InvocationRequest getCurrentRequest() {
+ return currentRequest.get();
+ }
+
/**
* Is this listener instance initialised.
*
@@ -341,6 +349,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, 20000); // TODO Fix magic number
More information about the jboss-svn-commits
mailing list