[jboss-remoting-commits] JBoss Remoting SVN: r4980 - remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet.

jboss-remoting-commits at lists.jboss.org jboss-remoting-commits at lists.jboss.org
Mon Apr 13 02:23:57 EDT 2009


Author: ron.sigal at jboss.com
Date: 2009-04-13 02:23:56 -0400 (Mon, 13 Apr 2009)
New Revision: 4980

Modified:
   remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
Log:
JBREM-1114: (1) Added "unwrapSingletonArray" parameter; (2) creates new InvocationRequest if request body is null.

Modified: remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java
===================================================================
--- remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java	2009-04-13 03:50:21 UTC (rev 4979)
+++ remoting2/branches/2.x/src/main/org/jboss/remoting/transport/servlet/ServletServerInvoker.java	2009-04-13 06:23:56 UTC (rev 4980)
@@ -48,10 +48,6 @@
 import java.io.ByteArrayOutputStream;
 import java.io.IOException;
 import java.net.InetAddress;
-import java.net.UnknownHostException;
-import java.security.AccessController;
-import java.security.PrivilegedActionException;
-import java.security.PrivilegedExceptionAction;
 import java.util.Enumeration;
 import java.util.HashMap;
 import java.util.Map;
@@ -66,22 +62,47 @@
  */
 public class ServletServerInvoker extends WebServerInvoker implements ServletServerInvokerMBean
 {
+   public static final String UNWRAP_SINGLETON_ARRAYS = "unwrapSingletonArrays";
+   
    private static final Logger log = Logger.getLogger(ServletServerInvoker.class);
+   
+   private boolean unwrapSingletonArrays;
 
    public ServletServerInvoker(InvokerLocator locator)
    {
       super(locator);
+      init();
    }
 
    public ServletServerInvoker(InvokerLocator locator, Map configuration)
    {
       super(locator, configuration);
+      init();
    }
 
    protected String getDefaultDataType()
    {
       return HTTPMarshaller.DATATYPE;
    }
+   
+   protected void init()
+   {
+      Object val = configuration.get(UNWRAP_SINGLETON_ARRAYS);
+      if (val != null)
+      {
+         try
+         {
+            unwrapSingletonArrays = Boolean.valueOf((String)val).booleanValue();
+            log.debug(this + " setting unwrapSingletonArrays to " + unwrapSingletonArrays);
+         }
+         catch (Exception e)
+         {
+            log.warn(this + " could not convert " + 
+                     UNWRAP_SINGLETON_ARRAYS + " value of " +
+                     val + " to a boolean value.");
+         }
+      }
+   }
 
    public void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
    {
@@ -97,8 +118,37 @@
       }
 
       Map urlParams = request.getParameterMap();
-      metadata.putAll(urlParams);
+      if (unwrapSingletonArrays)
+      {
+         Iterator it = urlParams.keySet().iterator();
+         while (it.hasNext())
+         {
+            Object key = it.next();
+            Object value = urlParams.get(key);
+            String[] valueArray = (String[]) value;
+            if (valueArray.length == 1)
+            {
+               value = valueArray[0];
+            }
+            metadata.put(key, value);
+         }
+      }
+      else
+      {
+         metadata.putAll(urlParams);
+      }
       
+      if(log.isTraceEnabled())
+      {
+         log.trace("metadata:");
+         Iterator it = metadata.keySet().iterator();
+         while (it.hasNext())
+         {
+            Object key = it.next();
+            log.trace("  " + key + ": " + metadata.get(key));
+         }
+      }
+      
       // UnMarshaller may not be an HTTPUnMarshaller, in which case it
       // can ignore this parameter.
       Object o = configuration.get(HTTPUnMarshaller.PRESERVE_LINES);
@@ -222,7 +272,25 @@
       }
 
       Map urlParams = request.getParameterMap();
-      metadata.putAll(urlParams);
+      if (unwrapSingletonArrays)
+      {
+         Iterator it = urlParams.keySet().iterator();
+         while (it.hasNext())
+         {
+            Object key = it.next();
+            Object value = urlParams.get(key);
+            String[] valueArray = (String[]) value;
+            if (valueArray.length == 1)
+            {
+               value = valueArray[0];
+            }
+            metadata.put(key, value);
+         }
+      }
+      else
+      {
+         metadata.putAll(urlParams);
+      }
 
       metadata.put(HTTPMetadataConstants.METHODTYPE, request.getMethod());
       
@@ -250,43 +318,50 @@
 
       try
       {
+         InvocationRequest invocationRequest = null;
          Object responseObject = null;
-
-         ServletInputStream inputStream = request.getInputStream();
-         UnMarshaller unmarshaller = getUnMarshaller();
-         Object obj = null;
-         if (unmarshaller instanceof VersionedUnMarshaller)
-            obj = ((VersionedUnMarshaller)unmarshaller).read(new ByteArrayInputStream(requestByte), metadata, getVersion());
-         else
-            obj = unmarshaller.read(new ByteArrayInputStream(requestByte), metadata);
-         inputStream.close();
-
          boolean isError = false;
-         InvocationRequest invocationRequest = null;
 
-         if(obj instanceof InvocationRequest)
+         String method = request.getMethod();
+         if (method.equals("GET") || method.equals("HEAD") || (method.equals("OPTIONS") && request.getContentLength() <= 0))
          {
-            invocationRequest = (InvocationRequest) obj;
-            
-            Map requestMap = invocationRequest.getRequestPayload();
-            if (requestMap == null)
-            {
-               invocationRequest.setRequestPayload(metadata);
-            }
-            else
-            {
-               requestMap.putAll(metadata);
-            }
+            invocationRequest = createNewInvocationRequest(metadata, null);
          }
          else
          {
-            if(WebUtil.isBinary(requestContentType))
+            ServletInputStream inputStream = request.getInputStream();
+            UnMarshaller unmarshaller = getUnMarshaller();
+            Object obj = null;
+            if (unmarshaller instanceof VersionedUnMarshaller)
+               obj = ((VersionedUnMarshaller)unmarshaller).read(new ByteArrayInputStream(requestByte), metadata, getVersion());
+            else
+               obj = unmarshaller.read(new ByteArrayInputStream(requestByte), metadata);
+            inputStream.close();
+
+            if(obj instanceof InvocationRequest)
             {
-               invocationRequest = getInvocationRequest(metadata, obj);
+               invocationRequest = (InvocationRequest) obj;
+
+               Map requestMap = invocationRequest.getRequestPayload();
+               if (requestMap == null)
+               {
+                  invocationRequest.setRequestPayload(metadata);
+               }
+               else
+               {
+                  requestMap.putAll(metadata);
+               }
             }
             else
             {
-               invocationRequest = createNewInvocationRequest(metadata, obj);
+               if(WebUtil.isBinary(requestContentType))
+               {
+                  invocationRequest = getInvocationRequest(metadata, obj);
+               }
+               else
+               {
+                  invocationRequest = createNewInvocationRequest(metadata, obj);
+               }
             }
          }
 




More information about the jboss-remoting-commits mailing list