Contact Us 1-800-596-4880

Creating an Anypoint Connector Project

DevKit is compatible only with Studio 6 and Mule 3. To build Mule 4 connectors, see the Mule SDK documentation.

To build a custom Anypoint Connector for Studio, you can use the Anypoint Connector DevKit. In Anypoint Studio, you can add an extension module that enables you to use Anypoint Connector DevKit.

Prerequisites

The DevKit documentation assumes you have:

  • A working knowledge of Mule, Anypoint Studio, and Java development in general.

  • Explored the existing connectors.

  • Access to a sandbox environment for the target system or source, and documentation on the Web service it exposes.

  • A general familiarity with the Java language, specifically the use of Java annotations. DevKit’s functionality is exposed to connector developers through Java annotations that inject code into your connector classes. The injected code provides the interface between the connector and Mule that would otherwise require each connector developer to include extensive boilerplate code. This documentation explains each DevKit-specific annotation in the context of examples.

    To build connector projects, you must first install the Anypoint Connector DevKit Plugin into Anypoint Studio.

Building Connectors in Studio

The following sections describe several DevKit features that facilitate your work to develop and test your connector. Anypoint Studio offers you the following advantages for building connectors:

  • Wizards for creating and importing connectors

  • A specialized DevKit View to easily navigate your connector

  • Lots of templates that assist in the creation of your connector

  • Quick fixes and content assistance

  • Several predefined actions to assist you in the development.

  • Generate functional tests for your connectors with just 1 click

Creating a New Anypoint Connector Project

Note: To import an existing connector project, see Importing An Existing Connector Project.

  1. Click File > New, then select Anypoint Connector Project:

    new proj2

    Create an Anypoint Connector Project:

    createconnector36
    Field Entry

    Connector Name

    Define a unique name for your Anypoint Connector project.

    Project Name

    Connector project name.

    Namespace

    Connector project namespace.

    Location

    Connector project location.

    API:

    Type

    Select the way your connector can access a resource with the Type field:

    resttype

    Authentication

    Click an authentication choice for how your connector accesses its resource: Connection Management, OAuth V1, or OAuth V2.

    WSDL location: (Only appears if Type is SOAP) - See Notes below.

    From WSDL file or URL

    Type in a location, or click the browse (…​) button to locate the WSDL file on your computer. You can also type or paste a URL for the WSDL file’s location.

    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. Use from folder if your WSDL import schema files are also located in the folder. That way the DevKit plugin knows it has to move not only the WSDL but any other file located in the folder to create the distribution.

    DataSense:

    Add DataSense methods

    Provides methods to display metadata on the resource’s entities. For more information, see Adding DataSense.

    Add DataSense Query Method

    Adds method for the DataSense Query Language. For more information, see Adding DataSense Query Language.

    Notes on the WSDL-to-Connector feature:

    • As of Mule 3.5.2, the DevKit Plugin has been improved so that for SOAP projects, the connector populates from the content in the WSDL. After creating your new SOAP connector project, your connector is ready to install in Anypoint Studio. For more information on installing a completed connector, see Installing or Updating Your Connector in Anypoint Studio.

    • This feature works with any Mule version from 3.5.0 onward.

    • This feature doesn’t support RCP-encoded WSDLs.

    • If you update the WSDL, you need to regenerate the project to update the connector code. If different port types have the same methods, the generated code results in multiple methods with the same name. You would need to remove or rename the methods to resolve conflicts.

  2. Click Next, then enter values in the fields of the final screen of the wizard according to table below. The default values might apply without needing any changes.

    Field Description

    Maven Settings

    Click Manually set values, if needed, to change the Maven Group ID, Artifact ID, or the version of the connector.

    GitHub Settings

    Click Add GitHub information, if needed, to link your project to a new or existing GitHub repository.

  3. Click Finish. This generates a project containing the structure with all the required elements such as images, sample docs, and some basic tests for your connector. Refer to the DevKit documentation to build upon this initial, basic structure in Installing and Testing Your Connector in Studio.

    screen05

Importing An Existing Connector Project

To import an existing connector project, click File > Import > Anypoint Studio > Anypoint Connector Project from External Location, choose a URL or a .zip file, and complete the wizard to locate and import the project.

See also: "Creating a Compressed Project File" in Packaging Your Connector for Release.

Viewing the Connector Structure

This Anypoint Connector DevKit module includes an Eclipse perspective that displays all of the DevKit classes, properties, methods, processors, and configurable fields from all your connectors inside the selected project.

To configure DevKit View:

  1. Click the Add View icon in the upper right of the screen and click Other.

    viewbutton
  2. Click Devkit and OK to open the DevKit Perspective.

    devkitview
  3. Click any item in the Devkit perspective to display the code which defines it, for example:

    devkitperspective

The DevKit view lets you:

  • Double-click a Configurable field or a method to easily navigate to the line of code where it is defined.

  • Check the name with which your operation is exposed in the XML.

  • Double-click an XSD name to see examples in the sample doc file.

  • Filter to find elements in your connector.

Using Auto-Completion

When editing your connector’s main Java file, the auto-complete function provides a scaffold structure for several common methods that you may want to add. These structures come with rudimentary Javadoc documentation, which you should populate so that your project passes build tests successfully and your connector’s users can access reference material about your connector.

With your cursor on the @Connector class or any other @ annotation, type Ctrl + spacebar to view a list of suggested entries:

connectorhelpinfo

For more information on @Connector and other Anypoint Connector DevKit annotations, see the Annotation Reference.

Using Templates

Templates are customizable pieces of code that you can add to your connector, and which provide a basic structure for elements you commonly use. Type the name or part of it and press [Command | Ctrl] + space to insert the template into the current Connector Class.

screen23

Available DevKit templates:

Template Description

configurable

Add a configurable field.

datasense

Add a DataSense operation.

processor

Add a processor to your connector. There are several options with different templates.

transformer

Add a transformer method. Transformers convert one input to another.

restconfig

Add a configurable element to a REST-based connector, such as URI params, query params, or header params.

restprocessor

Add a @RestCall processor. Note: REST-based connectors insert the @RestCall parameter when you create an Anypoint Connector Project.

Installing or Updating Your Connector in Anypoint Studio

After coding your connector, you can install it in Anypoint Studio and give it a test drive. Once installed, you can use your connector in a Mule Project and verify that it works as you intended.

Copy Your Connector to Anypoint Studio

  1. In the package explorer of Anypoint Studio, right-click your project root.

  2. Select Anypoint Connector > Install or Update:

    installorupdate
  3. At Check the items you wish to install, click Next.

  4. At Review the items to be installed, click Next.

  5. At Review Licenses, click I accept the terms of the license agreement, and click Finish.

  6. Restart Anypoint Studio.

Test Drive Your Connector

  1. To try your connector, create a new project by clicking New > Mule Project.

  2. Add an HTTP connector to the canvas.

  3. Search for your connector by name and add it to the flow.

    For example:

    36connectorflow

More DevKit Actions

The plugin also provides actions in the tool bar:

The same actions can be accessed by right-clicking your project in the package explorer:

screen21

Actions that are enabled when selecting the root of a DevKit project:

Task Description

Generate Tests

Generates Functional tests cases for your connector processors.

Install Or Update

Installs or updates the connector in Anypoint Studio and in your local repository.

Preview Documentation

Generates Javadoc for your connector, making use of the samples included in the sample doc file.

Generate Sources

Generate the sources, schemas, editors and everything required to integrate with Mule and Anypoint Studio. This can be useful if you want to debug the behavior of your connector in a Mule app.

Enable | Disable Javadoc check

Before releasing a connector, check that your Javadocs are in order. By enabling this flag, when attempting to build, you see all the processors that are missing Javadoc comments or samples.

Using Your Connector

You can copy your connector into Anypoint Studio by clicking Install or Update. To easily find it in the palette, type the name in the search box:

screen18

Previewing Documentation

When you build a connector, DevKit automatically creates an HTML file that serves as a user-friendly reference for the Javadoc annotations that you have added within your code. You can preview the contents of this file without having to build the entire project. This is equivalent to running the following command from a terminal in the project folder:

mvn clean package -DskipTests javadoc:javadoc

Generating Sources

You can instruct DevKit to build your connector and generate both a .zip file and a .jar file in your project’s /target folder. Use these files to test, or use the connector in your instance of Studio or another separate instance of Studio. To generate the sources, right-click your project in the Package Explorer, then select Anypoint Connector > Generate Sources. This is equivalent to running the following command from the command console from within the project folder:

mvn clean package -DskipTests -Ddevkit.studio.package.skip=true -Ddevkit.javadoc.check.skip=true -Dmaven.javadoc.skip=true

Disabling the Javadoc Check

DevKit enforces the requirement that you provide Javadoc documentation for every callable method in your connector. For the sake of testing a work-in-progress project, however, you may want to disable the Javadoc Check to postpone documentation until the project is complete and ready for testing.

mvn clean package -Ddevkit.javadoc.check.skip=true

Adding Samples

To navigate to a sample, click a sample link while holding the command key pressed (Ctrl key in Windows). If a sample exists, the sample editor opens the processor’s sample.

If you enable the Javadoc check, quickfix helps you add the missing samples, which you can trigger by typing Ctrl + space.

screen24

This is what a sample looks like, which is an XML file. There are a few simple templates you can use within them:

screen25

Understanding the Generated Connector

Your Connector basically consists of a set of operations and configurable elements users populate in order to consume the API your connector was developed for.

Configurables

A configurable field in your connector looks like this in the DevKit view:

screen11 1

Users can configure its fields in Studio when adding a configuration global element for the connector.

After you install your connector by right-clicking the connector and clicking Anypoint Connector > Install or Update, completing the prompts, and restarting Studio, users can create Mule Projects and use your connector. The steps that follow describe how a user can configure your connector per the Configurable section of your connector.

To configure:

  1. Drag an instance of your connector to the canvas

  2. Double-click the connector to open its properties editor

  3. Click the green plus sign next to the Connector Configuration field:

  4. Set a value for the field. The default value you configure in the connector is presented as the initial value in the connector’s configuration field My Property:

    devkitproperty

Processors

When users configure a Mule Project created from a connector, the Operation field options correspond to the @Processor code in the connector. In the top view of the illustration, the Demo connector has as its Operation, My Processor. The lower part of the illustration shows the processor values in the connector.

myprocessor

In this example, a single string was configured as an input in the method for this processor, it displays as an input field once the operation is selected:

content

Importing an Existing Connector

You can import a connector project, stored in a .zip file or an existing directory.

Use the File > Import menu:

import

Adding Native Libraries and JARs to a Connector Build

When building connectors with dependencies that cannot be bundled within the same JAR, you can instruct Anypoint Studio to prompt users to add the files to your connector.

To add native libraries and JAR files to a build:

  1. Add a file to trigger this feature. The connector must have one file per configuration at this path:

    <_root_connector_folder_>src/main/resources/META-INF/<_connector_name_>-<_configElementNam_e>*-required-libs.xml

  2. Ensure that the *-required-libs.xml file contains namespace, require, and jar tags.

    <namespace xmlns="http://www.mulesoft.org/schema/mule/tooling.attributes" xmlns:mule="http://www.mulesoft.org/schema/mule/core">
        <require>
           <jar name="PeopleSoft Java Object Adapter (psjoa-1.0.jar)"
    fileName="psjoa(.*)\.jar" targetFolder="/lib/peoplesoft"
    targetRuntimeFolder="/plugins" className="psft.pt8.joa.IPSMessage"/>
        </require>
    </namespace>

    For example, in the PeopleSoft connector, the jar element contains these attributes:

    • name: The JAR name to display in the Anypoint Studio prompt.

    • fileName: Filter to apply to the selected JAR to verify that it’s the required one. This matches the actual file name of the JAR.

    • targetFolder: Folder in the project where to copy the JAR.

    • targetRuntimeFolder: Folder to put the runtime.

    • className: Filter to apply to the JAR to verify that it’s the required one. This looks for the declared class inside the selected JAR. The class name must be the full-qualified name of the class.

  3. Specifying a required libraries XML file causes Anypoint Studio to modify your configuration description so that Studio displays an option for installing libraries:

    36reqddeps

Note: If a library is not required for a particular configuration, do not create a required-libs.xml file for that configuration.

See Also