Author: ron.sigal(a)jboss.com
Date: 2009-08-26 15:46:43 -0400 (Wed, 26 Aug 2009)
New Revision: 5393
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java
Log:
JBREM-1145: Made use of new content type test optional.
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-08-26
19:44:41 UTC (rev 5392)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/marshal/http/HTTPUnMarshaller.java 2009-08-26
19:46:43 UTC (rev 5393)
@@ -26,6 +26,7 @@
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.BufferedReader;
import java.io.ByteArrayInputStream;
@@ -228,11 +229,56 @@
private boolean isBinaryData(Map metadata) throws IOException
{
+ String useRemotingContentType = (String)
metadata.get(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE);
+ if (Boolean.valueOf(useRemotingContentType).booleanValue())
+ {
+ return isBinaryDataNew(metadata);
+ }
+ else
+ {
+ return isBinaryDataOld(metadata);
+ }
+ }
+
+ private boolean isBinaryDataOld(Map metadata) throws IOException
+ {
+ if (log.isTraceEnabled()) log.trace(this + " using isBinaryDataOld()");
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);
+ }
+ }
+
+ if (log.isTraceEnabled()) log.trace(this + " isBinary: " + isBinary);
+ return isBinary;
+ }
+
+ private boolean isBinaryDataNew(Map metadata) throws IOException
+ {
+ if (log.isTraceEnabled()) log.trace(this + " using isBinaryDataNew()");
+ boolean isBinary = true;
+
+ if(metadata != null)
+ {
+ // need to get the content type
String remotingContentType = null;
Object o = metadata.get(HTTPMetadataConstants.REMOTING_CONTENT_TYPE);
if (o instanceof List)
@@ -245,11 +291,29 @@
}
else
{
- log.warn(this + " unrecognized remotingContentType: " + o);
+ o = metadata.get(HTTPMetadataConstants.REMOTING_CONTENT_TYPE_LC);
+ if (o instanceof List)
+ {
+ remotingContentType = (String) ((List) o).get(0);
+ }
+ else if (o instanceof String)
+ {
+ remotingContentType = (String) o;
+ }
+ else if (o != null)
+ {
+ log.debug(this + " unrecognized remotingContentType: " + o);
+ }
}
-
- isBinary =
HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING.equals(remotingContentType);
+
+ if (log.isTraceEnabled()) log.trace(this + " remotingContentType: " +
remotingContentType);
+ if (remotingContentType != null)
+ {
+ isBinary =
HTTPMetadataConstants.REMOTING_CONTENT_TYPE_NON_STRING.equals(remotingContentType);
+ }
}
+
+ if (log.isTraceEnabled()) log.trace(this + " isBinary: " + isBinary);
return isBinary;
}
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2009-08-26
19:44:41 UTC (rev 5392)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/coyote/CoyoteInvoker.java 2009-08-26
19:46:43 UTC (rev 5393)
@@ -80,6 +80,8 @@
protected ProtocolHandler protocolHandler = null;
protected String URIEncoding = null;
+
+ protected String useRemotingContentType = "false";
/** Indicates if client is HTTPClientInvoker */
protected boolean isRemotingUserAgent;
@@ -178,7 +180,17 @@
{
URIEncoding = String.valueOf(value);
}
-
+
+ value = config.get(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE);
+ if (value != null && value instanceof String)
+ {
+ useRemotingContentType = (String) value;
+ }
+ else
+ {
+ log.warn(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE + " value should
be a String: " + value);
+ }
+ log.debug(this + " useRemotingContentType: " + useRemotingContentType);
}
protected ServerSocketFactory getDefaultServerSocketFactory() throws IOException
@@ -481,6 +493,7 @@
{
// must be POST or PUT
UnMarshaller unmarshaller = getUnMarshaller();
+ request.put(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE,
useRemotingContentType);
Object obj = null;
if (unmarshaller instanceof VersionedUnMarshaller)
obj =
((VersionedUnMarshaller)unmarshaller).read(request.getInputStream(), request, version);
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java 2009-08-26
19:44:41 UTC (rev 5392)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPClientInvoker.java 2009-08-26
19:46:43 UTC (rev 5393)
@@ -102,7 +102,8 @@
protected static final Logger log = Logger.getLogger(HTTPClientInvoker.class);
protected boolean unmarshalNullStream = true;
-
+ protected boolean useRemotingContentType = false;
+
private Object timeoutThreadPoolLock = new Object();
private ThreadPool timeoutThreadPool;
@@ -272,6 +273,8 @@
{
conn.setRequestProperty(HTTPMetadataConstants.CONTENTTYPE,
WebUtil.getContentType(invocation));
}
+
+ metadata.put(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE,
Boolean.toString(useRemotingContentType));
// set the remoting version
conn.setRequestProperty(HTTPMetadataConstants.REMOTING_VERSION_HEADER, new
Integer(Version.getDefaultVersion()).toString());
@@ -549,6 +552,8 @@
map.put(HTTPUnMarshaller.PRESERVE_LINES, o);
}
+ map.put(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE,
Boolean.toString(useRemotingContentType));
+
try
{
if (unmarshaller instanceof VersionedUnMarshaller)
@@ -562,6 +567,7 @@
}
catch (IOException e)
{
+ log.trace(this + " unable to read response", e);
if (-1 == is.read())
{
throw new EOFException();
@@ -936,6 +942,22 @@
val + " to a boolean value.");
}
}
+
+ val = configuration.get(HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE);
+ if (val != null)
+ {
+ try
+ {
+ useRemotingContentType = Boolean.valueOf((String)val).booleanValue();
+ log.debug(this + " setting useRemotingContent to " +
useRemotingContentType);
+ }
+ catch (Exception e)
+ {
+ log.warn(this + " could not convert " +
+ HTTPMetadataConstants.USE_REMOTING_CONTENT_TYPE + " value of
" +
+ val + " to a boolean value.");
+ }
+ }
}
/**
Modified:
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java
===================================================================
---
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java 2009-08-26
19:44:41 UTC (rev 5392)
+++
remoting2/branches/2.2/src/main/org/jboss/remoting/transport/http/HTTPMetadataConstants.java 2009-08-26
19:46:43 UTC (rev 5393)
@@ -65,8 +65,11 @@
/** Used to distinguish special case of payload of type String. */
public static final String REMOTING_CONTENT_TYPE = "remotingContentType";
+ public static final String REMOTING_CONTENT_TYPE_LC =
"remotingcontenttype";
public static final String REMOTING_CONTENT_TYPE_STRING =
"remotingContentTypeString";
public static final String REMOTING_CONTENT_TYPE_NON_STRING =
"remotingContentTypeNonString";
+
+ public static final String USE_REMOTING_CONTENT_TYPE =
"useRemotingContentType";
}
\ No newline at end of file
Show replies by date