In the previous chapter, we looked at how we can design an API in API Designer. We’ll now look at Anypoint Studio. Anypoint Studio is an Eclipse-based integrated development environment (IDE) tool used to design and develop Mule applications. We can also use this tool to test our applications.
Anypoint Studio enables users to drag and drop connectors and modules to create a Mule application. Many versions of Anypoint Studio are available, and it is recommended to practice in the latest version.
We will see how to download and install Anypoint Studio and what the different views, perspectives, and menu options available in Anypoint Studio are. Once familiar with the tool, we will learn how to create a simple Hello World Mule application and test the application using the Postman application.
After reading this chapter, you’ll come away with an understanding of the following topics:
You will need the following software for this chapter:
Let’s get started by learning how to download and install Anypoint Studio.
In this section, we will learn how to download and install Anypoint Studio. The first step begins with downloading a software file to the computer, which may take a few minutes as the file size is around 2 GB. Afterward, we will install and launch Studio. Let’s begin with downloading now.
These steps can be followed for a simple and easy download:
The .zip (Windows/macOS)/.tar.gz (Linux) file of the latest version of Anypoint Studio is downloaded to the computer.
The Anypoint Studio file is bundled with the following components:
Now that we’ve downloaded the file, let’s start the installation. The application can be simply installed by extracting the compressed .zip/.tar .gz file.
In this section, we will see how to install Anypoint Studio on the Windows OS. A similar procedure can be followed while installing it on other OSs, such as macOS and Linux:
Tip
For the Windows OS, do not extract the ZIP file in a large path. Try to place the file directly in C:/ or D:/. This helps avoid the path is too long error.
Figure 3.1 – Extracting Anypoint Studio for installation
We have extracted the folders to the chosen path. Next, we will see how to launch Anypoint Studio on our computer.
Follow these steps to launch Anypoint Studio:
Figure 3.2 – Selecting a workspace location
Note
A workspace is a location on your computer where all the work you do through Anypoint Studio is stored as files. It is easier to create one workspace and save it as the default so that the Anypoint Studio remembers the workspace next time.
Figure 3.3 – Anypoint Studio: Home
Now that Anypoint Studio is all set, let us explore its various components and try building a Mule project. We will start by getting to know the Mule Palette.
The Mule Palette has modules and connectors that we can use in the flow. We can also download new modules or connectors from Anypoint Exchange, as shown in Figure 3.4. Core, HTTP, and Sockets are default modules in the Palette. Based on the project requirements, we can add modules to the Palette by using the Add Modules option. While developing a project, you can drag and drop the required components from the Mule Palette onto the canvas:
Figure 3.4 – The Mule Palette
An artist palette is a thin board that has a set of colors that enables mixing and painting on canvas. Similarly, the Mule Palette has collections of components that the developer can drag and drop onto the canvas to design or develop the Mule project.
With this, we have learned about the components available in the Mule Palette. Next, let’s move on to learn about the Mule project structure.
Before getting into creating a Mule project, it is important that we get familiar with the Mule project structure. Let us see the project structure of a Mule application in Package Explorer. These are the main folders and files that are important for every Mule project:
Figure 3.5 clearly shows the project structure of a Mule application in which helloworld.xml is the Mule configuration file:
Figure 3.5 – Project structure
Similarly, we can see the other folders, as well as the mule-artifact.json and pom.xml files in the project structure.
Now that we’ve learned how Mule project folders are structured to store different folders and files, let’s explore the different views and perspectives available in Anypoint Studio.
The views and perspectives of any IDE can be customized based on the user’s preference. A perspective is nothing but a collection of views. Let’s learn about different views and perspectives.
Views in Anypoint Studio are the graphical representation of project metadata or properties for the active editor window. We can easily maximize, minimize, and remove views from the active window. The following are some of the views in Studio:
These are the various views that we can see in the Anypoint Studio window. Each view gives information relevant to the particular view. On the whole, it gives a clear picture of what the user needs to see in the active window based on their preferences.
Perspectives
As mentioned earlier, a perspective is a collection of views and editors. The default perspective of Anypoint Studio is the Design perspective. We can create our own perspective and add any of the views.
The different perspectives already available in the Studio are:
The user can change the perspective based on their role or activities. For example, a developer might choose the Design perspective, while a tester might choose the Debug perspective to test the application. By doing so, they can work easily with the required views. Now that we have explored the basics of Anypoint Studio, let’s try and build our own Mule application.
We have explored various components, views, and perspectives of Anypoint Studio. Now it is time to put all of what we have learned together with a new project. The steps involved in every Mule project are build, run, and test. Let’s elaborate on each step.
In this section, let us learn how to create a new Mule project:
Figure 3.6 – Package Explorer
Figure 3.7 – Project Settings
Figure 3.8 – Mule application – home
Figure 3.9 – Mule properties for HTTP Listener
Figure 3.10 – HTTP connector configuration
Figure 3.11 – Listener properties configuration
Figure 3.12 – Searching for Logger in the Mule Palette
Figure 3.13 – Logger properties
Figure 3.14 – Mule Palette: Core module
%dw 2.0 output application/json --- { "message" : "Hello World" }
Figure 3.15 – DataWeave code in Transform Message
Figure 3.16 – Saving the Mule application
With this, we have created the Mule application successfully. The next step is to run the application, which involves nothing more than deploying the application into Mule runtime.
In this section, we will see how to run the Mule application from Anypoint Studio:
Figure 3.17 – Running the Mule application
Figure 3.18 – Console view
Tip
If the deployed status is FAILED due to (java.net.BindException) or Caused by: java.net.BindException: Address already in use, then try to use different ports, such as 8083, 8084, or any other port available in the system that is not used by any other applications.
Now that we have deployed the application in Anypoint Studio, the next step is to test the application.
In this section, let us see how to test the Mule application using the API/web service testing tool (the Postman application).
Note
Postman is an application used for API/web service testing. It is an HTTP client that tests HTTP requests (GET, POST, and other methods) and receives the response. It is not related to Mule components. If you don’t have a Postman application or any other web service testing tools on your computer, then install the Postman application by referring to the link that is referenced in the Technical requirements section of this chapter.
Once the application is deployed, you can follow these steps:
Figure 3.19 – Sending a request from the Postman app
We will receive a successful response with the 200 HTTP status code and the HTTP status description as OK. Also, we will be able to see the response message in JSON format, which we set in the Transform Message step (see Figure 3.20):
Figure 3.20 – HTTP successful response
Figure 3.21 – Logger message in console
As you can see in the preceding figure, Logger has printed the required log message in the console. If the application is deployed into CloudHub, the Logger logs the message in the server log.
Good going! We are done with the very first Mule application project. In this Hello World project, the HTTP listener receives the incoming request, then, in turn, calls the logger to log the message, and finally, returns JSON output using the Transform Message step. Now, you should be confident enough to try other simple Mule projects using other components from the Mule Palette. As we move on, we will next explore how Mule files can be exported and imported.
In the previous example, we developed a new Mule project in Anypoint Studio. If we need to share the project with other developers or deploy this application into CloudHub or another deployment model, then we have to export the project.
We can export the project using the following options:
Let us look into each of these in detail.
Let’s try exporting the Mule application as a .jar (Java Archive) file now:
Figure 3.22 – Exporting settings as JAR
We can share this .jar file with other developers to import into their Anypoint Studio. We can also use this .jar file to deploy the Mule application into CloudHub.
Now that we have got a clear idea of how to export a Mule application as a .jar file, let’s try exporting it as a filesystem.
Let’s try exporting a Mule application as a filesystem (as a folder and files) now:
Figure 3.23 – Export settings: Filesystem
The Mule project is exported to the location specified as a filesystem.
By importing the filesystem into Anypoint Studio, it is easy to create a Mule application in Studio. This will be very useful when a user wants to share the Mule project with other users.
Now, let’s see how to import a Mule application from a .jar file.
Let’s try importing a Mule application from a .jar file in Anypoint Studio:
Figure 3.24 – Importing a Mule project
Figure 3.25 – Imported project from Package Explorer
As shown in Figure 3.25, we have imported the .jar file and created our Mule project successfully. Let’s explore another option to import the Mule project.
Let’s try importing a Mule application from the filesystem (as a folder and files) now:
Figure 3.26 – Importing a Mule project
Note
If you don’t uncheck the Copy project into workspace checkbox, shown in the previous screenshot, and you’re using a Git repository, your changes won’t be reflected in the original project folder. Instead, a copy of the project will be created under Anypoint Studio’s current workspace. If you want to continue using the original project folder from your Git repository, then make sure you uncheck this option.
Now, the project is imported into Anypoint Studio (see Figure 3.27):
Figure 3.27 – Imported project in Package Explorer
As shown in the preceding figure, we have imported the filesystem and created our Mule project successfully.
With this, we can conclude that we have learned the concept of exporting and importing Mule applications.
We can also change or enhance the appearance of the Anypoint Studio user interface by updating the theme. Let’s move on to learn more about themes.
Each developer prefers a different user interface. Some may prefer a dark theme, while others like a light theme. The theme sets the mood for the developer to help them focus. For example, a dark theme reduces strain on the eyes and makes it easier to notice the different syntaxes as they come with different colors. The look and feel of Anypoint Studio can be updated based on user preferences. Let’s learn how to change the theme:
Figure 3.28 – Studio appearance
With this, we have learned how to customize the IDE experience by changing the theme in Anypoint Studio.
Now that we’re familiar with multiple concepts and the working of Anypoint Studio, it is important to note the importance of updating the software in Anypoint Studio. Let’s see how to do this in the next section.
Software updates are mandatory for bug fixing, getting new features, and avoiding performance issues. Let’s see how to update the software in Anypoint Studio:
Figure 3.29 – Available Updates
Figure 3.30 – License agreements
Figure 3.31 – Restart Now
It is always recommended to periodically check for any software updates.
In this chapter, we explored how to download and install Anypoint Studio. We also had a look into the various views and perspectives, as well as the Mule Palette. We created a Hello World Mule application using the HTTP connector, after which we tried to run it. Finally, we tested it using an external Postman application.
We also learned about exporting and importing a Mule application. This is important when we need to deploy these applications into different deployment models (CloudHub, on-premises, and so on) and also to share them with other developers. We next saw how to update the theme and software version of Anypoint Studio.
On completing this chapter, you have an elaborate enough knowledge of the Anypoint Studio IDE to feel confident in developing your own Mule application.
In the next chapter, we’ll explore Core module components within Anypoint Studio to understand more about flow controls, scope, endpoints, transformers, batch, and error handling.
Take a moment to answer the following questions to serve as a recap of what you just learned in this chapter:
18.118.122.46