Back Home

Maven Archtypes

Cloud Connector archtype

 mvn archetype:generate -DarchetypeGroupId=org.mule.tools.devkit 
-DarchetypeArtifactId=mule-devkit-archetype-cloud-connector -DarchetypeVersion=3.3.1 -DgroupId=org.hello 
-DartifactId=hello-connector -Dversion=1.0-SNAPSHOT -DmuleVersion=3.3.0 -DmuleConnectorName=Hello 
-Dpackage=org.hello -DarchetypeRepository=http://repository.mulesoft.org/releases

Replace “hello” with the name of your mule connector application.

 mvn package -Ddevkit.studio.package.skip=false

or the following groovy script does the replacement

#!/usr/bin/env groovy
println "generating cloud connector script"
 
if ( args.length < 1) {
  println "usage: genConnectorArch connector-name"
  return
}
def project = args[0]
 
def cmd = """mvn archetype:generate -DarchetypeGroupId=org.mule.tools.devkit 
-DarchetypeArtifactId=mule-devkit-archetype-cloud-connector -DarchetypeVersion=3.3.1 -DgroupId=org.ricston 
-DartifactId=$project-connector -Dversion=1.0-SNAPSHOT -DmuleVersion=3.3.0 -DmuleConnectorName=$project
-Dpackage=org.ricston -DarchetypeRepository=http://repository.mulesoft.org/releases"""
 
println cmd

Mule Module Archtype

 mvn archetype:generate -DarchetypeGroupId=org.mule.tools.devkit -DarchetypeArtifactId=mule-devkit-archetype-generic -DarchetypeVersion=3.3.2 -DarchetypeRepository=http://repository.mulesoft.org/releases/ -DgroupId=com.mycompany -DartifactId=cool-module -Dversion=1.0-SNAPSHOT -DmuleVersion=3.3.1 -DmuleModuleName=SolrExtension -Dpackage=fastnet.solrExtension -DarchetypeRepository=http://repository.mulesoft.org/releases 

The default code generated does not appear to compile out of the box, a recent component I updated to 3.4 and ensured the annotations existed and it then compiled ( default test classes had a similar problems)

Building the Mule Connector Package

The key bit is package

mvn clean install -Ddevkit.javadoc.check.skip

To build an Update.zip

mvn clean package  -Ddevkit.javadoc.check.skip

To have the sample file required for a clean build:

<!-- BEGIN_INCLUDE(ssh:send) -->
    <ssh:send content="ls" />    
<!-- END_INCLUDE(ssh:send) -->
<!-- BEGIN_INCLUDE(ssh:close) -->
    <ssh:close />    
<!-- END_INCLUDE(ssh:close) -->

Component Annotations

  • Class Level
    • @Connector, to mark a class as a Connector
      @Connector(name = "ldap", schemaVersion = "3.3", friendlyName="LDAP", minMuleVersion="3.2.0", 
      description="LDAP Connector that allows you to connect to any LDAP server and perform every LDAP operation")

Method Level:

  • @Configurable, to involve a field in configuration
    • This will appear as a <config/> element in the schemea
    • In Studio it will appear as an item in the visual dialog. The field can be:
      • @Optional
      • The field may have a @Default value when the user doesn't supply a value.
      • A @FriendlyName
      • A @Placement Annotations can also help Studio decide how to label the field and where to group the same in the configuration dialog.
        • group parameter ??
 @Configurable
    @Placement(group = "Connection", order = 0)
    @FriendlyName("URL")
    private String url;

Source

@Source indicates an endpoint that can receive messages e.g

 @Source
    @InvalidateConnectionOn(exception = AmazonClientException.class)
    public void receiveMessages(SourceCallback callback, 
                                @Optional @Default("30") Integer visibilityTimeout, 
                                @Optional @Default("false") Boolean preserveMessages,
                                @Optional @Default("1000") Long pollPeriod,
                                @Optional @Default("1") Integer numberOfMessages)
            throws AmazonServiceException {

This will invoke the process that it lives ..

See the SQS amazon msg queue as an example https://github.com/mulesoft/sqs-connector/blob/master/src/main/java/org/mule/modules/sqs/SQSConnector.java

Processor

Processors process messages:

  • A drop down of processor operations will appear if a class has multiple processors
@Processor
public void addFromMap(@Optional @FriendlyName("DN") String dn, @Optional @Default("#[payload:]") Map<String, Object> entry) throws Exception
{

When a processor operation is selected it can also have a number of different parameters

 @Processor
    public ResponseList<Status> getUserTimeline(@Placement(group = "Pagination") @Default(value = "1") @Optional int page,
                                                @Placement(group = "Pagination") @Default(value = "20") @Optional int count,
                                                @Placement(group = "Pagination") @Default(value = "-1") @Optional long sinceId)
            throws TwitterException {
        return twitter.getUserTimeline(getPaging(page, count, sinceId));

Processors can also take Mule expressions as parameters

  public void add(@Optional @Default("#[payload:]") LDAPEntry entry) throws Exception

@Disconnect, invoked when as part of the maintenance of the Connection Pool @ValidateConnection, invoked before the invocation of an operation

@Transformer** provide message/type transformation. For example to transform “ldap Entry To Map”

 @Transformer(sourceTypes = {LDAPEntry.class})
    public static Map<String, Object> ldapEntryToMap(LDAPEntry entry)
    {
        return entry != null ? entry.toMap() : null;
    }

DevKit Configuration Settings

Textbox

A configurable String field will appear as a text box

Tab

the placement parameter can define the tab and group box for the configuration parameters

@Placement(order = 4, group = "Connection", tab = "General")

Checkbox

boolean value are mapped to a checkbox

 @Optional
    @Configurable
    @Default("true")
    @FriendlyName("Use SSL")
    private boolean useSSL;

Drop downs can be configured with an enum

public enum HttpMethod
{
    GET, POST
};

@Configurable
@Default(value = "GET")
@Optional
@Placement(order = 4, group = "Connection", tab = "General")
private HttpMethod method;

Password fields

 @Configurable
    @Optional
    @Placement(group = "Proxy settings", tab = "Proxy")
    @Password
    private String proxyPassword;

Many of these exapmples were taken from the Twitter Processor and the TwitterConnector.java

 
mule_devkit.txt · Last modified: 2014/03/01 10:57 by root
 
RSS - 200 © CrosswireDigitialMedia Ltd