Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

This section walks you through the steps you need to follow when writing a connector.

...

Table of Contents
maxLevel3

Anchor
basic
basic

Create the Maven project template

  1. To use the maven archetype to generate the Maven project template and sample connector code, run the following command in the directory where you want to create the connector on your local machine:

    Code Block
    mvn org.apache.maven.plugins:maven-archetype-plugin:2.4:generate -DarchetypeGroupId=org.wso2.carbon.extension.archetype -DarchetypeArtifactId=org.wso2.carbon.extension.esb.connector-archetype -DarchetypeVersion=2.0.4 -DgroupId=org.wso2.carbon.esb.connector -DartifactId=org.wso2.carbon.esb.connector.helloworld -Dversion=1.0.0 -DarchetypeRepository=http://maven.wso2.org/nexus/content/repositories/wso2-public/

    Above is tested with Apache Maven 3.0.5.

...

Create the Maven project template

  1. To use the maven archetype to generate the Maven project template and sample connector code, run
    Note

    If maven version is 2.x.x, use the following command in the directory where you want to create the connector on your local machine:

    code

    mvn

    archetype:generate

    -DarchetypeGroupId=org.wso2.carbon.extension.archetype

    -DarchetypeArtifactId=org.wso2.carbon.extension.esb.connector-archetype

    -DarchetypeVersion=2.0.

    0

    4 -DgroupId=org.wso2.carbon.esb.connector

    -DartifactId=org.wso2.carbon.connector.helloworld

    -Dversion=1.0.0

     -DarchetypeRepository=http://maven.wso2.org/nexus/content/repositories/wso2-public/

  2. When prompted, enter a name for the connector. Specify the name in upper camel case, such as HelloWorld. Type y to confirm.

...

The directory structure includes the following files and directories.

pom.xml
Contains the required dependencies for the connector core libraries, relevant Synapse libraries, and Maven repositories for a specific connector.
assembly
Contains files that are used at the connector build time. You do not need to modify these files.
src/main/java directoryContains any Java code for the connector.
src/main/resources directoryContains the configurations and definitions for the connector and its methods (referred to as operations). The config directory defines the initialization of the connector. You add additional directories for each category of operations (component) you want to create. In the Hello World sample, there is just one additional directory, sample, where the single operation for this sample connector is defined. However, in the ActiveCollab connector, for example, there are several component subdirectories such as activecollab-people and activecollab-projects, which contain the operations relevant to working with people and projects, respectively.
component.xml Defines the metadata for the operations in each component. You create a component.xml file in each subdirectory under src/main/resources.
sample-template.xmlDefines an operation. This is the actual API operation calling configuration including the Synapse template of the sequence. It contains the steps necessary to call the API that is exposed by the third party. For example, the ActiveCollab connector has createClient.xml and listCompanies.xml in the activecollab-people directory to define those two operations for working with people. Each operation of the API can be written in a manner similar to init.xml . If there is any Java code, the code should be included under src/main/java (e.g., the HelloWorldConnector.java file), and the relevant dependencies should be added to pom.xml.
init.xml Appears in the config directory under src/main/resources. This is mandatory for every connector and is used to initialize the connector environment. For example, if writing a Salesforce connector, include the login call here, and store the session token and API URL that are returned in the response as properties to use with other operations. For this sample, you do not need to change the file.
connector.xmlDefines the connector name and dependent modules (i.e., the metadata of the connector).
src/test directoryContains integration tests. This is required for integration tests for Java-based connectors. For more information, Perform integration tests below.

After creating the Maven project template, import it to an IDE, and edit the following files.

...

The properties of the above connector.xml file are described below.

PropertyDescription
componentDefines the name of the connector, the package, and the components inside the resources directory that you want the connector to expose.
name

A name for the connector. This connector name should be unique, as the connector methods will refer to the connector using this name as shown in the following example:
<twitter.getSearchTweets>...</twitter.getSearchTweets>

packageThe Java package from which connectors are implemented.
dependency

Each dependency points to a component in the resources directory. It will be used to load all operations implemented in that component into the ESB.

The component property specifies the name of the component. For example, "twitter-search" is the resource name of the following dependency:
<dependency component="twitter-search"/>

iconRelative path of the connector icon.

Edit the component.xml file

...

The properties of the component.xml file are described below.

PropertyDescription
name

The name of the component.

typeThe type of the Synapse component. These resources are Synapse templates, so the type is specified as synapse/template.
subComponents

Defines the operations in the component.

file

The name of the operation file with the extension.

description

A brief description about the functionality of the operation.

Edit the sample Synapse template (sample-template.xml file)

...

For detailed information on working with connectors via the the ESB Management Console, see Working with Connectors via the Management Console.