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 se...@apache.org on 2008/11/07 22:01:01 UTC

svn commit: r712261 - in /webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules: base/ jms/ jms/src/main/java/org/apache/axis2/format/ jms/src/main/java/org/apache/axis2/transport/jms/

Author: senaka
Date: Fri Nov  7 13:01:01 2008
New Revision: 712261

URL: http://svn.apache.org/viewvc?rev=712261&view=rev
Log:
1. Adding Map Message Builder implementation for JMS Transport's Map Message processing logic.
2. Removing unwanted dependency in base module.
3. Modifying JMSUtils and the jms module build system to incorporate the Map Message Builder implementation.

Added:
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilder.java
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilderAdapter.java
Modified:
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/pom.xml
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/pom.xml
    webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java

Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/pom.xml?rev=712261&r1=712260&r2=712261&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/pom.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/pom.xml Fri Nov  7 13:01:01 2008
@@ -92,11 +92,6 @@
             <artifactId>axiom-dom</artifactId>
             <version>${axiom.version}</version>
         </dependency>
-        <dependency>
-            <groupId>org.apache.ws.commons.axiom</groupId>
-            <artifactId>sciflex-axiom-patch</artifactId>
-            <version>${sciflex-axiom-patch.version}</version>
-        </dependency>
         <!-- Axis2 -->
         <dependency>
             <groupId>org.apache.axis2</groupId>
@@ -153,7 +148,6 @@
         <axiom.version>SNAPSHOT</axiom.version>
         <axis2.version>SNAPSHOT</axis2.version>
         <commons.logging.version>1.1</commons.logging.version>
-        <sciflex-axiom-patch.version>0.9-SNAPSHOT</sciflex-axiom-patch.version>
     </properties>
 
 </project>

Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/pom.xml?rev=712261&r1=712260&r2=712261&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/pom.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/pom.xml Fri Nov  7 13:01:01 2008
@@ -52,6 +52,7 @@
                         <Bundle-SymbolicName>${pom.artifactId}</Bundle-SymbolicName>
                         <Export-Package>
                             org.apache.axis2.transport.jms.*;-split-package:=merge-last,
+                            org.apache.axis2.format.*;-split-package:=merge-last,
                         </Export-Package>
                         <Import-Package>
                             !javax.xml.namespace,

Added: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilder.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilder.java?rev=712261&view=auto
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilder.java (added)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilder.java Fri Nov  7 13:01:01 2008
@@ -0,0 +1,40 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.format;
+
+import java.util.Map;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.builder.Builder;
+import org.apache.axis2.context.MessageContext;
+
+/**
+ * Message builder able to build messages from a Map.
+ * This interface can be optionally implemented by {@link Builder}
+ * implementations that support building a message from a {@link Map}
+ * <p>
+ * This interface is currently used by the JMS transport to process
+ * {@link javax.jms.MapMessage} instances.
+ */
+public interface MapMessageBuilder extends Builder {
+    public OMElement processDocument(Map map, String contentType,
+            MessageContext messageContext) throws AxisFault;
+}

Added: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilderAdapter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilderAdapter.java?rev=712261&view=auto
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilderAdapter.java (added)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/format/MapMessageBuilderAdapter.java Fri Nov  7 13:01:01 2008
@@ -0,0 +1,75 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you 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.format;
+
+import java.io.InputStream;
+import java.util.Map;
+
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+import javax.xml.namespace.QName;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMFactory;
+import org.apache.axiom.om.ds.MapDataSource;
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.builder.Builder;
+import org.apache.axis2.context.MessageContext;
+import org.apache.axis2.transport.base.BaseConstants;
+
+/**
+ * Adapter to add the {@link MapMessageBuilder} interface to an
+ * existing {@link Builder}.
+ * It implements the {@link MapMessageBuilder#processDocument(Map, String, MessageContext)}.
+ */
+public class MapMessageBuilderAdapter implements MapMessageBuilder {
+    private final Builder builder;
+
+    public MapMessageBuilderAdapter(Builder builder) {
+        this.builder = builder;
+    }
+
+    public OMElement processDocument(InputStream inputStream, String contentType,
+                                     MessageContext messageContext) throws AxisFault {
+        return builder.processDocument(inputStream, contentType, messageContext);
+    }
+
+    public OMElement processDocument(Map map, String contentType,
+                                     MessageContext messageContext) throws AxisFault {
+        String charset;
+        try {
+            ContentType ct = new ContentType(contentType);
+            charset = ct.getParameter("charset");
+        } catch (ParseException ex) {
+            charset = null;
+        }
+        if (charset == null) {
+            charset = MessageContext.DEFAULT_CHAR_SET_ENCODING;
+        }
+        messageContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charset);
+        OMFactory omBuilderFactory = OMAbstractFactory.getOMFactory();
+        QName wrapperQName = BaseConstants.DEFAULT_MAP_WRAPPER;
+        return omBuilderFactory.createOMElement(new MapDataSource(map, wrapperQName.getLocalPart(),
+            omBuilderFactory.createOMNamespace(wrapperQName.getNamespaceURI(), wrapperQName.getPrefix())), wrapperQName.getLocalPart(),
+            omBuilderFactory.createOMNamespace(wrapperQName.getNamespaceURI(), wrapperQName.getPrefix()));
+    }
+}

Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java?rev=712261&r1=712260&r2=712261&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java Fri Nov  7 13:01:01 2008
@@ -15,11 +15,7 @@
 */
 package org.apache.axis2.transport.jms;
 
-import org.apache.axiom.om.OMAbstractFactory;
 import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMFactory;
-import org.apache.axiom.om.OMNamespace;
-import org.apache.axiom.om.ds.MapDataSource;
 import org.apache.axiom.soap.SOAPEnvelope;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
@@ -30,6 +26,8 @@
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
 import org.apache.axis2.description.ParameterIncludeImpl;
+import org.apache.axis2.format.MapMessageBuilder;
+import org.apache.axis2.format.MapMessageBuilderAdapter;
 import org.apache.axis2.format.TextMessageBuilder;
 import org.apache.axis2.format.TextMessageBuilderAdapter;
 import org.apache.commons.logging.Log;
@@ -357,9 +355,33 @@
                     = textMessageBuilder.processDocument(content, contentType, msgContext);
             msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
         } else if (message instanceof MapMessage) {
+            String type;
+            if (contentType == null) {
+                log.debug("No content type specified; assuming text/xml.");
+                type = contentType = "text/xml";
+            } else {
+                int index = contentType.indexOf(';');
+                if (index > 0) {
+                    type = contentType.substring(0, index);
+                } else {
+                    type = contentType;
+                }
+            }
+            Builder builder = BuilderUtil.getBuilderFromSelector(type, msgContext);
+            if (builder == null) {
+                if (log.isDebugEnabled()) {
+                    log.debug("No message builder found for type '" + type + "'. Falling back to SOAP.");
+                }
+                builder = new SOAPBuilder();
+            }
             Map payloadMap = getMessageMapPayload(message);
-            OMFactory omBuilderFactory = OMAbstractFactory.getOMFactory();
-            OMElement payload = omBuilderFactory.createOMElement(new MapDataSource(payloadMap, "map", omBuilderFactory.createOMNamespace("http://ws.apache.org/commons/ns/payload", "ns")), "map",omBuilderFactory.createOMNamespace("http://ws.apache.org/commons/ns/payload", "ns")); 
+            MapMessageBuilder mapMessageBuilder;
+            if (builder instanceof MapMessageBuilder) {
+                mapMessageBuilder = (MapMessageBuilder)builder;
+            } else {
+                mapMessageBuilder = new MapMessageBuilderAdapter(builder);
+            }
+            OMElement payload = mapMessageBuilder.processDocument(payloadMap, contentType, msgContext);
             msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(payload));
         }
     }