Anypoint Connectors enables easy integration of MuleSoft applications with third-party APIs and standard integration protocols. They are used within application's flow to send and receive data via a protocol or specific API. Few basic connectors are already bundled with Anypoint Studio, and apart from these a large library of additional connectors are available for download from MuleSoft Connectors Library site. Most of the Connectors are available by default at no cost and few premium connectors are licensed. Anypoint Connector DevKit provided by MuleSoft enables to create custom connectors.
Advantages of custom connectors
- Could be reused at all integration points to that system
- Hides integration complexity
- Could connect to any API or protocol
A typical custom connector development life-cycle follows below procedure:
- Setting up a Connector Project
- Writing Connector Code
- Writing Connector Tests
- Documenting a Connector Project
- Packaging a Connector
Setting Up a Connector Project
Pre-requisites – The following components have to be installed and should be working in local environment:
- Java Development Kit (JDK) version 6 or 7 required to compile and build the Java code
- Anypoint Studio as the IDE so as to build and test the connector
- Maven as a plugin to Anypoint Studio to manage the build
- Anypoint Connector DevKit plugin in the Anypoint studio from http://studio.mulesoft.org/r3/addons/beta
Writing Connector Code
1. Click on File -> New , then select Anypoint Connector project
2. Define the attributes as needed:
- Connector Name: Define a unique name for the Anypoint Connector project.
- Run time: Select the compatible Mule runtime for the connector. This information in the page applies to all Mule versions from 3.5.0 and later
- Type: Select the way connector can access a resource with the Type field:
GENERIC (Java): For Creating a Connector using a Java Client Library
REST: For Implementing a REST Connector
SOAP: For implementing SOAP Connector and specify WSDL location
- Authentication: Choose an authentication of how the connector accesses its resource: Basic, OAuth V1, or OAuth V2 or any as per requirement.
- WSDL location: (Only appears if Type is SOAP)
- From WSDL file or URL: Type in a location or click the browse (...) button to locate the WSDL file on computer. A URL for the WSDL file's location can be typed or even pasted
- From folder: Type in a location or click the browse (...) button to locate a folder containing the WSDL file.
(Note: The first WSDL file in the folder is used)
Add DataSense methods: Provides methods to display metadata on the resource's entities
Add DataSense Query Method: The method for DataSense Query Language is added.
3. A default connector class will be generated after which the below annotations need to be configured.
- @Connector --- For defining the connector details like name schema version
- @Connect -- For providing the authentication using username and password
- @Configurable –To define the properties that are required to connect to the Connector
- @ValidateConnection --- To check the connection status
- @Disconnect –For closing the connection
- @Processor – Actual operation is being defined here
- @RestCall –In case of connecting to rest implemented services using the attributes uri,method
The below screenshot shows a sample connector which will append “Hello” to the content . The required functionality can be defined for connecting to data base and also to any external API's, ERP Systems etc..
4. Now the connector is ready with the functionality defined. Write the test cases for the connector.
Writing Connector Tests1. Right click on the project in package explorer and click Anypoint Connector > Generate Tests
2. Next, click on the methods that is required to generate the tests and this can be changed as per requirement Writing the test cases are optional .
Documenting a Connector Project
Mule builds on Javadoc to automate and simplify the creation of technical reference documentation for the connector, adding a custom Javadoc doclet and some DevKit-specific Java annotations. This document describes on how the documentation can be generated and what needs to be included.
Packaging Your Connector for Release
When the connector is ready for release to a broad audience, some additional steps are necessary to be followed so as to ensure user success:
Create a license agreement for the connector.
Develop end-to-end walkthroughs to illustrate performing common use cases with the connector
1. Now, the connector can be built by going to the command line and run the following command:
$ cd custom-connector
$ mvn package -Ddevkit.studio.package.skip=false
2. Now, the project from Anypoint studio needs to be imported and then the connector from Mule studio
- Go to the Help Menu and select Install Software
- Click the Add button to add an update site
Enter a name of "Custom Connector" which is created, enter the full path to your connector, prefixed by "file:/", and click OK. (see below)
- Select the connector from the update site
- Follow the steps to accept the license and restart Mule Studio
3. Type the connector name in the search box.
4. Drag and drop the connector ,add the required parameters .Select the desired operation as required.
If you would like to find out more about how Systems Integration could help you make the most out of your current infrastructure while enabling you to open your digital horizons, do give us a call at +44 (0)203 475 7980 or email us at firstname.lastname@example.org.
Other useful links: