axis-java-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From asan...@apache.org
Subject svn commit: r530531 - /webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
Date Thu, 19 Apr 2007 20:01:06 GMT
Author: asankha
Date: Thu Apr 19 13:01:06 2007
New Revision: 530531

URL: http://svn.apache.org/viewvc?view=rev&rev=530531
Log:
merge support for pure POX and binary JMS messages from 1.1 branch that had not been included
into the trunk earlier

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

Modified: webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
URL: http://svn.apache.org/viewvc/webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java?view=diff&rev=530531&r1=530530&r2=530531
==============================================================================
--- webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
(original)
+++ webservices/axis2/branches/java/1_2/modules/kernel/src/org/apache/axis2/transport/jms/JMSUtils.java
Thu Apr 19 13:01:06 2007
@@ -16,10 +16,19 @@
 package org.apache.axis2.transport.jms;
 
 import org.apache.axiom.om.OMOutputFormat;
+import org.apache.axiom.om.OMText;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.util.StAXUtils;
 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.soap.SOAP11Constants;
 import org.apache.axiom.soap.SOAP12Constants;
 import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+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.builder.BuilderUtil;
@@ -27,6 +36,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.http.HTTPConstants;
 import org.apache.axis2.util.JavaUtils;
@@ -38,10 +48,10 @@
 import javax.jms.Message;
 import javax.jms.TextMessage;
 import javax.xml.stream.XMLStreamException;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
+import javax.xml.stream.XMLStreamReader;
+import javax.xml.namespace.QName;
+import javax.activation.DataHandler;
+import java.io.*;
 import java.util.Hashtable;
 import java.util.List;
 import java.util.StringTokenizer;
@@ -302,25 +312,101 @@
             throws XMLStreamException {
 
         SOAPEnvelope envelope = null;
-        StAXBuilder builder;
+        StAXBuilder builder = null;
         String contentType = JMSUtils.getProperty(message, JMSConstants.CONTENT_TYPE);
 
-        if (contentType != null && contentType.indexOf(
-                HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
-            builder = BuilderUtil.getAttachmentsBuilder(
-                    msgContext, in, contentType, true);
-            envelope = (SOAPEnvelope) builder.getDocumentElement();
-        } else {
-            String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
-            String soapNS = BuilderUtil.getEnvelopeNamespace(contentType);
-            builder = BuilderUtil.getSOAPBuilder(in, charSetEnc);
+        if (contentType != null) {
+            if (contentType.indexOf(
+                    HTTPConstants.HEADER_ACCEPT_MULTIPART_RELATED) > -1) {
+                builder = BuilderUtil.getAttachmentsBuilder(
+                        msgContext, in, contentType, true);
+                envelope = (SOAPEnvelope) builder.getDocumentElement();
+            } else {
+                String charSetEnc = BuilderUtil.getCharSetEncoding(contentType);
+                builder = BuilderUtil.getSOAPBuilder(in, charSetEnc);
+
+                // Set the encoding scheme in the message context
+                msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+                envelope = (SOAPEnvelope) builder.getDocumentElement();
+            }
+        }
+
+        // handle pure plain vanilla POX and binary content (non SOAP)
+        if (builder == null) {
+            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, charSetEnc);
+                // 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");
+
+                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);
+                }
+            }
         }
-        envelope = (SOAPEnvelope) builder.getDocumentElement();
 
-        String charEncOfMessage = builder.getCharsetEncoding();
+        String charEncOfMessage = builder == null ? null :
+            builder.getDocument() == null ? null : builder.getDocument().getCharsetEncoding();
         String charEncOfTransport = ((String) msgContext.getProperty(
                 Constants.Configuration.CHARACTER_SET_ENCODING));
 
@@ -328,22 +414,41 @@
                 !(charEncOfMessage.trim().length() == 0) &&
                 !charEncOfMessage.equalsIgnoreCase(charEncOfTransport)) {
 
-            String faultCode;
-
-            if (envelope.getNamespace() != null &&
-                    SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.
-                            equals(envelope.getNamespace().getNamespaceURI())) {
-                faultCode = SOAP12Constants.FAULT_CODE_SENDER;
-            } else {
-                faultCode = SOAP11Constants.FAULT_CODE_SENDER;
-            }
-
             handleException(
                     "Character Set Encoding from transport information do not " +
                             "match with character set encoding in the received " +
                             "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