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/02 19:10:37 UTC
svn commit: r709899 - in
/webservices/commons/trunk/scratch/senaka/sci-flex/transport:
modules/base/src/main/java/org/apache/axis2/format/
modules/base/src/main/java/org/apache/axis2/transport/base/ modules/jms/
modules/jms/src/main/java/org/apache/axi...
Author: senaka
Date: Sun Nov 2 10:10:36 2008
New Revision: 709899
URL: http://svn.apache.org/viewvc?rev=709899&view=rev
Log:
Incorporating Recent Changes on Trunk to this branch.
Modified:
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
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/JMSConnectionFactory.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/mail/pom.xml
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/parent/pom.xml
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java
webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/xmpp/pom.xml
webservices/commons/trunk/scratch/senaka/sci-flex/transport/src/site/xdoc/jms.xml
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/format/TextMessageBuilderAdapter.java Sun Nov 2 10:10:36 2008
@@ -23,8 +23,12 @@
import java.io.Reader;
import java.io.StringReader;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
+
import org.apache.axiom.om.OMElement;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
import org.apache.axis2.builder.Builder;
import org.apache.axis2.context.MessageContext;
@@ -51,10 +55,19 @@
public OMElement processDocument(Reader reader, String contentType,
MessageContext messageContext) throws AxisFault {
- // TODO: check that using the default charset encoding and leaving the content type unaltered is a valid strategy
- return processDocument(
- new ReaderInputStream(reader, MessageContext.DEFAULT_CHAR_SET_ENCODING),
- contentType, messageContext);
+ 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);
+ return processDocument(new ReaderInputStream(reader, charset), contentType,
+ messageContext);
}
public OMElement processDocument(String content, String contentType,
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java Sun Nov 2 10:10:36 2008
@@ -22,36 +22,19 @@
import java.io.IOException;
import java.io.InputStream;
import java.util.List;
-import java.util.Map;
-import javax.activation.DataHandler;
-import javax.mail.internet.ContentType;
-import javax.mail.internet.ParseException;
import javax.xml.namespace.QName;
import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamReader;
-import org.apache.axiom.attachments.ByteArrayDataSource;
-import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMNamespace;
import org.apache.axiom.om.OMOutputFormat;
-import org.apache.axiom.om.OMSourcedElement;
-import org.apache.axiom.om.OMText;
-import org.apache.axiom.om.ds.MapDataSource;
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.SOAPFactory;
import org.apache.axiom.soap.impl.builder.StAXSOAPModelBuilder;
-import org.apache.axiom.soap.impl.llom.soap11.SOAP11Factory;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
-import org.apache.axis2.builder.BuilderUtil;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
@@ -65,7 +48,7 @@
import org.apache.axis2.format.BinaryFormatter;
import org.apache.axis2.format.PlainTextFormatter;
-public abstract class BaseUtils {
+public class BaseUtils {
private static final Log log = LogFactory.getLog(BaseUtils.class);
@@ -178,216 +161,6 @@
}
}
- /**
- * Create a SOAPEnvelope from the given message and set it into
- * the axis MessageContext passed
- *
- * @param message the message object
- * @param msgContext the axis MessageContext
- * @param contentType
- * @throws AxisFault on errors encountered while setting the envelope to the message context
- */
- public void setSOAPEnvelope(Object message, MessageContext msgContext, String contentType)
- throws AxisFault {
-
- SOAPEnvelope envelope = null;
- StAXBuilder builder = null;
-
- String charSetEnc = null;
- try {
- if (contentType != null) {
- charSetEnc = new ContentType(contentType).getParameter("charset");
- }
- } catch (ParseException ex) {
- // ignore
- }
-
- InputStream in = getInputStream(message);
-
- // handle SOAP payloads when a correct content type is available
- try {
- if (contentType != null) {
- if (contentType.indexOf(BaseConstants.MULTIPART_RELATED) > -1) {
- builder = BuilderUtil.getAttachmentsBuilder(msgContext, in, contentType, true);
- envelope = (SOAPEnvelope) builder.getDocumentElement();
- msgContext.setDoingSwA(true);
-
- } else {
- builder = BuilderUtil.getSOAPBuilder(in, charSetEnc);
- envelope = (SOAPEnvelope) builder.getDocumentElement();
- }
- }
- } catch (Exception ignore) {
- try {
- in.close();
- } catch (IOException e) {
- // ignore
- }
- in = getInputStream(message);
- }
-
-
- // handle SOAP when content type is missing, or any other POX, binary or text payload
- if (builder == null) {
-
- SOAPFactory soapFactory = new SOAP11Factory();
- try {
- builder = new StAXOMBuilder(StAXUtils.createXMLStreamReader(in, charSetEnc));
- builder.setOMBuilderFactory(OMAbstractFactory.getOMFactory());
- OMNamespace ns = builder.getDocumentElement().getNamespace();
- if (ns != null) {
- String nsUri = ns.getNamespaceURI();
-
- if (SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsUri)) {
- envelope = BaseUtils.getEnvelope(in, SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
- } else if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(nsUri)) {
- envelope = BaseUtils.getEnvelope(in, SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI);
-
- }
- }
- if (envelope == null) {
- // this is POX ... mark message as REST
- msgContext.setDoingREST(true);
- envelope = soapFactory.getDefaultEnvelope();
- envelope.getBody().addChild(builder.getDocumentElement());
- }
-
- } catch (Exception e) {
- envelope = handleLegacyMessage(msgContext, message);
- }
- }
-
- // Set the encoding scheme in the message context
- msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
-
- String charEncOfMessage =
- builder == null ? null :
- builder.getDocument() == null ? null : builder.getDocument().getCharsetEncoding();
-
- if (!isBlank(charEncOfMessage) &&
- !isBlank(charSetEnc) &&
- !charEncOfMessage.equalsIgnoreCase(charSetEnc)) {
- handleException("Charset encoding of transport differs from that of the payload");
- }
-
- msgContext.setEnvelope(envelope);
- }
-
- /**
- * Handle a non SOAP and non XML message, and create a SOAPEnvelope to hold the
- * pure text or binary content as necessary
- *
- * @param msgContext the axis message context
- * @param message the legacy message
- * @return the SOAP envelope
- */
- private SOAPEnvelope handleLegacyMessage(MessageContext msgContext, Object message) {
-
- SOAPFactory soapFactory = new SOAP11Factory();
- SOAPEnvelope envelope;
-
- if (log.isDebugEnabled()) {
- log.debug("Non SOAP/XML message received");
- }
-
- // pick the name of the element that will act as the wrapper element for the
- // non-xml payload. If service doesn't define one, default
- Parameter wrapperParam = msgContext.getAxisService().
- getParameter(BaseConstants.WRAPPER_PARAM);
-
- QName wrapperQName = null;
- OMElement wrapper = null;
- if (wrapperParam != null) {
- wrapperQName = BaseUtils.getQNameFromString(wrapperParam.getValue());
- }
-
- String textPayload = getMessageTextPayload(message);
- if (textPayload != null) {
- OMTextImpl textData = (OMTextImpl) soapFactory.createOMText(textPayload);
-
- if (wrapperQName == null) {
- wrapperQName = BaseConstants.DEFAULT_TEXT_WRAPPER;
- }
- wrapper = soapFactory.createOMElement(wrapperQName, null);
- wrapper.addChild(textData);
-
- } else {
- byte[] msgBytes = getMessageBinaryPayload(message);
- if (msgBytes != null) {
- DataHandler dataHandler = new DataHandler(new ByteArrayDataSource(msgBytes));
- OMText textData = soapFactory.createOMText(dataHandler, true);
- if (wrapperQName == null) {
- wrapperQName = BaseConstants.DEFAULT_BINARY_WRAPPER;
- }
- wrapper = soapFactory.createOMElement(wrapperQName, null);
- wrapper.addChild(textData);
- msgContext.setDoingMTOM(true);
-
- } else {
- Map msgMap = getMessageMapPayload(message);
- if (msgMap != null) {
- if (wrapperQName == null) {
- wrapperQName = BaseConstants.DEFAULT_MAP_WRAPPER;
- }
- OMSourcedElement omData = soapFactory.createOMElement(new MapDataSource(msgMap,
- wrapperQName.getLocalPart(), soapFactory.createOMNamespace(wrapperQName.getNamespaceURI(), wrapperQName.getPrefix())),
- wrapperQName.getLocalPart(), soapFactory.createOMNamespace(wrapperQName.getNamespaceURI(), wrapperQName.getPrefix()));
- wrapper = (OMElement) omData;
- } else {
- handleException("Unable to read payload from message of type : "
- + message.getClass().getName());
- }
- }
- }
-
- envelope = soapFactory.getDefaultEnvelope();
- envelope.getBody().addChild(wrapper);
-
- return envelope;
- }
-
- /**
- * Get a String property from a message
- *
- * @param message the message object
- * @param property property name
- * @return property value
- */
- public abstract String getProperty(Object message, String property);
-
- /**
- * Get an InputStream to the message payload
- *
- * @param message Object
- * @return an InputStream to the payload
- */
- public abstract InputStream getInputStream(Object message);
-
- /**
- * Get the message payload as a String, if the message is a non-SOAP, non-XML, plain text message
- *
- * @param message the message Object
- * @return the plain text payload of the message if applicable
- */
- public abstract String getMessageTextPayload(Object message);
-
- /**
- * Get the message payload as a byte[], if the message is a non-SOAP, non-XML, binary message
- *
- * @param message the message Object
- * @return the payload of the message as a byte[]
- */
- public abstract byte[] getMessageBinaryPayload(Object message);
-
- /**
- * Get the message payload as a Map, if the message is a non-SOAP, non-XML, binary Map-based message
- *
- * @param message the message Object
- * @return the payload of the message as a Map
- */
- public abstract Map getMessageMapPayload(Object message);
-
protected static void handleException(String s) {
log.error(s);
throw new BaseTransportException(s);
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=709899&r1=709898&r2=709899&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 Sun Nov 2 10:10:36 2008
@@ -53,6 +53,11 @@
<Export-Package>
org.apache.axis2.transport.jms.*;-split-package:=merge-last,
</Export-Package>
+ <Import-Package>
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ *; resolution:=optional
+ </Import-Package>
</instructions>
</configuration>
</plugin>
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.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/JMSConnectionFactory.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConnectionFactory.java Sun Nov 2 10:10:36 2008
@@ -524,6 +524,10 @@
log.error("JMS connection factory " + name + " encountered an error", e);
boolean wasError = true;
+ if (jmsListener != null) {
+ jmsListener.error(null, e);
+ }
+
// try to connect
// if error occurs wait and try again
while (wasError == true) {
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.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/JMSConstants.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSConstants.java Sun Nov 2 10:10:36 2008
@@ -81,7 +81,10 @@
* The Parameter name indicating the JMS connection factory JNDI name
*/
public static final String CONFAC_JNDI_NAME_PARAM = "transport.jms.ConnectionFactoryJNDIName";
-
+ /**
+ * The parameter indicating the expected content type for messages received by the service.
+ */
+ public static final String CONTENT_TYPE_PARAM = "transport.jms.ContentType";
//------------ message context / transport header properties and client options ------------
/**
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.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/JMSListener.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSListener.java Sun Nov 2 10:10:36 2008
@@ -26,6 +26,9 @@
import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.base.BaseUtils;
import org.apache.axis2.transport.base.ManagementSupport;
+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 java.util.HashMap;
import java.util.Map;
@@ -52,7 +55,8 @@
* <parameter name="transport.jms.Destination" locked="true">
* dynamicTopics/something.TestTopic</parameter>
*/
-public class JMSListener extends AbstractTransportListener implements ManagementSupport {
+public class JMSListener extends AbstractTransportListener implements ManagementSupport,
+ TransportErrorSource {
public static final String TRANSPORT_NAME = Constants.TRANSPORT_JMS;
@@ -60,6 +64,8 @@
/** A Map of service name to the JMS EPR addresses */
private Map<String,String> serviceNameToEPRMap = new HashMap<String,String>();
+ private final TransportErrorSourceSupport tess = new TransportErrorSourceSupport(this);
+
/**
* This is the TransportListener initialization method invoked by Axis2
*
@@ -237,4 +243,16 @@
handleException("Error shutting down the listener for maintenence", e);
}
}
+
+ public void addErrorListener(TransportErrorListener listener) {
+ tess.addErrorListener(listener);
+ }
+
+ public void removeErrorListener(TransportErrorListener listener) {
+ tess.removeErrorListener(listener);
+ }
+
+ void error(AxisService service, Throwable ex) {
+ tess.error(service, ex);
+ }
}
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.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/JMSMessageReceiver.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java Sun Nov 2 10:10:36 2008
@@ -15,7 +15,6 @@
*/
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;
@@ -161,10 +160,10 @@
msgContext.setProperty(JMSConstants.JMS_COORELATION_ID, message.getJMSMessageID());
} catch (JMSException ignore) {}
+ AxisService service = null;
try {
- String soapAction = JMSUtils.getInstace().
+ String soapAction = JMSUtils.
getProperty(message, BaseConstants.SOAPACTION);
- AxisService service = null;
// set to bypass dispatching if we know the service - we already should!
if (serviceName != null) {
@@ -205,11 +204,16 @@
}
}
- String contentType =
- JMSUtils.getInstace().getProperty(message, BaseConstants.CONTENT_TYPE);
+ String contentType = null;
+ if (service != null) {
+ contentType = (String)service.getParameterValue(JMSConstants.CONTENT_TYPE_PARAM);
+ }
+ if (contentType == null) {
+ contentType
+ = JMSUtils.getProperty(message, BaseConstants.CONTENT_TYPE);
+ }
- // set the message payload to the message context
- JMSUtils.getInstace().setSOAPEnvelope(message, msgContext, contentType);
+ JMSUtils.setSOAPEnvelope(message, msgContext, contentType);
jmsListener.handleIncomingMessage(
msgContext,
@@ -219,12 +223,10 @@
);
metrics.incrementMessagesReceived();
- } catch (JMSException e) {
- handleException("JMS Exception reading the message Destination or JMS ReplyTo", e);
- metrics.incrementFaultsReceiving();
- } catch (AxisFault e) {
- handleException("Axis fault creating a MessageContext", e);
+ } catch (Throwable e) {
metrics.incrementFaultsReceiving();
+ jmsListener.error(service, e);
+ log.error("Exception while processing incoming message", e);
}
}
}
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.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/JMSSender.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java Sun Nov 2 10:10:36 2008
@@ -627,15 +627,19 @@
// workaround as Axis2 1.2 is about to be released and Synapse 1.0
responseMsgCtx.setServerSide(false);
- String contentType = JMSUtils.getInstace().getProperty(message, BaseConstants.CONTENT_TYPE);
+ String contentType = JMSUtils.getProperty(message, BaseConstants.CONTENT_TYPE);
- JMSUtils.getInstace().setSOAPEnvelope(message, responseMsgCtx, contentType);
+ try {
+ JMSUtils.setSOAPEnvelope(message, responseMsgCtx, contentType);
+ } catch (JMSException ex) {
+ throw AxisFault.makeFault(ex);
+ }
// responseMsgCtx.setServerSide(true);
handleIncomingMessage(
responseMsgCtx,
JMSUtils.getTransportHeaders(message),
- JMSUtils.getInstace().getProperty(message, BaseConstants.SOAPACTION),
+ JMSUtils.getProperty(message, BaseConstants.SOAPACTION),
contentType
);
}
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=709899&r1=709898&r2=709899&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 Sun Nov 2 10:10:36 2008
@@ -16,27 +16,32 @@
package org.apache.axis2.transport.jms;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
+import org.apache.axis2.builder.Builder;
import org.apache.axis2.builder.BuilderUtil;
+import org.apache.axis2.builder.SOAPBuilder;
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.description.AxisService;
import org.apache.axis2.description.Parameter;
import org.apache.axis2.description.ParameterIncludeImpl;
+import org.apache.axis2.format.TextMessageBuilder;
+import org.apache.axis2.format.TextMessageBuilderAdapter;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.axis2.transport.base.BaseConstants;
+import org.apache.axis2.transport.TransportUtils;
import org.apache.axis2.transport.base.BaseUtils;
import javax.jms.*;
import javax.jms.Queue;
+import javax.mail.internet.ContentType;
+import javax.mail.internet.ParseException;
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.Reference;
+import javax.xml.stream.XMLStreamException;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.InputStream;
-import java.io.UnsupportedEncodingException;
import java.lang.reflect.Method;
import java.util.*;
@@ -49,12 +54,6 @@
private static final Class[] NOARGS = new Class[] {};
private static final Object[] NOPARMS = new Object[] {};
- private static BaseUtils _instance = new JMSUtils();
-
- public static BaseUtils getInstace() {
- return _instance;
- }
-
/**
* Create a JMS Queue using the given connection with the JNDI destination name, and return the
* JMS Destination name of the created queue
@@ -217,10 +216,9 @@
* @param property property name
* @return property value
*/
- @Override
- public String getProperty(Object message, String property) {
+ public static String getProperty(Message message, String property) {
try {
- return ((Message)message).getStringProperty(property);
+ return message.getStringProperty(property);
} catch (JMSException e) {
return null;
}
@@ -296,40 +294,57 @@
}
}
- /**
- * Get an InputStream to the JMS message payload
- *
- * @param message the JMS message
- * @return an InputStream to the payload
- */
- @Override
- public InputStream getInputStream(Object message) {
-
- try {
- if (message instanceof BytesMessage) {
- byte[] buffer = new byte[1024];
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- BytesMessage byteMsg = (BytesMessage) message;
- byteMsg.reset();
- for (int bytesRead = byteMsg.readBytes(buffer); bytesRead != -1;
- bytesRead = byteMsg.readBytes(buffer)) {
- out.write(buffer, 0, bytesRead);
+ public static void setSOAPEnvelope(Message message, MessageContext msgContext, String contentType) throws AxisFault, JMSException {
+ if (message instanceof BytesMessage) {
+ if (contentType == null) {
+ log.debug("No content type specified; assuming application/octet-stream.");
+ contentType = "application/octet-stream";
+ } else {
+ // Extract the charset encoding from the content type and
+ // set the CHARACTER_SET_ENCODING property as e.g. SOAPBuilder relies on this.
+ String charSetEnc = null;
+ try {
+ if (contentType != null) {
+ charSetEnc = new ContentType(contentType).getParameter("charset");
+ }
+ } catch (ParseException ex) {
+ // ignore
}
- return new ByteArrayInputStream(out.toByteArray());
-
- } else if (message instanceof TextMessage) {
- TextMessage txtMsg = (TextMessage) message;
- String contentType = getProperty(txtMsg, BaseConstants.CONTENT_TYPE);
-
- if (contentType != null) {
- return new ByteArrayInputStream(
- txtMsg.getText().getBytes(BuilderUtil.getCharSetEncoding(contentType)));
+ msgContext.setProperty(Constants.Configuration.CHARACTER_SET_ENCODING, charSetEnc);
+ }
+
+ SOAPEnvelope envelope;
+ try {
+ envelope = TransportUtils.createSOAPMessage(msgContext,
+ new BytesMessageInputStream((BytesMessage)message), contentType);
+ } catch (XMLStreamException ex) {
+ handleException("Error parsing XML", ex);
+ return; // Make compiler happy
+ }
+ msgContext.setEnvelope(envelope);
+ } else if (message instanceof TextMessage) {
+ String type;
+ if (contentType == null) {
+ log.debug("No content type specified; assuming text/plain.");
+ type = contentType = "text/plain";
+ } else {
+ int index = contentType.indexOf(';');
+ if (index > 0) {
+ type = contentType.substring(0, index);
} else {
- return new ByteArrayInputStream(
- txtMsg.getText().getBytes(MessageContext.DEFAULT_CHAR_SET_ENCODING));
+ 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();
+ }
+ TextMessageBuilder textMessageBuilder;
+ if (builder instanceof TextMessageBuilder) {
+ textMessageBuilder = (TextMessageBuilder)builder;
} else if (message instanceof MapMessage) {
MapMessage mapMsg = (MapMessage) message;
String contentType = getProperty(mapMsg, BaseConstants.CONTENT_TYPE);
@@ -341,15 +356,13 @@
}
} else {
- handleException("Unsupported JMS message type : " + message.getClass().getName());
+ textMessageBuilder = new TextMessageBuilderAdapter(builder);
}
-
- } catch (JMSException e) {
- handleException("JMS Exception reading message payload", e);
- } catch (UnsupportedEncodingException e) {
- handleException("Encoding exception getting InputStream into message", e);
+ String content = ((TextMessage)message).getText();
+ OMElement documentElement
+ = textMessageBuilder.processDocument(content, contentType, msgContext);
+ msgContext.setEnvelope(TransportUtils.createSOAPEnvelope(documentElement));
}
- return null;
}
/**
@@ -695,43 +708,6 @@
}
- @Override
- public String getMessageTextPayload(Object message) {
- if (message instanceof TextMessage) {
- try {
- return ((TextMessage) message).getText();
- } catch (JMSException e) {
- handleException("Error reading JMS text message payload", e);
- }
- }
- return null;
- }
-
- @Override
- public byte[] getMessageBinaryPayload(Object message) {
-
- if (message instanceof BytesMessage) {
- BytesMessage bytesMessage = (BytesMessage) message;
-
- try {
- bytesMessage.reset();
-
- byte[] buffer = new byte[1024];
- ByteArrayOutputStream out = new ByteArrayOutputStream();
-
- for (int bytesRead = bytesMessage.readBytes(buffer); bytesRead != -1;
- bytesRead = bytesMessage.readBytes(buffer)) {
- out.write(buffer, 0, bytesRead);
- }
- return out.toByteArray();
-
- } catch (JMSException e) {
- handleException("Error reading JMS binary message payload", e);
- }
- }
- return null;
- }
-
public Map getMessageMapPayload(Object message) {
if (message instanceof MapMessage) {
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/mail/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/mail/pom.xml?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/mail/pom.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/mail/pom.xml Sun Nov 2 10:10:36 2008
@@ -53,6 +53,11 @@
<Export-Package>
org.apache.axis2.transport.mail.*;-split-package:=merge-last,
</Export-Package>
+ <Import-Package>
+ !javax.xml.namespace,
+ javax.xml.namespace; version=0.0.0,
+ *; resolution:=optional
+ </Import-Package>
</instructions>
</configuration>
</plugin>
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/parent/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/parent/pom.xml?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/parent/pom.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/parent/pom.xml Sun Nov 2 10:10:36 2008
@@ -286,6 +286,11 @@
<version>3.0.4</version>
</dependency>
<dependency>
+ <groupId>org.igniterealtime</groupId>
+ <artifactId>smackx</artifactId>
+ <version>3.0.4</version>
+ </dependency>
+ <dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
<version>2.3</version>
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/JMSTransportTest.java Sun Nov 2 10:10:36 2008
@@ -50,8 +50,6 @@
"(&(test=AsyncXML)(messageType=SOAP11)(data=ASCII))" +
"(&(test=EchoXML)(messageType=POX)(data=ASCII))))");
- // SYNAPSE-304:
- suite.addExclude("(&(test=AsyncTextPlain)(client=jms)(jmsType=bytes))");
// SYNAPSE-436:
suite.addExclude("(&(test=EchoXML)(replyDestType=topic)(endpoint=axis))");
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/tests/src/test/java/org/apache/axis2/transport/jms/MockEchoEndpoint.java Sun Nov 2 10:10:36 2008
@@ -34,6 +34,7 @@
import javax.jms.Session;
import javax.jms.TextMessage;
+import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.testkit.endpoint.InOutEndpoint;
import org.apache.axis2.transport.testkit.endpoint.InOutEndpointSupport;
import org.apache.axis2.transport.testkit.name.Name;
@@ -87,6 +88,7 @@
throw new UnsupportedOperationException("Unsupported message type");
}
reply.setJMSCorrelationID(message.getJMSMessageID());
+ reply.setStringProperty(BaseConstants.CONTENT_TYPE, message.getStringProperty(BaseConstants.CONTENT_TYPE));
producer.send(reply);
log.info("Message sent: ID = " + reply.getJMSMessageID());
} catch (Throwable ex) {
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/xmpp/pom.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/xmpp/pom.xml?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/xmpp/pom.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/modules/xmpp/pom.xml Sun Nov 2 10:10:36 2008
@@ -83,7 +83,11 @@
<dependency>
<groupId>org.igniterealtime</groupId>
<artifactId>smack</artifactId>
- </dependency>
+ </dependency>
+ <dependency>
+ <groupId>org.igniterealtime</groupId>
+ <artifactId>smackx</artifactId>
+ </dependency>
<dependency>
<groupId>commons-lang</groupId>
<artifactId>commons-lang</artifactId>
Modified: webservices/commons/trunk/scratch/senaka/sci-flex/transport/src/site/xdoc/jms.xml
URL: http://svn.apache.org/viewvc/webservices/commons/trunk/scratch/senaka/sci-flex/transport/src/site/xdoc/jms.xml?rev=709899&r1=709898&r2=709899&view=diff
==============================================================================
--- webservices/commons/trunk/scratch/senaka/sci-flex/transport/src/site/xdoc/jms.xml (original)
+++ webservices/commons/trunk/scratch/senaka/sci-flex/transport/src/site/xdoc/jms.xml Sun Nov 2 10:10:36 2008
@@ -52,72 +52,47 @@
<section name="Service configuration">
<table class="bodyTable">
<tr>
- <th>
- Parameter
- </th>
- <th>
- Require
- </th>
- <th>
- Description
- </th>
- </tr>
- <tr>
- <td>
- transport.jms.ConnectionFactory
- </td>
- <td>
- Optional
- </td>
- <td>
- The JMS connection factory definition (from axis2.xml) to be used to
- listen for messages for this service
- </td>
- </tr>
- <tr>
- <td>
- transport.jms.Destination
- </td>
- <td>
- Optional
- </td>
- <td>
- The JMS destination name (Defaults to a Queue with the service name)
- </td>
- </tr>
- <tr>
- <td>
- transport.jms.DestinationType
- </td>
- <td>
- Optional
- </td>
- <td>
- The JMS destination type. Accept values 'queue' or 'topic' (default:
- queue)
- </td>
- </tr>
- <tr>
- <td>
- transport.jms.ReplyDestination
- </td>
- <td>
- Optional
- </td>
- <td>
- The destination where a reply will be posted
- </td>
- </tr>
- <tr>
- <td>
- transport.jms.Wrapper
- </td>
- <td>
- Optional
- </td>
- <td>
- The wrapper element for the JMS message
- </td>
+ <th>Parameter</th>
+ <th>Require</th>
+ <th>Description</th>
+ </tr>
+ <tr>
+ <td>transport.jms.ConnectionFactory</td>
+ <td>Optional</td>
+ <td>The JMS connection factory definition (from axis2.xml) to be used to
+ listen for messages for this service.</td>
+ </tr>
+ <tr>
+ <td>transport.jms.Destination</td>
+ <td>Optional</td>
+ <td>The JMS destination name (Defaults to a Queue with the service name).</td>
+ </tr>
+ <tr>
+ <td>transport.jms.DestinationType</td>
+ <td>Optional</td>
+ <td>The JMS destination type. Accept values 'queue' or 'topic' (default:
+ queue).</td>
+ </tr>
+ <tr>
+ <td>transport.jms.ReplyDestination</td>
+ <td>Optional</td>
+ <td>The destination where a reply will be posted.</td>
+ </tr>
+ <tr>
+ <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>
+ </tr>
+ <tr>
+ <td>Wrapper</td>
+ <td>Optional</td>
+ <td>The wrapper element for pure text or binary messages. Note that this parameter is
+ actually not JMS specific but recognized by the message builders for text/plain and
+ application/octet-stream (which are the respective default content types for JMS text
+ and binary messages).</td>
</tr>
</table>
<p>Sample services.xml:</p>