By default, when you create a custom connector using Anypoint Devkit in the Mule ESB, the category of the custom connector will be the Connectors.
For example, I create an Anypoint Connector Project as follows:
After right-clicking on the project, selecting Anypoint Connector and selecting Install or Update, you will see this Connector appear in the Connectors category of Mule Palete as follows:
In the sense, if your Connector is connecting to a particular system, this default category seems correct. But if it does not do these things, then if we keep the default category for it, it will not be very reasonable.
In the Mule ESB, a connector has the following categories:
- Connectors
- Scopes
- Endpoints
- Components
- Transformers
- Filters
- Flow Control
- Error Handling
- Miscellaneous
- Security
Choosing the right category that our Connector belongs to, will help us when using our Connector feel more comfortable, more reasonable.
So how to change this default category? Anypoint Devkit allows us to do this by using the @Category annotation (org.mule.api.annotations.Category) in the main class of our Connector.
In this annotation @Category we have an attribute name, declaring the value of this name attribute will help us set the correct category for our Connector.
Here is a list of the values of the name attribute in the @Category annotation for each category:
- Connectors (DEFAULT): org.mule.tooling.category.cloudconnector
- Scopes: org.mule.tooling.category.scopes
- Endpoints: org.mule.tooling.category.endpoints
- Components: org.mule.tooling.category.core
- Transformers: org.mule.tooling.category.transformers
- Filters: org.mule.tooling.category.filters
- Flow Control: org.mule.tooling.category.flowControl
- Error Handling: org.mule.tooling.ui.modules.core.exceptions
- Miscellaneous: org.mule.tooling.ui.modules.core.miscellaneous
- Security: org.mule.tooling.category.security
Assuming now, I want to set the Connector category in the example above to Components, I will edit the HuongDanJavaConnector class to add the @Category annotation as follows:
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 |
package com.huongdanjava.huongdanjava; import org.mule.api.annotations.Category; import org.mule.api.annotations.Config; import org.mule.api.annotations.Connector; import org.mule.api.annotations.Processor; import com.huongdanjava.huongdanjava.config.ConnectorConfig; @Connector(name="huong-dan-java", friendlyName="HuongDanJava") @Category(name = "org.mule.tooling.category.core", description = "Huong Dan Java Component") public class HuongDanJavaConnector { @Config ConnectorConfig config; /** * Custom processor * * @param friend Name to be used to generate a greeting message. * @return A greeting message */ @Processor public String greet(String friend) { /* * MESSAGE PROCESSOR CODE GOES HERE */ return config.getGreeting() + " " + friend + ". " + config.getReply(); } public ConnectorConfig getConfig() { return config; } public void setConfig(ConnectorConfig config) { this.config = config; } } |
Then, you will see our Connector appear in the Components category of the Mule Palete as follows: