Create and deploy custom mediator in WSO2 ESB - wso2

I have created custom mediator with Factory and Serializer classes. Created jar with \META-INF\services\ files and put it to dropins folder.
But after restart when I deployed test proxy with my mediator, I always get error like this:
org.apache.synapse.SynapseException: Unknown mediator referenced by configuration element :
at org.apache.synapse.config.xml.MediatorFactoryFinder.getMediator(MediatorFactoryFinder.java:218)
It looks like ESB isn't able to find the Factory class. Where is my mistake& And may be someone has working example custom mediator with factory and serializer clases?

Related

WSO2 class mediator not work

This is my first time to write NTLM mediator followed by NTLM Mediator
The mediator project:
Exported Jar and [ESB_HOME]/repository/components/dropins
Proxy service to test:
The mediator seems not work:
Line 73 throw out exception:
You have to put jars into lib ($ESB_HOME/repository/components/lib). Delete jar in the dropins. As ESB start, it will put that jar into dropins folder. Try that.
If not you may have to add three folders as given in documentation[2].
Further references:
[1] https://docs.wso2.com/display/ESB490/Class+Mediator
[2] https://docs.wso2.com/display/ESB490/Places+for+Putting+Custom+Mediators
The issue seems to be related to the mediation logic. The mediator seems to have deployed correctly since there is no ClassNotFound exceptions. To figure out the error you can add logs to the mediator or remote debug the mediator by starting ESB server in debug mode
(./wso2server.sh debug 5005). You should debug the mediate() method. The error that you have got is thrown due to some exception being thrown in your class mediator's mediate() method.
DilshaniS' answer is correct. You have to place your mediator jar in lib folder (also need to delete the existing jar in dropins folder). Following is the reason.
WSO2 products can only load/activate a jar placed in dropins folder only if it is written as an osgi component. In your case, it is just a jar. There are no classes which should be there in a osgi bundle. If it is a normal jar, you have to place it in the repository/components/lib folder. Then, when the server starts, it creates a osgi bundle from that jar and places it in the dropins folder. Then that osgi bundle gets activated and you are able to uses the classes in it.

WSO2 ESB Callout Mediator axis2Configuration

I have a question regarding the WSO2 ESB callout mediator using an individual Axis2 configuration file. I would like to have the individual Axis2 configuration to be deployed using a carbon application. Unfortunately the callout mediator doesn't seem to be able to read the Axis2 configuration from the registry. I'm getting an error that the file axis2_blocking_client_proxy.xml can't be resolved when I deploy the carbon application that contains the mediation with my callout mediator.
The deployment works when I Quote a relative file path that points to the configuration file. Does anybody know if there is a way to tweak carbon application files so that distinct resources will be written to a dedicated directory on the WSO2 ESB Server?
Best regards,
Heiko
AFAIU, your requirement is to deploy an axis2 configuration file using a CAR (carbon application) file. This is not a recommended approach. If you need to deploy a configuration file in to the ESB, you can deploy that during the server creation time. CAR files are used to deploy the actual implementation code rather than the static configuration files.

How to create Class Mediator in wso2 esb /

I would like to create class mediator. I tried with ordinary java class i put into components/lib folder then i restart this system.
Can anyone tell me step by step procedure.
Write a class which implements org.apache.synapse.Mediator and override the mediate(MessageContext mc) method and create a jar file.
public class SimpleClassMediator implements Mediator {
private String varible1="10";
private String varible2="10";
public boolean mediate(MessageContext mc) {
//To test you can print something here
return true;
}
//getters and setters
}
Copy the jar to ESB_HOME/repository/components/lib and start the ESB.
Then in synapse config you can call this mediator as follow.
class name="packageName.ClassName"
You can create class mediator easily by extending the "AbstractMediator".
Mediator can be an OSGI build or jar file. Both can be deployed with WSO2 ESB. If You need to deploy the Jar file in to /repository/components/lib directory. If it is an OSGI bundle, it must be deployed in to /repository/components/dropins directory. If there are any external dependent libraries, you can put them it to /repository/components/lib directory
Update the synapse configure with the full qualified class name
You can find sample more detail from here. It contains a sample mediator code that you can look in to.
1. First create a Maven module e.g org.wso2.carbon.mediator and then create e.g ESBMessageMediator class which is extended from AbstractMediator.
2. Above maven module can be configured as OSGI budle or jar file.
3. Build the module using maven.
4. If it is OSGI bundle put it in to the /repository/components/dropins else put it to the
/repository/components/lib
5. configure synapse.xml file located in the "/repository/deployment/server/synapse-configs/default"
e.g <class name="org.wso2.carbon.mediator.ESBMessageMediator">
<property name="defaultPercentage" value="10"/>
</class>
6.Run the ESB and try to create a proxy service by adding the above meaditor as class mediator.if it load succesfully it is done.
you can read about class mediator in WSO2 in this site [1]
You can write the logic in the mediate() method :)

WSO2 ESB 4.5.0 fails to create proxy service from governance registry

I have WSO2 ESB and WSO2 GREG running with registry being mounted to ESB instance.
While trying to create Loging proxy service I picked up the WSDL from registry. The WSDL has a schema import which it depends on. However ESB fails to resolve the schema location trying to find it on the local FS.
Screen here
Logs here.
Can this be overcame? Or that's another bug for WSO2?
Thanks,
Vladimir.
Use exactly the same "SchemaLocation" attribute value used in your WSDL in the "SchemaLocation" attribute of the "resource" element of the "publishWSDL" option.
For example, if the WSDL has a the schema imported as,
<schema namespace="some_namespace" schemaLocation="./TestSchema.xsd">
Then the "schemaLocation" attribute of the "resource" tag should also have the same as mentioned below.
<resource schemaLocation="./TestSchema.xsd" ...>

Changing Wso2 HTTP Method from POST to GET

How can i chnage the HTTP Method in wso2 esb using java class mediator
currently I am using
mc.setDoingGET(false);
mc.setDoingPOX(true);
I want to take a post request to ESB and then send to a webservice via GET or vice versa
but the above code is not working at all
Use the property mediator with property name: HTTP_METHOD and http method name as the value (GET,POST etc) and scope as 'axis2'.
If you want to change this property in the java class level, you may do the following:
msgCtx.setProperty(Constants.Configuration.HTTP_METHOD, "GET");