You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@synapse.apache.org by ru...@apache.org on 2007/08/07 09:13:24 UTC
svn commit: r563410 - in /webservices/synapse/trunk/java/modules/core/src:
main/java/org/apache/synapse/ main/java/org/apache/synapse/config/xml/
main/java/org/apache/synapse/mediators/ext/
main/java/org/apache/synapse/startup/ test/java/org/apache/syn...
Author: ruwan
Date: Tue Aug 7 00:13:22 2007
New Revision: 563410
URL: http://svn.apache.org/viewvc?view=rev&rev=563410
Log:
Adding the POJOCommandMediator and the testcases
Added:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Command.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java
- copied, changed from r562074, webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/Startup.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestHelper.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestImplementedMediator.java
webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestMediator.java
Removed:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/Startup.java
Modified:
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupWrapperFactory.java
webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Command.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Command.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Command.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Command.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,34 @@
+/*
+ * 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;
+
+/**
+ * This is the Command interface that will be implemented to write command objects, but it is not
+ * required to implement this interface Synapse will use reflection to find an execute method as
+ * a convention in the command pattern and will start the execution from the execute method
+ */
+public interface Command {
+
+ /**
+ * Thsi method will be implemented with a set of getters and setters for the command properties
+ * in an implementation of a Command
+ */
+ public void execute();
+}
Copied: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java (from r562074, webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/Startup.java)
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java?view=diff&rev=563410&p1=webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/Startup.java&r1=562074&p2=webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/Startup.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/Startup.java Tue Aug 7 00:13:22 2007
@@ -1,9 +1,35 @@
-package org.apache.synapse.startup;
+/*
+ * 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.
+ */
-import javax.xml.namespace.QName;
+package org.apache.synapse;
-import org.apache.synapse.ManagedLifecycle;
+import javax.xml.namespace.QName;
+/**
+ * This startup interface will be instatiated to create startup tasks
+ */
public interface Startup extends ManagedLifecycle{
- public QName getTagQName();
+
+ /**
+ * This will return the configuration tag QName of the implemented startup
+ *
+ * @return QName representing the configuraiton element for the startup
+ */
+ public QName getTagQName();
}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorFactoryFinder.java Tue Aug 7 00:13:22 2007
@@ -26,6 +26,7 @@
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
import org.apache.synapse.Mediator;
+import org.apache.synapse.mediators.ext.POJOCommandMediator;
import org.apache.synapse.config.xml.XSLTMediatorFactory;
import org.apache.synapse.config.xml.ValidateMediatorFactory;
import org.apache.synapse.config.XMLToObjectMapper;
@@ -63,7 +64,8 @@
RMSequenceMediatorFactory.class,
ClassMediatorFactory.class,
ValidateMediatorFactory.class,
- XSLTMediatorFactory.class
+ XSLTMediatorFactory.class,
+ POJOCommandMediatorFactory.class
};
private static MediatorFactoryFinder instance = null;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/MediatorSerializerFinder.java Tue Aug 7 00:13:22 2007
@@ -51,7 +51,8 @@
RMSequenceMediatorSerializer.class,
ClassMediatorSerializer.class,
ValidateMediatorSerializer.class,
- XSLTMediatorSerializer.class
+ XSLTMediatorSerializer.class,
+ POJOCommandMediatorSerializer.class
};
private static MediatorSerializerFinder instance = null;
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorFactory.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,94 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMAttribute;
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.ext.POJOCommandMediator;
+
+import javax.xml.namespace.QName;
+import java.util.Iterator;
+
+/**
+ * Creates an instance of a Class mediator using XML configuration specified
+ * <p/>
+ * <pre>
+ * <pojoCommand name="class-name">
+ * <property name="string" value="literal">
+ * either literal or XML child
+ * </property>
+ * <property name="string" expression="XPATH expression"/>
+ * </pojoCommand>
+ * </pre>
+ */
+public class POJOCommandMediatorFactory extends AbstractMediatorFactory {
+
+ private static final Log log = LogFactory.getLog(POJOCommandMediatorFactory.class);
+
+ private static final QName POJO_COMMAND_Q =
+ new QName(Constants.SYNAPSE_NAMESPACE, "pojoCommand");
+
+ public Mediator createMediator(OMElement elem) {
+
+ POJOCommandMediator pojoMediator = new POJOCommandMediator();
+
+ // Class name of the Command object should be present
+ OMAttribute name = elem.getAttribute(new QName(Constants.NULL_NAMESPACE, "name"));
+ if (name == null) {
+ String msg = "The name of the actual POJO command implementation class" +
+ " is a required attribute";
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
+
+ // load the class for the command object
+ try {
+ pojoMediator.setCommand(
+ getClass().getClassLoader().loadClass(name.getAttributeValue()));
+ } catch (ClassNotFoundException e) {
+ handleException("Unable to load the class specified as the command "
+ + name.getAttributeValue(), e);
+ }
+
+ // setting the properties to the command. these properties will be instantiated
+ // at the mediation time
+ for (Iterator it = elem.getChildElements(); it.hasNext();) {
+ OMElement child = (OMElement) it.next();
+ if("property".equals(child.getLocalName())) {
+ pojoMediator.addProperty(child);
+ }
+ }
+
+ return pojoMediator;
+ }
+
+ public QName getTagQName() {
+ return POJO_COMMAND_Q;
+ }
+
+ private void handleException(String message, Throwable e) {
+ log.error(message + e.getMessage());
+ throw new SynapseException(message, e);
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializer.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,89 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+import org.apache.axiom.om.OMElement;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.SynapseException;
+import org.apache.synapse.mediators.ext.POJOCommandMediator;
+
+import java.util.Iterator;
+
+/**
+ * Creates an instance of a Class mediator using XML configuration specified
+ * <p/>
+ * <pre>
+ * <pojoCommand name="class-name">
+ * <property name="string" value="literal">
+ * either literal or XML child
+ * </property>
+ * <property name="string" expression="XPATH expression"/>
+ * </pojoCommand>
+ * </pre>
+ */
+public class POJOCommandMediatorSerializer extends AbstractMediatorSerializer {
+
+ private static final Log log = LogFactory.getLog(POJOCommandMediatorSerializer.class);
+
+ public OMElement serializeMediator(OMElement parent, Mediator m) {
+
+ if (!(m instanceof POJOCommandMediator)) {
+ handleException("Unsupported mediator passed in for serialization : " + m.getType());
+ }
+
+ POJOCommandMediator mediator = (POJOCommandMediator) m;
+
+ OMElement pojoCommand = fac.createOMElement("pojoCommand", synNS);
+ finalizeSerialization(pojoCommand, mediator);
+
+ if (mediator.getCommand() != null && mediator.getCommand().getClass().getName() != null) {
+ pojoCommand.addAttribute(fac.createOMAttribute(
+ "name", nullNS, mediator.getCommand().getName()));
+ } else {
+ handleException("Invalid POJO Command mediator. The command class name is required");
+ }
+
+ Iterator itr = mediator.getProperties().iterator();
+ while(itr.hasNext()) {
+ Object property = itr.next();
+ if (property instanceof OMElement) {
+ pojoCommand.addChild((OMElement) property);
+ } else {
+ handleException("POJOCommandMediator property can not be serialized");
+ }
+ }
+
+ if (parent != null) {
+ parent.addChild(pojoCommand);
+ }
+ return pojoCommand;
+ }
+
+ public String getMediatorClassName() {
+ return POJOCommandMediator.class.getName();
+ }
+
+ private void handleException(String message) {
+ log.error(message);
+ throw new SynapseException(message);
+ }
+}
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFactory.java Tue Aug 7 00:13:22 2007
@@ -5,7 +5,7 @@
import javax.xml.namespace.QName;
import org.apache.axiom.om.OMElement;
-import org.apache.synapse.startup.Startup;
+import org.apache.synapse.Startup;
public interface StartupFactory {
public Startup createStartup(OMElement elem);
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupFinder.java Tue Aug 7 00:13:22 2007
@@ -12,7 +12,7 @@
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.SynapseException;
-import org.apache.synapse.startup.Startup;
+import org.apache.synapse.Startup;
import sun.misc.Service;
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupSerializer.java Tue Aug 7 00:13:22 2007
@@ -3,7 +3,7 @@
import org.apache.axiom.om.OMElement;
-import org.apache.synapse.startup.Startup;
+import org.apache.synapse.Startup;
public interface StartupSerializer {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupWrapperFactory.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupWrapperFactory.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupWrapperFactory.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/StartupWrapperFactory.java Tue Aug 7 00:13:22 2007
@@ -6,7 +6,7 @@
import org.apache.axiom.om.OMElement;
-import org.apache.synapse.startup.Startup;
+import org.apache.synapse.Startup;
public class StartupWrapperFactory {
Modified: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java?view=diff&rev=563410&r1=563409&r2=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java (original)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/config/xml/SynapseXMLConfigurationSerializer.java Tue Aug 7 00:13:22 2007
@@ -21,7 +21,7 @@
import org.apache.synapse.config.xml.endpoints.EndpointAbstractSerializer;
import org.apache.synapse.core.axis2.ProxyService;
import org.apache.synapse.endpoints.Endpoint;
-import org.apache.synapse.startup.Startup;
+import org.apache.synapse.Startup;
public class SynapseXMLConfigurationSerializer implements
ConfigurationSerializer {
Added: webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/mediators/ext/POJOCommandMediator.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,152 @@
+/*
+ * 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.ext;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.*;
+import org.apache.synapse.config.xml.PropertyHelper;
+import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+import org.apache.axiom.om.OMElement;
+
+import java.util.List;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.lang.reflect.Method;
+import java.lang.reflect.InvocationTargetException;
+
+/**
+ * This mediator will use the specified command object and execute the command after setting
+ * the properties specified to it through the configuraiton. The specified command object may or
+ * may not implement the Command interface. If the Command object has not implemented the Command
+ * interface then this will use reflection to find a method called execute() and execute it.
+ *
+ * @see org.apache.synapse.Command interface
+ */
+public class POJOCommandMediator extends AbstractMediator {
+
+ /**
+ * This will hold the log variable to be used for logging
+ */
+ private static final Log log = LogFactory.getLog(POJOCommandMediator.class);
+
+ /**
+ * This will hold the trace object to be used for tracing
+ */
+ private static final Log trace = LogFactory.getLog(Constants.TRACE_LOGGER);
+
+ /**
+ * This will hold the command object to be executed
+ */
+ private Class command = null;
+
+ private Object commandObject = null;
+
+ /**
+ * This will hold the properties of the relevent Command object as OMElements for the
+ * use of serialization
+ */
+ private List properties = new ArrayList();
+
+ /**
+ * Implements the mediate method of the Mediator interface. This method will instantiate all
+ * the properties and call the execute method of the Command object.
+ *
+ * @param synCtx - Synapse MessageContext to be mediated
+ * @return boolean true since this will not stop exection chain
+ */
+ public boolean mediate(MessageContext synCtx) {
+
+ // instantiate the command object
+ try {
+ commandObject = command.newInstance();
+ } catch (InstantiationException e) {
+ handleException("Unable to instantiate the Command object", e);
+ } catch (IllegalAccessException e) {
+ handleException("Unable to instantiate the Command object", e);
+ }
+
+ // then set the properties
+ Iterator itr = properties.iterator();
+ while(itr.hasNext()) {
+ Object property = itr.next();
+ if(property instanceof OMElement) {
+ if(PropertyHelper.isStaticProperty((OMElement) property)) {
+ PropertyHelper.setStaticProperty((OMElement) property, commandObject);
+ } else {
+ PropertyHelper.setDynamicProperty((OMElement) property, commandObject, synCtx);
+ }
+ }
+ }
+
+ // then call the execute method if the Command interface is implemented
+ if(commandObject instanceof Command) {
+ ((Command) commandObject).execute();
+ } else {
+ // use the reflection to find the execute method
+ try {
+ Method exeMethod = command.getMethod("execute", new Class[]{});
+ try {
+ exeMethod.invoke(commandObject, new Object[]{});
+ } catch (IllegalAccessException e) {
+ handleException("Unable to invoke the execute() method", e);
+ } catch (InvocationTargetException e) {
+ handleException("Unable to invoke the execute() method", e);
+ }
+ } catch (NoSuchMethodException e) {
+ // nothing to do in here (Command has no implementation)
+ }
+ }
+
+ // continue the mediator execution
+ return true;
+ }
+
+ public Class getCommand() {
+ return command;
+ }
+
+ public void setCommand(Class command) {
+ this.command = command;
+ }
+
+ public void addProperty(OMElement property) {
+ this.properties.add(property);
+ }
+
+ public List getProperties() {
+ return this.properties;
+ }
+
+ private void handleException(String message, Throwable e) {
+ if (log.isDebugEnabled()) {
+ log.debug(message + e.getMessage());
+ }
+ throw new SynapseException(message, e);
+ }
+
+ private void handleException(String message) {
+ if (log.isDebugEnabled()) {
+ log.debug(message);
+ }
+ throw new SynapseException(message);
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/config/xml/POJOCommandMediatorSerializationTest.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.synapse.config.xml;
+
+/**
+ * This Testcase will test the Factory and Serializer of the POJOCommandMediator
+ */
+public class POJOCommandMediatorSerializationTest extends AbstractTestCase {
+
+ POJOCommandMediatorFactory pojoCommandMediatorFactory;
+ POJOCommandMediatorSerializer pojoCommandMediatorSerializer;
+
+ public POJOCommandMediatorSerializationTest() {
+ super(POJOCommandMediatorSerializationTest.class.getName());
+ pojoCommandMediatorFactory = new POJOCommandMediatorFactory();
+ pojoCommandMediatorSerializer = new POJOCommandMediatorSerializer();
+ }
+
+ public void testPOJOCommandNotImplementedMediatorWithoutPropertySerialization() throws Exception {
+ String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+ "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\"/> ";
+ assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+ assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+ }
+
+ public void testPOJOCommandMediatorImplementedWithoutPropertySerialization() throws Exception {
+ String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+ "name=\"org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator\"/> ";
+ assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+ assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+ }
+
+ public void testPOJOCommandNotImplementedMediatorWithPropertySerialization() throws Exception {
+ String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+ "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
+ "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>";
+ assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+ assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+ }
+
+ public void testPOJOCommandMediatorImplementedWithPropertySerialization() throws Exception {
+ String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+ "name=\"org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator\">" +
+ "<property name=\"testProp\" expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>";
+ assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+ assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+ }
+
+ public void testPOJOCommandMediatorWithStaticPropertySerialization() throws Exception {
+ String inputXml = "<pojoCommand xmlns=\"http://ws.apache.org/ns/synapse\" " +
+ "name=\"org.apache.synapse.mediators.ext.POJOCommandTestMediator\">" +
+ "<property name=\"testProp\" value=\"Test Property\"/></pojoCommand>";
+ assertTrue(serialization(inputXml, pojoCommandMediatorFactory, pojoCommandMediatorSerializer));
+ assertTrue(serialization(inputXml, pojoCommandMediatorSerializer));
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandMediatorTest.java Tue Aug 7 00:13:22 2007
@@ -0,0 +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.ext;
+
+import org.apache.synapse.config.xml.AbstractTestCase;
+import org.apache.synapse.config.xml.MediatorFactoryFinder;
+import org.apache.synapse.Mediator;
+import org.apache.synapse.TestMessageContext;
+
+/**
+ * Tests the pojo command mediator instantiation and setting of literal and
+ * XPath parameters at runtime.
+ */
+public class POJOCommandMediatorTest extends AbstractTestCase {
+
+ public void testPojoWithoutPropertiesNotCommandImpl() throws Exception {
+ Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+ "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>"));
+ POJOCommandTestHelper.reset();
+ pcm.mediate(new TestMessageContext());
+ assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+ }
+
+ public void testPojoWithPropertiesNotCommandImpl() throws Exception {
+ Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+ "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestMediator' " +
+ "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " +
+ "expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>"));
+ POJOCommandTestHelper.reset();
+ pcm.mediate(new TestMessageContext());
+ assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty());
+ assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+ }
+
+ public void testPojoWithoutPropertiesCommandImpl() throws Exception {
+ Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+ "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " +
+ "xmlns='http://ws.apache.org/ns/synapse'/>"));
+ POJOCommandTestHelper.reset();
+ pcm.mediate(new TestMessageContext());
+ assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+ }
+
+ public void testPojoWithPropertiesCommandImpl() throws Exception {
+ Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+ "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " +
+ "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " +
+ "expression=\"fn:concat('XPATH ', 'FUNC')\"/></pojoCommand>"));
+ POJOCommandTestHelper.reset();
+ pcm.mediate(new TestMessageContext());
+ assertEquals("XPATH FUNC", POJOCommandTestHelper.getInstance().getChangedProperty());
+ assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+ }
+
+ public void testPojoWithStaticPropertiesCommandImpl() throws Exception {
+ Mediator pcm = MediatorFactoryFinder.getInstance().getMediator(createOMElement(
+ "<pojoCommand name='org.apache.synapse.mediators.ext.POJOCommandTestImplementedMediator' " +
+ "xmlns='http://ws.apache.org/ns/synapse'><property name=\"testProp\" " +
+ "value=\"Test Property\"/></pojoCommand>"));
+ POJOCommandTestHelper.reset();
+ pcm.mediate(new TestMessageContext());
+ assertEquals("Test Property", POJOCommandTestHelper.getInstance().getChangedProperty());
+ assertTrue(POJOCommandTestHelper.getInstance().isExecuted());
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestHelper.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestHelper.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestHelper.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestHelper.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,62 @@
+/*
+ * 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.ext;
+
+/**
+ * This class will be used to test the execution of the POJOCommand mediator because POJOCommands
+ * are instantiated and destroyed in the mediation time. This will provide a common point that can
+ * be accessed by the test case as well as by the POJOCommand
+ */
+public class POJOCommandTestHelper {
+
+ private static POJOCommandTestHelper HELPER_OBJ = null;
+
+ private boolean executed = false;
+
+ private String changedProperty = null;
+
+ public static POJOCommandTestHelper getInstance() {
+ if(HELPER_OBJ == null) {
+ HELPER_OBJ = new POJOCommandTestHelper();
+ }
+ return HELPER_OBJ;
+ }
+
+ public static void reset() {
+ getInstance().setExecuted(false);
+ getInstance().setChangedProperty(null);
+ }
+
+ public boolean isExecuted() {
+ return this.executed;
+ }
+
+ public void setExecuted(boolean executed) {
+ this.executed = executed;
+ }
+
+ public void setChangedProperty(String changedProperty) {
+ this.changedProperty = changedProperty;
+ }
+
+ public String getChangedProperty() {
+ return this.changedProperty;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestImplementedMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestImplementedMediator.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestImplementedMediator.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestImplementedMediator.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,44 @@
+/*
+ * 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.ext;
+
+import org.apache.synapse.Command;
+
+/**
+ * This class is just to test the behaviour of the POJO Command when implemented by implementing
+ * the Command interface. This will use static members to accomplish the test tasks.
+ */
+public class POJOCommandTestImplementedMediator implements Command {
+
+ public static String testProp = null;
+
+ public void execute() {
+ POJOCommandTestHelper.getInstance().setExecuted(true);
+ }
+
+ public void setTestProp(String s) {
+ testProp = s;
+ POJOCommandTestHelper.getInstance().setChangedProperty(testProp);
+ }
+
+ public String getTestProp() {
+ return testProp;
+ }
+}
Added: webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestMediator.java
URL: http://svn.apache.org/viewvc/webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestMediator.java?view=auto&rev=563410
==============================================================================
--- webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestMediator.java (added)
+++ webservices/synapse/trunk/java/modules/core/src/test/java/org/apache/synapse/mediators/ext/POJOCommandTestMediator.java Tue Aug 7 00:13:22 2007
@@ -0,0 +1,45 @@
+/*
+ * 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.ext;
+
+import org.apache.synapse.MessageContext;
+import org.apache.synapse.core.SynapseEnvironment;
+
+/**
+ * This class is just to test the behaviour of the POJO Command when implemented as just a POJO not
+ * implementing the Command interface. This will use static members to accomplish the test tasks.
+ */
+public class POJOCommandTestMediator {
+
+ public static String testProp = null;
+
+ public void execute() {
+ POJOCommandTestHelper.getInstance().setExecuted(true);
+ }
+
+ public void setTestProp(String s) {
+ testProp = s;
+ POJOCommandTestHelper.getInstance().setChangedProperty(testProp);
+ }
+
+ public String getTestProp() {
+ return testProp;
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: synapse-dev-unsubscribe@ws.apache.org
For additional commands, e-mail: synapse-dev-help@ws.apache.org