Question

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

I am getting the Error as follows:

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.

Was it helpful?

Solution

I got to work this as below,

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

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

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

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>

My proxy is as follows,

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

In the proxy you can see the bean=[bean id of the springtest.xml] and class=qualified name of the class

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>

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

OTHER TIPS

These are the steps for spring mediator in brief as Isuru explained above

  1. Create spring mediator library by extending AbstractMediator

  2. Copy into ESB_HOME/repository/components/lib

  3. Re-start the server

  4. Register springtest.xml file in the Registry (http://madhukaudantha.blogspot.com/2012/07/wso2-esb-proxy-from-registry.html up to step 5 as Isuru explained)

  5. Then, create a Custom proxy with Spring Mediator.

In there, add Bean as “springtest” (defined bean id for the mediator class within the xml file)

Select the Key as where the configuration registry file stored according to the 4th step.

Ex : If you have stored that springtest.xml file into path “_system/config/repository/”
Select Key as “/_system/config/repository/springtest.xml”

Note:

  • Verify in ESB_HOME/repository/components/dropins folder for OSGI bundle of the mediator of the created spring mediator library which is copied into ESB_HOME/repository/components/lib. If it is not there after restarting server, it may be a problem in created mediator library.

  • As well as, put unique package name for the mediator class to avoid conflicts with other mediator class in ESB_HOME/repository/components/lib.

  • Keep in mind to add unique bean id for the .xml file which is registered in the registry when you registered .xml file in 4th step.

This is because of the esb finds the springsample.xml file in the path repository/conf/sample/resources

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

But the springsample.xml file location is in repository/samples/resources/ . Therefore it should be corrected as the following,

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

In documentation, the configuration is not correct, If you start the esb by the command wso2esb-samples -sn 470 (as mentioned in the documentation) the esb will load the file in repository/samples/synapse_sample_470.xml where in this file above parameter is correctly configured.

Hope this will solve your problem :)

UPDATED:

According to your comment, as your are directly using sample spring example, this occur due to permission of the file trying to access, Or this can be due to file path error. So please try with absolute file url.

when i send a message, the only error message i got is this one

ERROR - SpringMediator No bean named 'springtest' is defined

so it means, the config file has been found. But what about the instanciation of the bean inside, i cannot see any explicit error. The jar file is in components/lib and i can see it also in dropins folder.

:/

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top