3. Overview of Devkit
• What is Devkit?
• Devkit has the tooling and interfaces for the custom connector creation
• Where to get it?
• Devkit can be found as a plugin to the Anypoint Studio in update sites.
• What it does?
• Devkit provides all the supporting tools and pulls all the dependency
interfaces in order to create our own custom connector.
4. Custom Connector Creation
• Anypoint Studio supports to create our own connector project
• Steps :
• New – Select Anypoint Connector Project
• This should be maven based project
• Should automatically pull all the dependencies for the connector project
• Look for the FunctionalTest java file which is implemented with the sample
processor.
• By default there should be Greet operation implemented for this connector
5. Connection Management
• The Connection Management framework provides multi-tenancy
capabilities for a connector (managing multiple simultaneous
connections with different credentials for each connector within your
application), as well as connection pooling and instance pooling.
• These benefits are available for most authentication schemes other
than OAuth, and for APIs that do not require authentication. Basic
Authentication is designated in a connector with the
@ConnectionManagement attribute.
6. About Connection Management
• Transparent multi-tenancy – A Mule application can open many
connections to a single target using different credentials to connect
on behalf of many users simultaneously.
• Connection pooling – Automated management of a pool of instances
of the connector class to manage connection resources effectively.
• Exceptions - The ability to automatically invalidate connections on
exceptions and to reconnect as needed.
7. Connection Management Framework and
Authentication Protocols
• Connection Management framework in conjunction with most
authentication protocols, such as
• username and password authentication (most common),
• SAML,
• Kerberos,
• LDAP,
• NTLM
• OAuth related annotations can be used for more OAuth based
authentication
8. Connection Management Annotation
• @ConnectionManagement uses following method level annotations
• @Connect method - Creates a connection
• @Disconnect method - Explicitly closes a connection
• @ValidateConnection method - Returns true if a connection is still valid, false
otherwise
• @ConnectionIdentifier method - Returns a prefix used in generating unique
identifiers for connector instances in the connection pool
9. ConnectionManagementStrategy class
• @ConnectionManagement(friendlyName="Connector Connection")
public class ConnectionManagementStrategy{
@Connect @TestConnectivity public void
connect(@ConnectionKey String username, @Password String
password){ ... }
@Disconnect public void disconnect() { client = null; }
@ValidateConnection public boolean isConnected() { return client !=
null; }
@ConnectionIdentifier public String connectionId() { return
client.toString(); } }
10. Note:
• All the annotated methods are called automatically as needed by the
DevKit framework; you never call them directly from your code
11. @Connector class
• @Connector(name = "connector")
public class MyConnectorWithConnectionManagement {
@ConnectionStrategy
@Config
ConnectorConfig config;
private ConnectionManagementStrategy strategy;
/** * Processors */
}
13. @Connect
• This method is responsible for creating a connection to the target.
• The @Connect method is called automatically by Mule when the
connector starts up, or if the connection to the API has been lost and
must be reestablished.
• When this method finishes, if authentication is successful, the
connector instance is ready to make operations
14. More on @Connect
• A method annotated with @Connect must:
• Be public
• Throw org.mule.api.ConnectionException (and no other exceptions)
• Have a void return type
• Annotate only one method with @Connect
• Annotate @Connect method with @TestConnectivity
• Annotate at least one parameter with @ConnectionKey
16. @TestConnectivity
• Annotation displays a button in Anypoint Studio when configuring the
Connector, this button allows the user to test if the connection is
successful with his configuration.
• @TestConnectivity runs @Connect method and expects an
org.mule.api.ConnectionExcetion, if this exception occurs then the
test fails, if not connection is assumed successful.
• This can be set as inactive by specifying,
• @TestConnectivity(active = false)
17. @ConnectionKey
• For username and password authentication, the username is the
obvious choice for @ConnectionKey
• For other protocols, identify the value that is most obviously
associated with different users and access privileges that connect to
your service, and use this value as your @ConnectionKey
18. @Disconnect
• This annotation indicates the method inside a
@ConnectionManagement class that is responsible for disposal of a
connection. This method is called when the connector is shut down
or the connection is explicitly terminated.
• A method annotated with @Disconnect must:
Be public
Take no input parameters
Have a void return type
The class must have exactly one annotated @Disconnect method
20. @ValidateConnection
• This method is called by Mule to check whether the connection is
actually open or not.
• A method annotated with @ValidateConnection
• Be public
• Take no input parameters
• Return boolean or java.lang.Boolean
• Only one method on the class can be annotated with @ValidateConnection
22. @ConnectionIdentifier
• This annotation identifies a method inside the
@ConnectionManagement class that returns a unique identifier for
the connection, used for logging and debugging.
• A method annotated with @ConnectionIdentifier must,
• Be public
• Not be static
• Not take arguments
• Return java.lang.String
• Annotate only one method with @ConnectionIdentifier
23. @ConnectionIdentifier
• This code returns the connection
SessionId as an identifier (if
available).
• The SessionHeader object in this
case contains header
information about the current
connection to the API, including
the session ID.
24. @ReconnectOn
• Receives list of exceptions instead of just a single exception, and can
be used at both the class and processor levels.
• This annotation is used for exception handling related to connections.
It can be used at class level or at a method level. If the Connector or
Processor throws an exception of this class @ReconnectOn then
automatically invalidates the connection
• @ReconnectOn receives a list containing the classes of the exceptions
to be caught.
When an exception occurs, the @ReconnectOn behavior is based on the configured reconnection strategy
25. Example @ReconnectOn
• @Processor @ReconnectOn(exceptions = {InvalidSessionFault.class,
PasswordChangedException.class})
public void myOperation(@Optional String source, @Optional Object
destination) throws InvalidSessionFault, PasswordChangedException,
InvalidParameterException {
/** * CODE FOR MY OPERATION */
}