axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r479700 - in /webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms: JMSConstants.java JMSUtils.java
Date Mon, 27 Nov 2006 17:40:51 GMT
Author: asankha
Date: Mon Nov 27 09:40:49 2006
New Revision: 479700

URL: http://svn.apache.org/viewvc?view=rev&rev=479700
Log:
Fix for AXIS2-1752

Modified:
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
    webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java?view=diff&rev=479700&r1=479699&r2=479700
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSConstants.java
Mon Nov 27 09:40:49 2006
@@ -47,6 +47,15 @@
     public static final String CONFAC_PARAM = "transport.jms.ConnectionFactory";
     /** The Parameter name indicating the JMS connection factory JNDI name */
     public static final String CONFAC_JNDI_NAME_PARAM = "transport.jms.ConnectionFactoryJNDIName";
+    /** The Parameter name indicating the operation to dispatch non SOAP/XML messages */
+    public static final String OPERATION_PARAM = "transport.jms.Operation";
+    /** The Parameter name indicating the wrapper element for non SOAP/XML messages */
+    public static final String WRAPPER_PARAM = "transport.jms.Wrapper";
+    /** The default operation name to be used for non SOAP/XML messages
+     if the operation cannot be determined*/
+    public static final QName DEFAULT_OPERATION = new QName("urn:mediate");
+    /** The name of the element which wraps non SOAP/XML content into a SOAP envelope */
+    public static final QName DEFAULT_WRAPPER = new QName(Constants.AXIS2_NAMESPACE_URI,
"jmsMessage");
     /** The local (Axis2) JMS connection factory name of the default connection
      * factory to be used, if a service does not explicitly state the connection
      * factory it should be using by a Parameter named JMSConstants.CONFAC_PARAM

Modified: webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java?view=diff&rev=479700&r1=479699&r2=479700
==============================================================================
--- webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
(original)
+++ webservices/axis2/branches/java/1_1/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
Mon Nov 27 09:40:49 2006
@@ -15,13 +15,15 @@
 */
 package org.apache.axis2.transport.jms;
 
-import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.*;
 import org.apache.axiom.om.impl.builder.StAXBuilder;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.impl.llom.OMTextImpl;
 import org.apache.axiom.om.util.StAXUtils;
-import org.apache.axiom.soap.SOAP11Constants;
-import org.apache.axiom.soap.SOAP12Constants;
-import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.*;
 import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
+import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
+import org.apache.axiom.attachments.ByteArrayDataSource;
 import org.apache.axis2.AxisFault;
 import org.apache.axis2.Constants;
 import org.apache.axis2.util.JavaUtils;
@@ -29,6 +31,7 @@
 import org.apache.axis2.context.OperationContext;
 import org.apache.axis2.description.AxisService;
 import org.apache.axis2.description.Parameter;
+import org.apache.axis2.description.AxisOperation;
 import org.apache.axis2.engine.AxisConfiguration;
 import org.apache.axis2.transport.TransportUtils;
 import org.apache.axis2.transport.http.HTTPConstants;
@@ -41,10 +44,10 @@
 import javax.jms.TextMessage;
 import javax.xml.stream.XMLStreamException;
 import javax.xml.stream.XMLStreamReader;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import javax.xml.stream.XMLStreamConstants;
+import javax.xml.namespace.QName;
+import javax.activation.DataHandler;
+import java.io.*;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -343,18 +346,81 @@
         }
 
         if (builder == null) {
-            XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader(in,
-                                                                        MessageContext.DEFAULT_CHAR_SET_ENCODING);
+            SOAPFactory soapFactory = new SOAP11Factory();
+            try {
+                XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader
+                    (in, MessageContext.DEFAULT_CHAR_SET_ENCODING);
+
+                // Set the encoding scheme in the message context
+                msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
+                                       MessageContext.DEFAULT_CHAR_SET_ENCODING);
+                builder = new StAXOMBuilder(xmlreader);
+                builder.setOMBuilderFactory(soapFactory);
+
+                String ns = builder.getDocumentElement().getNamespace().getNamespaceURI();
+                if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns)) {
+                    envelope = getEnvelope(in, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(ns)) {
+                    envelope = getEnvelope(in, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
+                } else {
+                    // this is POX ... mark MC as REST
+                    msgContext.setDoingREST(true);
+                    envelope = soapFactory.getDefaultEnvelope();
+                    envelope.getBody().addChild(builder.getDocumentElement());
+                }
+            } catch (Exception e) {
+                log.debug("Non SOAP/XML JMS message received");
 
-            // Set the encoding scheme in the message context
-            msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING,
-                                   MessageContext.DEFAULT_CHAR_SET_ENCODING);
-            builder = new StAXSOAPModelBuilder(
-                xmlreader, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-            envelope = (SOAPEnvelope) builder.getDocumentElement();
+                Parameter operationParam = msgContext.getAxisService().
+                    getParameter(JMSConstants.OPERATION_PARAM);
+                QName operationQName = (operationParam != null ?
+                    getQName(operationParam.getValue()) : JMSConstants.DEFAULT_OPERATION);
+
+                AxisOperation operation = msgContext.getAxisService().getOperation(operationQName);
+                if (operation != null) {
+                    msgContext.setAxisOperation(operation);
+                } else {
+                    handleException("Cannot find operation : " + operationQName + " on the
service "
+                        + msgContext.getAxisService());
+                }
+
+
+                Parameter wrapperParam = msgContext.getAxisService().
+                    getParameter(JMSConstants.WRAPPER_PARAM);
+                QName wrapperQName = (wrapperParam != null ?
+                    getQName(wrapperParam.getValue()) : JMSConstants.DEFAULT_WRAPPER);
+
+                OMElement wrapper = soapFactory.createOMElement(wrapperQName, null);
+
+                try {
+                    if (message instanceof TextMessage) {
+                        OMTextImpl textData = (OMTextImpl) soapFactory.createOMText(
+                            ((TextMessage) message).getText());
+                        wrapper.addChild(textData);
+                    } else if (message instanceof BytesMessage) {
+                        BytesMessage bm = (BytesMessage) message;
+                        byte[] msgBytes = new byte[(int) bm.getBodyLength()];
+                        bm.reset();
+                        bm.readBytes(msgBytes);
+                        DataHandler dataHandler = new DataHandler(
+                            new ByteArrayDataSource(msgBytes));
+                        OMText textData = soapFactory.createOMText(dataHandler, true);
+                        wrapper.addChild(textData);
+                        msgContext.setDoingMTOM(true);
+                    } else {
+                        handleException("Unsupported JMS Message format : " + message.getJMSType());
+                    }
+                    envelope = soapFactory.getDefaultEnvelope();
+                    envelope.getBody().addChild(wrapper);
+
+                } catch (JMSException j) {
+                    handleException("Error wrapping JMS message into a SOAP envelope ", j);
+                }
+            }
         }
 
-        String charEncOfMessage = builder.getDocument().getCharsetEncoding();
+        String charEncOfMessage = builder == null ? null :
+            builder.getDocument() == null ? null : builder.getDocument().getCharsetEncoding();
         String charEncOfTransport = ((String) msgContext.getProperty(
             Constants.Configuration.CHARACTER_SET_ENCODING));
 
@@ -378,6 +444,35 @@
                 "SOAP message");
         }
         return envelope;
+    }
+
+    private static SOAPEnvelope getEnvelope(InputStream in, String namespace) throws XMLStreamException
{
+
+        try {
+            in.reset();
+        } catch (IOException e) {
+            throw new XMLStreamException("Error resetting message input stream", e);
+        }
+        XMLStreamReader xmlreader = StAXUtils.createXMLStreamReader
+            (in, MessageContext.DEFAULT_CHAR_SET_ENCODING);
+        StAXBuilder builder = new StAXSOAPModelBuilder(xmlreader, namespace);
+        return (SOAPEnvelope) builder.getDocumentElement();
+    }
+
+    private static QName getQName(Object obj) {
+        String value;
+        if (obj instanceof QName) {
+            return (QName) obj;
+        } else {
+            value = obj.toString();
+        }
+        int open = value.indexOf('{');
+        int close = value.indexOf('}');
+        if (close > open && open > -1 && value.length() > close)
{
+            return new QName(value.substring(open+1, close-open), value.substring(close+1));
+        } else {
+            return new QName(value);
+        }
     }
 
     private static void handleException(String s) {



---------------------------------------------------------------------
To unsubscribe, e-mail: axis-cvs-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-cvs-help@ws.apache.org


Mime
View raw message