You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by sa...@apache.org on 2006/05/02 07:59:13 UTC
svn commit: r398818 [2/2] - in
/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse:
./ api/ axis2/ config/ mediators/ mediators/base/ mediators/builtin/
mediators/builtin/axis2/ mediators/builtin/xslt/ mediators/ext/ mediators...
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/AbstractMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,29 @@
+/*
+* 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.mediators;
+
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.api.Mediator;
+
+public abstract class AbstractMediator implements Mediator {
+
+ protected final Log log = LogFactory.getLog(getClass());
+
+ public String getName() {
+ return getClass().getName();
+ }
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SequenceMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,61 @@
+/*
+* 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.mediators.base;
+
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractListMediator;
+
+/**
+ * The Sequence mediator either refers to another Sequence mediator instance
+ * or is a *Named* list/sequence of other (child) Mediators
+ */
+public class SequenceMediator extends AbstractListMediator {
+
+ private String name = null;
+ private String ref = null;
+
+ /**
+ * If this mediator refers to another named Sequence, execute that. Else
+ * execute the list of mediators (children) contained within this.
+ *
+ * @param synMsg the synapse message
+ * @return as per standard mediator result
+ */
+ public boolean mediate(SynapseMessage synMsg) {
+ if (ref == null) {
+ return super.mediate(synMsg);
+ } else {
+ return synMsg.getSynapseEnvironment().getConfiguration().
+ getNamedMediator(ref).mediate(synMsg);
+ }
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public String getRef() {
+ return ref;
+ }
+
+ public void setRef(String ref) {
+ this.ref = ref;
+ }
+}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java?rev=398818&r1=398817&r2=398818&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/base/SynapseMediator.java Mon May 1 22:59:02 2006
@@ -16,12 +16,12 @@
package org.apache.synapse.mediators.base;
+import org.apache.synapse.mediators.AbstractListMediator;
+
/**
- *
- *
- * This implements the main processor. Delegates to ListProcessor
- * Here in case we need the main <synapse> to do anything special
- *
+ * 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.
*/
public class SynapseMediator extends AbstractListMediator {
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java?rev=398818&r1=398817&r2=398818&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/DropMediator.java Mon May 1 22:59:02 2006
@@ -16,20 +16,19 @@
package org.apache.synapse.mediators.builtin;
-import org.apache.synapse.api.Mediator;
-
import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
/**
- * Implementaion of <drop/>
+ * Halts further processing/mediation of the current message.
*/
-public class DropMediator implements Mediator {
-
- public boolean mediate(SynapseMessage sm) {
- if (sm.getTo() == null) {
+public class DropMediator extends AbstractMediator {
+
+ public boolean mediate(SynapseMessage synMsg) {
+ if (synMsg.getTo() == null) {
return false;
- }else{
- sm.setTo(null);
+ } else {
+ synMsg.setTo(null);
return false;
}
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/HeaderMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/HeaderMediator.java?rev=398818&r1=398817&r2=398818&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/HeaderMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/HeaderMediator.java Mon May 1 22:59:02 2006
@@ -19,43 +19,40 @@
import org.apache.synapse.HeaderType;
import org.apache.synapse.SynapseMessage;
-
-import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.AbstractMediator;
/**
- *
- * @see org.apache.synapse.HeaderType
- * <p> Sets aspects of the header to new values.
- * Uses HeaderType to set header values
- *
+ * @see org.apache.synapse.HeaderType
+ * <p> Sets aspects of the header to new values.
+ * Uses HeaderType to set header values
*/
-public class HeaderMediator implements Mediator{
-
- private HeaderType headerType = new HeaderType();
-
- private String value = null;
-
- public void setHeaderType(String ht) {
- headerType.setHeaderType(ht);
- }
-
- public String getHeaderType() {
- return headerType.getHeaderType();
- }
-
- public boolean mediate(SynapseMessage sm) {
-
- headerType.setHeader(sm, getValue());
- return true;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
-
- public String getValue() {
- return value;
- }
+public class HeaderMediator extends AbstractMediator {
+
+ private HeaderType headerType = new HeaderType();
+
+ private String value = null;
+
+ public void setHeaderType(String ht) {
+ headerType.setHeaderType(ht);
+ }
+
+ public String getHeaderType() {
+ return headerType.getHeaderType();
+ }
+
+ public boolean mediate(SynapseMessage sm) {
+
+ headerType.setHeader(sm, getValue());
+ return true;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ }
+
+ public String getValue() {
+ return value;
+ }
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java?rev=398818&r1=398817&r2=398818&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/LogMediator.java Mon May 1 22:59:02 2006
@@ -16,40 +16,135 @@
package org.apache.synapse.mediators.builtin;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-
+import org.apache.axiom.soap.SOAPHeader;
import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
-import org.apache.synapse.api.Mediator;
+import java.util.Iterator;
+import java.util.List;
/**
- *
- * <p>
- * Logs the message using commons logging
- *
- * <p>
- * TODO make configurable - short or detailed logs
- *
+ * Logs the specified message into the configured logger. The log levels specify
+ * which attributes would be logged, and is configurable.
*/
-public class LogMediator implements Mediator {
-
- private Log log = LogFactory.getLog(getClass());
-
- public boolean mediate(SynapseMessage smc) {
- log.info("---------------------------------------");
- if (smc.getTo() != null)
- log.info("To: " + smc.getTo().getAddress());
- if (smc.getFrom() != null)
- log.info("From: " + smc.getFrom().getAddress());
- if (smc.getReplyTo() != null)
- log.info("ReplyTo: " + smc.getReplyTo().getAddress());
- if (smc.getEnvelope() != null)
- log.info("Envelope: " + smc.getEnvelope().toString());
- log.info("---------------------------------------");
- return true;
- }
-
+public class LogMediator extends AbstractMediator {
+ public static final int CUSTOM = 0;
+ public static final int SIMPLE = 1;
+ public static final int HEADERS = 2;
+ public static final int FULL = 3;
+
+ private int logLevel = SIMPLE;
+ private String SEP = "\n";
+ private List properties = null;
+
+ public boolean mediate(SynapseMessage synMsg) {
+ log.info(getLogMessage(synMsg));
+ return true;
+ }
+
+ private String getLogMessage(SynapseMessage synMsg) {
+ switch (logLevel) {
+ case CUSTOM:
+ return getCustomLogMessage(synMsg);
+ case SIMPLE:
+ return getSimpleLogMessage(synMsg);
+ case HEADERS:
+ return getHeadersLogMessage(synMsg);
+ case FULL:
+ return getFullLogMessage(synMsg);
+ default:
+ return "Invalid log level specified";
+ }
+ }
+
+ private String getCustomLogMessage(SynapseMessage synMsg) {
+ StringBuffer sb = new StringBuffer();
+ setCustomProperties(sb, synMsg);
+ return sb.toString();
+ }
+
+ private String getSimpleLogMessage(SynapseMessage synMsg) {
+ StringBuffer sb = new StringBuffer();
+ if (synMsg.getTo() != null)
+ sb.append(SEP + "To: " + synMsg.getTo().getAddress());
+ if (synMsg.getFrom() != null)
+ sb.append(SEP + "From: " + synMsg.getFrom().getAddress());
+ if (synMsg.getWSAAction() != null)
+ sb.append(SEP + "WSAction: " + synMsg.getWSAAction());
+ if (synMsg.getSoapAction() != null)
+ sb.append(SEP + "SOAPAction: " + synMsg.getSoapAction());
+ if (synMsg.getReplyTo() != null)
+ sb.append(SEP + "ReplyTo: " + synMsg.getReplyTo().getAddress());
+ if (synMsg.getMessageID() != null)
+ sb.append(SEP + "MessageID: " + synMsg.getMessageID());
+ setCustomProperties(sb, synMsg);
+ return sb.toString();
+ }
+
+ private String getHeadersLogMessage(SynapseMessage synMsg) {
+ StringBuffer sb = new StringBuffer();
+ Iterator iter = synMsg.getEnvelope().getHeader().examineAllHeaderBlocks();
+ while (iter.hasNext()) {
+ SOAPHeader header = (SOAPHeader) iter.next();
+ sb.append(SEP + header.getLocalName() + " : " + header.getText());
+ }
+ setCustomProperties(sb, synMsg);
+ return sb.toString();
+ }
+
+ private String getFullLogMessage(SynapseMessage synMsg) {
+ StringBuffer sb = new StringBuffer();
+ sb.append(getSimpleLogMessage(synMsg));
+ if (synMsg.getEnvelope() != null)
+ sb.append(SEP + "Envelope: " + synMsg.getEnvelope());
+ setCustomProperties(sb, synMsg);
+ return sb.toString();
+ }
+
+ private void setCustomProperties(StringBuffer sb, SynapseMessage synMsg) {
+ if (properties != null && !properties.isEmpty()) {
+ Iterator iter = properties.iterator();
+ while (iter.hasNext()) {
+ Property prop = (Property) iter.next();
+ sb.append(SEP + prop.getName() + " = " +
+ prop.getValue() != null ? prop.getValue() : prop.getEvaluatedExpression());
+ }
+ }
+ }
+
+ public class Property {
+ private String name;
+ private String value;
+ private String expression;
+
+ 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 String getExpression() {
+ return expression;
+ }
+
+ public void setExpression(String expression) {
+ this.expression = expression;
+ }
+
+ public String getEvaluatedExpression() {
+ return expression; //TODO later use XPath xtention eval
+ }
+ }
}
Modified: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java?rev=398818&r1=398817&r2=398818&view=diff
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java (original)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/builtin/SendMediator.java Mon May 1 22:59:02 2006
@@ -16,31 +16,27 @@
package org.apache.synapse.mediators.builtin;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.api.Mediator;
import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
/**
- *
- * <p>
- *
- * This sends the message on (or back)
- *
+ * The Send mediator sends the message using the following semantics.
+ * <p/>
+ * This is a leaf mediator (i.e. further processing does not continue after this is invoked)
+ * <p/>
+ * TODO support endpoints, loadbalancing and failover
*/
-public class SendMediator implements Mediator {
-
-
- private Log log = LogFactory.getLog(getClass());
-
-
- public boolean mediate(SynapseMessage smc) {
- log.debug("mediate");
- smc.getSynapseEnvironment().send(smc);
- return false;
-
- }
-
-
+public class SendMediator extends AbstractMediator {
+ /**
+ * This is a leaf mediator. i.e. processing stops once send is invoked.
+ *
+ * @param synMsg
+ * @return false always as this is a leaf mediator
+ */
+ public boolean mediate(SynapseMessage synMsg) {
+ log.debug(getName() + " mediate()");
+ synMsg.getSynapseEnvironment().send(synMsg);
+ return false;
+ }
}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ClassMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,60 @@
+/*
+ * 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.mediators.ext;
+
+
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.api.Mediator;
+import org.apache.synapse.mediators.AbstractMediator;
+
+
+/**
+ * This executes the "mediate" operation on a new instance of the specified class
+ * <p/>
+ * TODO add support for simple properties to be set
+ */
+public class ClassMediator extends AbstractMediator {
+
+ private Class clazz = null;
+
+
+ public boolean mediate(SynapseMessage smc) {
+ Mediator m = null;
+
+ try {
+ m = (Mediator) getClazz().newInstance();
+ } catch (Exception e) {
+ throw new SynapseException(e);
+ }
+ /*if (EnvironmentAware.class.isAssignableFrom(m.getClass())) {
+ ((EnvironmentAware) m).setSynapseEnvironment(se);
+ }*/
+ return m.mediate(smc);
+
+ }
+
+
+ public void setClazz(Class clazz) {
+ this.clazz = clazz;
+ }
+
+ public Class getClazz() {
+ return clazz;
+ }
+
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ServiceMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ServiceMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ServiceMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/ext/ServiceMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,104 @@
+/*
+ * 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.mediators.ext;
+
+
+import org.apache.axis2.AxisFault;
+import org.apache.axis2.context.*;
+import org.apache.axis2.description.AxisOperation;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisConfiguration;
+import org.apache.axis2.engine.AxisEngine;
+import org.apache.axis2.util.Utils;
+import org.apache.synapse.Constants;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.axis2.Axis2SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
+
+
+/**
+ * <p/>
+ * This class executes a service in the "owning" axis2 engine.
+ * The service operation will be "mediate" and the service name is set as the ServiceName property
+ */
+public class ServiceMediator extends AbstractMediator {
+
+
+ private String serviceName = null;
+
+ public boolean mediate(SynapseMessage smc) {
+ MessageContext messageContext = null;
+ try {
+ messageContext = ((Axis2SynapseMessage) smc)
+ .getMessageContext();
+ } catch (ClassCastException cce) {
+ throw new SynapseException(
+ "A non-Axis2 MC SOAPMessageContext has been passed to the Axis2 MediationExecutor",
+ cce);
+ }
+
+
+ try {
+ ConfigurationContext cc = messageContext.getConfigurationContext();
+ AxisConfiguration ac = cc.getAxisConfiguration();
+ AxisEngine ae = new AxisEngine(cc);
+
+ AxisService as = null;
+ AxisOperation ao = null;
+
+ as = ac.getService(getServiceName());
+ if (as == null)
+ throw new SynapseException("cannot locate service "
+ + getServiceName());
+
+ ao = as.getOperation(Constants.MEDIATE_OPERATION_NAME);
+ OperationContext oc = OperationContextFactory
+ .createOperationContext(ao.getAxisSpecifMEPConstant(), ao);
+ ao.registerOperationContext(messageContext, oc);
+
+ ServiceContext sc = Utils.fillContextInformation(as, cc);
+ oc.setParent(sc);
+
+ messageContext.setOperationContext(oc);
+ messageContext.setServiceContext(sc);
+
+ messageContext.setAxisOperation(ao);
+ messageContext.setAxisService(as);
+
+ ae.receive(messageContext);
+
+ } catch (AxisFault e) {
+ throw new SynapseException(e);
+
+ }
+
+ return ((Boolean) messageContext
+ .getProperty(Constants.MEDIATOR_RESPONSE_PROPERTY))
+ .booleanValue();
+
+ }
+
+ public void setServiceName(String serviceName) {
+ this.serviceName = serviceName;
+ }
+
+ public String getServiceName() {
+ return serviceName;
+ }
+
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/filters/FilterMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,95 @@
+/*
+ * 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.mediators.filters;
+
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractListMediator;
+import org.jaxen.JaxenException;
+
+import java.util.regex.Pattern;
+
+
+/**
+ * The filter mediator combines the regex and xpath filtering functionality. If an xpath
+ * is set, it is evaluated; else the given regex is evaluated against the source xpath.
+ */
+public class FilterMediator extends AbstractListMediator {
+
+ private String source = null;
+ private String regex = null;
+ private String xpath = null;
+
+ public boolean mediate(SynapseMessage synMsg) {
+ if (test(synMsg)) {
+ return super.mediate(synMsg);
+ } else {
+ return true;
+ }
+ }
+
+ public boolean test(SynapseMessage synMsg) {
+ try {
+ if (xpath != null) {
+ AXIOMXPath xp = new AXIOMXPath(xpath);
+ return xp.booleanValueOf(synMsg.getEnvelope());
+
+ } else if (source != null && regex != null) {
+ Pattern pattern = Pattern.compile(regex);
+ AXIOMXPath xp = new AXIOMXPath(source);
+ Object result = xp.evaluate(synMsg.getEnvelope());
+ return pattern.matcher(result.toString()).matches();
+
+ } else {
+ log.error("Invalid configuration specified");
+ return false;
+ }
+
+ } catch (JaxenException e) {
+ log.error("XPath error : " + e.getMessage());
+ return false;
+ }
+ }
+
+
+ public String getSource() {
+ return source;
+ }
+
+ public void setSource(String source) {
+ this.source = source;
+ }
+
+ public String getRegex() {
+ return regex;
+ }
+
+ public void setRegex(String regex) {
+ this.regex = regex;
+ }
+
+ public String getXpath() {
+ return xpath;
+ }
+
+ public void setXpath(String xpath) {
+ this.xpath = xpath;
+ }
+
+ //TODO name space addition support for xpath
+ // i.e. xp.addNamespace(prefix, uri);
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/FaultMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,98 @@
+/*
+ * 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.mediators.transform;
+
+import org.apache.axiom.om.OMAbstractFactory;
+import org.apache.axiom.om.OMDocument;
+import org.apache.axiom.soap.SOAP12Constants;
+import org.apache.axiom.soap.SOAPEnvelope;
+import org.apache.axiom.soap.SOAPFactory;
+import org.apache.axis2.addressing.EndpointReference;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
+
+import javax.xml.namespace.QName;
+
+/**
+ * <p/> This returns a fault in response to this message
+ */
+public class FaultMediator extends AbstractMediator {
+
+ private Log log = LogFactory.getLog(getClass());
+
+ private QName faultCode;
+ private String reason;
+
+ public boolean mediate(SynapseMessage smc) {
+ log.debug("process");
+
+ SOAPEnvelope envelop = smc.getEnvelope();
+ SOAPFactory factory;
+ if (envelop != null) {
+ if (envelop.getNamespace().getName().equals(
+ SOAP12Constants.SOAP_ENVELOPE_NAMESPACE_URI)) {
+ factory = OMAbstractFactory.getSOAP12Factory();
+ } else {
+ factory = OMAbstractFactory.getSOAP11Factory();
+ }
+
+ } else {
+ factory = OMAbstractFactory.getSOAP11Factory();
+ }
+ try {
+ // TODO : Figure out how to easily gen the correct fault
+
+ // Replace this
+ OMDocument soapFaultDocument = factory.createOMDocument();
+ SOAPEnvelope faultEnvelope = factory.getDefaultFaultEnvelope();
+ soapFaultDocument.addChild(faultEnvelope);
+
+ smc.setEnvelope(faultEnvelope);
+ } catch (Exception e) {
+ throw new SynapseException(e);
+ }
+ smc.setResponse(true);
+
+ // Flipping the headers
+ EndpointReference tempEPR = smc.getTo();
+ smc.setTo(smc.getReplyTo());
+ smc.setReplyTo(tempEPR);
+
+ smc.getSynapseEnvironment().injectMessage(smc);
+
+ return false;
+ }
+
+ public QName getFaultCode() {
+ return faultCode;
+ }
+
+ public void setFaultCode(QName faultCode) {
+ this.faultCode = faultCode;
+ }
+
+ public String getReason() {
+ return reason;
+ }
+
+ public void setReason(String reason) {
+ this.reason = reason;
+ }
+}
Added: incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java
URL: http://svn.apache.org/viewcvs/incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java?rev=398818&view=auto
==============================================================================
--- incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java (added)
+++ incubator/synapse/trunk/scratch/synapse2/modules/core/src/org/apache/synapse/mediators/transform/XSLTMediator.java Mon May 1 22:59:02 2006
@@ -0,0 +1,87 @@
+package org.apache.synapse.mediators.transform;
+
+
+import org.apache.axiom.om.OMNode;
+import org.apache.axiom.om.impl.builder.StAXOMBuilder;
+import org.apache.axiom.om.xpath.AXIOMXPath;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.SynapseMessage;
+import org.apache.synapse.mediators.AbstractMediator;
+import org.jaxen.JaxenException;
+
+import javax.xml.stream.XMLOutputFactory;
+import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamWriter;
+import javax.xml.transform.*;
+import javax.xml.transform.stream.StreamResult;
+import javax.xml.transform.stream.StreamSource;
+import java.io.ByteArrayInputStream;
+import java.io.ByteArrayOutputStream;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+
+/**
+ * @see org.apache.synapse.mediators.base.builtin.xslt.XSLTProcessorConfigurator
+ * <p> This class is the class that transforms messages using XSLT.
+ */
+public class XSLTMediator extends AbstractMediator {
+
+ private URL xsltUrl = null;
+ private URL xqUrl = null;
+ private String source = null;
+
+ public boolean mediate(SynapseMessage synMsg) {
+
+ if (xsltUrl != null) {
+ performXLST(synMsg);
+ return true;
+ } else if (xqUrl != null) {
+ //TODO later
+ return true;
+ } else {
+ log.error("Invalid configuration - xslt/xq not specified");
+ return false;
+ }
+ }
+
+ private void performXLST(SynapseMessage synMsg) {
+ try {
+ Transformer transformer = TransformerFactory.newInstance().newTransformer(
+ new StreamSource(xsltUrl.openStream()));
+
+ ByteArrayOutputStream baos = new ByteArrayOutputStream();
+ XMLStreamWriter xsWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(baos);
+
+ AXIOMXPath xp = new AXIOMXPath(source);
+ OMNode sourceNode = (OMNode) xp.evaluate(synMsg.getEnvelope());
+ sourceNode.serialize(xsWriter);
+
+ synMsg.getEnvelope().getBody().serialize(xsWriter);
+
+ Source transformSrc = new StreamSource(new ByteArrayInputStream(baos.toByteArray()));
+ ByteArrayOutputStream baos2 = new ByteArrayOutputStream();
+ StreamResult transformTgt = new StreamResult(baos2);
+ transformer.transform(transformSrc, transformTgt);
+
+ StAXOMBuilder builder = new StAXOMBuilder(new ByteArrayInputStream(baos2.toByteArray()));
+ sourceNode.getParent().addChild(builder.getDocumentElement());
+
+ } catch (MalformedURLException mue) {
+ throw new SynapseException(mue);
+ } catch (TransformerConfigurationException tce) {
+ throw new SynapseException(tce);
+ } catch (XMLStreamException xse) {
+ throw new SynapseException(xse);
+ } catch (JaxenException je) {
+ throw new SynapseException(je);
+ } catch (TransformerException te) {
+ throw new SynapseException(te);
+ } catch (IOException ioe) {
+ throw new SynapseException(ioe);
+ }
+ }
+
+}
+
+
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org