You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commons-dev@ws.apache.org by ve...@apache.org on 2008/11/07 02:54:46 UTC

svn commit: r712036 - in /webservices/commons/trunk/modules/transport: modules/jms/ modules/jms/src/main/java/org/apache/axis2/transport/jms/ modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ modules/jms/src/test/ modules/jms/src/test/jav...

Author: veithen
Date: Thu Nov  6 17:54:43 2008
New Revision: 712036

URL: http://svn.apache.org/viewvc?rev=712036&view=rev
Log:
SYNAPSE-424 (part 1): Implemented a simple rule based mechanism to determine the content type of incoming JMS messages.

Added:
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/test/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml   (with props)
    webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml   (with props)
Modified:
    webservices/commons/trunk/modules/transport/modules/jms/pom.xml
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
    webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
    webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml

Modified: webservices/commons/trunk/modules/transport/modules/jms/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/pom.xml?rev=712036&r1=712035&r2=712036&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/pom.xml (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/pom.xml Thu Nov  6 17:54:43 2008
@@ -76,6 +76,18 @@
             <artifactId>geronimo-jms_1.1_spec</artifactId>
             <version>${jms-1.1-spec.version}</version>
         </dependency>
+        
+        <dependency>
+            <groupId>junit</groupId>
+            <artifactId>junit</artifactId>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.mockejb</groupId>
+            <artifactId>mockejb</artifactId>
+            <version>0.6-beta2</version>
+            <scope>test</scope>
+        </dependency>        
     </dependencies>
     
     <properties>

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java?rev=712036&r1=712035&r2=712036&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSEndpoint.java Thu Nov  6 17:54:43 2008
@@ -16,6 +16,7 @@
 package org.apache.axis2.transport.jms;
 
 import org.apache.axis2.description.AxisService;
+import org.apache.axis2.transport.jms.ctype.ContentTypeRuleSet;
 
 /**
  * Class that links an Axis2 service to a JMS destination. Additionally, it contains
@@ -27,7 +28,7 @@
     private String jndiDestinationName;
     private String destinationType;
     private String endpointReference;
-    private String contentType;
+    private ContentTypeRuleSet contentTypeRuleSet;
 
     public AxisService getService() {
         return service;
@@ -65,11 +66,11 @@
         this.endpointReference = endpointReference;
     }
 
-    public String getContentType() {
-        return contentType;
+    public ContentTypeRuleSet getContentTypeRuleSet() {
+        return contentTypeRuleSet;
     }
 
-    public void setContentType(String contentType) {
-        this.contentType = contentType;
+    public void setContentTypeRuleSet(ContentTypeRuleSet contentTypeRuleSet) {
+        this.contentTypeRuleSet = contentTypeRuleSet;
     }
 }

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java?rev=712036&r1=712035&r2=712036&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java Thu Nov  6 17:54:43 2008
@@ -29,10 +29,17 @@
 import org.apache.axis2.transport.base.event.TransportErrorListener;
 import org.apache.axis2.transport.base.event.TransportErrorSource;
 import org.apache.axis2.transport.base.event.TransportErrorSourceSupport;
+import org.apache.axis2.transport.jms.ctype.ContentTypeRuleFactory;
+import org.apache.axis2.transport.jms.ctype.ContentTypeRuleSet;
+import org.apache.axis2.transport.jms.ctype.MessageTypeRule;
+import org.apache.axis2.transport.jms.ctype.PropertyRule;
 
 import java.util.HashMap;
 import java.util.Map;
 
+import javax.jms.BytesMessage;
+import javax.jms.TextMessage;
+
 /**
  * The JMS Transport listener implementation. A JMS Listner will hold one or
  * more JMS connection factories, which would be created at initialization
@@ -180,7 +187,21 @@
                 endpoint.getJndiDestinationName()));
         serviceNameToEndpointMap.put(service.getName(), endpoint);
         
-        endpoint.setContentType((String)service.getParameterValue(JMSConstants.CONTENT_TYPE_PARAM));
+        Parameter contentTypeParam = service.getParameter(JMSConstants.CONTENT_TYPE_PARAM);
+        if (contentTypeParam == null) {
+            ContentTypeRuleSet contentTypeRuleSet = new ContentTypeRuleSet();
+            contentTypeRuleSet.addRule(new PropertyRule(BaseConstants.CONTENT_TYPE));
+            contentTypeRuleSet.addRule(new MessageTypeRule(BytesMessage.class, "application/octet-stream"));
+            contentTypeRuleSet.addRule(new MessageTypeRule(TextMessage.class, "text/plain"));
+            endpoint.setContentTypeRuleSet(contentTypeRuleSet);
+        } else {
+            try {
+                endpoint.setContentTypeRuleSet(ContentTypeRuleFactory.parse(contentTypeParam));
+            } catch (AxisFault ex) {
+                // TODO: this is ugly; we should allow startListeningForService to throw AxisFaults
+                throw new AxisJMSException("Invalid value in parameter " + JMSConstants.CONTENT_TYPE_PARAM, ex);
+            }
+        }
         
         log.info("Starting to listen on destination : " + endpoint.getJndiDestinationName() + " of type "
                 + endpoint.getDestinationType() + " for service " + service.getName());

Modified: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java?rev=712036&r1=712035&r2=712036&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java (original)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java Thu Nov  6 17:54:43 2008
@@ -15,6 +15,7 @@
 */
 package org.apache.axis2.transport.jms;
 
+import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.transport.base.threads.WorkerPool;
 import org.apache.axis2.transport.base.BaseUtils;
@@ -199,10 +200,10 @@
                     }
                 }
 
-                String contentType = endpoint.getContentType();
+                String contentType = endpoint.getContentTypeRuleSet().getContentType(message);
                 if (contentType == null) {
-                    contentType
-                        = JMSUtils.getProperty(message, BaseConstants.CONTENT_TYPE);
+                    throw new AxisFault("Unable to determine content type for message " +
+                            msgContext.getMessageID());
                 }
                 
                 JMSUtils.setSOAPEnvelope(message, msgContext, contentType);

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,33 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+/**
+ * Interface implemented by content type rules.
+ */
+public interface ContentTypeRule {
+    /**
+     * Attempt to determine the content type of the given JMS message.
+     * 
+     * @param message the message
+     * @return the content type of the message, or null if the rule doesn't match
+     * @throws JMSException
+     */
+    String getContentType(Message message) throws JMSException;
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,74 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import java.util.Iterator;
+
+import javax.jms.BytesMessage;
+import javax.jms.TextMessage;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.description.Parameter;
+
+/**
+ * Utility class to create content type rules and rule sets from XML.
+ */
+public class ContentTypeRuleFactory {
+    private ContentTypeRuleFactory() {}
+    
+    public static ContentTypeRule parse(OMElement element) throws AxisFault {
+        String name = element.getLocalName();
+        String value = element.getText();
+        if (name.equals("jmsProperty")) {
+            return new PropertyRule(value);
+        } else if (name.equals("textMessage")) {
+            return new MessageTypeRule(TextMessage.class, value);
+        } else if (name.equals("bytesMessage")) {
+            return new MessageTypeRule(BytesMessage.class, value);
+        } else if (name.equals("default")) {
+            return new DefaultRule(value);
+        } else {
+            throw new AxisFault("Unknown content rule type '" + name + "'");
+        }
+    }
+    
+    public static ContentTypeRuleSet parse(Parameter param) throws AxisFault {
+        ContentTypeRuleSet ruleSet = new ContentTypeRuleSet();
+        Object value = param.getValue();
+        if (value instanceof OMElement) {
+            OMElement element = (OMElement)value;
+            
+            // DescriptionBuilder#processParameters actually sets the parameter element
+            // itself as the value. We need to support this case.
+            // TODO: seems like a bug in Axis2 and is inconsistent with Synapse's way of parsing parameter in proxy definitions
+            if (element == param.getParameterElement()) {
+                element = element.getFirstElement();
+            }
+            
+            if (element.getLocalName().equals("rules")) {
+                for (Iterator it = element.getChildElements(); it.hasNext(); ) {
+                    ruleSet.addRule(parse((OMElement)it.next()));
+                }
+            } else {
+                throw new AxisFault("Expected <rules> element");
+            }
+        } else {
+            ruleSet.addRule(new DefaultRule((String)value));
+        }
+        return ruleSet;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,56 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+/**
+ * A set of content type rules.
+ */
+public class ContentTypeRuleSet {
+    private final List<ContentTypeRule> rules = new ArrayList<ContentTypeRule>();
+    
+    /**
+     * Add a content type rule to this set.
+     * 
+     * @param rule the rule to add
+     */
+    public void addRule(ContentTypeRule rule) {
+        rules.add(rule);
+    }
+    
+    /**
+     * Determine the content type of the given message.
+     * This method will try the registered rules in turn until the first rule matches.
+     * 
+     * @param message the message
+     * @return the content type of the message or null if none of the rules matches
+     * @throws JMSException
+     */
+    public String getContentType(Message message) throws JMSException {
+        for (ContentTypeRule rule : rules) {
+            String contentType = rule.getContentType(message);
+            if (contentType != null) {
+                return contentType;
+            }
+        }
+        return null;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleSet.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,33 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import javax.jms.Message;
+
+/**
+ * Content type rule that always matches and that returns a fixed (default) content type.
+ */
+public class DefaultRule implements ContentTypeRule {
+    private final String contentType;
+
+    public DefaultRule(String contentType) {
+        this.contentType = contentType;
+    }
+
+    public String getContentType(Message message) {
+        return contentType;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/DefaultRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,35 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import javax.jms.Message;
+
+/**
+ * Content type rule that matches a given message type and returns a fixed content type.
+ */
+public class MessageTypeRule implements ContentTypeRule {
+    private final Class<? extends Message> messageType;
+    private final String contentType;
+    
+    public MessageTypeRule(Class<? extends Message> messageType, String contentType) {
+        this.messageType = messageType;
+        this.contentType = contentType;
+    }
+
+    public String getContentType(Message message) {
+        return messageType.isInstance(message) ? contentType : null;
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/MessageTypeRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,34 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import javax.jms.JMSException;
+import javax.jms.Message;
+
+/**
+ * Content type rule that attempts to extract the content type from a message property.
+ */
+public class PropertyRule implements ContentTypeRule {
+    private final String propertyName;
+
+    public PropertyRule(String propertyName) {
+        this.propertyName = propertyName;
+    }
+
+    public String getContentType(Message message) throws JMSException {
+        return message.getStringProperty(propertyName);
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/PropertyRule.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,23 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+
+/**
+ * Provides classes and interfaces to define content type rules.
+ * 
+ * Content type rules are used to determine the content type of a
+ * received message based on JMS properties, message type, etc.
+ */
+package org.apache.axis2.transport.jms.ctype;
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/ctype/package-info.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java Thu Nov  6 17:54:43 2008
@@ -0,0 +1,76 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed under the Apache License, Version 2.0 (the "License");
+* you may not use this file except in compliance with the License.
+* You may obtain a copy of the License at
+*
+*      http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing, software
+* distributed under the License is distributed on an "AS IS" BASIS,
+* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+* See the License for the specific language governing permissions and
+* limitations under the License.
+*/
+package org.apache.axis2.transport.jms.ctype;
+
+import java.io.InputStream;
+
+import javax.jms.Message;
+
+import junit.framework.TestCase;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.deployment.ServiceBuilder;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.mockejb.jms.BytesMessageImpl;
+import org.mockejb.jms.ObjectMessageImpl;
+import org.mockejb.jms.TextMessageImpl;
+
+public class ContentTypeRuleTest extends TestCase {
+    private ContentTypeRuleSet ruleSet;
+    
+    @Override
+    public void setUp() throws Exception {
+        AxisConfiguration axisCfg = new AxisConfiguration();
+        ConfigurationContext cfgCtx = new ConfigurationContext(axisCfg);
+        AxisService service = new AxisService();
+        
+        InputStream in = ContentTypeRuleTest.class.getResourceAsStream(getName() + ".xml");
+        try {
+            OMElement element = new StAXOMBuilder(in).getDocumentElement();
+            new ServiceBuilder(cfgCtx, service).populateService(element);
+        } finally {
+            in.close();
+        }
+        
+        ruleSet = ContentTypeRuleFactory.parse(service.getParameter("test"));
+    }
+    
+    public void test1() throws Exception {
+        Message message = new BytesMessageImpl();
+        message.setStringProperty("contentType", "application/xml");
+        assertEquals("application/xml", ruleSet.getContentType(message));
+        
+        assertEquals("text/plain", ruleSet.getContentType(new TextMessageImpl()));
+        assertEquals("application/octet-stream", ruleSet.getContentType(new BytesMessageImpl()));
+        assertEquals(null, ruleSet.getContentType(new ObjectMessageImpl()));
+    }
+    
+    public void test2() throws Exception {
+        Message message = new BytesMessageImpl();
+        message.setStringProperty("contentType", "application/xml");
+        assertEquals("application/xml", ruleSet.getContentType(message));
+        
+        message = new TextMessageImpl();
+        message.setStringProperty("ctype", "application/xml");
+        assertEquals("application/xml", ruleSet.getContentType(message));
+
+        assertEquals("text/xml", ruleSet.getContentType(new TextMessageImpl()));
+        assertEquals("text/xml", ruleSet.getContentType(new BytesMessageImpl()));
+    }
+}

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/test/java/org/apache/axis2/transport/jms/ctype/ContentTypeRuleTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml Thu Nov  6 17:54:43 2008
@@ -0,0 +1,9 @@
+<service>
+    <parameter name="test">
+        <rules>
+            <jmsProperty>contentType</jmsProperty>
+            <textMessage>text/plain</textMessage>
+            <bytesMessage>application/octet-stream</bytesMessage>
+        </rules>
+    </parameter>
+</service>
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test1.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Added: webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml?rev=712036&view=auto
==============================================================================
--- webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml (added)
+++ webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml Thu Nov  6 17:54:43 2008
@@ -0,0 +1,9 @@
+<service>
+    <parameter name="test">
+        <rules>
+            <jmsProperty>contentType</jmsProperty>
+            <jmsProperty>ctype</jmsProperty>
+            <default>text/xml</default>
+        </rules>
+    </parameter>
+</service>
\ No newline at end of file

Propchange: webservices/commons/trunk/modules/transport/modules/jms/src/test/resources/org/apache/axis2/transport/jms/ctype/test2.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml?rev=712036&r1=712035&r2=712036&view=diff
==============================================================================
--- webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml (original)
+++ webservices/commons/trunk/modules/transport/src/site/xdoc/jms.xml Thu Nov  6 17:54:43 2008
@@ -79,12 +79,45 @@
                     <td>The destination where a reply will be posted.</td>
                 </tr>
                 <tr>
-                    <td>transport.jms.contentType</td>
+                    <td>transport.jms.ContentType</td>
                     <td>Optional</td>
-                    <td>The expected content type of the received messages. This parameter is
-                    only useful if the messages don't have a Content-Type property. If this parameter
-                    is not specified and the messages don't have a Content-Type, they will be processed
-                    as application/octet-stream or text/plain, depending on the JMS message type.</td>
+                    <td>Specifies how the transport listener should determine the content type of received messages.
+                    This can either be a simple string value, in which case the transport listener assumes that
+                    the received messages always have the specified content type, or a set of rules as in the following example:
+<pre><![CDATA[
+<parameter name="transport.jms.ContentType">
+    <rules>
+        <jmsProperty>contentType</jmsProperty>
+        <jmsProperty>ctype</jmsProperty>
+        <default>text/xml</default>
+    </rules>
+</parameter>
+]]></pre>
+                    The rules are evaluated in turn until the first matches. The following rule types are defined:
+                    <dl>
+                        <dt>jmsProperty</dt>
+                        <dd>Extract the content type from the specified message property.</dd>
+                        <dt>bytesMessage</dt>
+                        <dt>textMessage</dt>
+                        <dd>Match the corresponding message type. The content type is specified as the value of
+                        the rule, e.g. <tt><![CDATA[<bytesMessage>binary/octet-stream</bytesMessage>]]>.</tt></dd>
+                        <dt>default</dt>
+                        <dd>Defines the default content type. This rule always matches and should therefore
+                        be the last rule in the rule set.</dd>
+                    </dl>
+                    If none of the rules matches, an error is triggered and the message is not processed.
+                    The default value for this property corresponds to the following set of rules:
+<pre><![CDATA[
+<parameter name="transport.jms.ContentType">
+    <rules>
+        <jmsProperty>Content-Type</jmsProperty>
+        <bytesMessage>application/octet-stream</bytesMessage>
+        <textMessage>text/plain</textMessage>
+    </rules>
+</parameter>
+]]></pre>
+                    This choice preserves compatibility with previous versions of the JMS transport. Note however
+                    that "Content-Type" is not a valid JMS property name and will not work with some JMS providers.</td>
                 </tr>
                 <tr>
                     <td>Wrapper</td>