Author: ruwan
Date: Tue Oct 2 02:35:18 2007
New Revision: 581170
URL: http://svn.apache.org/viewvc?rev=581170&view=rev
Log:
Clone Mediator modified according the logging and tracing refactoring and added
the Iterate Mediator
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPConstants.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorFactory.java
Tue Oct 2 02:35:18 2007
@@ -40,9 +40,14 @@
protected static final QName ATT_KEY = new QName("key");
protected static final QName ATT_SOURCE = new QName("source");
protected static final QName ATT_ONERROR = new QName("onError");
- protected static final QName ATT_STATS = new
QName(XMLConfigConstants.STATISTICS_ATTRIB_NAME);
- protected static final QName PROP_Q = new
QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property");
- protected static final QName FEATURE_Q = new
QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "feature");
+ protected static final QName ATT_STATS
+ = new QName(XMLConfigConstants.STATISTICS_ATTRIB_NAME);
+ protected static final QName PROP_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property");
+ protected static final QName FEATURE_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "feature");
+ protected static final QName TARGET_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "target");
/**
* A constructor that makes subclasses pick up the correct logger
@@ -74,13 +79,13 @@
}
}
- protected static void handleException(String message, Exception e) {
- log.error(message, e);
+ protected void handleException(String message, Exception e) {
+ LogFactory.getLog(this.getClass()).error(message, e);
throw new SynapseException(message, e);
}
- protected static void handleException(String message) {
- log.error(message);
+ protected void handleException(String message) {
+ LogFactory.getLog(this.getClass()).error(message);
throw new SynapseException(message);
}
}
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractMediatorSerializer.java
Tue Oct 2 02:35:18 2007
@@ -44,7 +44,8 @@
= fac.createOMNamespace(XMLConfigConstants.SYNAPSE_NAMESPACE,
"syn");
protected static final OMNamespace nullNS
= fac.createOMNamespace(XMLConfigConstants.NULL_NAMESPACE, "");
- protected static final QName PROP_Q = new
QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property", "syn");
+ protected static final QName PROP_Q
+ = new QName(XMLConfigConstants.SYNAPSE_NAMESPACE, "property", "syn");
/**
* A constructor that makes subclasses pick up the correct logger
@@ -116,13 +117,13 @@
}
}
- protected static void handleException(String msg) {
- log.error(msg);
+ protected void handleException(String msg) {
+ LogFactory.getLog(this.getClass()).error(msg);
throw new SynapseException(msg);
}
- protected static void handleException(String msg, Exception e) {
- log.error(msg, e);
+ protected void handleException(String msg, Exception e) {
+ LogFactory.getLog(this.getClass()).error(msg, e);
throw new SynapseException(msg, e);
}
}
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/CloneMediatorSerializer.java
Tue Oct 2 02:35:18 2007
@@ -43,10 +43,11 @@
/**
* This method will implement the serializeMediator method of the
MediatorSerializer interface
+ * and implements the serialization of CloneMediator to its configuration
*
- * @param parent - OMElement describing the parent element to which the
newlly generated
- * clone element should be attached as a child, if provided
- * @param m - Mediator of the type CloneMediator which is subjected to the
serialization
+ * @param parent OMElement describing the parent element to which the
newlly generated
+ * clone element should be attached as a child, if provided
+ * @param m Mediator of the type CloneMediator which is subjected to the
serialization
* @return OMElement serialized in to xml from the given parameters
*/
public OMElement serializeMediator(OMElement parent, Mediator m) {
@@ -78,8 +79,7 @@
* This method will implement the getMediatorClassName method of the
* MediatorSerializer interface
*
- * @return String representing the full class name of the Mediator
- * which is serialized by this Serializer
+ * @return full class name of the Mediator which is serialized by this
Serializer
*/
public String getMediatorClassName() {
return CloneMediator.class.getName();
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorFactory.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorFactory.java?rev=581170&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorFactory.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorFactory.java
Tue Oct 2 02:35:18 2007
@@ -0,0 +1,133 @@
+/*
+ * 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.synapse.config.xml;
+
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseConstants;
+import org.apache.synapse.mediators.eip.splitter.IterateMediator;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.jaxen.JaxenException;
+
+import javax.xml.namespace.QName;
+
+/**
+ * The <iterate> element is used to split messages in Synapse to smaller
messages with only
+ * one part of the elements described in the XPATH expression.
+ * <p/>
+ * <pre>
+ * <iterate continueParent=(true | false) preservePayload=(true | false)
+ * expression="XPATH
expression">
+ * <target to="TO address" [soapAction="urn:Action"] sequence="sequence
ref"
+ * endpoint="endpoint
ref">
+ * <sequence> (mediator +) </sequence>
+ * <endpoint> endpoint </endpoint>
+ * </target>
+ * </iterate>
+ * </pre>
+ */
+public class IterateMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log =
LogFactory.getLog(IterateMediatorFactory.class);
+
+ /**
+ * Holds the QName for the IterateMeditor xml configuration
+ */
+ private static final QName ITERATE_Q = new
QName(SynapseConstants.SYNAPSE_NAMESPACE, "iterate");
+ private static final QName ATT_CONTPAR = new QName("continueParent");
+ private static final QName ATT_PREPLD = new QName("preservePayload");
+ private static final QName ATT_ATTACHPATH = new QName("attachPath");
+
+ /**
+ * This method will create the IterateMediator by parsing the given xml
configuration
+ *
+ * @param elem OMElement describing the configuration of the
IterateMediaotr
+ * @return IterateMediator created from the given configuration
+ */
+ public Mediator createMediator(OMElement elem) {
+
+ IterateMediator mediator = new IterateMediator();
+ processTraceState(mediator, elem);
+
+ OMAttribute continueParent = elem.getAttribute(ATT_CONTPAR);
+ if (continueParent != null) {
+ mediator.setContinueParent(
+
Boolean.valueOf(continueParent.getAttributeValue()).booleanValue());
+ }
+
+ OMAttribute preservePayload = elem.getAttribute(ATT_PREPLD);
+ if (preservePayload != null) {
+ mediator.setPreservePayload(
+
Boolean.valueOf(preservePayload.getAttributeValue()).booleanValue());
+ }
+
+ OMAttribute expression = elem.getAttribute(ATT_EXPRN);
+ if (expression != null) {
+ try {
+ AXIOMXPath xp = new AXIOMXPath(expression.getAttributeValue());
+ OMElementUtils.addNameSpaces(xp, elem, log);
+ mediator.setExpression(xp);
+ } catch (JaxenException e) {
+ handleException("Unable to build the IterateMediator. " +
"Invalid XPATH " +
+ expression.getAttributeValue(), e);
+ }
+ } else {
+ handleException("XPATH expression is required " +
+ "for an IterateMediator under the \"expression\" attribute");
+ }
+
+ OMAttribute attachPath = elem.getAttribute(ATT_ATTACHPATH);
+ String attachPathValue = ".";
+ if (attachPath != null && !mediator.isPreservePayload()) {
+ handleException("Wrong configuration for the iterate mediator ::
if the iterator " +
+ "should not preserve payload, then attachPath can not be
present");
+ } else if (attachPath != null) {
+ attachPathValue = attachPath.getAttributeValue();
+ }
+
+ try {
+ AXIOMXPath xp = new AXIOMXPath(attachPathValue);
+ OMElementUtils.addNameSpaces(xp, elem, log);
+ mediator.setAttachPath(xp);
+ } catch (JaxenException e) {
+ handleException("Unable to build the IterateMediator. Invalid
XPATH " +
+ attachPathValue, e);
+ }
+
+ OMElement targetElement = elem.getFirstChildWithName(TARGET_Q);
+ if (targetElement != null) {
+ mediator.setTarget(TargetFactory.createTarget(targetElement));
+ }
+
+ return mediator;
+ }
+
+ /**
+ * Get the IterateMediator configuration tag name
+ *
+ * @return QName specifying the IterateMediator tag name of the xml
configuration
+ */
+ public QName getTagQName() {
+ return ITERATE_Q;
+ }
+}
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorSerializer.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorSerializer.java?rev=581170&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorSerializer.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/IterateMediatorSerializer.java
Tue Oct 2 02:35:18 2007
@@ -0,0 +1,95 @@
+/*
+ * 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.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.eip.splitter.IterateMediator;
+
+/**
+ * This class will be acting as the serializer for the IterateMediator which
will convert the
+ * IterateMediator instance to the following xml configuration
+ *
+ * <pre>
+ * <iterate continueParent=(true | false) expression="XPATH expression">
+ * <target to="TO address" [soapAction="urn:Action"] sequence="sequence
ref"
+ * endpoint="endpoint
ref">
+ * <sequence> (mediator +) </sequence>
+ * <endpoint> endpoint </endpoint>
+ * </target>
+ * </iterate>
+ * </pre>
+ */
+public class IterateMediatorSerializer extends AbstractMediatorSerializer {
+
+ /**
+ * This method will implement the serialization logic of the
IterateMediator class to the
+ * relevant xml configuration
+ *
+ * @param parent
+ * OMElement specifying the parent element to which the
created configurtaion
+ * element will be attached
+ *
+ * @param m
+ * IterateMediator to be serialized
+ *
+ * @return OMElement describing the serialized configuration of the
IterateMediator
+ */
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof IterateMediator)) {
+ handleException("Unsupported mediator passed in for serialization
: " + m.getType());
+ }
+
+ OMElement itrElem = fac.createOMElement("iterate", synNS);
+ saveTracingState(itrElem, m);
+
+ IterateMediator itrMed = (IterateMediator) m;
+ if (itrMed.isContinueParent()) {
+ itrElem.addAttribute("continueParent", Boolean.toString(true),
nullNS);
+ }
+
+ if (itrMed.getExpression() != null) {
+ itrElem.addAttribute("expression",
itrMed.getExpression().toString(), nullNS);
+ serializeNamespaces(itrElem, itrMed.getExpression());
+ } else {
+ handleException("Missing expression of the IterateMediator which
is required.");
+ }
+
+ itrElem.addChild(TargetSerializer.serializeTarget(itrMed.getTarget()));
+
+ // attach the serialized element to the parent if specified
+ if (parent != null) {
+ parent.addChild(itrElem);
+ }
+
+ return itrElem;
+ }
+
+ /**
+ * This method implements the getMediatorClassName of the interface
MediatorSerializer and
+ * will be used in getting the mediator class name which will be
serialized by this serializer
+ *
+ * @return String representing the full class name of the mediator
+ */
+ public String getMediatorClassName() {
+ return IterateMediator.class.getName();
+ }
+}
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
Tue Oct 2 02:35:18 2007
@@ -64,6 +64,7 @@
XSLTMediatorFactory.class,
POJOCommandMediatorFactory.class,
CloneMediatorFactory.class,
+ IterateMediatorFactory.class,
DBReportMediatorFactory.class,
DBLookupMediatorFactory.class
};
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
Tue Oct 2 02:35:18 2007
@@ -52,6 +52,7 @@
XSLTMediatorSerializer.class,
POJOCommandMediatorSerializer.class,
CloneMediatorSerializer.class,
+ IterateMediatorSerializer.class,
DBLookupMediatorSerializer.class,
DBReportMediatorSerializer.class
};
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPConstants.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPConstants.java?rev=581170&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPConstants.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPConstants.java
Tue Oct 2 02:35:18 2007
@@ -0,0 +1,33 @@
+/*
+ * 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.synapse.mediators.eip;
+
+/** Holds all the constants related to the eip mediators */
+public final class EIPConstants {
+
+ /** Constant for the corelation property key */
+ public static final String AGGREGATE_CORELATION = "aggregateCorelation";
+
+ /** Constant for the message sequence property key */
+ public static final String MESSAGE_SEQUENCE = "messageSequence";
+
+ /** Delimeter for the message sequence value */
+ public static final String MESSAGE_SEQUENCE_DELEMITER = "/";
+}
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/EIPUtils.java
Tue Oct 2 02:35:18 2007
@@ -19,18 +19,12 @@
package org.apache.synapse.mediators.eip;
-import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
import org.apache.axiom.om.OMNode;
import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.axiom.soap.SOAP11Constants;
import org.apache.axiom.soap.SOAPEnvelope;
-import org.apache.axis2.AxisFault;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.jaxen.JaxenException;
import java.util.ArrayList;
@@ -42,12 +36,6 @@
*/
public class EIPUtils {
- public static final String AGGREGATE_CORELATION = "aggregateCorelation";
-
- public static final String MESSAGE_SEQUENCE = "messageSequence";
-
- public static final String MESSAGE_SEQUENCE_DELEMITER = "/";
-
/**
* This will be used for logging purposes
*/
@@ -56,147 +44,77 @@
/**
* This static util method will be used to extract out the set of all
elements described by the
* given XPath over the given SOAPEnvelope
- *
- * @param envelope - SOAPEnvelope from which the the elements will be
extracted
- * @param expression - AXIOMXPath expression describing the elements
+ *
+ * @param envelope SOAPEnvelope from which the the elements will be
extracted
+ * @param expression AXIOMXPath expression describing the elements
* @return List of OMElements in the envelope matching the expression
+ * @throws JaxenException if the XPath expression evaluation fails for
some reason
*/
-// asankha - 26 sep - pending review
-// public static List getElements(SOAPEnvelope envelope, AXIOMXPath
expression) {
-// try {
-// Object o = expression.evaluate(envelope);
-// if (o instanceof OMNode) {
-// List list = new ArrayList();
-// list.add(o);
-// return list;
-// } else if (o instanceof List) {
-// return (List) o;
-// } else {
-// handleException("The evaluation of the XPath expression "
-// + expression + " must result in an OMNode");
-// }
-// } catch (JaxenException e) {
-// handleException("Error evaluating XPath " + expression + " on
message");
-// }
-//
-// return null;
-// }
+ public static List getMatchingElements(SOAPEnvelope envelope, AXIOMXPath
expression)
+ throws JaxenException {
+
+ Object o = expression.evaluate(envelope);
+ if (o instanceof OMNode) {
+ List list = new ArrayList();
+ list.add(o);
+ return list;
+ } else if (o instanceof List) {
+ return (List) o;
+ } else {
+ return null;
+ }
+ }
/**
- * This static util method will be used to create a new MessageContext by
passing the
- * MessageContext and the SOAPEnvelope to be filled with the newly created
MessageContext
- *
- * @param synCtx - MessageContext which is subjected to the creation of
the new MC
- * @param envelope - SOAPEnvelope to be set to the new MC
- * @return MessageContext created from the paased arguments
+ * @param envelope
+ * @param expression
+ * @return
+ * @throws JaxenException
*/
- public static MessageContext createNewMessageContext(
- MessageContext synCtx, SOAPEnvelope envelope) throws AxisFault {
+ public static List getDetachedMatchingElements(SOAPEnvelope envelope,
AXIOMXPath expression)
+ throws JaxenException {
- // create the message context and then copy the transportIn/Out from
the original message
- MessageContext newCtx = synCtx.getEnvironment().createMessageContext();
- org.apache.axis2.context.MessageContext axis2MC
- = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
- org.apache.axis2.context.MessageContext newAxis2MC
- = ((Axis2MessageContext) newCtx).getAxis2MessageContext();
-
- newAxis2MC.setTransportIn(axis2MC.getTransportIn());
- newAxis2MC.setTransportOut(axis2MC.getTransportOut());
-
- newAxis2MC.setServiceContext(axis2MC.getServiceContext());
- newAxis2MC.setOperationContext(axis2MC.getOperationContext());
- newAxis2MC.setAxisMessage(axis2MC.getAxisMessage());
- newAxis2MC.getAxisMessage().setParent(axis2MC.getAxisOperation());
- newAxis2MC.setAxisService(axis2MC.getAxisService());
-
- newAxis2MC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
-
axis2MC.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
-
- //try {
- newCtx.setEnvelope(envelope);
-
- // copy all the properties to the newCtx
- Iterator propItr = synCtx.getPropertyKeySet().iterator();
- while (propItr.hasNext()) {
- Object o = propItr.next();
- // If there are non String keyed properties neglect them
rathern than trow exception
- if (o instanceof String) {
- newCtx.setProperty((String) o, synCtx.getProperty((String)
o));
+ List elementList = new ArrayList();
+ Object o = expression.evaluate(envelope);
+ if (o instanceof OMNode) {
+ elementList.add(((OMNode) o).detach());
+ } else if (o instanceof List) {
+ for (Iterator itr = ((List) o).iterator(); itr.hasNext();) {
+ Object elem = itr.next();
+ if (elem instanceof OMNode) {
+ elementList.add(((OMNode) elem).detach());
}
}
-
- // set the parent details to the splitted MC
- newCtx.setProperty(AGGREGATE_CORELATION, synCtx.getMessageID());
-
- // set the parent properties to the splitted MC
- newCtx.setTo(synCtx.getTo());
- newCtx.setReplyTo(synCtx.getReplyTo());
- newCtx.setSoapAction(synCtx.getSoapAction());
- newCtx.setWSAAction(synCtx.getWSAAction());
-
-// asankha - 26 sep - pending review
-// } catch (AxisFault axisFault) {
-// handleException("Unable to split the message" +
axisFault.getMessage(), axisFault);
-// }
-
- return newCtx;
+ }
+ return elementList;
}
/**
* This static util method will be used to enrich the envelope passed, by
the element described
* by the XPath over the enricher envelope
- *
- * @param envelope - SOAPEnvelope to be enriched with the content
- * @param enricher - SOAPEnvelope from which the enriching element will be
extracted
- * @param expression - AXIOMXPath describing the enriching element
- */
-// asankha - 26 - sep - pending review
-// public static void enrichEnvelope(SOAPEnvelope envelope,
-// SOAPEnvelope enricher, AXIOMXPath
expression) {
-// OMElement enrichingElement;
-// Object o = getElements(envelope, expression).get(0);
-// if (o instanceof OMElement && ((OMElement) o).getParent() instanceof
OMElement) {
-// enrichingElement = (OMElement) ((OMElement) o).getParent();
-// } else {
-// enrichingElement = envelope.getBody();
-// }
-//
-// Iterator itr = getElements(enricher, expression).iterator();
-// while (itr.hasNext()) {
-// o = itr.next();
-// if (o != null && o instanceof OMElement) {
-// enrichingElement.addChild((OMElement) o);
-// }
-// }
-//
-// }
-
- /**
- * This static util method will be used to clone the SOAPEnvelope passed
to the method
- *
- * @param env - SOAPEnvelope to be cloned
- * @return SOAPEnvelope cloned from env
+ *
+ * @param envelope SOAPEnvelope to be enriched with the content
+ * @param enricher SOAPEnvelope from which the enriching element will be
extracted
+ * @param expression AXIOMXPath describing the enriching element
*/
- public static SOAPEnvelope cloneEnvelope(SOAPEnvelope env) {
-
- SOAPEnvelope envelope;
- if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI.equals(
- env.getBody().getNamespace().getNamespaceURI())) {
- envelope =
OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ public static void enrichEnvelope(SOAPEnvelope envelope, SOAPEnvelope
enricher,
+ AXIOMXPath expression) throws JaxenException {
+ OMElement enrichingElement;
+ Object o = getMatchingElements(envelope, expression).get(0);
+ if (o instanceof OMElement && ((OMElement) o).getParent() instanceof
OMElement) {
+ enrichingElement = (OMElement) ((OMElement) o).getParent();
} else {
- envelope =
OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
+ enrichingElement = envelope.getBody();
}
-
- Iterator itr = env.getHeader().getChildren();
- while (itr.hasNext()) {
- envelope.getHeader().addChild(((OMElement)
itr.next()).cloneOMElement());
- }
-
- itr = env.getBody().getChildren();
+
+ Iterator itr = getMatchingElements(enricher, expression).iterator();
while (itr.hasNext()) {
- envelope.getBody().addChild(((OMElement)
itr.next()).cloneOMElement());
+ o = itr.next();
+ if (o != null && o instanceof OMElement) {
+ enrichingElement.addChild((OMElement) o);
+ }
}
-
- return envelope;
+
}
+
}
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java?rev=581170&r1=581169&r2=581170&view=diff
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
(original)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/CloneMediator.java
Tue Oct 2 02:35:18 2007
@@ -19,26 +19,25 @@
package org.apache.synapse.mediators.eip.splitter;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.util.MessageHelper;
import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.mediators.eip.EIPUtils;
import org.apache.synapse.mediators.eip.Target;
+import org.apache.synapse.mediators.eip.EIPConstants;
import org.apache.axis2.AxisFault;
import java.util.ArrayList;
import java.util.List;
/**
- * This mediator will clone the message in to different messages and mediated
as specified in
- * the target elements.
+ * This mediator will clone the message in to different messages and mediated
as specified in the
+ * target elements.
*/
public class CloneMediator extends AbstractMediator {
/**
- * This variable specifies whether to continue the parent message
- * (i.e. message which is sbjuected to cloning) or not
+ * This variable specifies whether to continue the parent message (i.e.
message which is
+ * sbjuected to cloning) or not
*/
private boolean continueParent = false;
@@ -52,14 +51,29 @@
* functionality of cloning message in to the specified targets and
mediation
*
* @param synCtx - MessageContext which is subjected to the cloning
- * @return boolean true if this needs to be further mediated
(continueParent=true)
- * false otherwise
+ * @return boolean true if this needs to be further mediated
(continueParent=true) false
+ * otherwise
*/
public boolean mediate(MessageContext synCtx) {
+ // tracing and debuggin related mediation initiation
+ boolean traceOn = isTraceOn(synCtx);
+ boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "Start : Clone mediator");
+
+ if (traceOn && trace.isTraceEnabled()) {
+ trace.trace("Message : " + synCtx);
+ }
+ }
+
+ // get the targets list, clone the message for the number of targets
and then
+ // mediate the cloned messages using the targets
if (targets.size() != 0) {
for (int i = 0; i < targets.size(); i++) {
+ // clone message context for this target
MessageContext newContext = getClonedMessageContext(synCtx, i,
targets.size());
Object o = targets.get(i);
@@ -70,6 +84,13 @@
}
}
+ // finalize tracing and debugging
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "End : Clone mediator");
+ }
+
+ // if continue parent is true mediators after the clone will be called
for the further
+ // mediation of the message which is subjected for clonning (parent
message)
return continueParent;
}
@@ -81,19 +102,20 @@
* @param messageCount - int complete count of cloned messages
* @return MessageContext which is cloned from the given parameters
*/
- private MessageContext getClonedMessageContext(MessageContext synCtx,
- int messageSequence, int messageCount) {
+ private MessageContext getClonedMessageContext(MessageContext synCtx, int
messageSequence,
+ int messageCount) {
MessageContext newCtx = null;
try {
- newCtx = EIPUtils.createNewMessageContext(synCtx,
synCtx.getEnvelope());
+ // clones the message context
+ newCtx = MessageHelper.cloneMessageContext(synCtx);
} catch (AxisFault axisFault) {
handleException("Error creating a new message context", axisFault,
synCtx);
}
// Sets the property MESSAGE_SEQUENCE to the MC for aggragation
purposes
- newCtx.setProperty(EIPUtils.MESSAGE_SEQUENCE,
String.valueOf(messageSequence)
- + EIPUtils.MESSAGE_SEQUENCE_DELEMITER + messageCount);
+ newCtx.setProperty(EIPConstants.MESSAGE_SEQUENCE,
+ String.valueOf(messageSequence) +
EIPConstants.MESSAGE_SEQUENCE_DELEMITER + messageCount);
return newCtx;
}
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java?rev=581170&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/eip/splitter/IterateMediator.java
Tue Oct 2 02:35:18 2007
@@ -0,0 +1,228 @@
+/*
+ * 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.synapse.mediators.eip.splitter;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.eip.EIPUtils;
+import org.apache.synapse.mediators.eip.Target;
+import org.apache.synapse.mediators.eip.EIPConstants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.util.MessageHelper;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNode;
+import org.apache.axis2.AxisFault;
+import org.jaxen.JaxenException;
+
+import java.util.List;
+import java.util.Iterator;
+
+/**
+ * This mediator will split the message in the criterian specified to it and
inject in to Synapse
+ */
+public class IterateMediator extends AbstractMediator {
+
+ /**
+ * This holds whether to continue mediation on the parent message or not
+ */
+ private boolean continueParent = false;
+
+ /**
+ * This holds whether to preserve the payload and attach the iteration
child to specified node
+ * or to attach the child to the body of the envelope
+ */
+ private boolean preservePayload = false;
+
+ /**
+ * This holds the expression which will be evaluated for the presence of
elements in the
+ * mediating message for iterations
+ */
+ private AXIOMXPath expression = null;
+
+ /**
+ * This holds the node to which the iteration childs will be attached.
This does not have any
+ * meaning when the preservePayload is set to false
+ */
+ private AXIOMXPath attachPath = null;
+
+ /**
+ * This holds the target object for the newly created messages by the
iteration
+ */
+ private Target target = null;
+
+ /**
+ * This method implemenents the Mediator interface and this mediator
implements the message
+ * splitting logic
+ *
+ * @param synCtx - MessageContext to be mediated
+ * @return boolean false if need to stop processing the parent message,
boolean true if further
+ * processing of the parent message is required
+ */
+ public boolean mediate(MessageContext synCtx) {
+
+ // initializes the logging and tracing for the mediator
+ boolean traceOn = isTraceOn(synCtx);
+ boolean traceOrDebugOn = isTraceOrDebugOn(traceOn);
+
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "Start : Iterate mediator");
+
+ if (traceOn && trace.isTraceEnabled()) {
+ trace.trace("Message : " + synCtx);
+ }
+ }
+
+ try {
+ // get a copy of the message for the processing, if the
continueParent is set to true
+ // this original message can go in further mediations and hence we
should not change
+ // the original message context
+ SOAPEnvelope envelope =
MessageHelper.cloneSOAPEnvelope(synCtx.getEnvelope());
+
+ // get the iteration elements and iterate through the list,
+ // this call will also detach all the iteration elements
+ List splitElements =
EIPUtils.getDetachedMatchingElements(envelope, expression);
+ if (splitElements != null) {
+
+ int msgCount = splitElements.size();
+ int msgNumber = 0;
+
+ // if not preservePayload remove all the child elements
+ if (!preservePayload && envelope.getBody() != null) {
+ for (Iterator itr = envelope.getBody().getChildren();
itr.hasNext();) {
+ ((OMNode) itr.next()).detach();
+ }
+ }
+
+ // iterate through the list
+ for (Iterator itr = splitElements.iterator(); itr.hasNext();) {
+
+ Object o = itr.next();
+ // clone the message for the mediation in iteration
+ MessageContext newCtx =
MessageHelper.cloneMessageContext(synCtx);
+ // set the messageSequence property for possibal
aggreagtions
+ newCtx.setProperty(EIPConstants.MESSAGE_SEQUENCE,
+ msgNumber + EIPConstants.MESSAGE_SEQUENCE_DELEMITER +
msgCount);
+ // get a clone of the envelope to be attached
+ SOAPEnvelope newEnvelope =
MessageHelper.cloneSOAPEnvelope(envelope);
+
+ // for the moment iterator will look for an OMNode as the
iteration element
+ if (!(o instanceof OMNode)) {
+ handleException(
+ "Error in splitting the message with expression :
" + expression,
+ synCtx);
+ }
+
+ // if payload should be preserved then attach the
iteration element to the
+ // node specified by the attachPath
+ if (preservePayload) {
+
+ Object attachElem = attachPath.evaluate(newEnvelope);
+ if (attachElem instanceof List) {
+ attachElem = ((List) attachElem).get(0);
+ }
+
+ // for the moment attaching element should be an
OMElement
+ if (attachElem instanceof OMElement) {
+ ((OMElement) attachElem).addChild((OMNode) o);
+ } else {
+ handleException("Error in attaching the splitted
elements :: " +
+ "Unable to get the attach path specified by
the expression " +
+ attachPath, synCtx);
+ }
+ // if not preserve payload then attach the iteration
element to the body
+ } else if (o instanceof OMNode && newEnvelope.getBody() !=
null) {
+ newEnvelope.getBody().addChild((OMNode) o);
+ }
+
+ // set the envelope ant mediate as specified in the target
+ newCtx.setEnvelope(newEnvelope);
+ target.mediate(newCtx);
+ msgNumber++;
+
+ }
+
+ } else {
+ handleException(
+ "Splitting by expression : " + expression + " did not
yeild in an OMElement",
+ synCtx);
+ }
+
+ } catch (JaxenException e) {
+ handleException("Error evaluating XPath expression : " +
expression, e, synCtx);
+ } catch (AxisFault axisFault) {
+ handleException("Unable to split the message using the expression
: " + expression,
+ axisFault, synCtx);
+ }
+
+ // finalizing the tracing and logging on the iterate mediator
+ if (traceOrDebugOn) {
+ traceOrDebug(traceOn, "End : Iterate mediator");
+ }
+
+ // whether to continue mediation on the original message
+ return continueParent;
+ }
+
+
///////////////////////////////////////////////////////////////////////////////////////
+ // Getters and Setters
//
+
///////////////////////////////////////////////////////////////////////////////////////
+
+ public boolean isContinueParent() {
+ return continueParent;
+ }
+
+ public void setContinueParent(boolean continueParent) {
+ this.continueParent = continueParent;
+ }
+
+ public boolean isPreservePayload() {
+ return preservePayload;
+ }
+
+ public void setPreservePayload(boolean preservePayload) {
+ this.preservePayload = preservePayload;
+ }
+
+ public AXIOMXPath getExpression() {
+ return expression;
+ }
+
+ public void setExpression(AXIOMXPath expression) {
+ this.expression = expression;
+ }
+
+ public AXIOMXPath getAttachPath() {
+ return attachPath;
+ }
+
+ public void setAttachPath(AXIOMXPath attachPath) {
+ this.attachPath = attachPath;
+ }
+
+ public Target getTarget() {
+ return target;
+ }
+
+ public void setTarget(Target target) {
+ this.target = target;
+ }
+
+}
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
URL:
http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java?rev=581170&view=auto
==============================================================================
---
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
(added)
+++
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/util/MessageHelper.java
Tue Oct 2 02:35:18 2007
@@ -0,0 +1,245 @@
+package org.apache.synapse.util;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.eip.EIPConstants;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPHeader;
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.soap.SOAP11Constants;
+import org.apache.axiom.attachments.Attachments;
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.OMNamespace;
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMNode;
+import org.apache.axis2.addressing.AddressingConstants;
+import org.apache.axis2.AxisFault;
+
+import java.util.Iterator;
+import java.util.ArrayList;
+
+/**
+ *
+ */
+public class MessageHelper {
+
+ /**
+ * This method will simulate cloning the message context and creating an
exact copy of the
+ * passed message. One should use this method with care; that is because,
inside the new MC,
+ * most of the attributes of the MC like opCtx and so on are still kept as
references inside
+ * the axis2 MessageContext for performance improvements. (Note: U dont
have to worrie
+ * about the SOAPEnvelope, it is a cloned copy and not a reference from
any other MC)
+ *
+ * @param synCtx - this will be cloned
+ * @return cloned Synapse MessageContext
+ * @throws AxisFault if there is a failure in creating the new Synapse MC
or in a failure in
+ * clonning the underlying axis2 MessageContext
+ *
+ * @see MessageHelper#cloneAxis2MessageContext
+ */
+ public static MessageContext cloneMessageContext(MessageContext synCtx)
throws AxisFault {
+
+ // creates the new MessageContext and clone the internal axis2
MessageContext
+ // inside the synapse message context and place that in the new one
+ MessageContext newCtx = synCtx.getEnvironment().createMessageContext();
+ Axis2MessageContext axis2MC = (Axis2MessageContext) newCtx;
+ axis2MC.setAxis2MessageContext(
+ cloneAxis2MessageContext(((Axis2MessageContext)
synCtx).getAxis2MessageContext()));
+
+ // set the parent corelation details to the cloned MC -
+ // for the use of aggregation like tasks
+ newCtx.setProperty(EIPConstants.AGGREGATE_CORELATION,
synCtx.getMessageID());
+
+ // copying the core parameters of the synapse MC
+ newCtx.setTo(synCtx.getTo());
+ newCtx.setReplyTo(synCtx.getReplyTo());
+ newCtx.setSoapAction(synCtx.getSoapAction());
+ newCtx.setWSAAction(synCtx.getWSAAction());
+
+ // copy all the synapse level properties to the newCtx
+ Iterator propItr = synCtx.getPropertyKeySet().iterator();
+ while (propItr.hasNext()) {
+ Object o = propItr.next();
+ // If there are non String keyed properties neglect them rathern
than trow exception
+ if (o instanceof String) {
+ newCtx.setProperty((String) o, synCtx.getProperty((String) o));
+ }
+ }
+
+ return newCtx;
+ }
+
+ /**
+ * This method will simulate cloning the message context and creating an
exact copy of the
+ * passed message. One should use this method with care; that is because,
inside the new MC,
+ * most of the attributes of the MC like opCtx and so on are still kept as
references. Otherwise
+ * there will be perf issues. But ..... this may reveal in some conflicts
in the cloned message
+ * if you try to do advanced mediations with the cloned message, in which
case you should
+ * mannually get a clone of the changing part of the MC and set that
cloned part to your MC.
+ * Changing the MC after doing that will solve most of the issues. (Note:
U dont have to worrie
+ * about the SOAPEnvelope, it is a cloned copy and not a reference from
any other MC)
+ *
+ * @param mc - this will be cloned for getting an exact copy
+ * @return cloned MessageContext from the given mc
+ * @throws AxisFault if there is a failure in copying the certain
attributes of the
+ * provided message context
+ */
+ public static org.apache.axis2.context.MessageContext
cloneAxis2MessageContext(
+ org.apache.axis2.context.MessageContext mc) throws AxisFault {
+
+ org.apache.axis2.context.MessageContext newMC =
+ new org.apache.axis2.context.MessageContext();
+
+ // do not copy options from the original todo: Y?
+ newMC.setConfigurationContext(mc.getConfigurationContext());
+ newMC.setServiceContext(mc.getServiceContext());
+ newMC.setOperationContext(mc.getOperationContext());
+ newMC.setAxisMessage(mc.getAxisMessage());
+ if (newMC.getAxisMessage() != null) {
+ newMC.getAxisMessage().setParent(mc.getAxisOperation());
+ }
+ newMC.setAxisService(mc.getAxisService());
+ newMC.setMessageID(UUIDGenerator.getUUID());
+ newMC.setTo(mc.getTo());
+ newMC.setSoapAction(mc.getSoapAction());
+
+ // copying behavioral attributes from the original message
+
newMC.setProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING,
+
mc.getProperty(org.apache.axis2.Constants.Configuration.CHARACTER_SET_ENCODING));
+ newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM,
+
mc.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_MTOM));
+ newMC.setProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA,
+
mc.getProperty(org.apache.axis2.Constants.Configuration.ENABLE_SWA));
+
+ // todo: isnt this duplicate with the above
+ newMC.setDoingREST(mc.isDoingREST());
+ newMC.setDoingMTOM(mc.isDoingMTOM());
+ newMC.setDoingSwA(mc.isDoingSwA());
+
+ // if the original request carries any attachments, copy them to the
clone
+ // as well, except for the soap part if any
+ Attachments attachments = mc.getAttachmentMap();
+ if (attachments != null && attachments.getAllContentIDs().length > 0) {
+ String[] cIDs = attachments.getAllContentIDs();
+ String soapPart = attachments.getSOAPPartContentID();
+ for (int i = 0; i < cIDs.length; i++) {
+ if (!cIDs[i].equals(soapPart)) {
+ newMC.addAttachment(cIDs[i],
attachments.getDataHandler(cIDs[i]));
+ }
+ }
+ }
+
+ newMC.setServerSide(false);
+
+ // attaching the cloned envelope to the new message context
+ newMC.setEnvelope(cloneSOAPEnvelope(mc.getEnvelope()));
+
+ // copying transport related parts from the original
+ newMC.setTransportIn(mc.getTransportIn());
+ newMC.setTransportOut(mc.getTransportOut());
+ newMC.setProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO,
+ mc.getProperty(org.apache.axis2.Constants.OUT_TRANSPORT_INFO));
+
newMC.setProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
+
mc.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS));
+
+ // Copying properties in the original message
+ Iterator iter = mc.getProperties().keySet().iterator();
+ while (iter.hasNext()) {
+ String key = (String) iter.next();
+ newMC.setProperty(key, mc.getProperty(key));
+ }
+
+ return newMC;
+ }
+
+ /**
+ * This method will clone the provided SOAPEnvelope and returns the cloned
envelope
+ * as an exact copy of the provided envelope
+ *
+ * @param envelope - this will be cloned to get the new envelope
+ * @return cloned SOAPEnvelope from the provided one
+ */
+ public static SOAPEnvelope cloneSOAPEnvelope(SOAPEnvelope envelope) {
+ SOAPEnvelope newEnvelope;
+ if (SOAP11Constants.SOAP_ENVELOPE_NAMESPACE_URI
+ .equals(envelope.getBody().getNamespace().getNamespaceURI())) {
+ newEnvelope =
OMAbstractFactory.getSOAP11Factory().getDefaultEnvelope();
+ } else {
+ newEnvelope =
OMAbstractFactory.getSOAP12Factory().getDefaultEnvelope();
+ }
+
+ if (envelope.getHeader() != null) {
+ Iterator itr = envelope.getHeader().cloneOMElement().getChildren();
+ while (itr.hasNext()) {
+ newEnvelope.getHeader().addChild((OMNode) itr.next());
+ }
+ }
+
+ if (envelope.getBody() != null) {
+ Iterator itr = envelope.getBody().cloneOMElement().getChildren();
+ while (itr.hasNext()) {
+ newEnvelope.getBody().addChild((OMNode) itr.next());
+ }
+ }
+
+ return newEnvelope;
+ }
+
+ /**
+ * Removes Submission and Final WS-Addressing headers and return the
SOAPEnvelope from the given
+ * message context
+ *
+ * @param axisMsgCtx the Axis2 Message context
+ * @return the resulting SOAPEnvelope
+ */
+ public static SOAPEnvelope removeAddressingHeaders(
+ org.apache.axis2.context.MessageContext axisMsgCtx) {
+
+ SOAPEnvelope env = axisMsgCtx.getEnvelope();
+ SOAPHeader soapHeader = env.getHeader();
+ ArrayList addressingHeaders;
+
+ if (soapHeader != null) {
+ addressingHeaders =
+
soapHeader.getHeaderBlocksWithNSURI(AddressingConstants.Submission.WSA_NAMESPACE);
+
+ if (addressingHeaders != null && addressingHeaders.size() != 0) {
+ detachAddressingInformation(addressingHeaders);
+
+ } else {
+ addressingHeaders =
+
soapHeader.getHeaderBlocksWithNSURI(AddressingConstants.Final.WSA_NAMESPACE);
+ if (addressingHeaders != null && addressingHeaders.size() !=
0) {
+ detachAddressingInformation(addressingHeaders);
+ }
+ }
+ }
+ return env;
+ }
+
+ /**
+ * Remove WS-A headers
+ *
+ * @param headerInformation headers to be removed
+ */
+ private static void detachAddressingInformation(ArrayList
headerInformation) {
+ Iterator iterator = headerInformation.iterator();
+ while (iterator.hasNext()) {
+ Object o = iterator.next();
+ if (o instanceof SOAPHeaderBlock) {
+ SOAPHeaderBlock headerBlock = (SOAPHeaderBlock) o;
+ headerBlock.detach();
+ } else if (o instanceof OMElement) {
+ // work around for a known addressing bug which sends non
SOAPHeaderBlock objects
+ OMElement om = (OMElement) o;
+ OMNamespace ns = om.getNamespace();
+ if (ns != null && (
+
AddressingConstants.Submission.WSA_NAMESPACE.equals(ns.getNamespaceURI()) ||
+
AddressingConstants.Final.WSA_NAMESPACE.equals(ns.getNamespaceURI()))) {
+ om.detach();
+ }
+ }
+ }
+ }
+
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]