WSO2 ESB 4.6.0中Spring Mediator的工作示例

Kan*_*eel 1 spring wso2 apache-synapse wso2esb wso2carbon

你好我工作的弹簧调解员WSO2 ESB 4.6.0,使用教程

我收到错误如下:

ERROR - SpringMediator Cannot look up Spring configuration conf/sample/resources/spring/springsample.xml

ERROR - SpringMediatorCannot reference application context with key : conf/sample/resources/spring/springsample.xml
Run Code Online (Sandbox Code Playgroud)

你能解释一下如何解决这个问题.

Isu*_*ana 5

我得按照以下方式工作,

该类应扩展AbstractMediator并覆盖mediate()方法,如下所示,

package com.test.spring.mediator.workingexampleonspringmediator;

import org.apache.synapse.MessageContext;
import org.apache.synapse.mediators.AbstractMediator;

public class HelloWorld extends AbstractMediator{

           private String message;   
       public void setMessage(String message){
          this.message  = message;
       }

       public boolean mediate(MessageContext arg0) {

          System.out.println("HELLO "+message);
          return true;
    }
}
Run Code Online (Sandbox Code Playgroud)

然后将jar放在[ESBHOME]/repository/components/lib文件夹中

在mediate方法中,它打印一个带有参数的消息 HELLO 'arg'

我将以下文件添加到注册表中(/_system/config/repository/spring/springtest.xml),

<?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="com.test.spring.mediator.workingexampleonspringmediator.HelloWorld"  singleton="false">
   <property name="message"><value>ISURU</value></property>
   </bean>
</beans>
Run Code Online (Sandbox Code Playgroud)

我的代理人如下,

<proxy xmlns="http://ws.apache.org/ns/synapse" name="testSpring" transports="https,http" statistics="disable" trace="disable" startOnLoad="true">
   <target>
      <inSequence>
         <log level="full">
            <property name="START" value="__________________________"/>
         </log>
         <spring:spring xmlns:spring="http://ws.apache.org/ns/synapse" bean="springtest" key="conf:/repository/spring/springtest.xml"/>
         <log level="full">
            <property name="END" value="______________________"/>
         </log>
      </inSequence>
   </target>
   <description></description>
</proxy>
Run Code Online (Sandbox Code Playgroud)

在代理中,您可以看到bean=[bean id of the springtest.xml]class=qualified name of the class

在我的ESB终端中,我在springtest.xml中得到了以下带有给定属性值的输出,

[2013-11-07 17:38:30,654]  INFO - LogMediator To: /services/testSpring.testSpringHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bcae82e9-4027-43c5-bd7a-cbfa885aaf33, Direction: request, START = __________________________, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope>
HELLO ISURU
[2013-11-07 17:38:30,692]  INFO - LogMediator To: /services/testSpring.testSpringHttpSoap12Endpoint, WSAction: urn:mediate, SOAPAction: urn:mediate, MessageID: urn:uuid:bcae82e9-4027-43c5-bd7a-cbfa885aaf33, Direction: request, END = ______________________, Envelope: <?xml version='1.0' encoding='utf-8'?><soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"><soapenv:Body/></soapenv:Envelope>
Run Code Online (Sandbox Code Playgroud)

将jar放入repository/components/lib后,必须重新启动ESB