Table of contents
1.
Introduction
2.
Switch to a supported platform
3.
External resources should be inventoried.
4.
Located on the application server (s)
5.
Datasources
6.
Inventory secrets
6.1.
Passwords and secure strings
6.2.
Inventory certificates
7.
Determine whether and how the file system is used
7.1.
Read-only static content
7.2.
Dynamically published static content
7.3.
Dynamic or internal content
8.
Identify session persistence mechanism.
9.
Special cases
10.
Migration
10.1.
Parameterize the configuration
10.2.
Applications for Maven
10.3.
Maven-independent applications
10.4.
Azure portal Azure Command Line Interface
11.
Migrate JVM runtime options
11.1.
Populate secrets
11.2.
Configure custom domain and SSL
11.3.
Import backend certificates
11.4.
Migrate data sources, libraries, and JNDI resources
11.5.
Migrate remaining configuration
11.6.
Migrate scheduled jobs
11.7.
Restart and smoke-test
12.
Post-migration
13.
Placement Strategy
14.
Frequently Asked Questions
14.1.
What do you mean by Tomcat on Azure?
14.2.
How does the Tomcat server work?
14.3.
How is Apache Tomcat put to use?
14.4.
Can Apache and Tomcat run together?
14.5.
Can I utilize the Azure App service with Tomcat clustering?
15.
Conclusion
Last Updated: Mar 27, 2024
Easy

Tomcat to Azure App Service

Author Saksham Gupta
0 upvote
Career growth poll
Do you think IIT Guwahati certified course can help you in your career?

Introduction

This article will look at how to use the Microsoft Azure Migrate: Migrate Tomcat applications to Tomcat on Azure App Service. Existing apps can be easily containerized utilizing the procedure, which doesn't require access to your source. The tool lets you bundle the application components in a container image by leveraging the operating state of the apps on a server to identify the components. 

Introduction

Switch to a supported platform

App Service provides specific Tomcat versions for specific Java versions. To ensure that it is compatible, first migrate your application to one of the supported Tomcat and Java versions in its current environment before proceeding with the remaining steps. It is crucial to validate that our application works correctly on the supported java version. It becomes more critical when we are dealing with unsupported JDK. 

java

External resources should be inventoried.

External resources, namely data sources and JMS message brokers, are injected via (JNDI). These resources usually require migration or reconfiguration. Examine the file META-INF/context.xml. Within the Context> element, look for Resource> elements.

Located on the application server (s)

Examine the files $CATALINA BASE/conf/context.xml and $CATALINA BASE/conf/server.xml, as well as the.xml files in the $CATALINA BASE/conf/[engine-name]/[host-name] directories.

JNDI resources will be described in context.xml files by the Resource> elements within the top-level Context> element.

JNDI resources will be described in server.xml files by the Resource> elements contained within the GlobalNamingResources> element.

Datasources

JNDI resources with attribute of type to javax.sql.DataSource is data sources. In this guide, it is impossible to document every possible external dependency. Your team is responsible for ensuring that your application can satisfy all external dependencies after the migration.

Inventory secrets

Inventory secrets

Passwords and secure strings

Examine all production server(s) properties and configuration files for any secret strings or passwords. Check the server.xml and context.xml files in $CATALINA BASE/conf. META-INF/context.xml files and application. Properties or application.yml files for Spring Boot applications may be included.

Inventory certificates

All certificates for public SSL endpoints or communication with backend databases and other systems should be documented. To view all certificates, run the following command:

keytool -list -v -keystore <path to keystore>

Determine whether and how the file system is used

Any use of the application server's file system will necessitate reconfiguration or, in rare cases, architectural changes. You may recognize some or all of the scenarios below.

Read-only static content

If your app currently serves static content, you'll need to find a new home for it. Try to move static content to Azure Blob Storage and try to add Azure CDN for global lightning-fast downloads.

Dynamically published static content

Suppose your application supports static content that is uploaded/produced by your application but is immutable once created. In that case, you can use Azure Blob Storage and Azure CDN as described above.

Dynamic or internal content

For files frequently written and read by your application (such as temporary data files) or static files visible only to your application, you can mount Azure Storage into the App Service file system.

Identify session persistence mechanism.

To determine which session persistence manager is in use, examine the context.xml files in your application and Tomcat configuration. Look for the Manager> element and record the value of the className attribute.

Tomcat's built-in PersistentManager implementations, such as StandardManager and FileStore, are not designed for use with a distributed, scaled platform like App Service. Because App Service can load balance between multiple instances and transparently restart any instance at any time, saving mutable state to a file system is not recommended.

Use an alternative PersistentManager implementation that writes to an external data store, such as VMware Tanzu Session Manager with Redis Cache, if session persistence is required.

Note: If you have any processes running outside the application server, such as monitoring daemons, you must terminate or relocate them.

Special cases

Specific production scenarios may necessitate additional modifications or impose other constraints. While such scenarios are uncommon, it is critical to ensure that they are either inapplicable to your application or adequately resolved.

  • Determine whether the application relies on scheduled jobs
  • Determine whether your application contains OS-specific code
  • Determine whether Tomcat clustering is used
  • Determine whether non-HTTP connectors are used
  • Determine whether MemoryRealm is used
  • Determine whether SSL session tracking is used
  • Determine whether AccessLogValve is used

Migration

Migration

Parameterize the configuration

During the pre-migration steps, you most likely discovered some secrets and external dependencies, such as data sources, in the server.xml and context.xml files. After identifying, you have to replace any username, password, connection string, or URL with an environment variable for each item you identified.

Assume the context.xml file contains the following element:

<Resource
    name="jdbc/dbconnection"
    type="javax.sql.DataSource"
    url="jdbc:postgresql://postgresdb.contoso.com/wickedsecret?ssl=true"
    driverClassName="org.postgresql.Driver"
    username="postgres"
    password="t00secure2gue$$"
/>


In this case, you could change it as shown in the example below:

<Resource
    name="jdbc/dbconnection"
    type="javax.sql.DataSource"
    url="${postgresdb.connectionString}"
    driverClassName="org.postgresql.Driver"
    username="${postgresdb.username}"
    password="${postgresdb.password}"
/>

Applications for Maven

Use the Maven Webapp plugin to create the Web App and deploy it.

Maven-independent applications

If you are unable to use the Maven plugin, you must provision the Web App using another mechanism, such as:

Azure portal Azure Command Line Interface

PowerShell in Azure

Once the Web App has been created, deploy it using one of the available deployment mechanisms.

Migrate JVM runtime options

Populate secrets

Application Settings can be used to store any secrets unique to your application. Use Azure Key Vault instead if you intend to use the same secret(s) across multiple applications or if you need fine-grained access policies and audit capabilities.

Configure custom domain and SSL

If your application will be accessible via a custom domain, you must map it to it.The SSL certificate for that domain must then be bound to your App Service Web App.

Import backend certificates

App Service must have access to all certificates used to communicate with backend systems such as databases.

Migrate data sources, libraries, and JNDI resources

Follow the same steps as for data source JAR files to migrate any additional server-level classpath dependencies. Any additional Shared server-level JDNI resources should be migrated.

Migrate remaining configuration

After completing the preceding section, your customizable server configuration should be in /home/tomcat/conf.

Migrate scheduled jobs

Consider using a Timer trigger for Azure Functions to execute scheduled jobs on Azure. You do not need to convert the job code into a function. To start the job, the function can simply call a URL in your application. Consider using Spring Batch if such job executions must be dynamically invoked and/or centrally tracked. You can also create a Logic app with a Recurrence trigger to invoke the URL without having to write any code outside of your application.

Restart and smoke-test

Finally, you must restart your Web App in order for all configuration changes to take effect. Check that your application is running properly after the restart.

Post-migration

post-migration

Now that your application has been migrated to Azure App Service, you should ensure that it functions as expected. After that, we have some suggestions for you to make your application more Cloud-native

Must Read Apache Server

Placement Strategy

If you are looking for a perfect video to guide you about placements. Have a look at Parikh's sir video where you can find the complete Roadmap for Product based companies.

Frequently Asked Questions

What do you mean by Tomcat on Azure?

The Apache Software Foundation (ASF) created the Java Servlet Container, Tomcat, which is open-source. An extremely well-liked open-source relational database management system is MySQL.

How does the Tomcat server work?

A web container called Tomcat manages your servlets and their mappings. Tomcat checks the URL mappings after any request for a servlet is made to apache, and the result is generated in a way browsers can understand.

How is Apache Tomcat put to use?

One of Tomcat's connectors receives a request from a client. Tomcat routes this request to the proper Engine for processing. The range of Tomcat's search for the right Engine is constrained because these Engines are included within other elements like hosts and servers.

Can Apache and Tomcat run together?

Running Apache and Tomcat on the same computer is no problem. It's pretty common to run Tomcat on port 8080, run Apache on port 80/443, and use mod_proxy to allow Apache to serve apps hosted by Tomcat.

Can I utilize the Azure App service with Tomcat clustering?

The Azure App Service does not allow Tomcat clustering. Instead of requiring Tomcat-specific capabilities, you can configure and manage scalability and load balancing with Azure App Service. To make the session state accessible across replicas, you can store it in a different place.

Conclusion

In this article, we learned how to Migrate Tomcat applications to Tomcat on Azure App Service. To continue learning more about Azure, check out our other blogs on the AWS vs. azure vs. google cloudMicrosoft AzureAzure Service Fabric, and Microsoft Azure certification.

Refer to our guided paths on Coding Ninjas Studio to learn about Data Structure and Algorithms, Competitive Programming, JavaScript, etc. Enroll in our courses and refer to our mock test available. Have a look at the interview experiences and interview bundle for placement preparations.

Happy Coding!

Live masterclass