[jboss-svn-commits] JBL Code SVN: r29517 - in labs/jbossesb/trunk/product/rosetta/src/org/jboss: soa/esb/http and 1 other directories.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Wed Sep 30 15:03:32 EDT 2009
Author: tfennelly
Date: 2009-09-30 15:03:31 -0400 (Wed, 30 Sep 2009)
New Revision: 29517
Added:
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/http/HttpContentTypeUtil.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/internal/soa/esb/remoting/JBossRemotingUtil.java
labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpMessageComposer.java
Log:
https://jira.jboss.org/jira/browse/JBESB-2362
Support "binary/octet-stream" or "application/octet-stream" mimetype in JBossRemotingGatewayListenerSupport "binary/octet-stream" or "application/octet-stream" mimetype in JBossRemotingGatewayListener
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-09-30 15:03:06 UTC (rev 29516)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpMarshaller.java 2009-09-30 19:03:31 UTC (rev 29517)
@@ -43,28 +43,17 @@
if(object instanceof InvocationResponse) {
Object result = ((InvocationResponse)object).getResult();
InvocationRequest currentRequest = JBossRemotingGatewayListener.getCurrentRequest();
- boolean isRemotingClient = false;
- boolean isBinaryResponse = false;
+ boolean sendJavaResponse = false;
if(result != null && currentRequest != null) {
Map requestMetadata = currentRequest.getRequestPayload();
Map responseMetadata = currentRequest.getReturnPayload();
- Object userAgentObj = requestMetadata.get(HTTPMetadataConstants.REMOTING_USER_AGENT);
+ String userAgent = (String) 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);
- }
- }
+ sendJavaResponse = JBossRemotingUtil.sendJavaObjectPayload(responseMetadata, userAgent);
}
- if(isRemotingClient && !isBinaryResponse) {
+ if(!sendJavaResponse) {
// 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
@@ -72,6 +61,8 @@
outputStream.write((byte[])result);
outputStream.flush();
} else {
+ // Going to rely on the base class to encode it anyway because
+ // we don't know....
super.write(result, outputStream, version);
}
} else {
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-09-30 15:03:06 UTC (rev 29516)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/HttpUnmarshaller.java 2009-09-30 19:03:31 UTC (rev 29517)
@@ -23,6 +23,7 @@
import org.jboss.remoting.marshal.UnMarshaller;
import org.jboss.remoting.marshal.serializable.SerializableUnMarshaller;
import org.jboss.remoting.transport.http.HTTPMetadataConstants;
+import org.jboss.soa.esb.http.HttpContentTypeUtil;
import java.io.*;
import java.util.List;
@@ -55,7 +56,7 @@
* @throws ClassNotFoundException
*/
public Object read(InputStream inputStream, Map metadata, int version) throws IOException, ClassNotFoundException {
- if (JBossRemotingUtil.isBinaryPayload(metadata)) {
+ if (JBossRemotingUtil.receiveJavaObjectPayload(metadata)) {
try {
return super.read(inputStream, metadata, version);
}
@@ -64,8 +65,6 @@
}
}
- int contentLength = -1;
- Object ret = null;
int bufferSize = 1024;
byte[] byteBuffer = new byte[bufferSize];
ByteArrayOutputStream byteOutputStream = new ByteArrayOutputStream();
@@ -85,7 +84,7 @@
}
if (value instanceof String) {
try {
- contentLength = Integer.parseInt((String) value);
+ Integer.parseInt((String) value);
}
catch (NumberFormatException e) {
log.warn("Error converting Content-Length value (" + value + ") from metadata into int value.");
@@ -112,49 +111,18 @@
return null;
}
- //boolean isError = isErrorReturn(metadata);
- //if(isBinary || isError)
-
- if (metadata != null) {
- 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);
- }
- }
- final String contentType = (String)value ;
- if (contentType.startsWith("multipart/"))
- {
- return totalByteArray ;
- }
- /*
- * Requests reaching this code might still have a binary content. For instance
- * "binary/octet-stream" mime type. This will make sure we return a byte array for theses
- * cases. The isBinaryData method called at the beginning of this method only filters
- * "application/octet-stream" it also assumes that binary==java serializable which is not
- * always a valid assumption.
- */
- if (contentType.endsWith("octet-stream")) {
- return totalByteArray;
- }
- }
+ String contentType = JBossRemotingUtil.getContentType(metadata);
+ if(!HttpContentTypeUtil.isTextMimetype(contentType)) {
+ return totalByteArray ;
}
try {
- ret = new String(totalByteArray);
+ return new String(totalByteArray);
}
catch (Exception e) {
log.error("Can not unmarshall inputstream. Tried to unmarshall as both an object and string type.", e);
throw new IOException("Can not unmarshall inputstream.");
}
-
- return ret;
-
}
public UnMarshaller cloneUnMarshaller() throws CloneNotSupportedException {
Modified: labs/jbossesb/trunk/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 2009-09-30 15:03:06 UTC (rev 29516)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/internal/soa/esb/remoting/JBossRemotingUtil.java 2009-09-30 19:03:31 UTC (rev 29517)
@@ -22,10 +22,10 @@
package org.jboss.internal.soa.esb.remoting;
import org.jboss.remoting.transport.web.WebUtil;
+import org.jboss.remoting.transport.http.HTTPMetadataConstants;
import java.util.Map;
import java.util.List;
-import java.io.IOException;
/**
* JBoss Remoting utility methods.
@@ -35,24 +35,43 @@
public class JBossRemotingUtil {
/**
- * Check the request/response metadata and determine whether or not the
- * message payload is a binary payload type.
+ * Check if the server should expect a Java Object payload.
+ * <p/>
+ * Only relevant if the client is a JBoss Remoting client.
+ *
+ * @param metadata Request metadata.
+ * @return True if the metadata indicates that the client/server is/should expect a Java Object
+ * payload, otherwise false.
+ */
+ public static boolean receiveJavaObjectPayload(Map metadata) {
+ return isJavaPayloadToFromJBRClient(metadata, (String) metadata.get(HTTPMetadataConstants.REMOTING_USER_AGENT));
+ }
+
+ /**
+ * Check if the server should send a Java Object payload.
+ * <p/>
+ * Only relevant if the client is a JBoss Remoting client.
*
- * @param metadata Request/Response metadata.
- * @return True of the Content-Type indicates a binary payload, otherwise false.
+ * @param metadata Response metadata.
+ * @param clientUserAgent Client User Agent.
+ * @return True if the metadata indicates that the client/server is/should expect a Java Object
+ * payload, otherwise false.
*/
- public static boolean isBinaryPayload(Map metadata) {
- boolean isBinary = false;
+ public static boolean sendJavaObjectPayload(Map metadata, String clientUserAgent) {
+ return isJavaPayloadToFromJBRClient(metadata, clientUserAgent);
+ }
+ private static boolean isJavaPayloadToFromJBRClient(Map metadata, String clientUserAgent) {
if (metadata != null) {
- String value = getContentType(metadata);
-
- if (value != null) {
- isBinary = WebUtil.isBinary(value);
+ if(clientUserAgent != null && clientUserAgent.startsWith("JBossRemoting")) {
+ String value = getContentType(metadata);
+ if (value != null) {
+ return WebUtil.isBinary(value);
+ }
}
}
-
- return isBinary;
+
+ return false;
}
/**
@@ -61,6 +80,10 @@
* @return The content type if set, otherwise null.
*/
public static String getContentType(Map metadata) {
+ if(metadata == null) {
+ return null;
+ }
+
Object value = metadata.get("Content-Type");
if (value == null) {
Added: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/http/HttpContentTypeUtil.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/http/HttpContentTypeUtil.java (rev 0)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/http/HttpContentTypeUtil.java 2009-09-30 19:03:31 UTC (rev 29517)
@@ -0,0 +1,57 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, JBoss Inc., and others contributors as indicated
+ * by the @authors tag. All rights reserved.
+ * See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ * This copyrighted material is made available to anyone wishing to use,
+ * modify, copy, or redistribute it subject to the terms and conditions
+ * of the GNU Lesser General Public License, v. 2.1.
+ * This program is distributed in the hope that it will be useful, but WITHOUT A
+ * 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,
+ * v.2.1 along with this distribution; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
+ * MA 02110-1301, USA.
+ *
+ * (C) 2005-2006, JBoss Inc.
+ */
+package org.jboss.soa.esb.http;
+
+import org.jboss.soa.esb.common.ModulePropertyManager;
+
+import java.util.regex.Pattern;
+
+/**
+ * HTTP Content Type utility methods.
+ *
+ * @author <a href="mailto:tom.fennelly at jboss.com">tom.fennelly at jboss.com</a>
+ */
+public abstract class HttpContentTypeUtil {
+
+ private static Pattern[] textMimePatterns;
+
+ static {
+ String[] textTypes = ModulePropertyManager.getPropertyManager("core").getProperty("org.jboss.soa.esb.mime.text.types", "text/*;application/xml;application/*-xml").split(";");
+
+ textMimePatterns = new Pattern[textTypes.length];
+ for(int i = 0; i < textMimePatterns.length; i++) {
+ textMimePatterns[i] = Pattern.compile(textTypes[i].trim().replace("*", ".*"));
+ }
+ }
+
+ public static boolean isTextMimetype(String contentType) {
+ if(contentType == null) {
+ return false;
+ }
+
+ for(int i = 0; i < textMimePatterns.length; i++) {
+ if(textMimePatterns[i].matcher(contentType).matches()) {
+ return true;
+ }
+ }
+
+ return false;
+ }
+}
\ No newline at end of file
Modified: labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpMessageComposer.java
===================================================================
--- labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpMessageComposer.java 2009-09-30 15:03:06 UTC (rev 29516)
+++ labs/jbossesb/trunk/product/rosetta/src/org/jboss/soa/esb/listeners/gateway/http/HttpMessageComposer.java 2009-09-30 19:03:31 UTC (rev 29517)
@@ -22,7 +22,6 @@
import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.*;
-import java.util.regex.Pattern;
import java.nio.charset.Charset;
import javax.servlet.http.HttpServletRequest;
@@ -40,7 +39,6 @@
import org.jboss.soa.esb.message.Message;
import org.jboss.soa.esb.message.MessagePayloadProxy;
import org.jboss.soa.esb.message.MessagePayloadProxy.NullPayloadHandling;
-import org.jboss.soa.esb.common.ModulePropertyManager;
import org.jboss.soa.esb.services.security.auth.ws.WSSecurityInfoExtractor;
import org.jboss.soa.esb.services.security.auth.AuthenticationRequest;
import org.jboss.soa.esb.services.security.PublicCryptoUtil;
@@ -72,7 +70,6 @@
private MessagePayloadProxy payloadProxy;
private String payloadAs;
- private Pattern[] textMimePatterns;
private WSSecurityInfoExtractor wsSecurityExtractor = new WSSecurityInfoExtractor();
@@ -91,16 +88,7 @@
super.setConfiguration(config);
payloadProxy = new MessagePayloadProxy(config);
payloadProxy.setNullSetPayloadHandling(NullPayloadHandling.LOG);
-
payloadAs = config.getAttribute("payloadAs");
- if(payloadAs == null) {
- // Get the globally configured text mime types...
- String[] textTypes = ModulePropertyManager.getPropertyManager("core").getProperty("org.jboss.soa.esb.mime.text.types", "text/*;application/xml;application/*-xml").split(";");
- textMimePatterns = new Pattern[textTypes.length];
- for(int i = 0; i < textMimePatterns.length; i++) {
- textMimePatterns[i] = Pattern.compile(textTypes[i].trim().replace("*", ".*"));
- }
- }
}
protected MessagePayloadProxy getPayloadProxy() {
@@ -132,7 +120,7 @@
if(payloadAs == null) {
String contentType = request.getContentType();
- if(contentType != null && isTextMimetype(contentType)) {
+ if(contentType != null && HttpContentTypeUtil.isTextMimetype(contentType)) {
try {
String payload = new String(bodyBytes, charset.name());
@@ -164,17 +152,6 @@
requestInfo.setRequest(message);
}
- private boolean isTextMimetype(String contentType) {
- for(int i = 0; i < textMimePatterns.length; i++) {
- if(textMimePatterns[i].matcher(contentType).matches()) {
- return true;
- }
- }
-
- return false;
- }
-
-
/*
* Method for decompsing a esb message to a HttpServletResponse
*/
More information about the jboss-svn-commits
mailing list