Author: ruwan
Date: Mon Sep 20 03:04:37 2010
New Revision: 998765
URL: http://svn.apache.org/viewvc?rev=998765&view=rev
Log:
Adding the Spring sample, commiting for Charith. SYNAPSE-497
Added:
synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/
synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/SpringCustomLogger.java
synapse/trunk/java/repository/conf/sample/resources/spring/springCustomLogger.xml
synapse/trunk/java/repository/conf/sample/synapse_sample_460.xml
Modified:
synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
Added:
synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/SpringCustomLogger.java
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/SpringCustomLogger.java?rev=998765&view=auto
==============================================================================
---
synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/SpringCustomLogger.java
(added)
+++
synapse/trunk/java/modules/samples/src/main/java/samples/mediators/extensions/SpringCustomLogger.java
Mon Sep 20 03:04:37 2010
@@ -0,0 +1,59 @@
+/*
+ * 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 samples.mediators.extensions;
+
+import org.apache.synapse.mediators.AbstractMediator;
+import org.apache.synapse.MessageContext;
+import org.apache.commons.logging.Log;
+import org.apache.commons.logging.LogFactory;
+
+public class SpringCustomLogger extends AbstractMediator {
+
+ private static final Log log = LogFactory.getLog(SpringCustomLogger.class);
+ private String userName;
+ private String email;
+
+ public String getEmail() {
+ return email;
+ }
+
+ public void setEmail(String email) {
+ this.email = email;
+ }
+
+ public String getUserName() {
+ return userName;
+ }
+
+ public void setUserName(String userName) {
+ this.userName = userName;
+ }
+
+ /*This will log the username email that is initialised from Spring xml*/
+ public boolean mediate(MessageContext synCtx) {
+
+ log.info("Starting Spring Meditor");
+ log.info("Bean in Initialized with User:["+userName+"]");
+ log.info("E-MAIL:["+email+"]");
+ log.info("Massage Id: "+synCtx.getMessageID());
+ log.info("Logged....");
+ return true;
+ }
+}
Added:
synapse/trunk/java/repository/conf/sample/resources/spring/springCustomLogger.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/resources/spring/springCustomLogger.xml?rev=998765&view=auto
==============================================================================
---
synapse/trunk/java/repository/conf/sample/resources/spring/springCustomLogger.xml
(added)
+++
synapse/trunk/java/repository/conf/sample/resources/spring/springCustomLogger.xml
Mon Sep 20 03:04:37 2010
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
+ "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+
+ <bean id="springtest"
class="samples.mediators.extensions.SpringCustomLogger" singleton="false">
+ <property name="userName"><value>"Synapse User"</value></property>
+ <property name="email"><value>"[email protected]"</value></property>
+ </bean>
+
+</beans>
Added: synapse/trunk/java/repository/conf/sample/synapse_sample_460.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/repository/conf/sample/synapse_sample_460.xml?rev=998765&view=auto
==============================================================================
--- synapse/trunk/java/repository/conf/sample/synapse_sample_460.xml (added)
+++ synapse/trunk/java/repository/conf/sample/synapse_sample_460.xml Mon Sep 20
03:04:37 2010
@@ -0,0 +1,36 @@
+<?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.
+ -->
+
+<!--How to initialize and use Spring bean as a mediator -->
+<definitions xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+
+ <registry provider="org.apache.synapse.registry.url.SimpleURLRegistry">
+ <parameter
name="root">file:repository/conf/sample/resources/</parameter>
+ <parameter name="cachableDuration">15000</parameter>
+ </registry>
+
+ <sequence name="main">
+ <!--Setting the Spring Mediator and its Spring Beans xml file location
-->
+ <!--Note that springtest is the bean id used in springCustomLogger.xml
-->
+ <spring bean="springtest" key="spring/springCustomLogger.xml"/>
+ <send/>
+ </sequence>
+
+</definitions>
Modified: synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml
URL:
http://svn.apache.org/viewvc/synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml?rev=998765&r1=998764&r2=998765&view=diff
==============================================================================
--- synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml (original)
+++ synapse/trunk/java/src/site/xdoc/Synapse_Samples.xml Mon Sep 20 03:04:37
2010
@@ -308,6 +308,8 @@
<a href="#Sample451">Sample 451: Conditional URL rewriting</a></li>
<li>
<a href="#Sample452">Sample 452: Conditional URL rewriting with multiple
rules</a></li>
+<li>
+<a href="#Sample460">Sample 460: How to initialize and use a Spring Bean as a
Mediator</a></li>
</ul></li></ul></li>
<li>
<a href="#Task">Introduction to Eventing</a>
@@ -4589,6 +4591,52 @@ server and the client will receive a val
<p>Another important aspect shown by this sample is the ability of the URL
rewirte mediator to obtain the necessary
values by executing XPath expressions. The port numbers are calculated by
executing an XPath on the messages.</p>
</div>
+
+<h2>
+<a name="Sample460" id="Sample460">Sample 460: How to initialize and use a
Spring Bean as a Mediator</a></h2>
+<pre xml:space="preserve"><definitions
xmlns="http://synapse.apache.org/ns/2010/04/configuration">
+
+ <registry
provider="org.apache.synapse.registry.url.SimpleURLRegistry">
+ <parameter
name="root">file:repository/conf/sample/resources/</parameter>
+ <parameter name="cachableDuration">15000</parameter>
+ </registry>
+
+ <sequence name="main">
+ <!--Setting the Spring Mediator and its Spring Beans xml file
location -->
+ <!--Note that springtest is the bean id used in
springCustomLogger.xml -->
+ <spring bean="springtest" key="spring/springCustomLogger.xml"/>
+ <send/>
+ </sequence>
+
+</definitions>
+
+</pre>
+<p>springCustomLogger.xml file</p>
+<pre xml:space="preserve">
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
+ "http://www.springframework.org/dtd/spring-beans.dtd">
+
+<beans>
+
+ <bean id="springtest"
class="samples.mediators.extentions.SpringCustomLogger" singleton="false">
+ <property name="userName"><value>"Synapse
User"</value></property>
+ <property
name="email"><value>"[email protected]"</value></property>
+ </bean>
+
+</beans>
+
+</pre>
+<div>
+<p>
+<strong>Objective:</strong> Demonstrate How to initialize and use a SpringBean
as a mediator </p>
+<p>
+<strong>Prerequisites:</strong> Deploy the SimpleStockQuoteService in sample
Axis2 server and start it on port 9000. </p>
+<p>Start Synapse with the sample configuration 460 (i.e. synapse -sample 460).
</p>
+<p>In this sample, the Spring Bean, SpringCustomLogger get initialized using
springCustomLogger.xml file and then it log the message Id.</p>
+<p>Invoke the client as follows. </p>
+<pre xml:space="preserve">ant stockquote
-Daddurl=http://localhost:9000/services/SimpleStockQuoteService
-Dtrpurl=http://localhost:8280/</pre>
+</div>
<h2>
<a name="Sample500" id="Sample500">Sample 500: Simple Eventing Sample</a>
</h2>