Mule ESB
By Srilatha Kante
Java Component
• The Java component enables the developer to
package custom Java code that executes when
the component receives a message. The Java
component can be used to enhance the
functionality and capability of your web-based
applications written in Java.
Java Component
• To configure the Java component, selecting
a class is the only required entry.
• The class is simply a collection of properties,
attributes and methods the component applies to
all messages
• In addition, this component allows you to
optionally configure Singleton (object factory
that creates an object instance)
and Spring (object factory used to obtain Spring
bean instances) object factories, which are
invoked when a message is received
Example
Start..
• In the package explorer right click on your
project and select New > Class
• Name your class, and make the
package org.mule.transformers
• You can use the basic class as a skeleton to
construct a simple Java Component:
Java Class Sample
• package com.mypackage;
• public class JavaComponentDemo {
• public String greetMe(String name){
• return name;
• }
• }
Exception
• Check for the Exception related to Callable
interface
• Callable is an interface which is provided by
mule for using the Java Component in flows
• Callable needs an overridden method called
onCall()
Usage of Callable Interface
• package com.mypackage;
• import org.mule.api.MuleEventContext;
• import org.mule.api.lifecycle.Callable;
• public class JavaComponentDemo implements Callable{
• @Override
• public Object onCall(MuleEventContext eventContext) throws Exception
{
• return "Hello ";
• }
• }

Java component

  • 1.
  • 2.
    Java Component • TheJava component enables the developer to package custom Java code that executes when the component receives a message. The Java component can be used to enhance the functionality and capability of your web-based applications written in Java.
  • 3.
    Java Component • Toconfigure the Java component, selecting a class is the only required entry. • The class is simply a collection of properties, attributes and methods the component applies to all messages • In addition, this component allows you to optionally configure Singleton (object factory that creates an object instance) and Spring (object factory used to obtain Spring bean instances) object factories, which are invoked when a message is received
  • 4.
  • 5.
    Start.. • In thepackage explorer right click on your project and select New > Class • Name your class, and make the package org.mule.transformers • You can use the basic class as a skeleton to construct a simple Java Component:
  • 6.
    Java Class Sample •package com.mypackage; • public class JavaComponentDemo { • public String greetMe(String name){ • return name; • } • }
  • 7.
    Exception • Check forthe Exception related to Callable interface • Callable is an interface which is provided by mule for using the Java Component in flows • Callable needs an overridden method called onCall()
  • 8.
    Usage of CallableInterface • package com.mypackage; • import org.mule.api.MuleEventContext; • import org.mule.api.lifecycle.Callable; • public class JavaComponentDemo implements Callable{ • @Override • public Object onCall(MuleEventContext eventContext) throws Exception { • return "Hello "; • } • }