You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by in...@apache.org on 2007/03/05 11:33:29 UTC
svn commit: r514639 - in /webservices/synapse/trunk/java/modules:
core/src/main/java/org/apache/synapse/
core/src/main/java/org/apache/synapse/config/xml/
core/src/main/java/org/apache/synapse/core/axis2/
core/src/main/java/org/apache/synapse/mediators...
Author: indika
Date: Mon Mar 5 02:33:25 2007
New Revision: 514639
URL: http://svn.apache.org/viewvc?view=rev&rev=514639
Log:
Change the get-property XPath function to use two parameters – property name and scope
Improve Property mediator to reflect changes of get-property function
Change the implementation of Switch Mediator- remove switchcase mediator
add AnonymousList Mediator with Factory and Serializer
remove the Try Mediator
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java
Removed:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCaseDefaultMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCaseMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCaseMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TryMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/TryMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/TryMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchCaseMediator.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/TryMediatorSerializationTest.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/base/TryMediatorTest.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorSerializer.java
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/Constants.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/config/xml/PropertyMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/filters/SwitchMediatorTest.java
webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Constants.java Mon Mar 5 02:33:25 2007
@@ -52,6 +52,12 @@
*/
String SCOPE_AXIS2 = "axis2";
+ /**
+ * The scope for a set-property mediator, when the property should be set
+ * on the underlying transport
+ */
+ String SCOPE_TRANSPORT = "transport";
+
/** An string name which holds the out sequence property in the MessageContext */
String PROXY_SERVICE = "proxy.name";
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorFactory.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorFactory.java Mon Mar 5 02:33:25 2007
@@ -32,12 +32,11 @@
* This implements the basic logic to build a list mediator from a given XML
* configuration. It recursively builds the child mediators of the list.
*/
-public abstract class AbstractListMediatorFactory extends AbstractMediatorFactory {
+public abstract class AbstractListMediatorFactory extends AbstractMediatorFactory {
private static final Log log = LogFactory.getLog(AbstractListMediatorFactory.class);
- public void addChildren(OMElement el, ListMediator m)
- {
+ protected static void addChildren(OMElement el, ListMediator m) {
Iterator it = el.getChildElements();
while (it.hasNext()) {
OMElement child = (OMElement) it.next();
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorSerializer.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AbstractListMediatorSerializer.java Mon Mar 5 02:33:25 2007
@@ -32,7 +32,7 @@
private static final Log log = LogFactory.getLog(AbstractListMediatorSerializer.class);
- public void serializeChildren(OMElement parent, List list)
+ protected static void serializeChildren(OMElement parent, List list)
{
Iterator iter = list.iterator();
while (iter.hasNext()) {
@@ -46,7 +46,7 @@
}
}
- private void handleException(String msg) {
+ private static void handleException(String msg) {
log.error(msg);
throw new SynapseException(msg);
}
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?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- 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 Mon Mar 5 02:33:25 2007
@@ -32,7 +32,7 @@
* @param mediator
* @param mediatorOmElement
*/
- public void initMediator(Mediator mediator, OMElement mediatorOmElement) {
+ protected void initMediator(Mediator mediator, OMElement mediatorOmElement) {
OMAttribute trace = mediatorOmElement.getAttribute(
new QName(Constants.NULL_NAMESPACE, Constants.TRACE_ATTRIB_NAME));
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?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- 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 Mon Mar 5 02:33:25 2007
@@ -47,7 +47,7 @@
* @param mediatorOmElement the OMElement being created
* @param mediator the Mediator instance being serialized
*/
- public void finalizeSerialization(OMElement mediatorOmElement, Mediator mediator) {
+ protected static void finalizeSerialization(OMElement mediatorOmElement, Mediator mediator) {
int traceState = mediator.getTraceState();
String traceValue = null;
if (traceState == org.apache.synapse.Constants.TRACING_ON) {
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediator.java?view=auto&rev=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediator.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediator.java Mon Mar 5 02:33:25 2007
@@ -0,0 +1,32 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.mediators.AbstractListMediator;
+import org.apache.synapse.MessageContext;
+
+/**
+ * This mediator represents an unnamed the list of mediator
+ *
+ */
+
+public class AnonymousListMediator extends AbstractListMediator {
+
+ public boolean mediate(MessageContext synCtx) {
+ return super.mediate(synCtx);
+ }
+
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorFactory.java?view=auto&rev=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorFactory.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorFactory.java Mon Mar 5 02:33:25 2007
@@ -0,0 +1,49 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.SynapseException;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+
+import java.util.Iterator;
+
+/**
+ * This is factory for creating an anonymous list mediator(an unnamed list of mediators )
+ *
+ */
+
+public abstract class AnonymousListMediatorFactory extends AbstractListMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(AnonymousListMediator.class);
+
+ /**
+ * To create an anonymous list mediator form OMElement
+ * @param el
+ * @return List mediator
+ */
+ public static AnonymousListMediator createAnonymousListMediator(OMElement el) {
+ AnonymousListMediator mediator = new AnonymousListMediator();
+ {
+ addChildren(el, mediator);
+ }
+ return mediator;
+ }
+
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorSerializer.java?view=auto&rev=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorSerializer.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/AnonymousListMediatorSerializer.java Mon Mar 5 02:33:25 2007
@@ -0,0 +1,52 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.SynapseException;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+/**
+ * This is Serializer for serialization of an anonymous list mediator(an unnamed list of mediators )
+ */
+
+public abstract class AnonymousListMediatorSerializer extends AbstractListMediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(AnonymousListMediatorSerializer.class);
+
+ /**
+ * To serialize an anonymous list mediator
+ *
+ * @param parent
+ * @param m
+ * @return OMElement
+ */
+ public static OMElement serializeAnonymousListMediator(OMElement parent, Mediator m) {
+ if (!(m instanceof AnonymousListMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+ AnonymousListMediator mediator = (AnonymousListMediator) m;
+ serializeChildren(parent, mediator.getList());
+ return parent;
+ }
+
+ private static void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/Constants.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/Constants.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/Constants.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/Constants.java Mon Mar 5 02:33:25 2007
@@ -59,7 +59,12 @@
public static final String SCOPE_CORRELATE = org.apache.synapse.Constants.SCOPE_CORRELATE;
/** The String value for an Axis2 messagecontext property */
public static final String SCOPE_AXIS2 = org.apache.synapse.Constants.SCOPE_AXIS2;
-
+ /**
+ * The scope for a set-property mediator, when the property should be set
+ * on the underlying transport
+ */
+ String SCOPE_TRANSPORT = "transport";
+
// -- Synapse property values for WS-RM sequence handling --
/** The String value for a WS-RM version 1.0*/
public static final String SEQUENCE_VERSION_1_0 = org.apache.synapse.Constants.SEQUENCE_VERSION_1_0;
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?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- 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 Mon Mar 5 02:33:25 2007
@@ -41,7 +41,7 @@
* http://java.sun.com/j2se/1.3/docs/guide/jar/jar.html#Service%20Provider
*/
-public class MediatorFactoryFinder implements XMLToObjectMapper {
+public class MediatorFactoryFinder implements XMLToObjectMapper {
private static final Log log = LogFactory.getLog(MediatorFactoryFinder.class);
@@ -56,12 +56,9 @@
FaultMediatorFactory.class,
PropertyMediatorFactory.class,
SwitchMediatorFactory.class,
- SwitchCaseMediatorFactory.class,
- SwitchCaseDefaultMediatorFactory.class,
InMediatorFactory.class,
OutMediatorFactory.class,
- RMSequenceMediatorFactory.class,
- TryMediatorFactory.class,
+ RMSequenceMediatorFactory.class,
ClassMediatorFactory.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?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- 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 Mon Mar 5 02:33:25 2007
@@ -44,12 +44,9 @@
FaultMediatorSerializer.class,
PropertyMediatorSerializer.class,
SwitchMediatorSerializer.class,
- SwitchCaseMediatorSerializer.class,
- //?SwitchCaseDefaultMediatorSerializer.class,
InMediatorSerializer.class,
OutMediatorSerializer.class,
- RMSequenceMediatorSerializer.class,
- TryMediatorSerializer.class,
+ RMSequenceMediatorSerializer.class,
ClassMediatorSerializer.class
};
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/PropertyMediatorFactory.java Mon Mar 5 02:33:25 2007
@@ -79,15 +79,17 @@
}
if (scope != null) {
- if (!Constants.SCOPE_CORRELATE.equals(scope.getAttributeValue()) &&
- !Constants.SCOPE_AXIS2.equals(scope.getAttributeValue())) {
+ String valueStr = scope.getAttributeValue();
+ if (!Constants.SCOPE_CORRELATE.equals(valueStr) &&
+ !Constants.SCOPE_AXIS2.equals(valueStr) && !Constants.SCOPE_TRANSPORT.equals(valueStr)) {
String msg = "Only '" + Constants.SCOPE_CORRELATE + "' or '" + Constants.SCOPE_AXIS2
- + "' values are allowed for attribute scope for a property mediator"
+ + "' or '" + Constants.SCOPE_TRANSPORT
+ + "' values are allowed for attribute scope for a property mediator"
+ ", Unsupported scope " + scope.getAttributeValue();
log.error(msg);
throw new SynapseException(msg);
}
- propMediator.setScope(scope.getAttributeValue());
+ propMediator.setScope(valueStr);
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java?view=auto&rev=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchCase.java Mon Mar 5 02:33:25 2007
@@ -0,0 +1,103 @@
+/*
+* Copyright 2004,2005 The Apache Software Foundation.
+*
+* Licensed 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.mediators.AbstractListMediator;
+import org.apache.synapse.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+import java.util.regex.Pattern;
+
+/**
+ * A SwitchCase define a case element of Switch Mediator and It has a list mediator and
+ * a regex that is matched by its owning SwitchMediator for selection.
+ * If any SwitchCase has selected ,Then the list mediator of it, will responsible
+ * for message mediation
+ */
+
+public class SwitchCase {
+
+ private static final Log log = LogFactory.getLog(SwitchCase.class);
+ /** The regular expression pattern to be used */
+ private Pattern regex = null;
+ /** The list mediator for which responsible message mediation */
+ private AnonymousListMediator caseMediator;
+
+ public SwitchCase() {
+ }
+
+ /**
+ * To delegate message mediation to list mediator
+ *
+ * @param synCtx
+ * @return boolean value
+ */
+ public boolean mediate(MessageContext synCtx) {
+ if (caseMediator != null) {
+ return caseMediator.mediate(synCtx);
+ }
+ return true;
+ }
+
+ /**
+ * To get list mediator of this case element
+ *
+ * @return List mediator of switch case
+ */
+ public AnonymousListMediator getCaseMediator() {
+ return caseMediator;
+ }
+
+ /**
+ * To set the list mediator
+ *
+ * @param caseMediator
+ */
+ public void setCaseMediator(AnonymousListMediator caseMediator) {
+ this.caseMediator = caseMediator;
+ }
+
+ /**
+ * To get the regular expression pattern
+ *
+ * @return Pattern
+ */
+ public Pattern getRegex() {
+ return regex;
+ }
+
+ /**
+ * To set the regular expression pattern
+ *
+ * @param regex
+ */
+ public void setRegex(Pattern regex) {
+ this.regex = regex;
+ }
+
+ /**
+ * To evaluate regular expression pattern to a get switch case
+ *
+ * @param value
+ * @return boolean value
+ */
+ public boolean matches(String value) {
+ boolean retVal = regex.matcher(value).matches();
+ log.debug("Case : " + regex.pattern() + " evaluated to : " + retVal);
+ return retVal;
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorFactory.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorFactory.java Mon Mar 5 02:33:25 2007
@@ -26,16 +26,17 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
import org.apache.synapse.Mediator;
-import org.apache.synapse.mediators.filters.SwitchCaseMediator;
import org.apache.synapse.mediators.filters.SwitchMediator;
import org.jaxen.JaxenException;
import javax.xml.namespace.QName;
import java.util.Iterator;
+import java.util.regex.Pattern;
+import java.util.regex.PatternSyntaxException;
/**
* Constructs a Switch mediator instance from the given XML configuration
- *
+ * <p/>
* <pre>
* <switch source="xpath">
* <case regex="string">
@@ -47,18 +48,17 @@
* </switch>
* </pre>
*/
-public class SwitchMediatorFactory extends AbstractMediatorFactory {
+public class SwitchMediatorFactory extends AbstractMediatorFactory {
private static final Log log = LogFactory.getLog(SwitchMediatorFactory.class);
- private static final QName SWITCH_Q = new QName(Constants.SYNAPSE_NAMESPACE, "switch");
- private static final QName CASE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "case");
+ private static final QName SWITCH_Q = new QName(Constants.SYNAPSE_NAMESPACE, "switch");
+ private static final QName CASE_Q = new QName(Constants.SYNAPSE_NAMESPACE, "case");
private static final QName DEFAULT_Q = new QName(Constants.SYNAPSE_NAMESPACE, "default");
public Mediator createMediator(OMElement elem) {
SwitchMediator switchMediator = new SwitchMediator();
-
OMAttribute source = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "source"));
if (source == null) {
String msg = "A 'source' XPath attribute is required for a switch mediator";
@@ -78,21 +78,34 @@
}
// after successfully creating the mediator
// set its common attributes such as tracing etc
- initMediator(switchMediator,elem);
-
+ initMediator(switchMediator, elem);
Iterator iter = elem.getChildrenWithName(CASE_Q);
while (iter.hasNext()) {
- switchMediator.addCase((SwitchCaseMediator)
- MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+ OMElement caseElem = (OMElement) iter.next();
+ SwitchCase aCase = new SwitchCase();
+ OMAttribute regex = caseElem.getAttribute(new QName(Constants.NULL_NAMESPACE, "regex"));
+ if (regex == null) {
+ String msg = "The 'regex' attribute is required for a switch case definition";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ try {
+ aCase.setRegex(Pattern.compile(regex.getAttributeValue()));
+ } catch (PatternSyntaxException pse) {
+ String msg = "Invalid Regular Expression for attribute 'regex' : " + regex.getAttributeValue();
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+ aCase.setCaseMediator(AnonymousListMediatorFactory.createAnonymousListMediator(caseElem));
+ switchMediator.addCase(aCase);
}
-
iter = elem.getChildrenWithName(DEFAULT_Q);
while (iter.hasNext()) {
- switchMediator.addCase((SwitchCaseMediator)
- MediatorFactoryFinder.getInstance().getMediator((OMElement) iter.next()));
+ SwitchCase aCase = new SwitchCase();
+ aCase.setCaseMediator(AnonymousListMediatorFactory.createAnonymousListMediator((OMElement) iter.next()));
+ switchMediator.setDefaultCase(aCase);
break; // add only the *first* default if multiple are specified, ignore rest if any
}
-
return switchMediator;
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorSerializer.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SwitchMediatorSerializer.java Mon Mar 5 02:33:25 2007
@@ -24,7 +24,6 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
import org.apache.synapse.Mediator;
-import org.apache.synapse.mediators.filters.SwitchCaseMediator;
import org.apache.synapse.mediators.filters.SwitchMediator;
import java.util.Iterator;
@@ -41,8 +40,7 @@
* </switch>
* </pre>
*/
-public class SwitchMediatorSerializer extends AbstractMediatorSerializer
- {
+public class SwitchMediatorSerializer extends AbstractMediatorSerializer {
private static final Log log = LogFactory.getLog(SwitchMediatorSerializer.class);
@@ -54,11 +52,11 @@
SwitchMediator mediator = (SwitchMediator) m;
OMElement switchMed = fac.createOMElement("switch", synNS);
- finalizeSerialization(switchMed,mediator);
+ finalizeSerialization(switchMed, mediator);
if (mediator.getSource() != null) {
switchMed.addAttribute(fac.createOMAttribute(
- "source", nullNS, mediator.getSource().toString()));
+ "source", nullNS, mediator.getSource().toString()));
super.serializeNamespaces(switchMed, mediator.getSource());
} else {
@@ -66,11 +64,32 @@
}
Iterator iter = mediator.getCases().iterator();
- SwitchCaseMediatorSerializer swcms = new SwitchCaseMediatorSerializer();
while (iter.hasNext()) {
- swcms.serializeMediator(switchMed, (SwitchCaseMediator) iter.next());
+ OMElement caseElem = fac.createOMElement("case", synNS);
+ SwitchCase aCase = ((SwitchCase) iter.next());
+ if (aCase.getRegex() != null) {
+ caseElem.addAttribute(fac.createOMAttribute(
+ "regex", nullNS, aCase.getRegex().pattern()));
+ } else {
+ handleException("Invalid switch case. Regex required");
+ }
+ AnonymousListMediator caseMediator = aCase.getCaseMediator();
+ if (caseMediator != null) {
+ AnonymousListMediatorSerializer.serializeAnonymousListMediator(
+ caseElem, caseMediator);
+ switchMed.addChild(caseElem);
+ }
+ }
+ SwitchCase defaultCase = mediator.getDefaultCase();
+ if (defaultCase != null) {
+ OMElement caseDefaultElem = fac.createOMElement("default", synNS);
+ AnonymousListMediator caseDefaultMediator = defaultCase.getCaseMediator();
+ if (caseDefaultMediator != null) {
+ AnonymousListMediatorSerializer.serializeAnonymousListMediator(
+ caseDefaultElem, caseDefaultMediator);
+ switchMed.addChild(caseDefaultElem);
+ }
}
-
if (parent != null) {
parent.addChild(switchMed);
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/core/axis2/Axis2MessageContext.java Mon Mar 5 02:33:25 2007
@@ -300,11 +300,9 @@
handleException("Error setting up the Synapse XPath " +
"extension function for XPath : " + xpath, je);
}
-
try {
Object result = xpath.evaluate(synCtx.getEnvelope());
StringBuffer textValue = new StringBuffer();
-
if (result instanceof List) {
Iterator iter = ((List) result).iterator();
while (iter.hasNext()) {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java Mon Mar 5 02:33:25 2007
@@ -23,17 +23,19 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.MessageContext;
import org.apache.synapse.Constants;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.jaxen.Context;
import org.jaxen.Function;
import org.jaxen.FunctionCallException;
import org.jaxen.Navigator;
import org.jaxen.function.StringFunction;
-import java.util.Iterator;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
/**
- * Implements the XPath extension function synapse:get-property(prop-name)
+ * Implements the XPath extension function synapse:get-property(scope,prop-name)
*/
public class GetPropertyFunction implements Function {
@@ -50,41 +52,74 @@
}
public Object call(Context context, List args) throws FunctionCallException {
- if (args.isEmpty()) {
+
+ int size = args.size();
+ if (size == 0) {
log.warn("Property key value for lookup was not specified");
return null;
- } else if (synCtx == null) {
+ } else if (size == 1) {
+ return evaluate(Constants.SCOPE_CORRELATE, args.get(0), context.getNavigator());
+ } else if (size == 2) {
+ return evaluate(args.get(0), args.get(1), context.getNavigator());
+ } else {
+ String msg = "Invalid arguments for synapse:get-property(prop-name) 0r " +
+ "synapse:get-property(scope,prop-name) XPath function ";
+ log.warn(msg);
+ throw new FunctionCallException(msg);
+ }
+ }
+
+ public Object evaluate(Object scopeObject, Object keyObject, Navigator navigator) {
+ if (synCtx == null) {
log.warn("Synapse context has not been set for the XPath extension function" +
- "'synapse:get-property(prop-name)'");
+ "'synapse:get-property(prop-name)'");
return null;
- } else {
- Navigator navigator = context.getNavigator();
- Iterator iter = args.iterator();
- while (iter.hasNext()) {
- String key = StringFunction.evaluate(iter.next(), navigator);
- // ignore if more than one argument has been specified
- Object result = synCtx.getProperty(key);
+ }
+ String scope = StringFunction.evaluate(scopeObject, navigator);
+ String key = StringFunction.evaluate(keyObject, navigator);
- if (result != null) {
- return result;
+ if (key == null || "".equals(key)) {
+ log.warn("property-name should be provided when executing synapse:get-property(scope,prop-name)" +
+ " or synapse:get-property(prop-name) Xpath function");
+ return null;
+ }
+ if (Constants.SCOPE_CORRELATE.equals(scope)) {
+ Object result = synCtx.getProperty(key);
+ if (result != null) {
+ return result;
+ } else {
+ if (Constants.HEADER_TO.equals(key) && synCtx.getTo() != null) {
+ return synCtx.getTo().getAddress();
+ } else if (Constants.HEADER_FROM.equals(key) && synCtx.getFrom() != null) {
+ return synCtx.getFrom().getAddress();
+ } else if (Constants.HEADER_ACTION.equals(key) && synCtx.getWSAAction() != null) {
+ return synCtx.getWSAAction();
+ } else if (Constants.HEADER_FAULT.equals(key) && synCtx.getFaultTo() != null) {
+ return synCtx.getFaultTo().getAddress();
+ } else if (Constants.HEADER_REPLY_TO.equals(key) && synCtx.getReplyTo() != null) {
+ return synCtx.getReplyTo().getAddress();
} else {
- if (Constants.HEADER_TO.equals(key) && synCtx.getTo() != null) {
- return synCtx.getTo().getAddress();
- } else if (Constants.HEADER_FROM.equals(key) && synCtx.getFrom() != null) {
- return synCtx.getFrom().getAddress();
- } else if (Constants.HEADER_ACTION.equals(key) && synCtx.getWSAAction() != null) {
- return synCtx.getWSAAction();
- } else if (Constants.HEADER_FAULT.equals(key) && synCtx.getFaultTo() != null) {
- return synCtx.getFaultTo().getAddress();
- } else if (Constants.HEADER_REPLY_TO.equals(key) && synCtx.getReplyTo() != null) {
- return synCtx.getReplyTo().getAddress();
- } else {
- return null;
- }
+ return null;
}
}
+ } else if (Constants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) {
+ org.apache.axis2.context.MessageContext axis2MessageContext
+ = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+ return axis2MessageContext.getConfigurationContext().getProperty(key);
+ } else
+ if (Constants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) {
+ org.apache.axis2.context.MessageContext axis2MessageContext
+ = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
+ Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+ if (headers != null && headers instanceof Map) {
+ Map headersMap = (HashMap) headers;
+ return headersMap.get(key);
+ }
+ } else {
+ log.warn("Invalid scope : '" + scope + "' has been set for the synapse:get-property(scope,prop-name) XPath function");
}
return null;
}
}
+
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java Mon Mar 5 02:33:25 2007
@@ -215,7 +215,7 @@
/**
* Return the registry key used to load this sequence dynamically
- * @return
+ * @return registry key
*/
public String getRegistryKey() {
return registryKey;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java Mon Mar 5 02:33:25 2007
@@ -19,7 +19,6 @@
package org.apache.synapse.mediators.builtin;
-import org.apache.axiom.soap.SOAPHeader;
import org.apache.axiom.soap.SOAPHeaderBlock;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java Mon Mar 5 02:33:25 2007
@@ -28,6 +28,9 @@
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
+import java.util.Map;
+import java.util.HashMap;
+
/**
* The property mediator would save a named property as a local property
* of the Synapse Message Context. Properties set this way could be
@@ -45,6 +48,7 @@
/**
* Sets a property into the current (local) Synapse Context
+ *
* @param smc the message context
* @return true always
*/
@@ -54,33 +58,52 @@
if (shouldTrace) {
trace.trace("Start : Property mediator");
}
-
- String value = (getValue() != null ? getValue() : Axis2MessageContext.getStringValue(getExpression(), smc));
- log.debug("Setting property : " + getName() +
- " (scope:" + (scope == null ? "default" : scope) + ") = " + value);
+ String value = (this.value != null ? this.value : Axis2MessageContext.getStringValue(
+ getExpression(), smc));
+ log.debug("Setting property : " + name +
+ " (scope:" + (scope == null ? "default" : scope) + ") = " + value);
if (shouldTrace) {
- trace.trace("Property Name : " + getName() +
- " (scope:" + (scope == null ? "default" : scope) + ") set to " +
- (getValue() != null ? " value = " + getValue() :
- " result of expression " + getExpression() + " = " + value));
+ trace.trace("Property Name : " + name +
+ " (scope:" + (scope == null ? "default" : scope) + ") set to " +
+ (this.value != null ? " value = " + this.value :
+ " result of expression " + expression + " = " + value));
}
-
if (scope == null) {
- smc.setProperty(getName(), value);
+ smc.setProperty(name, value);
- } else if(Constants.SCOPE_CORRELATE.equals(getScope())) {
- smc.setProperty(getName(), value);
+ } else if (Constants.SCOPE_CORRELATE.equals(scope)) {
+ smc.setProperty(name, value);
+
+ } else if (Constants.SCOPE_AXIS2.equals(scope)
+ && smc instanceof Axis2MessageContext) {
+ Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
+ org.apache.axis2.context.MessageContext axis2MessageCtx =
+ axis2smc.getAxis2MessageContext();
+ axis2MessageCtx.getConfigurationContext().setProperty(name, value);
- } else if (Constants.SCOPE_AXIS2.equals(getScope()) && smc instanceof Axis2MessageContext) {
+ } else if (Constants.SCOPE_TRANSPORT.equals(scope)
+ && smc instanceof Axis2MessageContext) {
Axis2MessageContext axis2smc = (Axis2MessageContext) smc;
org.apache.axis2.context.MessageContext axis2MessageCtx =
- axis2smc.getAxis2MessageContext();
- axis2MessageCtx.getConfigurationContext().setProperty(getName(), value);
+ axis2smc.getAxis2MessageContext();
+ Object headers = axis2MessageCtx.getProperty(
+ org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
+
+ if (headers != null && headers instanceof Map) {
+ Map headersMap = (HashMap) headers;
+ headersMap.put(name, value);
+ }
+ if (headers == null) {
+ Map headersMap = new HashMap();
+ headersMap.put(name, value);
+ axis2MessageCtx.setProperty(
+ org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS,
+ headersMap);
+ }
} else {
String msg = "Unsupported scope : " + scope + " for set-property mediator";
- log.error(msg);
- throw new SynapseException(msg);
+ handleException(msg);
}
if (shouldTrace) {
@@ -89,6 +112,11 @@
return true;
}
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
public String getName() {
return name;
}
@@ -112,12 +140,12 @@
public void setExpression(AXIOMXPath expression) {
this.expression = expression;
}
-
+
public String getScope() {
- return scope;
+ return scope;
}
-
+
public void setScope(String scope) {
- this.scope = scope;
+ this.scope = scope;
}
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/ClassMediator.java Mon Mar 5 02:33:25 2007
@@ -61,7 +61,7 @@
if (shouldTrace) {
trace.trace("Start : Class mediator");
}
- Mediator m = null;
+ Mediator m ;
try {
try {
m = (Mediator) clazz.newInstance();
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/filters/SwitchMediator.java Mon Mar 5 02:33:25 2007
@@ -24,6 +24,8 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.Constants;
import org.apache.synapse.MessageContext;
+import org.apache.synapse.config.xml.SwitchCase;
+import org.apache.synapse.config.xml.AnonymousListMediator;
import org.apache.synapse.core.axis2.Axis2MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
@@ -42,18 +44,12 @@
private static final Log log = LogFactory.getLog(SwitchMediator.class);
private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
- /**
- * The XPath expression specifying the source element to apply the switch case expressions against
- */
+ /** The XPath expression specifying the source element to apply the switch case expressions against */
private AXIOMXPath source = null;
- /**
- * The list of switch cases
- */
+ /** The list of switch cases */
private List cases = new ArrayList();
- /**
- * The default switch case, if any
- */
- private SwitchCaseMediator defaultCase = null;
+ /** The default switch case, if any */
+ private SwitchCase defaultCase = null;
/**
* Iterate over switch cases and find match and execute selected sequence
@@ -77,18 +73,19 @@
trace.trace("Start Case mediator list");
}
Iterator iter = cases.iterator();
-
while (iter.hasNext()) {
- SwitchCaseMediator swCase = (SwitchCaseMediator) iter.next();
- if (swCase.matches(sourceText)) {
- if (shouldTrace) {
- trace.trace("Executing case for : " + swCase.getRegex());
+ SwitchCase swCase = (SwitchCase) iter.next();
+ if (swCase != null) {
+ if (swCase.matches(sourceText)) {
+ if (shouldTrace) {
+ trace.trace("Executing case for : " + swCase.getRegex());
+ }
+ return swCase.mediate(synCtx);
}
- return swCase.mediate(synCtx);
}
}
if (shouldTrace) {
- trace.trace("End Case mediator lis");
+ trace.trace("End Case mediator list");
}
if (defaultCase != null) {
log.debug("Executing default case");
@@ -112,7 +109,7 @@
*
* @param m the SwitchCaseMediator instance to be added
*/
- public void addCase(SwitchCaseMediator m) {
+ public void addCase(SwitchCase m) {
cases.add(m);
}
@@ -148,7 +145,11 @@
*
* @return the default csae
*/
- public SwitchCaseMediator getDefaultCase() {
+ public SwitchCase getDefaultCase() {
return defaultCase;
+ }
+
+ public void setDefaultCase(SwitchCase defaultCase) {
+ this.defaultCase = defaultCase;
}
}
Modified: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/filters/SwitchMediatorTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/filters/SwitchMediatorTest.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/filters/SwitchMediatorTest.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/filters/SwitchMediatorTest.java Mon Mar 5 02:33:25 2007
@@ -23,6 +23,8 @@
import org.apache.axiom.om.xpath.AXIOMXPath;
import org.apache.synapse.MessageContext;
import org.apache.synapse.Mediator;
+import org.apache.synapse.config.xml.SwitchCase;
+import org.apache.synapse.config.xml.AnonymousListMediator;
import org.apache.synapse.mediators.TestMediateHandler;
import org.apache.synapse.mediators.TestMediator;
import org.apache.synapse.mediators.TestUtils;
@@ -84,14 +86,25 @@
AXIOMXPath xpath = new AXIOMXPath("//wsx:symbol");
xpath.addNamespace("wsx", "http://www.webserviceX.NET/");
switchMediator.setSource(xpath);
-
+ SwitchCase caseOne = new SwitchCase();
+ caseOne.setRegex(Pattern.compile("IBM"));
+ AnonymousListMediator mediatorOne = new AnonymousListMediator();
+ mediatorOne.addAll(Arrays.asList(new Mediator[] {ibmMediator}));
+ caseOne.setCaseMediator(mediatorOne);
+ SwitchCase caseTwo = new SwitchCase();
+ caseTwo.setRegex(Pattern.compile("MSFT"));
+ AnonymousListMediator mediatorTwo = new AnonymousListMediator();
+ mediatorTwo.addAll(Arrays.asList(new Mediator[] {msftMediator}));
+ caseTwo.setCaseMediator(mediatorTwo);
+
+ SwitchCase caseDefault = new SwitchCase();
+ AnonymousListMediator mediatorDefault = new AnonymousListMediator();
+ mediatorDefault.addAll(Arrays.asList(new Mediator[] {defaultMediator}));
+ caseDefault.setCaseMediator(mediatorDefault);
// set ibm mediator to be called for IBM, msft for MSFT and default for others..
- switchMediator.addCase(new SwitchCaseMediator(Pattern.compile("IBM"), false,
- Arrays.asList(new Mediator[] {ibmMediator})));
- switchMediator.addCase(new SwitchCaseMediator(Pattern.compile("MSFT"), false,
- Arrays.asList(new Mediator[] {msftMediator})));
- switchMediator.addCase(new SwitchCaseMediator(null, true,
- Arrays.asList(new Mediator[] {defaultMediator})));
+ switchMediator.addCase(caseOne);
+ switchMediator.addCase(caseTwo);
+ switchMediator.setDefaultCase(caseDefault);
}
public void testSwitchConditionCaseOne() throws Exception {
Modified: webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java?view=diff&rev=514639&r1=514638&r2=514639
==============================================================================
--- webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java (original)
+++ webservices/synapse/trunk/java/modules/nhttp/src/org/apache/axis2/transport/nhttp/HttpCoreNIOSender.java Mon Mar 5 02:33:25 2007
@@ -165,6 +165,9 @@
*/
public InvocationResponse invoke(MessageContext msgContext) throws AxisFault {
+ // remove unwanted HTTP headers (if any from the current message)
+ removeUnwantedHeaders(msgContext);
+
EndpointReference epr = Util.getDestinationEPR(msgContext);
if (epr != null) {
if (!AddressingConstants.Final.WSA_NONE_URI.equals(epr.getAddress())) {
@@ -193,6 +196,24 @@
}
/**
+ * Remove unwanted headers from the http response of outgoing request. These are headers which
+ * should be dictated by the transport and not the user. We remove these as these may get
+ * copied from the request messages
+ * @param msgContext the Axis2 Message context from which these headers should be removed
+ */
+ private void removeUnwantedHeaders(MessageContext msgContext) {
+ Map headers = (Map) msgContext.getProperty(MessageContext.TRANSPORT_HEADERS);
+ if (headers != null && !headers.isEmpty()) {
+ headers.remove(HTTP.CONN_DIRECTIVE);
+ headers.remove(HTTP.TRANSFER_ENCODING);
+ headers.remove(HTTP.DATE_DIRECTIVE);
+ headers.remove(HTTP.SERVER_DIRECTIVE);
+ headers.remove(HTTP.CONTENT_TYPE);
+ headers.remove(HTTP.CONTENT_LEN);
+ }
+ }
+
+ /**
* Send the request message asynchronously to the given EPR
* @param epr the destination EPR for the message
* @param msgContext the message being sent
@@ -224,7 +245,7 @@
((ClientHandler) handler).submitRequest(conn, axis2Req);
log.debug("An existing connection reused");
}
-
+
axis2Req.streamMessageContents();
} catch (MalformedURLException e) {
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org