You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by as...@apache.org on 2007/03/17 17:18:47 UTC
svn commit: r519363 [6/16] - in /webservices/synapse/trunk/java:
modules/core/ modules/core/src/main/java/org/apache/synapse/
modules/core/src/main/java/org/apache/synapse/config/
modules/core/src/main/java/org/apache/synapse/config/xml/ modules/core/s...
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java Sat Mar 17 09:18:32 2007
@@ -1,83 +1,83 @@
-/*
- * 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;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.MessageContext;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-/**
- * This class implements the base functionality of a List mediator
- *
- * @see ListMediator
- */
-public abstract class AbstractListMediator extends AbstractMediator implements ListMediator {
-
- private static final Log log = LogFactory.getLog(AbstractListMediator.class);
-
- protected List mediators = new ArrayList();
-
- public boolean mediate(MessageContext synCtx) {
- try {
- log.debug("Implicit Sequence <" + getType() + "> :: mediate()");
- saveAndSetTraceState(synCtx);
- Iterator it = mediators.iterator();
- while (it.hasNext()) {
- Mediator m = (Mediator) it.next();
- if (!m.mediate(synCtx)) {
- return false;
- }
- }
- }
- finally {
- restoreTracingState(synCtx);
- }
- return true;
- }
-
- public List getList() {
- return mediators;
- }
-
- public boolean addChild(Mediator m) {
- return mediators.add(m);
- }
-
- public boolean addAll(List c) {
- return mediators.addAll(c);
- }
-
- public Mediator getChild(int pos) {
- return (Mediator) mediators.get(pos);
- }
-
- public boolean removeChild(Mediator m) {
- return mediators.remove(m);
- }
-
- public Mediator removeChild(int pos) {
- return (Mediator) mediators.remove(pos);
- }
-}
+/*
+ * 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;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+/**
+ * This class implements the base functionality of a List mediator
+ *
+ * @see ListMediator
+ */
+public abstract class AbstractListMediator extends AbstractMediator implements ListMediator {
+
+ private static final Log log = LogFactory.getLog(AbstractListMediator.class);
+
+ protected List mediators = new ArrayList();
+
+ public boolean mediate(MessageContext synCtx) {
+ try {
+ log.debug("Implicit Sequence <" + getType() + "> :: mediate()");
+ saveAndSetTraceState(synCtx);
+ Iterator it = mediators.iterator();
+ while (it.hasNext()) {
+ Mediator m = (Mediator) it.next();
+ if (!m.mediate(synCtx)) {
+ return false;
+ }
+ }
+ }
+ finally {
+ restoreTracingState(synCtx);
+ }
+ return true;
+ }
+
+ public List getList() {
+ return mediators;
+ }
+
+ public boolean addChild(Mediator m) {
+ return mediators.add(m);
+ }
+
+ public boolean addAll(List c) {
+ return mediators.addAll(c);
+ }
+
+ public Mediator getChild(int pos) {
+ return (Mediator) mediators.get(pos);
+ }
+
+ public boolean removeChild(Mediator m) {
+ return mediators.remove(m);
+ }
+
+ public Mediator removeChild(int pos) {
+ return (Mediator) mediators.remove(pos);
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractListMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java Sat Mar 17 09:18:32 2007
@@ -1,100 +1,100 @@
-/*
- * 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;
-
-import org.apache.synapse.Constants;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.MessageContext;
-
-/**
- * This class is an abstract Mediator, that defines the logging and debugging
- * elements of a mediator class.
- */
-public abstract class AbstractMediator implements Mediator {
-
- /** The parent tracing state */
- protected int parentTraceState = Constants.TRACING_UNSET;
-
- /** State of tracing for the current mediator */
- protected int traceState = Constants.TRACING_UNSET;
-
- /**
- * Returns the class name of the mediator
- *
- * @return the class name of the mediator
- */
- public String getType() {
- String cls = getClass().getName();
- int p = cls.lastIndexOf(".");
- if (p == -1)
- return cls;
- else
- return cls.substring(p + 1);
- }
-
- /**
- * Returns the tracing state
- *
- * @return int
- */
- public int getTraceState() {
- return traceState;
- }
-
- /**
- * Set the tracing state variable
- *
- * @param traceState
- */
- public void setTraceState(int traceState) {
- this.traceState = traceState;
- }
-
- /**
- * This method is used to save previous tracing state and set next the tracing state for a child
- * mediator
- *
- * @param synCtx current message
- */
- public void saveAndSetTraceState(MessageContext synCtx) {
- parentTraceState = synCtx.getTracingState();
- synCtx.setTracingState(traceState);
- }
-
- /**
- * This method is used to restore parent tracing state back
- * @param synCtx the current message
- */
- public void restoreTracingState(MessageContext synCtx){
- synCtx.setTracingState(parentTraceState);
- }
-
- /**
- * Should this mediator perform tracing? True if its explicitly asked to
- * trace, or its parent has been asked to trace and it does not reject it
- * @param parentTraceState parents trace state
- * @return true if tracing should be performed
- */
- public boolean shouldTrace(int parentTraceState){
- return (traceState == Constants.TRACING_ON) ||
- (traceState == Constants.TRACING_UNSET &&
- parentTraceState == Constants.TRACING_ON);
- }
-}
+/*
+ * 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;
+
+import org.apache.synapse.Constants;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.MessageContext;
+
+/**
+ * This class is an abstract Mediator, that defines the logging and debugging
+ * elements of a mediator class.
+ */
+public abstract class AbstractMediator implements Mediator {
+
+ /** The parent tracing state */
+ protected int parentTraceState = Constants.TRACING_UNSET;
+
+ /** State of tracing for the current mediator */
+ protected int traceState = Constants.TRACING_UNSET;
+
+ /**
+ * Returns the class name of the mediator
+ *
+ * @return the class name of the mediator
+ */
+ public String getType() {
+ String cls = getClass().getName();
+ int p = cls.lastIndexOf(".");
+ if (p == -1)
+ return cls;
+ else
+ return cls.substring(p + 1);
+ }
+
+ /**
+ * Returns the tracing state
+ *
+ * @return int
+ */
+ public int getTraceState() {
+ return traceState;
+ }
+
+ /**
+ * Set the tracing state variable
+ *
+ * @param traceState
+ */
+ public void setTraceState(int traceState) {
+ this.traceState = traceState;
+ }
+
+ /**
+ * This method is used to save previous tracing state and set next the tracing state for a child
+ * mediator
+ *
+ * @param synCtx current message
+ */
+ public void saveAndSetTraceState(MessageContext synCtx) {
+ parentTraceState = synCtx.getTracingState();
+ synCtx.setTracingState(traceState);
+ }
+
+ /**
+ * This method is used to restore parent tracing state back
+ * @param synCtx the current message
+ */
+ public void restoreTracingState(MessageContext synCtx){
+ synCtx.setTracingState(parentTraceState);
+ }
+
+ /**
+ * Should this mediator perform tracing? True if its explicitly asked to
+ * trace, or its parent has been asked to trace and it does not reject it
+ * @param parentTraceState parents trace state
+ * @return true if tracing should be performed
+ */
+ public boolean shouldTrace(int parentTraceState){
+ return (traceState == Constants.TRACING_ON) ||
+ (traceState == Constants.TRACING_UNSET &&
+ parentTraceState == Constants.TRACING_ON);
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/AbstractMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/FilterMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/FilterMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/FilterMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/FilterMediator.java Sat Mar 17 09:18:32 2007
@@ -1,39 +1,39 @@
-/*
- * 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;
-
-import org.apache.synapse.MessageContext;
-
-/**
- * The filter mediator is a list mediator, which executes the given (sub) list of mediators
- * if the specified condition is satisfied
- *
- * @see FilterMediator#test(org.apache.synapse.MessageContext)
- */
-public interface FilterMediator extends ListMediator {
-
- /**
- * Should return true if the sub/child mediators should execute. i.e. if the filter
- * condition is satisfied
- * @param synCtx
- * @return true if the configured filter condition evaluates to true
- */
- public boolean test(MessageContext synCtx);
-}
+/*
+ * 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;
+
+import org.apache.synapse.MessageContext;
+
+/**
+ * The filter mediator is a list mediator, which executes the given (sub) list of mediators
+ * if the specified condition is satisfied
+ *
+ * @see FilterMediator#test(org.apache.synapse.MessageContext)
+ */
+public interface FilterMediator extends ListMediator {
+
+ /**
+ * Should return true if the sub/child mediators should execute. i.e. if the filter
+ * condition is satisfied
+ * @param synCtx
+ * @return true if the configured filter condition evaluates to true
+ */
+ public boolean test(MessageContext synCtx);
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/FilterMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/GetPropertyFunction.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java Sat Mar 17 09:18:32 2007
@@ -1,72 +1,72 @@
-/*
- * 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;
-
-import org.apache.synapse.Mediator;
-
-import java.util.List;
-
-/**
- * The List mediator executes a given sequence/list of child mediators
- */
-public interface ListMediator extends Mediator {
-
- /**
- * Appends the specified mediator to the end of this mediator's (children) list
- * @param m the mediator to be added
- * @return true (as per the general contract of the Collection.add method)
- */
- public boolean addChild(Mediator m);
-
- /**
- * Appends all of the mediators in the specified collection to the end of this mediator's (children)
- * list, in the order that they are returned by the specified collection's iterator
- * @param c the list of mediators to be added
- * @return true if this list changed as a result of the call
- */
- public boolean addAll(List c);
-
- /**
- * Returns the mediator at the specified position
- * @param pos index of mediator to return
- * @return the mediator at the specified position in this list
- */
- public Mediator getChild(int pos);
-
- /**
- * Removes the first occurrence in this list of the specified mediator
- * @param m mediator to be removed from this list, if present
- * @return true if this list contained the specified mediator
- */
- public boolean removeChild(Mediator m);
-
- /**
- * Removes the mediator at the specified position in this list
- * @param pos the index of the mediator to remove
- * @return the mediator previously at the specified position
- */
- public Mediator removeChild(int pos);
-
- /**
- * Return the list of mediators of this List mediator instance
- * @return the child/sub mediator list
- */
- public List getList();
-}
+/*
+ * 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;
+
+import org.apache.synapse.Mediator;
+
+import java.util.List;
+
+/**
+ * The List mediator executes a given sequence/list of child mediators
+ */
+public interface ListMediator extends Mediator {
+
+ /**
+ * Appends the specified mediator to the end of this mediator's (children) list
+ * @param m the mediator to be added
+ * @return true (as per the general contract of the Collection.add method)
+ */
+ public boolean addChild(Mediator m);
+
+ /**
+ * Appends all of the mediators in the specified collection to the end of this mediator's (children)
+ * list, in the order that they are returned by the specified collection's iterator
+ * @param c the list of mediators to be added
+ * @return true if this list changed as a result of the call
+ */
+ public boolean addAll(List c);
+
+ /**
+ * Returns the mediator at the specified position
+ * @param pos index of mediator to return
+ * @return the mediator at the specified position in this list
+ */
+ public Mediator getChild(int pos);
+
+ /**
+ * Removes the first occurrence in this list of the specified mediator
+ * @param m mediator to be removed from this list, if present
+ * @return true if this list contained the specified mediator
+ */
+ public boolean removeChild(Mediator m);
+
+ /**
+ * Removes the mediator at the specified position in this list
+ * @param pos the index of the mediator to remove
+ * @return the mediator previously at the specified position
+ */
+ public Mediator removeChild(int pos);
+
+ /**
+ * Return the list of mediators of this List mediator instance
+ * @return the child/sub mediator list
+ */
+ public List getList();
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ListMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorFaultHandler.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java Sat Mar 17 09:18:32 2007
@@ -1,75 +1,75 @@
-/*
- * 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;
-
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.synapse.config.xml.Constants;
-
-import javax.xml.namespace.QName;
-
-/**
- * A mediator property is a name-value or name-expression pair which could be supplied
- * for certain mediators. If expressions are supplied they are evaluated at the runtime
- * against the current message into literal String values.
- */
-public class MediatorProperty {
-
- public static final QName PROPERTY_Q = new QName(Constants.SYNAPSE_NAMESPACE, "property");
- public static final QName ATT_NAME_Q = new QName(Constants.NULL_NAMESPACE, "name");
- public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
- public static final QName ATT_EXPR_Q = new QName(Constants.NULL_NAMESPACE, "expression");
-
- private String name;
- private String value;
- private AXIOMXPath expression;
-
- public MediatorProperty() {}
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public AXIOMXPath getExpression() {
- return expression;
- }
-
- public void setExpression(AXIOMXPath expression) {
- this.expression = expression;
- }
-
- public String getEvaluatedExpression(MessageContext synCtx) {
- return Axis2MessageContext.getStringValue(expression, synCtx);
- }
-
-}
+/*
+ * 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;
+
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.config.xml.Constants;
+
+import javax.xml.namespace.QName;
+
+/**
+ * A mediator property is a name-value or name-expression pair which could be supplied
+ * for certain mediators. If expressions are supplied they are evaluated at the runtime
+ * against the current message into literal String values.
+ */
+public class MediatorProperty {
+
+ public static final QName PROPERTY_Q = new QName(Constants.SYNAPSE_NAMESPACE, "property");
+ public static final QName ATT_NAME_Q = new QName(Constants.NULL_NAMESPACE, "name");
+ public static final QName ATT_VALUE_Q = new QName(Constants.NULL_NAMESPACE, "value");
+ public static final QName ATT_EXPR_Q = new QName(Constants.NULL_NAMESPACE, "expression");
+
+ private String name;
+ private String value;
+ private AXIOMXPath expression;
+
+ public MediatorProperty() {}
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public AXIOMXPath getExpression() {
+ return expression;
+ }
+
+ public void setExpression(AXIOMXPath expression) {
+ this.expression = expression;
+ }
+
+ public String getEvaluatedExpression(MessageContext synCtx) {
+ return Axis2MessageContext.getStringValue(expression, synCtx);
+ }
+
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/MediatorProperty.java
------------------------------------------------------------------------------
svn:eol-style = native
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=519363&r1=519362&r2=519363
==============================================================================
--- 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 Sat Mar 17 09:18:32 2007
@@ -1,221 +1,221 @@
-/*
- * 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.base;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Mediator;
-import org.apache.synapse.Constants;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.mediators.AbstractListMediator;
-import org.apache.synapse.mediators.MediatorFaultHandler;
-import org.apache.synapse.statistics.StatisticsUtils;
-import org.apache.synapse.statistics.StatisticsStack;
-import org.apache.synapse.statistics.impl.SequenceStatisticsStack;
-
-import java.util.Stack;
-
-/**
- * The Sequence mediator either refers to a named Sequence mediator instance
- * or is a *Named* list/sequence of other (child) Mediators
- * <p/>
- * If this instance defines a sequence mediator, then the name is required, and
- * an errorHandler sequence name optional. If this instance refers to another (defined)
- * sequence mediator, the errorHandler will not have a meaning, and if an error in
- * encountered in the reffered sequence, its errorHandler would execute.
- */
-public class SequenceMediator extends AbstractListMediator {
-
- private static final Log log = LogFactory.getLog(SequenceMediator.class);
- private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
- private String name = null;
- private String key = null;
- private String errorHandler = null;
- /** is this definition dynamic */
- private boolean dynamic = false;
- /** the registry key to load this definition if dynamic */
- private String registryKey = null;
-
- /** To decide to whether statistics should have collected or not */
- private int statisticsEnable = Constants.STATISTICS_UNSET;
-
- /**
- * If this mediator refers to another named Sequence, execute that. Else
- * execute the list of mediators (children) contained within this. If a referenced
- * named sequence mediator instance cannot be found at runtime, an exception is
- * thrown. This may occur due to invalid configuration of an erroneous runtime
- * change of the synapse configuration. It is the responsibility of the
- * SynapseConfiguration builder to ensure that dead references are not present.
- *
- * @param synCtx the synapse message
- * @return as per standard mediator result
- */
- public boolean mediate(MessageContext synCtx) {
- log.debug("Sequence mediator <" + (name == null ? "anonymous" : name) + "> :: mediate()");
- boolean shouldTrace = shouldTrace(synCtx.getTracingState());
- if (key == null) {
- // Setting Required property to collect the sequence statistics
- boolean isStatisticsEnable = (org.apache.synapse.Constants.STATISTICS_ON == statisticsEnable);
- if (isStatisticsEnable) {
- StatisticsStack sequenceStack = (StatisticsStack) synCtx.getProperty(Constants.SEQUENCE_STATISTICS_STACK);
- if (sequenceStack == null) {
- sequenceStack = new SequenceStatisticsStack();
- synCtx.setProperty(Constants.SEQUENCE_STATISTICS_STACK, sequenceStack);
- }
- String seqName = (name == null ? "anonymous" : name);
- boolean isFault =synCtx.getEnvelope().getBody().hasFault();
- sequenceStack.put(seqName, System.currentTimeMillis(), !synCtx.isResponse(), isStatisticsEnable,isFault);
- }
- try {
- if (shouldTrace) {
- trace.trace("Start : Sequence <" + (name == null ? "anonymous" : name) + ">");
- }
-
- // push the errorHandler sequence into the current message as the fault handler
- if (errorHandler != null) {
- synCtx.pushFaultHandler(
- new MediatorFaultHandler(synCtx.getSequence(errorHandler)));
- }
-
- boolean ret = super.mediate(synCtx);
-
- // pop our error handler from the fault stack before we exit, if we have pushed it
- Stack faultStack = synCtx.getFaultStack();
- if (errorHandler != null && !faultStack.isEmpty()) {
- Object o = faultStack.peek();
- if (o instanceof MediatorFaultHandler &&
- synCtx.getSequence(errorHandler).equals(
- ((MediatorFaultHandler) o).getFaultMediator())) {
- faultStack.pop();
- }
- }
-
- return ret;
-
- } finally {
-
- //If this sequence is finished it's task normally
- if (isStatisticsEnable) {
- StatisticsUtils.processSequenceStatistics(synCtx);
- }
- //If this sequence is a IN or OUT sequence of a proxy service
- StatisticsUtils.processProxyServiceStatistics(synCtx);
- if (shouldTrace) {
- trace.trace("End : Sequence <" + (name == null ? "anonymous" : name) + ">");
- }
- }
-
- } else {
- Mediator m = synCtx.getSequence(key);
- if (m == null) {
- if (shouldTrace) {
- trace.trace("Sequence named " + key + " cannot be found.");
- }
- handleException("Sequence named " + key + " cannot be found.");
- } else {
- if (shouldTrace) {
- trace.trace("Executing sequence named " + key);
- }
- return m.mediate(synCtx);
- }
- }
- return false;
- }
-
- private void handleException(String msg) {
- log.error(msg);
- throw new SynapseException(msg);
- }
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getKey() {
- return key;
- }
-
- public void setKey(String key) {
- this.key = key;
- }
-
- public String getErrorHandler() {
- return errorHandler;
- }
-
- public void setErrorHandler(String errorHandler) {
- this.errorHandler = errorHandler;
- }
-
- /**
- * To check whether statistics should have collected or not
- *
- * @return Returns the int value that indicate statistics is enabled or not.
- */
- public int getStatisticsEnable() {
- return statisticsEnable;
- }
-
- /**
- * To set the statistics enable variable value
- *
- * @param statisticsEnable
- */
- public void setStatisticsEnable(int statisticsEnable) {
- this.statisticsEnable = statisticsEnable;
- }
-
- /**
- * Is this a dynamic sequence?
- * @return true if dynamic
- */
- public boolean isDynamic() {
- return dynamic;
- }
-
- /**
- * Mark this as a dynamic sequence
- * @param dynamic true if this is a dynamic sequence
- */
- public void setDynamic(boolean dynamic) {
- this.dynamic = dynamic;
- }
-
- /**
- * Return the registry key used to load this sequence dynamically
- * @return registry key
- */
- public String getRegistryKey() {
- return registryKey;
- }
-
- /**
- * get the registry key used to load this sequence dynamically
- * @param registryKey
- */
- public void setRegistryKey(String registryKey) {
- this.registryKey = registryKey;
- }
-}
+/*
+ * 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.base;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.apache.synapse.mediators.MediatorFaultHandler;
+import org.apache.synapse.statistics.StatisticsUtils;
+import org.apache.synapse.statistics.StatisticsStack;
+import org.apache.synapse.statistics.impl.SequenceStatisticsStack;
+
+import java.util.Stack;
+
+/**
+ * The Sequence mediator either refers to a named Sequence mediator instance
+ * or is a *Named* list/sequence of other (child) Mediators
+ * <p/>
+ * If this instance defines a sequence mediator, then the name is required, and
+ * an errorHandler sequence name optional. If this instance refers to another (defined)
+ * sequence mediator, the errorHandler will not have a meaning, and if an error in
+ * encountered in the reffered sequence, its errorHandler would execute.
+ */
+public class SequenceMediator extends AbstractListMediator {
+
+ private static final Log log = LogFactory.getLog(SequenceMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+ private String name = null;
+ private String key = null;
+ private String errorHandler = null;
+ /** is this definition dynamic */
+ private boolean dynamic = false;
+ /** the registry key to load this definition if dynamic */
+ private String registryKey = null;
+
+ /** To decide to whether statistics should have collected or not */
+ private int statisticsEnable = Constants.STATISTICS_UNSET;
+
+ /**
+ * If this mediator refers to another named Sequence, execute that. Else
+ * execute the list of mediators (children) contained within this. If a referenced
+ * named sequence mediator instance cannot be found at runtime, an exception is
+ * thrown. This may occur due to invalid configuration of an erroneous runtime
+ * change of the synapse configuration. It is the responsibility of the
+ * SynapseConfiguration builder to ensure that dead references are not present.
+ *
+ * @param synCtx the synapse message
+ * @return as per standard mediator result
+ */
+ public boolean mediate(MessageContext synCtx) {
+ log.debug("Sequence mediator <" + (name == null ? "anonymous" : name) + "> :: mediate()");
+ boolean shouldTrace = shouldTrace(synCtx.getTracingState());
+ if (key == null) {
+ // Setting Required property to collect the sequence statistics
+ boolean isStatisticsEnable = (org.apache.synapse.Constants.STATISTICS_ON == statisticsEnable);
+ if (isStatisticsEnable) {
+ StatisticsStack sequenceStack = (StatisticsStack) synCtx.getProperty(Constants.SEQUENCE_STATISTICS_STACK);
+ if (sequenceStack == null) {
+ sequenceStack = new SequenceStatisticsStack();
+ synCtx.setProperty(Constants.SEQUENCE_STATISTICS_STACK, sequenceStack);
+ }
+ String seqName = (name == null ? "anonymous" : name);
+ boolean isFault =synCtx.getEnvelope().getBody().hasFault();
+ sequenceStack.put(seqName, System.currentTimeMillis(), !synCtx.isResponse(), isStatisticsEnable,isFault);
+ }
+ try {
+ if (shouldTrace) {
+ trace.trace("Start : Sequence <" + (name == null ? "anonymous" : name) + ">");
+ }
+
+ // push the errorHandler sequence into the current message as the fault handler
+ if (errorHandler != null) {
+ synCtx.pushFaultHandler(
+ new MediatorFaultHandler(synCtx.getSequence(errorHandler)));
+ }
+
+ boolean ret = super.mediate(synCtx);
+
+ // pop our error handler from the fault stack before we exit, if we have pushed it
+ Stack faultStack = synCtx.getFaultStack();
+ if (errorHandler != null && !faultStack.isEmpty()) {
+ Object o = faultStack.peek();
+ if (o instanceof MediatorFaultHandler &&
+ synCtx.getSequence(errorHandler).equals(
+ ((MediatorFaultHandler) o).getFaultMediator())) {
+ faultStack.pop();
+ }
+ }
+
+ return ret;
+
+ } finally {
+
+ //If this sequence is finished it's task normally
+ if (isStatisticsEnable) {
+ StatisticsUtils.processSequenceStatistics(synCtx);
+ }
+ //If this sequence is a IN or OUT sequence of a proxy service
+ StatisticsUtils.processProxyServiceStatistics(synCtx);
+ if (shouldTrace) {
+ trace.trace("End : Sequence <" + (name == null ? "anonymous" : name) + ">");
+ }
+ }
+
+ } else {
+ Mediator m = synCtx.getSequence(key);
+ if (m == null) {
+ if (shouldTrace) {
+ trace.trace("Sequence named " + key + " cannot be found.");
+ }
+ handleException("Sequence named " + key + " cannot be found.");
+ } else {
+ if (shouldTrace) {
+ trace.trace("Executing sequence named " + key);
+ }
+ return m.mediate(synCtx);
+ }
+ }
+ return false;
+ }
+
+ private void handleException(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getKey() {
+ return key;
+ }
+
+ public void setKey(String key) {
+ this.key = key;
+ }
+
+ public String getErrorHandler() {
+ return errorHandler;
+ }
+
+ public void setErrorHandler(String errorHandler) {
+ this.errorHandler = errorHandler;
+ }
+
+ /**
+ * To check whether statistics should have collected or not
+ *
+ * @return Returns the int value that indicate statistics is enabled or not.
+ */
+ public int getStatisticsEnable() {
+ return statisticsEnable;
+ }
+
+ /**
+ * To set the statistics enable variable value
+ *
+ * @param statisticsEnable
+ */
+ public void setStatisticsEnable(int statisticsEnable) {
+ this.statisticsEnable = statisticsEnable;
+ }
+
+ /**
+ * Is this a dynamic sequence?
+ * @return true if dynamic
+ */
+ public boolean isDynamic() {
+ return dynamic;
+ }
+
+ /**
+ * Mark this as a dynamic sequence
+ * @param dynamic true if this is a dynamic sequence
+ */
+ public void setDynamic(boolean dynamic) {
+ this.dynamic = dynamic;
+ }
+
+ /**
+ * Return the registry key used to load this sequence dynamically
+ * @return registry key
+ */
+ public String getRegistryKey() {
+ return registryKey;
+ }
+
+ /**
+ * get the registry key used to load this sequence dynamically
+ * @param registryKey
+ */
+ public void setRegistryKey(String registryKey) {
+ this.registryKey = registryKey;
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SequenceMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java Sat Mar 17 09:18:32 2007
@@ -1,76 +1,76 @@
-/*
- * 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.base;
-
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.statistics.StatisticsStack;
-import org.apache.synapse.statistics.StatisticsUtils;
-import org.apache.synapse.statistics.impl.SequenceStatisticsStack;
-import org.apache.synapse.mediators.AbstractListMediator;
-
-/**
- * The SynapseMediator is the "mainmediator" of the synapse engine. It is
- * given each message on arrival at the synapse engine. The synapse configuration
- * holds a reference to this special mediator instance. The SynapseMediator
- * holds the list of mediators supplied within the <rules> element of an XML
- * based Synapse configuration
- *
- * @see org.apache.synapse.config.SynapseConfiguration#getMainSequence()
- */
-public class SynapseMediator extends AbstractListMediator {
-
- private static final Log log = LogFactory.getLog(SynapseMediator.class);
- private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
-
- /**
- * Perform the mediation specified by the rule set
- *
- * @param synCtx the message context
- * @return as per standard mediate() semantics
- */
- public boolean mediate(MessageContext synCtx) {
- log.debug("Synapse main mediator :: mediate()");
- if(synCtx.isResponse()) {
- StatisticsUtils.processAllSequenceStatistics(synCtx);
- }
- StatisticsStack sequenceStack = (StatisticsStack) synCtx.getProperty(Constants.SEQUENCE_STATISTICS_STACK);
- if (sequenceStack == null) {
- sequenceStack = new SequenceStatisticsStack();
- synCtx.setProperty(Constants.SEQUENCE_STATISTICS_STACK, sequenceStack);
- }
- String seqName = "MainSequence";
- boolean isFault = synCtx.getEnvelope().getBody().hasFault();
- sequenceStack.put(seqName, System.currentTimeMillis(), !synCtx.isResponse(), true, isFault);
- boolean shouldTrace = shouldTrace(synCtx.getTracingState());
- try {
- if (shouldTrace) {
- trace.trace("Start : Synapse main mediator");
- }
- return super.mediate(synCtx);
- } finally {
- if (shouldTrace) {
- trace.trace("End : Synapse main mediator");
- }
- }
- }
-}
+/*
+ * 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.base;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.statistics.StatisticsStack;
+import org.apache.synapse.statistics.StatisticsUtils;
+import org.apache.synapse.statistics.impl.SequenceStatisticsStack;
+import org.apache.synapse.mediators.AbstractListMediator;
+
+/**
+ * The SynapseMediator is the "mainmediator" of the synapse engine. It is
+ * given each message on arrival at the synapse engine. The synapse configuration
+ * holds a reference to this special mediator instance. The SynapseMediator
+ * holds the list of mediators supplied within the <rules> element of an XML
+ * based Synapse configuration
+ *
+ * @see org.apache.synapse.config.SynapseConfiguration#getMainSequence()
+ */
+public class SynapseMediator extends AbstractListMediator {
+
+ private static final Log log = LogFactory.getLog(SynapseMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+
+ /**
+ * Perform the mediation specified by the rule set
+ *
+ * @param synCtx the message context
+ * @return as per standard mediate() semantics
+ */
+ public boolean mediate(MessageContext synCtx) {
+ log.debug("Synapse main mediator :: mediate()");
+ if(synCtx.isResponse()) {
+ StatisticsUtils.processAllSequenceStatistics(synCtx);
+ }
+ StatisticsStack sequenceStack = (StatisticsStack) synCtx.getProperty(Constants.SEQUENCE_STATISTICS_STACK);
+ if (sequenceStack == null) {
+ sequenceStack = new SequenceStatisticsStack();
+ synCtx.setProperty(Constants.SEQUENCE_STATISTICS_STACK, sequenceStack);
+ }
+ String seqName = "MainSequence";
+ boolean isFault = synCtx.getEnvelope().getBody().hasFault();
+ sequenceStack.put(seqName, System.currentTimeMillis(), !synCtx.isResponse(), true, isFault);
+ boolean shouldTrace = shouldTrace(synCtx.getTracingState());
+ try {
+ if (shouldTrace) {
+ trace.trace("Start : Synapse main mediator");
+ }
+ return super.mediate(synCtx);
+ } finally {
+ if (shouldTrace) {
+ trace.trace("End : Synapse main mediator");
+ }
+ }
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/base/SynapseMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/DropMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
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=519363&r1=519362&r2=519363
==============================================================================
--- 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 Sat Mar 17 09:18:32 2007
@@ -1,191 +1,191 @@
-/*
- * 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.builtin;
-
-import org.apache.axiom.soap.SOAPHeaderBlock;
-import org.apache.axiom.om.OMElement;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.mediators.MediatorProperty;
-
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-
-/**
- * Logs the specified message into the configured logger. The log levels specify
- * which attributes would be logged, and is configurable. Additionally custom
- * properties may be defined to the logger, where literal values or expressions
- * could be specified for logging. The custom properties are printed into the log
- * using the defined separator (\n, "," etc)
- */
-public class LogMediator extends AbstractMediator {
-
- private static final Log log = LogFactory.getLog(LogMediator.class);
- private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
- public static final int CUSTOM = 0;
- public static final int SIMPLE = 1;
- public static final int HEADERS = 2;
- public static final int FULL = 3;
- public static final String DEFAULT_SEP = ", ";
-
- private int logLevel = SIMPLE;
- private String separator = DEFAULT_SEP;
- private List properties = new ArrayList();
-
- /**
- * Logs the current message according to the supplied semantics
- *
- * @param synCtx (current) message to be logged
- * @return true always
- */
- public boolean mediate(MessageContext synCtx) {
- log.debug("Log mediator :: mediate()");
- boolean shouldTrace = shouldTrace(synCtx.getTracingState());
- if (shouldTrace) {
- trace.trace("Start : Log mediator");
- }
- String logMessage = getLogMessage(synCtx);
- log.info(logMessage);
- if (shouldTrace) {
- trace.trace(logMessage);
- trace.trace("End : Log mediator");
- }
- return true;
- }
-
- private String getLogMessage(MessageContext synCtx) {
- switch (logLevel) {
- case CUSTOM:
- return getCustomLogMessage(synCtx);
- case SIMPLE:
- return getSimpleLogMessage(synCtx);
- case HEADERS:
- return getHeadersLogMessage(synCtx);
- case FULL:
- return getFullLogMessage(synCtx);
- default:
- return "Invalid log level specified";
- }
- }
-
- private String getCustomLogMessage(MessageContext synCtx) {
- StringBuffer sb = new StringBuffer();
- setCustomProperties(sb, synCtx);
- return trimLeadingSeparator(sb);
- }
-
- private String getSimpleLogMessage(MessageContext synCtx) {
- StringBuffer sb = new StringBuffer();
- if (synCtx.getTo() != null)
- sb.append("To: " + synCtx.getTo().getAddress());
- else
- sb.append("To: ");
- if (synCtx.getFrom() != null)
- sb.append(separator + "From: " + synCtx.getFrom().getAddress());
- if (synCtx.getWSAAction() != null)
- sb.append(separator + "WSAction: " + synCtx.getWSAAction());
- if (synCtx.getSoapAction() != null)
- sb.append(separator + "SOAPAction: " + synCtx.getSoapAction());
- if (synCtx.getReplyTo() != null)
- sb.append(separator + "ReplyTo: " + synCtx.getReplyTo().getAddress());
- if (synCtx.getMessageID() != null)
- sb.append(separator + "MessageID: " + synCtx.getMessageID());
- setCustomProperties(sb, synCtx);
- return trimLeadingSeparator(sb);
- }
-
- private String getHeadersLogMessage(MessageContext synCtx) {
- StringBuffer sb = new StringBuffer();
- Iterator iter = synCtx.getEnvelope().getHeader().examineAllHeaderBlocks();
- while (iter.hasNext()) {
- Object o = iter.next();
- if (o instanceof SOAPHeaderBlock) {
- SOAPHeaderBlock header = (SOAPHeaderBlock) o;
- sb.append(separator + header.getLocalName() + " : " + header.getText());
- } else if (o instanceof OMElement) {
- OMElement headerElem = (OMElement) o;
- sb.append(separator + headerElem.getLocalName() + " : " + headerElem.getText());
- }
- }
- setCustomProperties(sb, synCtx);
- return trimLeadingSeparator(sb);
- }
-
- private String getFullLogMessage(MessageContext synCtx) {
- StringBuffer sb = new StringBuffer();
- sb.append(getSimpleLogMessage(synCtx));
- if (synCtx.getEnvelope() != null)
- sb.append(separator + "Envelope: " + synCtx.getEnvelope());
- return trimLeadingSeparator(sb);
- }
-
- private void setCustomProperties(StringBuffer sb, MessageContext synCtx) {
- if (properties != null && !properties.isEmpty()) {
- Iterator iter = properties.iterator();
- while (iter.hasNext()) {
- MediatorProperty prop = (MediatorProperty) iter.next();
- sb.append(separator + prop.getName() + " = " +
- (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synCtx)));
- }
- }
- }
-
- public int getLogLevel() {
- return logLevel;
- }
-
- public void setLogLevel(int logLevel) {
- this.logLevel = logLevel;
- }
-
- public String getSeparator() {
- return separator;
- }
-
- public void setSeparator(String separator) {
- this.separator = separator;
- }
-
- public void addProperty(MediatorProperty p) {
- properties.add(p);
- }
-
- public void addAllProperties(List list) {
- properties.addAll(list);
- }
-
- public List getProperties() {
- return properties;
- }
-
- private String trimLeadingSeparator(StringBuffer sb) {
- String retStr = sb.toString();
- if (retStr.startsWith(separator)) {
- return retStr.substring(separator.length());
- } else {
- return retStr;
- }
- }
-}
+/*
+ * 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.builtin;
+
+import org.apache.axiom.soap.SOAPHeaderBlock;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.mediators.MediatorProperty;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+
+/**
+ * Logs the specified message into the configured logger. The log levels specify
+ * which attributes would be logged, and is configurable. Additionally custom
+ * properties may be defined to the logger, where literal values or expressions
+ * could be specified for logging. The custom properties are printed into the log
+ * using the defined separator (\n, "," etc)
+ */
+public class LogMediator extends AbstractMediator {
+
+ private static final Log log = LogFactory.getLog(LogMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+ public static final int CUSTOM = 0;
+ public static final int SIMPLE = 1;
+ public static final int HEADERS = 2;
+ public static final int FULL = 3;
+ public static final String DEFAULT_SEP = ", ";
+
+ private int logLevel = SIMPLE;
+ private String separator = DEFAULT_SEP;
+ private List properties = new ArrayList();
+
+ /**
+ * Logs the current message according to the supplied semantics
+ *
+ * @param synCtx (current) message to be logged
+ * @return true always
+ */
+ public boolean mediate(MessageContext synCtx) {
+ log.debug("Log mediator :: mediate()");
+ boolean shouldTrace = shouldTrace(synCtx.getTracingState());
+ if (shouldTrace) {
+ trace.trace("Start : Log mediator");
+ }
+ String logMessage = getLogMessage(synCtx);
+ log.info(logMessage);
+ if (shouldTrace) {
+ trace.trace(logMessage);
+ trace.trace("End : Log mediator");
+ }
+ return true;
+ }
+
+ private String getLogMessage(MessageContext synCtx) {
+ switch (logLevel) {
+ case CUSTOM:
+ return getCustomLogMessage(synCtx);
+ case SIMPLE:
+ return getSimpleLogMessage(synCtx);
+ case HEADERS:
+ return getHeadersLogMessage(synCtx);
+ case FULL:
+ return getFullLogMessage(synCtx);
+ default:
+ return "Invalid log level specified";
+ }
+ }
+
+ private String getCustomLogMessage(MessageContext synCtx) {
+ StringBuffer sb = new StringBuffer();
+ setCustomProperties(sb, synCtx);
+ return trimLeadingSeparator(sb);
+ }
+
+ private String getSimpleLogMessage(MessageContext synCtx) {
+ StringBuffer sb = new StringBuffer();
+ if (synCtx.getTo() != null)
+ sb.append("To: " + synCtx.getTo().getAddress());
+ else
+ sb.append("To: ");
+ if (synCtx.getFrom() != null)
+ sb.append(separator + "From: " + synCtx.getFrom().getAddress());
+ if (synCtx.getWSAAction() != null)
+ sb.append(separator + "WSAction: " + synCtx.getWSAAction());
+ if (synCtx.getSoapAction() != null)
+ sb.append(separator + "SOAPAction: " + synCtx.getSoapAction());
+ if (synCtx.getReplyTo() != null)
+ sb.append(separator + "ReplyTo: " + synCtx.getReplyTo().getAddress());
+ if (synCtx.getMessageID() != null)
+ sb.append(separator + "MessageID: " + synCtx.getMessageID());
+ setCustomProperties(sb, synCtx);
+ return trimLeadingSeparator(sb);
+ }
+
+ private String getHeadersLogMessage(MessageContext synCtx) {
+ StringBuffer sb = new StringBuffer();
+ Iterator iter = synCtx.getEnvelope().getHeader().examineAllHeaderBlocks();
+ while (iter.hasNext()) {
+ Object o = iter.next();
+ if (o instanceof SOAPHeaderBlock) {
+ SOAPHeaderBlock header = (SOAPHeaderBlock) o;
+ sb.append(separator + header.getLocalName() + " : " + header.getText());
+ } else if (o instanceof OMElement) {
+ OMElement headerElem = (OMElement) o;
+ sb.append(separator + headerElem.getLocalName() + " : " + headerElem.getText());
+ }
+ }
+ setCustomProperties(sb, synCtx);
+ return trimLeadingSeparator(sb);
+ }
+
+ private String getFullLogMessage(MessageContext synCtx) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getSimpleLogMessage(synCtx));
+ if (synCtx.getEnvelope() != null)
+ sb.append(separator + "Envelope: " + synCtx.getEnvelope());
+ return trimLeadingSeparator(sb);
+ }
+
+ private void setCustomProperties(StringBuffer sb, MessageContext synCtx) {
+ if (properties != null && !properties.isEmpty()) {
+ Iterator iter = properties.iterator();
+ while (iter.hasNext()) {
+ MediatorProperty prop = (MediatorProperty) iter.next();
+ sb.append(separator + prop.getName() + " = " +
+ (prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression(synCtx)));
+ }
+ }
+ }
+
+ public int getLogLevel() {
+ return logLevel;
+ }
+
+ public void setLogLevel(int logLevel) {
+ this.logLevel = logLevel;
+ }
+
+ public String getSeparator() {
+ return separator;
+ }
+
+ public void setSeparator(String separator) {
+ this.separator = separator;
+ }
+
+ public void addProperty(MediatorProperty p) {
+ properties.add(p);
+ }
+
+ public void addAllProperties(List list) {
+ properties.addAll(list);
+ }
+
+ public List getProperties() {
+ return properties;
+ }
+
+ private String trimLeadingSeparator(StringBuffer sb) {
+ String retStr = sb.toString();
+ if (retStr.startsWith(separator)) {
+ return retStr.substring(separator.length());
+ } else {
+ return retStr;
+ }
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/LogMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/PropertyMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java?view=diff&rev=519363&r1=519362&r2=519363
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java Sat Mar 17 09:18:32 2007
@@ -1,227 +1,227 @@
-/*
- * 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.builtin;
-
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.Map;
-import java.util.Collections;
-
-import org.apache.axiom.om.OMElement;
-import org.apache.axiom.om.xpath.AXIOMXPath;
-import org.apache.axis2.util.UUIDGenerator;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.Constants;
-import org.apache.synapse.MessageContext;
-import org.apache.synapse.SynapseException;
-import org.apache.synapse.config.Entry;
-import org.apache.synapse.core.axis2.Axis2MessageContext;
-import org.apache.synapse.mediators.AbstractMediator;
-import org.jaxen.JaxenException;
-
-public class RMSequenceMediator extends AbstractMediator {
-
- private static Log log = LogFactory.getLog(RMSequenceMediator.class);
- private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
-
- private AXIOMXPath correlation = null;
- private AXIOMXPath lastMessage = null;
- private Boolean single = null;
- private String version = null;
-
- private static final String WSRM_SpecVersion_1_0 = "Spec_2005_02";
- private static final String WSRM_SpecVersion_1_1 = "Spec_2006_08";
- // set sequence expiry time to 5 minutes
- private static final long SEQUENCE_EXPIRY_TIME = 300000;
- private static Map sequenceMap = Collections.synchronizedMap(new HashMap());
-
- public boolean mediate(MessageContext smc) {
- if (log.isDebugEnabled()) {
- log.debug("RMSequence Mediator :: mediate() ");
- }
- boolean shouldTrace = shouldTrace(smc.getTracingState());
- if (shouldTrace) {
- trace.trace("Start : RMSequence mediator");
- }
- if (!(smc instanceof Axis2MessageContext)) {
- if (log.isDebugEnabled()) {
- log.debug("RMSequence Mediator :: only axis2 message context is supported ");
- }
- return true;
- }
- Axis2MessageContext axis2MessageCtx = (Axis2MessageContext) smc;
- org.apache.axis2.context.MessageContext orgMessageCtx =
- axis2MessageCtx.getAxis2MessageContext();
-
- cleanupSequenceMap();
-
- String version = getVersionValue();
- orgMessageCtx.getOptions().setProperty(
- Constants.SANDESHA_SPEC_VERSION, version);
- if (log.isDebugEnabled()) {
- log.debug("using WS-RM version " + version);
- }
-
- if (isSingle()) {
- String sequenceID = UUIDGenerator.getUUID();
- orgMessageCtx.getOptions().setProperty(
- Constants.SANDESHA_SEQUENCE_KEY, sequenceID);
- orgMessageCtx.getOptions().setProperty(
- Constants.SANDESHA_LAST_MESSAGE, "true");
- return true;
- }
-
- String correlationValue = getCorrelationValue(smc);
- if (log.isDebugEnabled()) {
- log.debug("correlation value is " + correlationValue);
- }
-
- boolean lastMessage = isLastMessage(smc);
- if (log.isDebugEnabled()) {
- log.debug("Is this message the last message in sequence: " + lastMessage);
- }
-
- String sequenceID = retrieveSequenceID(correlationValue);
- orgMessageCtx.getOptions().setProperty(
- Constants.SANDESHA_SEQUENCE_KEY, sequenceID);
- if (log.isDebugEnabled()) {
- log.debug("RMSequence Mediator :: using sequence " + sequenceID);
- }
-
- if (lastMessage) {
- orgMessageCtx.getOptions().setProperty(
- Constants.SANDESHA_LAST_MESSAGE, "true");
- sequenceMap.remove(correlationValue);
- }
-
- if (shouldTrace) {
- trace.trace("End : RMSequence mediator");
- }
- return true;
- }
-
- private String retrieveSequenceID(String correlationValue) {
- String sequenceID = null;
- if (!sequenceMap.containsKey(correlationValue)) {
- sequenceID = UUIDGenerator.getUUID();
- if (log.isDebugEnabled()) {
- log.debug("setting sequenceID " + sequenceID + " for correlation " + correlationValue);
- }
- Entry sequenceEntry = new Entry();
- sequenceEntry.setValue(sequenceID);
- sequenceEntry.setExpiryTime(System.currentTimeMillis() + SEQUENCE_EXPIRY_TIME);
- sequenceMap.put(correlationValue, sequenceEntry);
- } else {
- sequenceID = (String) ((Entry) sequenceMap.get(correlationValue)).getValue();
- if (log.isDebugEnabled()) {
- log.debug("got sequenceID " + sequenceID + " for correlation " + correlationValue);
- }
- }
- return sequenceID;
- }
-
- private String getCorrelationValue(MessageContext smc) {
- OMElement node = null;
- try {
- node = (OMElement) getCorrelation().selectSingleNode(smc.getEnvelope());
- } catch (JaxenException e) {
- log.error("XPath error : " + e.getMessage());
- throw new SynapseException("XPath error : " + e.getMessage());
- }
- if (node == null) {
- log.debug("XPath expression did not return any node");
- throw new SynapseException("XPath expression did not return any node");
- }
- return node.getText();
- }
-
- private String getVersionValue() {
- if (Constants.SEQUENCE_VERSION_1_1.equals(getVersion())) {
- return WSRM_SpecVersion_1_1;
- } else {
- return WSRM_SpecVersion_1_0;
- }
- }
-
- private boolean isLastMessage(MessageContext smc) {
- if (getLastMessage() == null) {
- return false;
- }
- try {
- return getLastMessage().booleanValueOf(smc.getEnvelope());
- } catch (JaxenException e) {
- log.error("XPath error : " + e.getMessage());
- throw new SynapseException("XPath error : " + e.getMessage());
- }
- }
-
- private synchronized void cleanupSequenceMap() {
- Iterator itKey = sequenceMap.keySet().iterator();
- while (itKey.hasNext()) {
- Object key = itKey.next();
- Entry sequenceEntry = (Entry) sequenceMap.get(key);
- if (sequenceEntry.isExpired()) {
- sequenceMap.remove(key);
- }
- }
- }
-
- public boolean isSingle() {
- if (getSingle() != null && getSingle().booleanValue()) {
- return true;
-
- } else {
- return false;
- }
- }
-
- public AXIOMXPath getCorrelation() {
- return correlation;
- }
-
- public void setCorrelation(AXIOMXPath correlation) {
- this.correlation = correlation;
- }
-
- public AXIOMXPath getLastMessage() {
- return lastMessage;
- }
-
- public void setLastMessage(AXIOMXPath lastMessage) {
- this.lastMessage = lastMessage;
- }
-
- public Boolean getSingle() {
- return single;
- }
-
- public void setSingle(Boolean single) {
- this.single = single;
- }
-
- public String getVersion() {
- return version;
- }
-
- public void setVersion(String version) {
- this.version = version;
- }
-}
+/*
+ * 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.builtin;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+import java.util.Collections;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.axis2.util.UUIDGenerator;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Constants;
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.config.Entry;
+import org.apache.synapse.core.axis2.Axis2MessageContext;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.jaxen.JaxenException;
+
+public class RMSequenceMediator extends AbstractMediator {
+
+ private static Log log = LogFactory.getLog(RMSequenceMediator.class);
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+
+ private AXIOMXPath correlation = null;
+ private AXIOMXPath lastMessage = null;
+ private Boolean single = null;
+ private String version = null;
+
+ private static final String WSRM_SpecVersion_1_0 = "Spec_2005_02";
+ private static final String WSRM_SpecVersion_1_1 = "Spec_2006_08";
+ // set sequence expiry time to 5 minutes
+ private static final long SEQUENCE_EXPIRY_TIME = 300000;
+ private static Map sequenceMap = Collections.synchronizedMap(new HashMap());
+
+ public boolean mediate(MessageContext smc) {
+ if (log.isDebugEnabled()) {
+ log.debug("RMSequence Mediator :: mediate() ");
+ }
+ boolean shouldTrace = shouldTrace(smc.getTracingState());
+ if (shouldTrace) {
+ trace.trace("Start : RMSequence mediator");
+ }
+ if (!(smc instanceof Axis2MessageContext)) {
+ if (log.isDebugEnabled()) {
+ log.debug("RMSequence Mediator :: only axis2 message context is supported ");
+ }
+ return true;
+ }
+ Axis2MessageContext axis2MessageCtx = (Axis2MessageContext) smc;
+ org.apache.axis2.context.MessageContext orgMessageCtx =
+ axis2MessageCtx.getAxis2MessageContext();
+
+ cleanupSequenceMap();
+
+ String version = getVersionValue();
+ orgMessageCtx.getOptions().setProperty(
+ Constants.SANDESHA_SPEC_VERSION, version);
+ if (log.isDebugEnabled()) {
+ log.debug("using WS-RM version " + version);
+ }
+
+ if (isSingle()) {
+ String sequenceID = UUIDGenerator.getUUID();
+ orgMessageCtx.getOptions().setProperty(
+ Constants.SANDESHA_SEQUENCE_KEY, sequenceID);
+ orgMessageCtx.getOptions().setProperty(
+ Constants.SANDESHA_LAST_MESSAGE, "true");
+ return true;
+ }
+
+ String correlationValue = getCorrelationValue(smc);
+ if (log.isDebugEnabled()) {
+ log.debug("correlation value is " + correlationValue);
+ }
+
+ boolean lastMessage = isLastMessage(smc);
+ if (log.isDebugEnabled()) {
+ log.debug("Is this message the last message in sequence: " + lastMessage);
+ }
+
+ String sequenceID = retrieveSequenceID(correlationValue);
+ orgMessageCtx.getOptions().setProperty(
+ Constants.SANDESHA_SEQUENCE_KEY, sequenceID);
+ if (log.isDebugEnabled()) {
+ log.debug("RMSequence Mediator :: using sequence " + sequenceID);
+ }
+
+ if (lastMessage) {
+ orgMessageCtx.getOptions().setProperty(
+ Constants.SANDESHA_LAST_MESSAGE, "true");
+ sequenceMap.remove(correlationValue);
+ }
+
+ if (shouldTrace) {
+ trace.trace("End : RMSequence mediator");
+ }
+ return true;
+ }
+
+ private String retrieveSequenceID(String correlationValue) {
+ String sequenceID = null;
+ if (!sequenceMap.containsKey(correlationValue)) {
+ sequenceID = UUIDGenerator.getUUID();
+ if (log.isDebugEnabled()) {
+ log.debug("setting sequenceID " + sequenceID + " for correlation " + correlationValue);
+ }
+ Entry sequenceEntry = new Entry();
+ sequenceEntry.setValue(sequenceID);
+ sequenceEntry.setExpiryTime(System.currentTimeMillis() + SEQUENCE_EXPIRY_TIME);
+ sequenceMap.put(correlationValue, sequenceEntry);
+ } else {
+ sequenceID = (String) ((Entry) sequenceMap.get(correlationValue)).getValue();
+ if (log.isDebugEnabled()) {
+ log.debug("got sequenceID " + sequenceID + " for correlation " + correlationValue);
+ }
+ }
+ return sequenceID;
+ }
+
+ private String getCorrelationValue(MessageContext smc) {
+ OMElement node = null;
+ try {
+ node = (OMElement) getCorrelation().selectSingleNode(smc.getEnvelope());
+ } catch (JaxenException e) {
+ log.error("XPath error : " + e.getMessage());
+ throw new SynapseException("XPath error : " + e.getMessage());
+ }
+ if (node == null) {
+ log.debug("XPath expression did not return any node");
+ throw new SynapseException("XPath expression did not return any node");
+ }
+ return node.getText();
+ }
+
+ private String getVersionValue() {
+ if (Constants.SEQUENCE_VERSION_1_1.equals(getVersion())) {
+ return WSRM_SpecVersion_1_1;
+ } else {
+ return WSRM_SpecVersion_1_0;
+ }
+ }
+
+ private boolean isLastMessage(MessageContext smc) {
+ if (getLastMessage() == null) {
+ return false;
+ }
+ try {
+ return getLastMessage().booleanValueOf(smc.getEnvelope());
+ } catch (JaxenException e) {
+ log.error("XPath error : " + e.getMessage());
+ throw new SynapseException("XPath error : " + e.getMessage());
+ }
+ }
+
+ private synchronized void cleanupSequenceMap() {
+ Iterator itKey = sequenceMap.keySet().iterator();
+ while (itKey.hasNext()) {
+ Object key = itKey.next();
+ Entry sequenceEntry = (Entry) sequenceMap.get(key);
+ if (sequenceEntry.isExpired()) {
+ sequenceMap.remove(key);
+ }
+ }
+ }
+
+ public boolean isSingle() {
+ if (getSingle() != null && getSingle().booleanValue()) {
+ return true;
+
+ } else {
+ return false;
+ }
+ }
+
+ public AXIOMXPath getCorrelation() {
+ return correlation;
+ }
+
+ public void setCorrelation(AXIOMXPath correlation) {
+ this.correlation = correlation;
+ }
+
+ public AXIOMXPath getLastMessage() {
+ return lastMessage;
+ }
+
+ public void setLastMessage(AXIOMXPath lastMessage) {
+ this.lastMessage = lastMessage;
+ }
+
+ public Boolean getSingle() {
+ return single;
+ }
+
+ public void setSingle(Boolean single) {
+ this.single = single;
+ }
+
+ public String getVersion() {
+ return version;
+ }
+
+ public void setVersion(String version) {
+ this.version = version;
+ }
+}
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/RMSequenceMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/builtin/SendMediator.java
------------------------------------------------------------------------------
svn:eol-style = native
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org