WSO2 ESB 4.6.0 中 Spring Mediator 的工作示例 [英] Working example on Spring Mediator in WSO2 ESB 4.6.0

查看:14
本文介绍了WSO2 ESB 4.6.0 中 Spring Mediator 的工作示例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我正在 WSO2 ESB 4.6.0 中使用 Spring Mediator,使用 this这个教程

Hi i am working on Spring Mediator in WSO2 ESB 4.6.0, using this and this tutorial

我收到如下错误:

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

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

Could you please explain me how to solve this.

推荐答案

我要按如下方式进行,

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

The class should extends AbstractMediator and override the mediate() method as follows,

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;
    }
}

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

Then place the jar in [ESBHOME]/repository/components/lib folder

在中介方法中,它会打印一条带有参数的消息,例如 HELLO 'arg'

In mediate method it prints a message with the argument like HELLO 'arg'

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

And I added the following file to registry (/_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>

我的代理如下,

<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>

在代理中可以看到bean=[springtest.xml的bean id]class=class的限定名

在我的 ESB 终端中,我使用 springtest.xml 中的给定属性值输出了以下内容,

In my ESB terminal, I got the following out put with the given property value in 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>

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

You must restart the ESB after placing the jar in repository/components/lib

这篇关于WSO2 ESB 4.6.0 中 Spring Mediator 的工作示例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆