You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rg...@apache.org on 2016/10/26 11:38:49 UTC

svn commit: r1766666 - in /qpid/java/trunk: broker-core/src/main/java/org/apache/qpid/server/model/ broker-core/src/main/java/org/apache/qpid/server/virtualhost/ broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/serv...

Author: rgodfrey
Date: Wed Oct 26 11:38:49 2016
New Revision: 1766666

URL: http://svn.apache.org/viewvc?rev=1766666&view=rev
Log:
QPID-7469 : Add content transfer encoding to managable message, validate this and mime type

Modified:
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManageableMessage.java
    qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
    qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManageableMessage.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManageableMessage.java?rev=1766666&r1=1766665&r2=1766666&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManageableMessage.java (original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/model/ManageableMessage.java Wed Oct 26 11:38:49 2016
@@ -51,4 +51,6 @@ public interface ManageableMessage exten
     Map<String,Object> getHeaders();
 
     Object getContent();
+
+    String getContentTransferEncoding();
 }

Modified: qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java?rev=1766666&r1=1766665&r2=1766666&view=diff
==============================================================================
--- qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java (original)
+++ qpid/java/trunk/broker-core/src/main/java/org/apache/qpid/server/virtualhost/AbstractVirtualHost.java Wed Oct 26 11:38:49 2016
@@ -38,6 +38,7 @@ import java.security.AccessControlContex
 import java.security.Principal;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
+import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
@@ -717,25 +718,43 @@ public abstract class AbstractVirtualHos
         {
             if(messageContent instanceof Map || messageContent instanceof List)
             {
+                if(message.getMimeType() != null || message.getEncoding() != null)
+                {
+                    throw new IllegalArgumentException("If the message content is provided as map or list, the mime type and encoding must be left unset");
+                }
                 body = (Serializable)messageContent;
             }
             else if(messageContent instanceof String)
             {
-                if(message.getMimeType() != null || message.getEncoding() != null)
+                String contentTransferEncoding = message.getContentTransferEncoding();
+                if("base64".equalsIgnoreCase(contentTransferEncoding))
                 {
-                    try
-                    {
-                        body = Strings.decodeBase64((String) messageContent);
-
-                    }
-                    catch(IllegalArgumentException e)
+                    body = Strings.decodeBase64((String) messageContent);
+                }
+                else if(contentTransferEncoding == null || contentTransferEncoding.trim().equals("") || contentTransferEncoding.trim().equalsIgnoreCase("identity"))
+                {
+                    String mimeType = message.getMimeType();
+                    if(mimeType != null && !(mimeType = mimeType.trim().toLowerCase()).equals(""))
                     {
-                        body = (String) messageContent;
+                        if (!(mimeType.startsWith("text/") || Arrays.asList("application/json", "application/xml")
+                                                                    .contains(mimeType)))
+                        {
+                            throw new IllegalArgumentException(message.getMimeType()
+                                                               + " is invalid as a MIME type for this message. "
+                                                               + "Only MIME types of the text type can be used if a string is supplied as the content");
+                        }
+                        else if (mimeType.matches(".*;\\s*charset\\s*="))
+                        {
+                            throw new IllegalArgumentException(message.getMimeType()
+                                                               + " is invalid as a MIME type for this message. "
+                                                               + "If a string is supplied as the content, the MIME type must not include a charset parameter");
+                        }
                     }
+                    body = (String) messageContent;
                 }
                 else
                 {
-                    body = (String) messageContent;
+                    throw new IllegalArgumentException("contentTransferEncoding value '" + contentTransferEncoding + "' is invalid.  The only valid values are base64 and identity");
                 }
             }
             else

Modified: qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java
URL: http://svn.apache.org/viewvc/qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java?rev=1766666&r1=1766665&r2=1766666&view=diff
==============================================================================
--- qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java (original)
+++ qpid/java/trunk/broker-plugins/management-http/src/main/java/org/apache/qpid/server/management/plugin/servlet/rest/RestServlet.java Wed Oct 26 11:38:49 2016
@@ -43,7 +43,7 @@ import javax.servlet.http.HttpServletReq
 import javax.servlet.http.HttpServletResponse;
 import javax.servlet.http.Part;
 
-import com.fasterxml.jackson.core.JsonParseException;
+import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import com.google.common.base.Joiner;
 import com.google.common.base.Predicate;
@@ -1021,7 +1021,15 @@ public class RestServlet extends Abstrac
             {
                 if ("data".equals(part.getName()) && "application/json".equals(part.getContentType()))
                 {
-                    providedObject = (T) mapper.readValue(part.getInputStream(), LinkedHashMap.class);
+                    try
+                    {
+                        providedObject = (T) mapper.readValue(part.getInputStream(), LinkedHashMap.class);
+                    }
+                    catch (JsonProcessingException e)
+                    {
+                        throw new IllegalArgumentException("Cannot parse the operation body as json",e);
+                    }
+
                 }
                 else
                 {
@@ -1039,7 +1047,7 @@ public class RestServlet extends Abstrac
             {
                 providedObject = mapper.readValue(request.getInputStream(), expectedClass);
             }
-            catch (JsonParseException e)
+            catch (JsonProcessingException e)
             {
                 throw new IllegalArgumentException("Cannot parse the operation body as json",e);
             }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org