This section walks you through the steps you need to follow when writing a connector.
...
Table of Contents | ||
---|---|---|
|
Anchor | ||||
---|---|---|---|---|
|
Create the Maven project template
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
- 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
0-DarchetypeVersion=
2.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/
- When prompted, enter a name for the connector. Specify the name in upper camel case, such as
HelloWorld
. Typey
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 directory | Contains any Java code for the connector. |
src/main/resources directory | Contains 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.xml | Defines 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.xml | Defines the connector name and dependent modules (i.e., the metadata of the connector). |
src/test directory | Contains 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.
Property | Description |
---|---|
component | Defines 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: |
package | The Java package from which connectors are implemented. |
dependency | Each dependency points to a component in the The |
icon | Relative path of the connector icon. |
Edit the component.xml
file
...
The properties of the component.xml
file are described below.
Property | Description |
---|---|
name | The name of the component. |
type | The 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.