Author: veithen
Date: Wed Oct 29 14:29:35 2008
New Revision: 709016
URL: http://svn.apache.org/viewvc?rev=709016&view=rev
Log:
SYNAPSE-304:
* Moved BaseUtils#setSOAPEnvelope and related methods to AMQPUtils, since this
is the last transport relying on this method and we don't want new transports
to use it.
* Removed dead code from JMSUtils and VFSUtils.
Modified:
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSMessageReceiver.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
Modified:
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java?rev=709016&r1=709015&r2=709016&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/base/src/main/java/org/apache/axis2/transport/base/BaseUtils.java
Wed Oct 29 14:29:35 2008
@@ -23,32 +23,18 @@
import java.io.InputStream;
import java.util.List;
-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.OMText;
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;
@@ -62,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);
@@ -175,197 +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 {
- 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);
-
protected static void handleException(String s) {
log.error(s);
throw new BaseTransportException(s);
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=709016&r1=709015&r2=709016&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
Wed Oct 29 14:29:35 2008
@@ -160,7 +160,7 @@
AxisService service = null;
try {
- String soapAction = JMSUtils.getInstace().
+ String soapAction = JMSUtils.
getProperty(message, BaseConstants.SOAPACTION);
// set to bypass dispatching if we know the service - we
already should!
@@ -208,7 +208,7 @@
}
if (contentType == null) {
contentType
- = JMSUtils.getInstace().getProperty(message,
BaseConstants.CONTENT_TYPE);
+ = JMSUtils.getProperty(message,
BaseConstants.CONTENT_TYPE);
}
JMSUtils.setSOAPEnvelope(message, msgContext, contentType);
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java?rev=709016&r1=709015&r2=709016&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSSender.java
Wed Oct 29 14:29:35 2008
@@ -518,7 +518,7 @@
// 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);
try {
JMSUtils.setSOAPEnvelope(message, responseMsgCtx, contentType);
@@ -530,7 +530,7 @@
handleIncomingMessage(
responseMsgCtx,
JMSUtils.getTransportHeaders(message),
- JMSUtils.getInstace().getProperty(message,
BaseConstants.SOAPACTION),
+ JMSUtils.getProperty(message, BaseConstants.SOAPACTION),
contentType
);
}
Modified:
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java?rev=709016&r1=709015&r2=709016&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/jms/src/main/java/org/apache/axis2/transport/jms/JMSUtils.java
Wed Oct 29 14:29:35 2008
@@ -16,7 +16,6 @@
package org.apache.axis2.transport.jms;
import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.OMException;
import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
import org.apache.axis2.Constants;
@@ -32,7 +31,6 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.axis2.transport.TransportUtils;
-import org.apache.axis2.transport.base.BaseConstants;
import org.apache.axis2.transport.base.BaseUtils;
import javax.jms.*;
@@ -42,13 +40,8 @@
import javax.naming.Context;
import javax.naming.NamingException;
import javax.naming.Reference;
-import javax.xml.parsers.FactoryConfigurationError;
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.*;
@@ -61,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
@@ -229,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;
}
@@ -370,52 +356,6 @@
}
/**
- * 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);
- }
- 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)));
- } else {
- return new ByteArrayInputStream(
-
txtMsg.getText().getBytes(MessageContext.DEFAULT_CHAR_SET_ENCODING));
- }
-
- } else {
- handleException("Unsupported JMS message type : " +
message.getClass().getName());
- }
-
- } catch (JMSException e) {
- handleException("JMS Exception reading message payload", e);
- } catch (UnsupportedEncodingException e) {
- handleException("Encoding exception getting InputStream into
message", e);
- }
- return null;
- }
-
- /**
* Set the JMS ReplyTo for the message
*
* @param replyDestination the JMS Destination where the reply is expected
@@ -758,43 +698,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;
- }
-
// ----------- JMS 1.0.2b compatibility methods -------------
public static Connection createConnection(ConnectionFactory conFactory,
String user,
String pass, String destinationType) throws JMSException {