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 :)
Related
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?
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.
I'm using a contract first approach to build JAX-WS Webservices. The clients pick the wsdl and xsd resources from a client jar as specified in this SO answer - https://stackoverflow.com/a/18323853/775467 by using the wsdlLocation attribute.
Is it possible to do the same on the server side. i.e is it possible to use wsdls and referred xsds from a jar in sun-jaxws.xml
<endpoint name='TestService'
implementation='provider.server.AddNumbersImpl'
wsdl='WEB-INF/wsdl/Test.wsdl'
service='{http://example.org}TestService'
port='{http://example.org}TestServicePort'
url-pattern='/test'/>
I know that I can refer to wsdls in the WEB-INF directory as in the above snippet but I don't want to package the wsdls and xsds into the WAR but would like to pick them up from a shared library jar deployed to the server in the same way how the client code picks the wsdl.
There's no possibility to change the location of the wsdl file. The wsdl attribute at sun-jaxws.xml must have the prefix "WEB-INF/wsdl". Else JAX-WS generates and publishes a new WSDL. If you take a look at the source code of jaxws-ri, you can find the implementation at the class com.sun.xml.ws.transport.http.DeploymentDescriptorParser, method getPrimaryWSDL:
...
if (wsdlFile != null) {
if (!wsdlFile.startsWith(JAXWS_WSDL_DD_DIR)) {
logger.log(Level.WARNING, "Ignoring wrong wsdl={0}. It should start with {1}. Going to generate and publish a new WSDL.", new Object[]{wsdlFile, JAXWS_WSDL_DD_DIR});
return null;
}
...
}
My application should show a list of stuff over RESTful WebServices.
This list of stuff is generated via an EJB which is deployed in JBoss AS 6 in a .jar.
My question is, how do I get this list of stuff in order to show it via Web Services?
If I try to inject #EJB in the stateless bean annotated with #WebService, and try to invoke the method that generates the list, I get an error saying that #EJB cannot be resolved (or imported). (fixed it, needed to modify maven dependencies).
Now I get a NullPointerException when I call the supposedly injected EJB...
I am using the webapp archetype from Maven, which contains an EAR, a JAR and a WAR.
I am at a total loss here, been trying to figure this for almost a week.
Thanks in advance!
--EDIT-- code and typo fixed
This is my stateless bean which SHOULD be exposed as a WebService (according to:
http://www.adam-bien.com/roller/abien/entry/restful_calculator_with_javascript_and )
#Stateless
#Path("/MyRESTApplication")
public class HelloWorldResource {
#EJB
private TestBean testBean;
#GET()
#Produces("text/plain")
public String sayHello(String name) {
return testBean.doMoreStuff();
}
}
the doMoreStuff() function simply returns "HELLO!".
I have created a pojo as below.
package demo;
public class HelloWorld {
public String sayHello(String name) {
return "Hello " + name;
}
}
I placed it in axis2 war and opened
http://localhost:8080/axis2/services/listServices.
Axis 2 is indicating it as faulty service
Faulty Services
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\demo\HelloWorld.class
But when I remove package declaration statement and place it on below location, everything works fine
<TOMCAT-DIR>\webapps\axis2\WEB-INF\pojo\HelloWorld.class
Now there are two possibilities
Package declaration is not allowed in pojo (and I don't believe this).
I am missing something.
Can anyone guide me?
In the book "Apache Axis Web Services, 2nd Edition", author described that when exposing a pojo class as a web service by dropping in into pojo folder, pojo class must be defined in default package.
When pojo class is defined some package, following link is helpful.
http://axis.apache.org/axis2/java/core/docs/pojoguide.html
Thanks to shashankaholic for sharing this link.