Nav
You are viewing an older version of this section. Click here to navigate to the latest version.

Defining Connector Attributes

Like all Mule elements, connectors have attributes that can be assigned in the connector’s global configuration dialog.

Prerequisites

This document assumes you are familiar with the Anypoint Connector DevKit and you have already covered the connector’s authentication methods.

@Configurable Annotation

The connector’s attributes are defined using the @Configurable annotation, which provide for essential fields, at least from a user perspective. Since DevKit 3.7, all @Configurable parameters must be placed inside the "Config" class instead of the @Connector class, normally defined in a separate Java file. These attributes are user assigned in the connector’s global configuration dialog, if not set by default. In addition to the @Configurable annotation for each attribute, the attributes need public getters and setters.

Note: A connector may make use of any number of simple or complex @Configurable attributes you define when writing code for the connector.

XML configuration:


         
      
1
<barn:config name="Barn" key="myKey" doc:name="Barn"/>

configurable-screenshot

@Optional Annotation

As mentioned before, @Configurable attributes are mandatory. If we want to make them optional we need to mark them with the @Optional annotation.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
public abstract class AbstractAnalyticsConfig {

...
  /**
  * Hostname of the proxy. If this property is not set then no proxy is used, otherwise proxy is going to be used but host can not be empty.
  */
  @Configurable
  @Optional
  @Placement(group = "Proxy Settings")
  @FriendlyName(value = "Host")
  private String proxyHost;

  /**
  * Port of the proxy. If host is set then this property has to be set and can not be a negative number.
  */
  @Configurable
  @Optional
  @Default("3128")
  @Placement(group = "Proxy Settings")
  @FriendlyName(value = "Port")
  private Integer proxyPort;
}

XML configuration for a partially complete configuration with some sample proxy settings defined:


         
      
1
<sfdc-analytics:config name="Salesforce_Analytics_Cloud__Basic_authentication" username="" password="" securityToken="" metadataFileName="" proxyHost="127.3.4.12" proxyUsername="dearuser" proxyPassword="asdfaesfasf" doc:name="Salesforce Analytics Cloud: Basic authentication" proxyPort="3127"/>

If unchanged, the default port number does not show up in the configuration. If changed, for example, proxyPort="3127" (default port number is "3128") it shows in the XML configuration line. See above.

@Default Annotation

For optional attributes only, you can set a default value using the @Default annotation. This value is used if no value is assigned to the attribute.

For example:


         
      
1
2
3
4
5
6
7
public abstract class AbstractAnalyticsConfig {
    ...
    @Configurable
    @Default("0")
    @Placement(group = "Connection")
    private int connectionTimeout;
    }

Note: Whenever an attribute is marked as @Default, it’s implicitly @Optional as well.

Customizing Attributes Look and Feel

By default, Anypoint DevKit infers the names and labels for the Studio dialog boxes from methods, parameters, JavaDoc comments, and instance variable names in your Java files. However, you can also use annotations to customize many aspects of the look and feel of your component to improve the user experience.

The package org.mule.api.annotations.display defines the annotations that let you perform these customizations.

You can (and should) use several annotations that control how the attribute appears in the connector’s dialog in Studio and in your connector documentation.

@FriendlyName Annotation

Use this annotation on variables and method parameters to override the default inferred nickname for a @Configurable variable or a @Processor/@Source/@Transformer method parameter. Providing a parameter with this annotation is required.


         
      
1
2
3
4
@Connector(name="barn", schemaVersion="1.0", friendlyName="Barn", minMuleVersion="3.6")
public class BarnConnector
{
  ...

friendlyName-screenshot-1

@Password Annotation

Use this annotation to identify a field or method parameter as a password or, more generally, as a variable which contains data that should not be displayed as plain text.


         
      
1
2
3
4
5
6
7
8
9
    /**
     * Password used to authenticate against the proxy.
     */
    @Configurable
    @Optional
    @Password
    @Placement(group = "Proxy Settings")
    @FriendlyName(value = "Password")
    private String proxyPassword;

@Summary Annotation

Use this annotation on variables and method parameters to override the default inferred description for a @Configurable variable or a @Processor/@Source/@Transformer method parameter.


         
      
1
2
3
4
5
6
@Processor
@Summary("This processor puts an animal in the barn")
public String putInBarn(String animal)
{
   return animal + "has been placed in the barn";
}

@Icons Custom Palette and Flow Editor Icons

Use this annotation on the connector class to override the default location of one or more of the required icons. The path needs to be relative to /src/main/java.


         
      
1
2
3
4
5
@Icons(connectorLarge="barn-icon-large.png", connectorSmall="barn-icon-small.png")
@Connector(name="barn", schemaVersion="1.0", friendlyName="Barn", minMuleVersion="3.6")
public class BarnConnector
{
   ...

@Placement Field Order, Grouping, and Tabs

Use this annotation on variables and method parameters. It accepts the following parameters:

  • order — The relative order of the annotated element within its group. If the value provided is duplicated then the order of these elements is arbitrarily defined. Value is relative; an element with order 10 has higher precedence than an element with value 25.

  • group — A logical way to display one or more variables together. If you do not specify a group, then Mule assumes a default group. To place multiple elements in the same group, assign the same values to them for this attribute.

  • tab — A logical way to group annotated elements together. This attribute specifies the name of the tab in which to display the annotated element. If no tab is specified, then Mule assumes a default tab. To display multiple parameters in the same the tab, assign the same values to them for this attribute.


         
      
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
@Configurable
@Placement(group = "Basic Settings", order = 1)
@FriendlyName("Consumer Key")
private String consumerKey;

@Configurable
@Placement(tab="Advanced Settings", group = "General Information", order = 2)
@Summary("the application name")
@FriendlyName("Application Name")
private String applicationName;

@Configurable
@Placement(group = "Basic Settings", order = 3)
@FriendlyName("Consumer Secret")
@Summary("consumer secret for authentication")
private String consumerSecret;

placement-1-screenshot

placement-2-screenshot

See Also