Difference between revisions of "Develop Generic VCL Call"

From GreenVulcano Wiki
Jump to: navigation, search
Line 14: Line 14:
 
The simplest mode is to define a User Libaries set, named "GVESB", as show in the image.
 
The simplest mode is to define a User Libaries set, named "GVESB", as show in the image.
  
[[File:GVESBUserLibraries.png|border|800px]]
+
[[File:GVESBUserLibraries.png|800px]]
  
 
The create an Eclipse Java project (ex.<code>GenericVCLCall</code>) and add the GVESB User Libraries set to the project's classpath.
 
The create an Eclipse Java project (ex.<code>GenericVCLCall</code>) and add the GVESB User Libraries set to the project's classpath.
  
[[File:SetGVESBUserLibraries.png|border|800px]]
+
[[File:SetGVESBUserLibraries.png|800px]]
  
 
==Generic VCL Call life cycle==
 
==Generic VCL Call life cycle==
Line 31: Line 31:
 
In the Eclipse project create a class with the parameters as illustrated in the image:
 
In the Eclipse project create a class with the parameters as illustrated in the image:
  
[[File:SampleGenericVCLClass.png|border|400px]]
+
[[File:SampleGenericVCLClass.png|400px]]
  
 
The example plug-in is a simple class that perform a toupper|tolowe|echo operation on a String input or optionally to cancel the input data.
 
The example plug-in is a simple class that perform a toupper|tolowe|echo operation on a String input or optionally to cancel the input data.
Line 75: Line 75:
  
  
===Plug-in initialization===
+
===Plug-in initialization code===
 
To read the plug-in's configuration parameters must be used the [[XMLConfig]] utility class.
 
To read the plug-in's configuration parameters must be used the [[XMLConfig]] utility class.
  
Line 122: Line 122:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
 +
 +
===Plug-in execution code===
 
The following code illustrate the plug-in logic execution:
 
The following code illustrate the plug-in logic execution:
 
<syntaxhighlight lang="java5">
 
<syntaxhighlight lang="java5">
Line 183: Line 185:
 
     }
 
     }
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
 +
 +
===Plug-in deployment===
 +
Export the Eclipse project as a jar file:
 +
 +
[[File:ExportProjectAsJar.png|400px]]
 +
 +
Generate the jar in GV_HOME/application/deploy/gvesb-javaee5-*.ear/lib, named, as example, test-vclcall.jar:
 +
 +
[[File:ExportSampleGenericVCLProjectAsJar.png|400px]]
 +
 +
 +
===Plug-in configuration===
 +
In a {{L_VULCON}} project insert a new generic-call operation and the required parameters:
 +
 +
[[File:CfgSampleGenericVCLCall.png|800px]]
 +
 +
{|class="gvtable"
 +
! Attribute !! Value
 +
|-
 +
| class || it.greenvulcano.gvesb.virtual.test.TestGenericCall
 +
|-
 +
| name || test-call
 +
|}
 +
 +
Its two call-parameter sub-elements are:
 +
{|class="gvtable"
 +
! Name !! Value
 +
|-
 +
| operation || <nowiki>toupper|tolower|echo</nowiki>
 +
|-
 +
| cancelData || <nowiki>true|false</nowiki>
 +
|}
 +
 +
Create a simple service named <code>TestGenericCall</code> (ex. through the [[VulCon first flow|Vulcon's Wizard New Service]]) that use the configured test-call operation:
 +
 +
[[File:SampleGenericVCLCallService.png|800px]]
 +
 +
then start {{GVESB}} server and deploy the service using the {{L_GVCONSOLE}}.
 +
Reload the GVCore.xml configuration file and invoke the deployed service <code>TestGenericCall</code> setting as input a lower-case string:

Revision as of 14:28, 16 December 2012

Description

A VCL Generic Call is a facility to enable the use of custom Java libraries in GreenVulcano® ESB. The plug-in must implement the CallOperation interface and can be configured in GV Console® or VulCon® through a simple configuration interface.

Configure the Eclipse workspace

To develop the plug-in is needed to reference some GreenVulcano® ESB libraries: in GV_HOME/application/deploy/gvesb-javaee5-*.ear/lib

  • gvbase-*.jar
  • gvcore-*.jar
  • gvvcl-*.jar

in JBOSS_HOME/commons/lib

  • log4j.jar

The simplest mode is to define a User Libaries set, named "GVESB", as show in the image.

GVESBUserLibraries.png

The create an Eclipse Java project (ex.GenericVCLCall) and add the GVESB User Libraries set to the project's classpath.

SetGVESBUserLibraries.png

Generic VCL Call life cycle

A Generic VCL Call life cycle is the same as every VCL plug-in:

  • VCL plug-in instances are pooled
  • the init method is called at instance creation time
  • the perform method is called at every service invocation
  • the cleanUp method is called after every perform invocation
  • the destroy method is called at instance destruction time

Create a Generic VCL Call class

In the Eclipse project create a class with the parameters as illustrated in the image:

SampleGenericVCLClass.png

The example plug-in is a simple class that perform a toupper|tolowe|echo operation on a String input or optionally to cancel the input data.

Basic development guidelines

Following some guidelines useful to develop a GreenVulcano® ESB VCL plug-in.

Package name

Using a package name that starts with it.greenvulcano.gvesb.virtual. automatically enable the logging in the GVVCL log file.

Logging

To enable the logging in GreenVulcano® ESB plug-in import the following class anche defines the logger instance as illustraded:

import it.greenvulcano.log.GVLogger;

import org.apache.log4j.Logger;

public class TestGenericCall implements CallOperation {
    private static final Logger logger    = GVLogger.getLogger(TestGenericCall.class);

The GVLogger class enable the logger reconfiguration at runtime.

VCL internal methods

Some methods defined by the CallOperation interface must be coded in a standard mode, as indicated in the following code:

    protected OperationKey      key       = null;
    ....

    public OperationKey getKey() {
        return key;
    }

    public void setKey(OperationKey key) {
        this.key = key;
    }

    public String getServiceAlias(GVBuffer gvBuffer) {
        return gvBuffer.getService();
    }

The indicated methods are used internally by the VCL framework.


Plug-in initialization code

To read the plug-in's configuration parameters must be used the XMLConfig utility class.

For the Generic VCL Call the XML node describing the configuration parameters is the following:

    <generic-call class="it.greenvulcano.gvesb.virtual.test.TestGenericCall"
                  name="test-call" type="call">
        <call-parameter name="operation"  value="toupper" type="param"/>
        <!-- optional -->
        <call-parameter name="cancelData" value="false"   type="param"/>
    </generic-call>

The following code illustrate the plug-in initialization:

    private String              operation  = null;
    private boolean             cancelData = false; 
    ....

    public void init(Node cfg) throws InitializationException {
        try {
            // reads the 'operation' configuration parameter as String
            operation = XMLConfig.get(cfg, "call-parameter[@name='operation']/@value");
            // reads the 'cancelData' configuration parameter as boolean, setting 'false' as default value
            cancelData = XMLConfig.getBoolean(cfg, "call-parameter[@name='cancelData']/@value", false);

            // check the 'operation' parameter value
            if ((operation == null) || !(operation.equals("toupper") || operation.equals("tolower") || operation.equals("echo"))) {
                logger.error("Invalid 'operation' value:" + operation);
                throw new InitializationException("GVVCL_XML_CONFIG_ERROR", new String[][]{{"exc", "Invalid 'operation' value:" + operation},
                        {"key", key.toString()}});
            }

            logger.debug("Initialized TestGenericCall: operation[" + operation + "] cancelData["
                         + cancelData + "]");
        }
        catch (InitializationException exc) {
            throw exc;
        }
        catch (Exception exc) {
            logger.error("An error occurred reading configuration data.", exc);
            throw new InitializationException("GVVCL_XML_CONFIG_ERROR", new String[][]{{"exc", exc.toString()},
                    {"key", key.toString()}}, exc);
        }
    }


Plug-in execution code

The following code illustrate the plug-in logic execution:

    public GVBuffer perform(GVBuffer gvBuffer) throws ConnectionException, CallException, InvalidDataException {
        try {
            String input = getInputString(gvBuffer);

            logger.debug("TestGenericCall input: " + input);
            String output = null;
            if (!cancelData) {
                if (operation.equals("toupper")) {
                    output = input.toUpperCase();
                }
                else if (operation.equals("tolower")) {
                    output = input.toLowerCase();
                }
                else {
                    output = input;
                }
            }
            logger.debug("TestGenericCall output: " + output);

            gvBuffer.setObject(output);
            return gvBuffer;
        }
        catch (Exception exc) {
            throw new CallException("GVVCL_CALL_SERVICE_ERROR", new String[][]{{"service", gvBuffer.getService()},
                    {"system", gvBuffer.getSystem()}, {"id", gvBuffer.getId().toString()},
                    {"message", exc.getMessage()}}, exc);
        }
    }

    private String getInputString(GVBuffer gvBuffer) throws Exception
    {
        String str = null;
        Object currentObject = gvBuffer.getObject();
        if (currentObject instanceof String) {
            str = (String) currentObject;
        }
        else if (currentObject instanceof byte[]) {
            str = new String((byte[]) currentObject);
        }
        else {
            str = currentObject.toString();
        }
        return str;
    }

The following code illustrate the plug-in clean-up, executed after every logic execution, in this case the code don't perform anything:

    public void cleanUp() {
        // do nothing
    }

The following code illustrate the plug-in destroy, in this case the code don't perform anything:

    public void destroy() {
        // do nothing
    }


Plug-in deployment

Export the Eclipse project as a jar file:

ExportProjectAsJar.png

Generate the jar in GV_HOME/application/deploy/gvesb-javaee5-*.ear/lib, named, as example, test-vclcall.jar:

ExportSampleGenericVCLProjectAsJar.png


Plug-in configuration

In a VulCon® project insert a new generic-call operation and the required parameters:

CfgSampleGenericVCLCall.png

Attribute Value
class it.greenvulcano.gvesb.virtual.test.TestGenericCall
name test-call

Its two call-parameter sub-elements are:

Name Value
operation toupper|tolower|echo
cancelData true|false

Create a simple service named TestGenericCall (ex. through the Vulcon's Wizard New Service) that use the configured test-call operation:

SampleGenericVCLCallService.png

then start GreenVulcano® ESB server and deploy the service using the GV Console®. Reload the GVCore.xml configuration file and invoke the deployed service TestGenericCall setting as input a lower-case string: