WSO2 ESB 4.6.0中Spring Mediator的工作示例

时间:2013-11-04 05:25:40

标签: spring wso2 wso2esb wso2carbon synapse

您好我正在使用thisthis教程在WSO2 ESB 4.6.0中使用Spring Mediator

我收到错误如下:

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

请你解释一下如何解决这个问题。

4 个答案:

答案 0 :(得分: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;
    }
}

然后将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>

我的代理如下,

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

将jar放入repository / components / lib

后,必须重新启动ESB

答案 1 :(得分:2)

正如Isuru上面解释的那样,这些是春季调解员的步骤

  1. 通过扩展AbstractMediator

  2. 创建spring mediator库
  3. 复制到ESB_HOME / repository / components / lib

  4. 重新启动服务器

  5. 在注册表中注册springtest.xml文件 (http://madhukaudantha.blogspot.com/2012/07/wso2-esb-proxy-from-registry.html直到第5步,正如Isuru所解释的那样)

  6. 然后,使用Spring Mediator创建一个自定义代理。

  7. 在那里, 将Bean添加为“springtest”(为xml文件中的mediator类定义的bean id)

    根据第4步选择密钥作为配置注册表文件的存储位置。

    例如:如果已将springtest.xml文件存储到路径“_system / config / repository /”中 选择Key为“/_system/config/repository/springtest.xml”

    注意:

    • 在ESG_HOME / repository / components / dropins文件夹中验证OSGI 创建的spring mediator库的中介包 被复制到ESB_HOME / repository / components / lib中。如果它不存在 重新启动服务器后,它可能是创建的介体中的问题 库。

    • 除此之外,还要为调解器类添加唯一的包名称以避免 与其他调解员阶级的冲突 ESB_HOME /存储库/组件/ lib中。

    • 请记住为.xml文件添加唯一的bean ID 在第4步中注册.xml文件时在注册表中注册。

答案 2 :(得分:1)

这是因为esb在路径springsample.xml

中找到了repository/conf/sample/resources文件
<parameter name="root">file:repository/conf/sample/resources/</parameter>

springsample.xml文件位置位于repository/samples/resources/。因此,应按以下方式予以纠正,

<parameter name="root">file:repository/samples/resources/</parameter>

在文档中,配置不正确,如果通过命令wso2esb-samples -sn 470启动esb(如文档中所述),esb将加载文件repository/samples/synapse_sample_470.xml此文件中的上述参数已正确配置。

希望这能解决您的问题:)

更新:

根据您的评论,由于您是直接使用示例弹簧示例,这是由于尝试访问的文件的权限而发生的,或者这可能是由于文件路径错误。所以请尝试使用绝对文件网址。

答案 3 :(得分:0)

当我发送消息时,我得到的唯一错误消息就是这个

ERROR - SpringMediator No bean named 'springtest' is defined

所以这意味着,找到了配置文件。但是内部bean的实例化怎么样,我看不出任何明显的错误。 jar文件在components / lib中,我也可以在dropins文件夹中看到它。

:/