Author: hiranya
Date: Sun Aug 4 23:32:20 2013
New Revision: 1510359
URL: http://svn.apache.org/r1510359
Log:
Improved message injector task to support injecting messages directly into
named sequences and proxy services. Patches applied from SYNAPSE-957
SYNAPSE-958 and SYNAPSE-959
Added:
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample301.xml
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample302.xml
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample301.java
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample302.java
synapse/trunk/java/modules/integration/src/test/resources/sample301.xml
synapse/trunk/java/modules/integration/src/test/resources/sample302.xml
synapse/trunk/java/repository/conf/sample/synapse_sample_301.xml
synapse/trunk/java/repository/conf/sample/synapse_sample_302.xml
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/tasks/MessageInjector.java
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples.xml
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
Modified:
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/tasks/MessageInjector.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/tasks/MessageInjector.java?rev=1510359&r1=1510358&r2=1510359&view=diff
==============================================================================
---
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/tasks/MessageInjector.java
(original)
+++
synapse/trunk/java/modules/core/src/main/java/org/apache/synapse/startup/tasks/MessageInjector.java
Sun Aug 4 23:32:20 2013
@@ -21,20 +21,29 @@ package org.apache.synapse.startup.tasks
import org.apache.axiom.om.OMAbstractFactory;
import org.apache.axiom.om.OMElement;
+import org.apache.axiom.soap.SOAPEnvelope;
import org.apache.axis2.AxisFault;
+import org.apache.axis2.Constants;
import org.apache.axis2.addressing.EndpointReference;
+import org.apache.axis2.context.ConfigurationContext;
+import org.apache.axis2.description.AxisService;
+import org.apache.axis2.engine.AxisEngine;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.synapse.ManagedLifecycle;
import org.apache.synapse.MessageContext;
import org.apache.synapse.SynapseException;
import org.apache.synapse.core.SynapseEnvironment;
+import org.apache.synapse.core.axis2.Axis2SynapseEnvironment;
import org.apache.synapse.mediators.MediatorFaultHandler;
+import org.apache.synapse.mediators.base.SequenceMediator;
import org.apache.synapse.task.Task;
import org.apache.synapse.util.PayloadHelper;
/**
- * Injects a Message in to the Synapse environment
+ * Injects a Message into a named sequence or a proxy service configured in
the Synapse
+ * mediation engine. By default this task implementation will inject messages
into the
+ * main sequence.
*/
public class MessageInjector implements Task, ManagedLifecycle {
@@ -73,6 +82,26 @@ public class MessageInjector implements
public final static String POX_FORMAT = "pox";
public final static String GET_FORMAT = "get";
+ private final static String INJECT_TO_PROXY = "proxy";
+ private final static String INJECT_TO_SEQUENCE = "sequence";
+ private final static String INJECT_TO_MAIN_SEQ = "main";
+
+ /**
+ * Artifact type which message should be injected
+ * Could be one of "proxy" | "sequence" | "main"
+ */
+ private String injectTo = INJECT_TO_MAIN_SEQ;
+
+ /**
+ * Name of the sequence which message should be injected
+ */
+ private String sequenceName = null;
+
+ /**
+ * Name of the proxy service which message should be injected
+ */
+ private String proxyName = null;
+
/**
* Initializes the Injector
*
@@ -115,7 +144,7 @@ public class MessageInjector implements
/**
* Sets the SOAPAction and valid only when the format is given as soap11
- *
+ *
* @param soapAction SOAPAction header value to be set
*/
public void setSoapAction(String soapAction) {
@@ -123,61 +152,185 @@ public class MessageInjector implements
}
/**
- * This will be invoked by the schedular to inject the message
+ * Artifact type which message should be injected
+ * @param injectTo Could be one of "proxy" | "sequence" | "main"
+ */
+ public void setInjectTo(String injectTo) {
+ this.injectTo = injectTo;
+ }
+
+ /**
+ * Set name of the sequence which message should be injected
+ * @param sequenceName sequence name
+ */
+ public void setSequenceName(String sequenceName) {
+ this.sequenceName = sequenceName;
+ }
+
+ /**
+ * Set name of the proxy service which message should be injected
+ * @param proxyName proxy service name
+ */
+ public void setProxyName(String proxyName) {
+ this.proxyName = proxyName;
+ }
+
+ /**
+ * This will be invoked by the scheduler to inject the message
* in to the SynapseEnvironment
*/
public void execute() {
- log.debug("execute");
+
+ if (log.isDebugEnabled()) {
+ log.debug("execute");
+ }
+
if (synapseEnvironment == null) {
- log.error("Synapse Environment not set");
- return;
+ handleError("Synapse Environment not set");
+ return;
}
- if (message == null) {
- log.error("message not set");
- return;
+ if (message == null) {
+ handleError("message not set");
+ return;
}
- if (to == null) {
- log.error("to address not set");
- return;
- }
+ if (INJECT_TO_PROXY.equalsIgnoreCase(injectTo)) {
+
+ if (proxyName == null || proxyName.equals("")) {
+ handleError("Proxy service name not specified");
+ }
+
+ // Prepare axis2 message context
+ org.apache.axis2.context.MessageContext axis2MsgCtx =
+ new org.apache.axis2.context.MessageContext();
+ ConfigurationContext configurationContext =
((Axis2SynapseEnvironment) synapseEnvironment).
+ getAxis2ConfigurationContext();
+ axis2MsgCtx.setConfigurationContext(configurationContext);
+ axis2MsgCtx.setIncomingTransportName(Constants.TRANSPORT_LOCAL);
+ axis2MsgCtx.setServerSide(true);
- MessageContext mc = synapseEnvironment.createMessageContext();
-// AspectHelper.setGlobalAudit(mc); TODO
- mc.pushFaultHandler(new MediatorFaultHandler(mc.getFaultSequence()));
- mc.setTo(new EndpointReference(to));
- if (format == null) {
- PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
- } else {
try {
- if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
-
mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
- } else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
-
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
- } else if (POX_FORMAT.equalsIgnoreCase(format)) {
- mc.setDoingPOX(true);
- } else if (GET_FORMAT.equalsIgnoreCase(format)) {
- mc.setDoingGET(true);
+ AxisService axisService =
configurationContext.getAxisConfiguration().
+ getService(proxyName);
+ if (axisService == null) {
+ handleError("Proxy Service: " + proxyName + " not found");
}
- PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
+ axis2MsgCtx.setAxisService(axisService);
} catch (AxisFault axisFault) {
- String msg = "Error in setting the message payload : " +
message;
- log.error(msg, axisFault);
- throw new SynapseException(msg, axisFault);
+ handleError("Error occurred while attempting to find the Proxy
Service");
+ }
+
+ if (to != null) {
+ axis2MsgCtx.setTo(new EndpointReference(to));
+ }
+
+ SOAPEnvelope envelope = null;
+ if (format == null) {
+ envelope =
OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
+ } else if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
+ envelope =
OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope();
+ } else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
+ envelope =
OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
+ } else if (POX_FORMAT.equalsIgnoreCase(format)) {
+ envelope =
OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
+ axis2MsgCtx.setDoingREST(true);
+ } else if (GET_FORMAT.equalsIgnoreCase(format)) {
+ envelope =
OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope();
+ axis2MsgCtx.setDoingREST(true);
+ axis2MsgCtx.setProperty(Constants.Configuration.HTTP_METHOD,
+ Constants.Configuration.HTTP_METHOD_GET);
+ } else {
+ handleError("incorrect format specified");
+ }
+
+ try {
+ PayloadHelper.setXMLPayload(envelope,
message.cloneOMElement());
+ axis2MsgCtx.setEnvelope(envelope);
+ } catch (AxisFault axisFault) {
+ handleError("Error in setting the message payload : " +
message);
+ }
+
+ if (soapAction != null) {
+ axis2MsgCtx.setSoapAction(soapAction);
+ }
+
+ try {
+ if (log.isDebugEnabled()) {
+ log.debug("injecting message to proxy service : " +
proxyName);
+ }
+ AxisEngine.receive(axis2MsgCtx);
+ } catch (AxisFault axisFault) {
+ handleError("Error occurred while invoking proxy service : " +
proxyName);
+ }
+
+ } else {
+ MessageContext mc = synapseEnvironment.createMessageContext();
+ mc.pushFaultHandler(new
MediatorFaultHandler(mc.getFaultSequence()));
+ if (to != null) {
+ mc.setTo(new EndpointReference(to));
+ }
+
+ if (format == null) {
+ PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
+ } else {
+ try {
+ if (SOAP11_FORMAT.equalsIgnoreCase(format)) {
+
mc.setEnvelope(OMAbstractFactory.getSOAP11Factory().createSOAPEnvelope());
+ } else if (SOAP12_FORMAT.equalsIgnoreCase(format)) {
+
mc.setEnvelope(OMAbstractFactory.getSOAP12Factory().createSOAPEnvelope());
+ } else if (POX_FORMAT.equalsIgnoreCase(format)) {
+ mc.setDoingPOX(true);
+ } else if (GET_FORMAT.equalsIgnoreCase(format)) {
+ mc.setDoingGET(true);
+ }
+ PayloadHelper.setXMLPayload(mc, message.cloneOMElement());
+ } catch (AxisFault axisFault) {
+ handleError("Error in setting the message payload : " +
message);
+ }
+ }
+
+ if (soapAction != null) {
+ mc.setSoapAction(soapAction);
+ }
+
+ if (INJECT_TO_SEQUENCE.equalsIgnoreCase(injectTo)) {
+ if (sequenceName == null || sequenceName.equals("")) {
+ handleError("Sequence name not specified");
+ }
+ SequenceMediator seq = (SequenceMediator)
synapseEnvironment.getSynapseConfiguration().
+ getSequence(sequenceName);
+ if (seq != null) {
+ if (log.isDebugEnabled()) {
+ log.debug("injecting message to sequence : " +
sequenceName);
+ }
+ synapseEnvironment.injectAsync(mc, seq);
+ } else {
+ handleError("Sequence: " + sequenceName + " not found");
+ }
+ } else {
+ if (log.isDebugEnabled()) {
+ log.debug("injecting message to main sequence");
+ }
+ synapseEnvironment.injectMessage(mc);
}
}
- if (soapAction != null) {
- mc.setSoapAction(soapAction);
- }
- synapseEnvironment.injectMessage(mc);
- }
+ }
/**
* Destroys the Injector
*/
public void destroy() {
- }
+ }
+
+ /**
+ * Log the error and throws a SynapseException
+ * @param msg the log message
+ */
+ private void handleError(String msg) {
+ log.error(msg);
+ throw new SynapseException(msg);
+ }
}
Modified:
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples.xml?rev=1510359&r1=1510358&r2=1510359&view=diff
==============================================================================
---
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples.xml
(original)
+++
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples.xml
Sun Aug 4 23:32:20 2013
@@ -128,6 +128,8 @@
<p>
<ul>
<li><a href="samples/sample300.html">Sample 300:
Introduction to tasks with simple trigger</a></li>
+ <li><a href="samples/sample301.html">Sample 301:
Message Injector Task to invoke a named sequence</a></li>
+ <li><a href="samples/sample302.html">Sample 302:
Message Injector Task to invoke a Proxy service</a></li>
</ul>
</p>
</subsection>
Added:
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample301.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample301.xml?rev=1510359&view=auto
==============================================================================
---
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample301.xml
(added)
+++
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample301.xml
Sun Aug 4 23:32:20 2013
@@ -0,0 +1,103 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+ ~ 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.
+ -->
+
+<document>
+ <properties>
+ <title>Apache Synapse - Sample 301</title>
+ </properties>
+ <body>
+ <section name="Sample 301: Message Injector Task to invoke a named
sequence">
+ <div class="xmlConf"><![CDATA[<definitions
xmlns="http://ws.apache.org/ns/synapse">
+ <task class="org.apache.synapse.startup.tasks.MessageInjector"
name="InjectToSequenceTask">
+ <property name="soapAction" value="urn:getQuote"/>
+ <property name="format" value="soap11"/>
+ <property name="injectTo" value="sequence"/>
+ <property name="sequenceName" value="SampleSequence"/>
+ <property name="message">
+ <m0:getQuote xmlns:m0="http://services.samples">
+ <m0:request>
+ <m0:symbol>IBM</m0:symbol>
+ </m0:request>
+ </m0:getQuote>
+ </property>
+ <trigger interval="5"/>
+ </task>
+ <sequence name="SampleSequence">
+ <log level="custom">
+ <property name="MSG" value="SampleSequence invoked"/>
+ </log>
+ <send receive="receivingSequence">
+ <endpoint>
+ <address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </sequence>
+ <sequence name="receivingSequence">
+ <log level="custom">
+ <property xmlns:ns="http://services.samples"
name="Stock_Quote_on"
+
expression="//ns:return/ns:lastTradeTimestamp/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="For_the_organization"
+
expression="//ns:return/ns:name/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="Last_Value"
+
expression="//ns:return/ns:last/child::text()"/>
+ </log>
+ </sequence>
+ </definitions>]]></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate how to schedule tasks to invoke a named
sequence periodically using
+ the MessageInjector task implementation
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample
Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 301
(repository/conf/sample/synapse_sample_301.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 301<br/>
+ Windows: synapse.bat -sample 301
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ The above configuration adds a scheduled task and
sequences to the Synapse runtime.
+ The task is configured to run every 5 seconds (note the
'interval' attribute on
+ the 'trigger' element).
+ </p>
+ <p>
+ In this sample, the sequence "SampleSequence" will be
invoked by the task and
+ then from the sequence, the injected messages will be sent
to the sample Axis2
+ server, which will send back a response to Synapse. So
every 5 seconds you will
+ notice that Axis2 is generating a quote and Synapse is
receiving the stock quote
+ response. You will also see "SampleSequence invoked"
message getting logged on
+ the console.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Added:
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample302.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample302.xml?rev=1510359&view=auto
==============================================================================
---
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample302.xml
(added)
+++
synapse/trunk/java/modules/documentation/src/site/xdoc/userguide/samples/sample302.xml
Sun Aug 4 23:32:20 2013
@@ -0,0 +1,108 @@
+<?xml version="1.0" encoding="ISO-8859-1" ?>
+<!--
+ ~ 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.
+ -->
+
+<document>
+ <properties>
+ <title>Apache Synapse - Sample 302</title>
+ </properties>
+ <body>
+ <section name="Sample 302: Message Injector Task to invoke a Proxy
service">
+ <div class="xmlConf"><![CDATA[<definitions
xmlns="http://ws.apache.org/ns/synapse">
+ <task class="org.apache.synapse.startup.tasks.MessageInjector"
name="InjectToProxyTask">
+ <property name="soapAction" value="urn:getQuote"/>
+ <property name="format" value="soap11"/>
+ <property name="injectTo" value="proxy"/>
+ <property name="proxyName" value="SampleProxy"/>
+ <property name="message">
+ <m0:getQuote xmlns:m0="http://services.samples">
+ <m0:request>
+ <m0:symbol>IBM</m0:symbol>
+ </m0:request>
+ </m0:getQuote>
+ </property>
+ <trigger interval="5"/>
+ </task>
+ <proxy name="SampleProxy" transports="http">
+ <target>
+ <inSequence>
+ <log level="custom">
+ <property name="MSG" value="SampleProxy
invoked"/>
+ </log>
+ <send>
+ <endpoint>
+ <address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </inSequence>
+ <outSequence>
+ <log level="custom">
+ <property xmlns:ns="http://services.samples"
name="Stock_Quote_on"
+
expression="//ns:return/ns:lastTradeTimestamp/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="For_the_organization"
+
expression="//ns:return/ns:name/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="Last_Value"
+
expression="//ns:return/ns:last/child::text()"/>
+ </log>
+ <drop/>
+ </outSequence>
+ </target>
+ </proxy>
+ </definitions>]]></div>
+ <subsection name="Objective">
+ <p>
+ Demonstrate how to schedule tasks to invoke a Proxy
service periodically using
+ the MessageInjector task implementation
+ </p>
+ </subsection>
+ <subsection name="Pre-requisites">
+ <p>
+ <ul>
+ <li>
+ Deploy the SimpleStockQuoteService in the sample
Axis2 server and start Axis2
+ </li>
+ <li>
+ Start Synapse using the configuration numbered 302
(repository/conf/sample/synapse_sample_302.xml)
+ <div class="command">
+ Unix/Linux: sh synapse.sh -sample 302<br/>
+ Windows: synapse.bat -sample 302
+ </div>
+ </li>
+ </ul>
+ </p>
+ </subsection>
+ <subsection name="Executing the Client">
+ <p>
+ The above configuration adds a scheduled task, and a proxy
service to the Synapse
+ runtime. The task is configured to run every 5 seconds
(note the 'interval'
+ attribute on the 'trigger' element).
+ </p>
+ <p>
+ In this sample, the proxy service "SampleProxy" will be
invoked by the task and
+ then from the proxy service, the injected messages will be
sent to the sample
+ Axis2 server, which will send back a response to Synapse.
So every 5 seconds you
+ will notice that Axis2 is generating a quote and Synapse
is receiving the stock
+ quote response. You will also see the "SampleProxy
invoked" message getting
+ loggedlog on the console.
+ </p>
+ </subsection>
+ </section>
+ <p><a href="../samples.html">Back to Catalog</a></p>
+ </body>
+</document>
\ No newline at end of file
Modified:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java?rev=1510359&r1=1510358&r2=1510359&view=diff
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
(original)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/TestSamplesHandlerSuite.java
Sun Aug 4 23:32:20 2013
@@ -22,7 +22,7 @@ package org.apache.synapse.samples.frame
import junit.framework.TestSuite;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
-import org.apache.synapse.samples.framework.tests.tasks.Sample300;
+import org.apache.synapse.samples.framework.tests.tasks.*;
import org.apache.synapse.samples.framework.tests.transport.Sample250;
import org.apache.synapse.samples.framework.tests.advanced.*;
import org.apache.synapse.samples.framework.tests.endpoint.*;
@@ -212,6 +212,8 @@ public class TestSamplesHandlerSuite ext
//Tasks
sampleClassRepo.put("300", Sample300.class);
+ sampleClassRepo.put("301", Sample301.class);
+ sampleClassRepo.put("302", Sample302.class);
//Advanced
sampleClassRepo.put("350", Sample350.class);
Added:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample301.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample301.java?rev=1510359&view=auto
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample301.java
(added)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample301.java
Sun Aug 4 23:32:20 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.samples.framework.tests.tasks;
+
+import org.apache.synapse.samples.framework.SynapseTestCase;
+
+public class Sample301 extends SynapseTestCase {
+
+ public Sample301() {
+ super(301);
+ }
+
+ public void testScheduledTaskInjectToSequence() throws Exception {
+ log.info("Waiting 10 seconds for the task to run...");
+ Thread.sleep(10000);
+ int messageCount =
getAxis2Server().getMessageCount("SimpleStockQuoteService", "getQuote");
+ log.info("Task sent " + messageCount + " messages.");
+ assertTrue(messageCount >= 2);
+ }
+}
Added:
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample302.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample302.java?rev=1510359&view=auto
==============================================================================
---
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample302.java
(added)
+++
synapse/trunk/java/modules/integration/src/test/java/org/apache/synapse/samples/framework/tests/tasks/Sample302.java
Sun Aug 4 23:32:20 2013
@@ -0,0 +1,37 @@
+/*
+ * 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.samples.framework.tests.tasks;
+
+import org.apache.synapse.samples.framework.SynapseTestCase;
+
+public class Sample302 extends SynapseTestCase {
+
+ public Sample302() {
+ super(302);
+ }
+
+ public void testScheduledTaskInjectToProxy() throws Exception {
+ log.info("Waiting 10 seconds for the task to run...");
+ Thread.sleep(10000);
+ int messageCount =
getAxis2Server().getMessageCount("SimpleStockQuoteService", "getQuote");
+ log.info("Task sent " + messageCount + " messages.");
+ assertTrue(messageCount >= 2);
+ }
+}
Added: synapse/trunk/java/modules/integration/src/test/resources/sample301.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/sample301.xml?rev=1510359&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/sample301.xml
(added)
+++ synapse/trunk/java/modules/integration/src/test/resources/sample301.xml Sun
Aug 4 23:32:20 2013
@@ -0,0 +1,20 @@
+<synapseSample>
+ <sampleID>301</sampleID>
+ <sampleName>Task injecting to a named sequence</sampleName>
+ <synapseConfig>
+ <!--if we don't specify the optional values, framework will use
defaults-->
+ <axis2Repo>modules/integration/target/test_repos/synapse</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/synapse/conf/axis2_def.xml</axis2Xml>
+ <synapseXml>repository/conf/sample/synapse_sample_301.xml</synapseXml>
+ </synapseConfig>
+ <backEndServerConfig>
+ <axis2Server id='0'>
+
<axis2Repo>modules/integration/target/test_repos/axis2Server</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml</axis2Xml>
+ <counterEnabled>true</counterEnabled>
+ </axis2Server>
+ </backEndServerConfig>
+ <clientConfig>
+
<clientRepo>modules/integration/target/test_repos/axis2Client</clientRepo>
+ </clientConfig>
+</synapseSample>
\ No newline at end of file
Added: synapse/trunk/java/modules/integration/src/test/resources/sample302.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/integration/src/test/resources/sample302.xml?rev=1510359&view=auto
==============================================================================
--- synapse/trunk/java/modules/integration/src/test/resources/sample302.xml
(added)
+++ synapse/trunk/java/modules/integration/src/test/resources/sample302.xml Sun
Aug 4 23:32:20 2013
@@ -0,0 +1,20 @@
+<synapseSample>
+ <sampleID>302</sampleID>
+ <sampleName>Task injecting to a Proxy service</sampleName>
+ <synapseConfig>
+ <!--if we don't specify the optional values, framework will use
defaults-->
+ <axis2Repo>modules/integration/target/test_repos/synapse</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/synapse/conf/axis2_def.xml</axis2Xml>
+ <synapseXml>repository/conf/sample/synapse_sample_302.xml</synapseXml>
+ </synapseConfig>
+ <backEndServerConfig>
+ <axis2Server id='0'>
+
<axis2Repo>modules/integration/target/test_repos/axis2Server</axis2Repo>
+
<axis2Xml>modules/integration/target/test_repos/axis2Server/conf/axis2_def.xml</axis2Xml>
+ <counterEnabled>true</counterEnabled>
+ </axis2Server>
+ </backEndServerConfig>
+ <clientConfig>
+
<clientRepo>modules/integration/target/test_repos/axis2Client</clientRepo>
+ </clientConfig>
+</synapseSample>
\ No newline at end of file
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_301.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_301.xml?rev=1510359&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_301.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_301.xml Sun Aug 4
23:32:20 2013
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- Task injecting to a named sequence -->
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <task class="org.apache.synapse.startup.tasks.MessageInjector"
name="InjectToSequenceTask">
+ <property name="soapAction" value="urn:getQuote"/>
+ <property name="format" value="soap11"/>
+ <property name="injectTo" value="sequence"/>
+ <property name="sequenceName" value="SampleSequence"/>
+ <property name="message">
+ <m0:getQuote xmlns:m0="http://services.samples">
+ <m0:request>
+ <m0:symbol>IBM</m0:symbol>
+ </m0:request>
+ </m0:getQuote>
+ </property>
+ <trigger interval="5"/>
+ </task>
+
+ <sequence name="SampleSequence">
+ <log level="custom">
+ <property name="MSG" value="SampleSequence invoked"/>
+ </log>
+ <send receive="receivingSequence">
+ <endpoint>
+ <address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </sequence>
+
+ <sequence name="receivingSequence">
+ <log level="custom">
+ <property xmlns:ns="http://services.samples" name="Stock_Quote_on"
+
expression="//ns:return/ns:lastTradeTimestamp/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="For_the_organization"
+ expression="//ns:return/ns:name/child::text()"/>
+ <property xmlns:ns="http://services.samples" name="Last_Value"
+ expression="//ns:return/ns:last/child::text()"/>
+ </log>
+ </sequence>
+
+</definitions>
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_302.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_302.xml?rev=1510359&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_302.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_302.xml Sun Aug 4
23:32:20 2013
@@ -0,0 +1,65 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<!-- Task injecting to a Proxy service -->
+<definitions xmlns="http://ws.apache.org/ns/synapse">
+
+ <task class="org.apache.synapse.startup.tasks.MessageInjector"
name="InjectToProxyTask">
+ <property name="soapAction" value="urn:getQuote"/>
+ <property name="format" value="soap11"/>
+ <property name="injectTo" value="proxy"/>
+ <property name="proxyName" value="SampleProxy"/>
+ <property name="message">
+ <m0:getQuote xmlns:m0="http://services.samples">
+ <m0:request>
+ <m0:symbol>IBM</m0:symbol>
+ </m0:request>
+ </m0:getQuote>
+ </property>
+ <trigger interval="5"/>
+ </task>
+
+ <proxy name="SampleProxy" transports="http">
+ <target>
+ <inSequence>
+ <log level="custom">
+ <property name="MSG" value="SampleProxy invoked"/>
+ </log>
+ <send>
+ <endpoint>
+ <address
uri="http://localhost:9000/services/SimpleStockQuoteService"/>
+ </endpoint>
+ </send>
+ </inSequence>
+ <outSequence>
+ <log level="custom">
+ <property xmlns:ns="http://services.samples"
name="Stock_Quote_on"
+
expression="//ns:return/ns:lastTradeTimestamp/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="For_the_organization"
+ expression="//ns:return/ns:name/child::text()"/>
+ <property xmlns:ns="http://services.samples"
name="Last_Value"
+ expression="//ns:return/ns:last/child::text()"/>
+ </log>
+ <drop/>
+ </outSequence>
+ </target>
+ </proxy>
+
+</definitions>