The Spring Mediator exposes a spring bean as a mediator. The Spring Mediator creates an instance of a mediator, which is managed by Spring. This Spring bean must implement the Mediator
interface for it to act as a Mediator.
...
Table of Contents |
---|
maxLevel | 3 |
---|
minLevel | 3 |
---|
style | border:1 |
---|
location | top |
---|
type | flat |
---|
separator | pipe |
---|
|
...
Syntax
Code Block |
---|
|
<spring:spring bean="exampleBean" key="string"/>
|
...
Info |
---|
|
You can configure the Mediator using XML. Click on "switch to source view" in the "Mediator" window.
|
...
Example
Code Block |
---|
|
<spring:spring bean="springtest" key="conf/sample/resources/spring/springsample.xml"/>
|
In the above configuration, the spring XML is in the registry and it can be looked up using the registry key conf/sample/resources/spring/springsample.xml
. This spring XML (i.e springsample.xml
) must contain a bean with the name springtest
. The following figure shows an example that can be used as the registry resource - springsample.xml
.
Code Block |
---|
|
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean id="springtest" class="org.apache.synapse.mediators.spring.SpringTestBean" singleton="false">
<property name="testProperty" value="100"/>
</bean>
</beans>
|
Also, you need to build the JAR file of the following Spring Bean class and place it in the <ESB_HOME>/repository/components/lib/
directory.
Code Block |
---|
|
package org.apache.synapse.mediators.spring;
import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;
public class SpringTestBean extends AbstractMediator{
private String testProperty;
public void setTestProperty(String testProperty){
this.testProperty = testProperty;
}
public boolean mediate(MessageContext mc) {
// Do somthing useful..
// Note the access to the Synapse Message context
return true;
}
} |
Excerpt |
---|
|
Description of the Spring Mediator in WSO2 ESB. |
For more examples, see Mediating with Spring.