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

Installing and Testing Your Connector

Having built a project with Maven and your IDE, you can install the skeletal connector in Studio to confirm its basic functionality before adding more operations to it. This document describes the steps to take to build, then install and test your connector in Mule Studio. The macro steps of this procedure are as follows:

  1. Set required @Connector annotations.

  2. Add a "say hello" operation to connector.

  3. Document the "say hello" operation.

  4. Build the connector project with Maven.

  5. Install the connector in Studio.

  6. Test the connector’s basic functionality.

Assumptions

This document assumes you have created a connector project

Setting @Connector Annotation Parameters

The @Connector annotation on the Maven-generated class has a required parameter: friendlyName. (See example below.) This parameter defines a human-readable name for the connector, which appears as the connector’s label in Studio’s palette. Without this parameter, the connector does not appear in the palette in Mule Studio releases after 3.4.0. 


         
      
1
@Connector(name = "helloConnector", schemaVersion = "1.0-SNAPSHOT", friendlyName = "Hello")

Adding an Operation

The connector project you created is immediately ready to build, then install and test in Mule Studio. However, to make testing more interesting, you can add an operation to the connector that receives a name as a string and returns the same name preceded by "Hello".  Follow the steps below to add this operation.

  1. In your IDE, open the main Java file, src/main/java/org.mulesoft.hello/HelloConnector.java

  2. Paste the following code at the very end of the connector class, before the final closing curly brackets. Use the identifier uname because the identifier name is reserved; you cannot use it for the parameter. 

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    /**
    * Custom processor
    *
    * {@sample.xml ../../../doc/hello-connector.xml.sample hello:say-hello}
    *
    * @param uname Name to be processed
    * @return Some string
    */
    @Processor
    public String sayHello(String uname)
    {
        return "Hello " + uname;
    }
      
  3. Confirm that the complete class appears as per the following.

    
                
             
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    
    /**
    * This file was automatically generated by the Mule Development Kit
    */
    package TestConnector;
    import org.mule.api.annotations.Connector;
    import org.mule.api.annotations.Connect;
    import org.mule.api.annotations.ValidateConnection;
    import org.mule.api.annotations.ConnectionIdentifier;
    import org.mule.api.annotations.Disconnect;
    import org.mule.api.annotations.param.ConnectionKey;
    import org.mule.api.ConnectionException;
    import org.mule.api.annotations.Configurable;
    import org.mule.api.annotations.Processor;
    /**
    * Cloud Connector
    *
    * @author MuleSoft, Inc.
    */
     
    @Connector(name="helloConnector", schemaVersion="1.0-SNAPSHOT", friendlyName="Hello")
    public class HelloConnector
    {
     
        /**
        * Configurable
        */
        @Configurable
        private String myProperty;
     
        /**
        * Set property
        *
        * @param myProperty My property
        */
        public void setMyProperty(String myProperty)
        {
            this.myProperty = myProperty;
        }
     
        /**
        * Get property
        */
        public String getMyProperty()
        {
            return this.myProperty;
        }
     
        /**
        * Connect
        *
        * @param username A username
        * @param password A password
        * @throws ConnectionException
        */
        @Connect public void connect(@ConnectionKey String username, String password)
        throws ConnectionException
        {
     
            /**
            * CODE FOR ESTABLISHING A CONNECTION GOES IN HERE
            */
        }
     
        /**
        * Disconnect
        */ @Disconnect
        public void disconnect()
        {
     
            /**
            * CODE FOR CLOSING A CONNECTION GOES IN HERE
            */
        }
     
        /**
        * Are we connected
        */
        @ValidateConnection public boolean isConnected()
        {
            return true;
        }
     
        /**
        * Connection Identifier
        */
        @ConnectionIdentifier public String connectionId()
        {
            return "001";
        }
     
        /**
        * Custom processor
        *
        * {@sample.xml ../../../doc/MyTest-connector.xml.sample mytest:my-processor}
        *
        * @param content Content to be processed
        * @return Some string
        */ @Processor
        public String myProcessor(String content)
        {
            /**
            * MESSAGE PROCESSOR CODE GOES HERE
            */
            return content;
        }
     
        /**
        * Custom processor
        *
        * {@sample.xml ../../../doc/hello-connector.xml.sample hello:say-hello}
        *
        * @param uname Name to be processed
        * @return Some string
        */ 
     
     
     @Processor
        public String sayHello(String uname)
        {
            return "Hello " + uname;
        }
    }

Documenting the Operation

Because DevKit enforces proper documentation of all projects, you must provide at least one example of how to use each operation you add to a connector. If you attempt to build the project without documentation, the build fails.

  1. In your IDE, open the file  doc/Hello-connector.xml.sample  then paste the following snippet at the end.

    
                 
              
    1
    2
    3
    4
    5
    
    <!-- BEGIN_INCLUDE(hello:say-hello) -->
     
        <hello:say-hello uname="#[payload.uname]" />
     
    <!-- END_INCLUDE(hello:say-hello) -->
      
  2. Confirm that the complete contents of the file appear as per the following.

    
                 
              
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    
    <!-- BEGIN_INCLUDE(hello:my-processor) -->
     
        <hello:my-processor content="#[map-payload:content]" />
     
    <!-- END_INCLUDE(hello:my-processor) -->
     
     
     
    <!-- BEGIN_INCLUDE(hello:say-hello) -->
     
        <hello:say-hello uname="#[payload.uname]" />
     
    <!-- END_INCLUDE(hello:say-hello) -->

Note that the name of the processor in our Java file is sayHello, yet in the sample XML file, the name is say-hello.

DevKit automatically converts the CamelCase name for the processor to a hyphenated name, thus, it does not recognize a processor labeled sayHello in your sample XML file.

Building the Project with Maven

At this point the connector is ready to be built and used for the first time. Maven automates the process of building the connector, running tests, and packaging it to be used in Mule Studio.  

If using Studio as your IDE, note that the Maven support for developing Mule projects does not apply to building DevKit projects. You must, therefore, build connectors using Maven and the command line, or using m2e menu commands.

  1. To compile the project, access the command console, then run the following command in the project directory.

    
                
             
    1
    
    mvn clean package -Ddevkit.studio.package.skip=false
      
    . The target folder in your IDE now contains a fully functional – albeit, very basic – connector that is ready to be installed in Mule Studio.

Installing the Connector in Mule Studio

  1. Under the Help menu in Mule Studio, select Install New Software

  2. Click Add…​ next to the Work with field, then enter the following values:

    1. NameHello Connector

    2. Location: the filepath of your connector’s update-site.zip file (inside the target folder) prepended with file:/

  3. In the table below the filter field (see image below), use the checkboxes to select your Mule extension (i.e. connector (click to expand the folders to select individual items), then click Next

  4. Review the details of the item you selected, then click Next.

  5. Click to accept terms and conditions of the product, then click Finish.

  6. Click Restart Now to complete the installation.  

  7. After Studio restarts, expand the Cloud Connectors palette group to see your new Hello Connector.

Testing the Connector

To see your new connector function, create, then run a Mule application which uses the Hello Connector.

  1. Create a simple flow using an HTTP endpoint and your new Hello connector. Use the default values configured in the HTTP endpoint (port:`8081`, host: localhost).

  2. Select the connector to open the properties editor. Notice the parameters Studio makes available to the end user to configure. Configure the parameters according to the table below.

    Parameter Value

    Display Name

    Hello

    Config Reference

    see next step

    Operation

    Say hello

    Uname

    #[message.inboundProperties['uname']] 

  3. Click the plus sign next to the Config Reference field to create a new global element for your connector to use.

  4. In the My Property field, enter any string as the value, then click OK.

  5. Save, then run the project as a Mule Application (right-click project name, then select Run As > Mule Application).

  6. From a browser, navigate to http://localhost:8081/?uname=Dave

  7. The application returns the response in your browser (see below).

  1. Create a simple flow using an http:inbound-endpoint and your new hello:config. Configure the parameters of each element according to the code sample below.

    
           
                   
                
    1
    2
    3
    4
    5
    6
    7
    8
    9
    
    &lt;mule xmlns:hello="http://www.mulesoft.org/schema/mule/hello" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation" xmlns:spring="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd http://www.mulesoft.org/schema/mule/hello http://www.mulesoft.org/schema/mule/hello/1.0-SNAPSHOT/mule-hello.xsd"&gt; 
        &lt;hello:config name="Hello" myProperty="asdf" doc:name="Hello"&gt;
            &lt;hello:connection-pooling-profile initialisationPolicy="INITIALISE_ONE" exhaustedAction="WHEN_EXHAUSTED_GROW"/&gt; 
        &lt;/hello:config&gt; 
        &lt;flow name="Hello-connector-testFlow1" doc:name="Hello-connector-testFlow1"&gt; 
            &lt;http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/&gt; 
            &lt;hello:say-hello config-ref="Hello" uname="#[message.inboundProperties['uname']]" doc:name="Hello"/&gt; 
        &lt;/flow&gt; 
    &lt;/mule&gt;
  2. Save, then run the project.

  3. From a browser, navigate to http://localhost:8081/?uname=Dave

  4. The application returns the response in your browser.

See Also