Understanding JBoss Undertow Deployment on Default Server and Default Host

Hey Dev, are you looking to deploy applications using JBoss Undertow? Undertow is a high-performance web server that can be easily integrated into your Java applications. In this article, we will explore how to deploy your application on the default server and default host. Let’s get started!

What is JBoss Undertow?

Before we dive into the topic, let’s understand what JBoss Undertow is. Undertow is a fast, lightweight, and flexible web server that is designed to be embedded in your Java applications. It is part of the WildFly application server and can also be used as a standalone web server.

Undertow provides an easy-to-use programming interface and supports a wide range of protocols, including HTTP/1.1, HTTP/2, and WebSocket. It also supports Servlet and WebSocket API, making it a popular choice for building modern web applications.

What is Default Server and Default Host in Undertow?

In Undertow, a server represents an instance of Undertow that is running on a specific port. By default, Undertow starts with a single server, which is called the default server. The default server listens on port 8080 and serves HTTP requests.

A host, on the other hand, represents a virtual server that can serve requests for multiple domains or IP addresses. By default, Undertow starts with a single host, which is called the default host. The default host listens on all available network interfaces and serves requests for any domain that is not explicitly defined.

Deploying Applications on Default Server and Default Host

Now that we know what default server and default host are, let’s learn how to deploy applications on them. Here are the steps you need to follow:

Step 1: Build your application

The first step is to build your application as a WAR file. Make sure your application is built using Servlet API 3.1 or higher, as Undertow requires this version.

Step 2: Deploy the WAR file

Once you have built your application, you can deploy it on the default server and default host by copying the WAR file to the deployments directory of your WildFly installation. The deployments directory is located at $WILDFLY_HOME/standalone/deployments.

Undertow will automatically deploy your application and create a context root based on the name of your WAR file. For example, if your WAR file is named “myapp.war”, the context root will be “/myapp”.

Step 3: Access your application

Once your application is deployed, you can access it using the following URL: http://localhost:8080/yourapp. Replace “yourapp” with the name of your WAR file without the .war extension. For example, if your WAR file is named “myapp.war”, the URL will be http://localhost:8080/myapp.

Customizing the Default Server and Default Host

While deploying applications on the default server and default host is easy, you may need to customize them based on your requirements. Here are some common customization options:

Changing the Port

By default, Undertow listens on port 8080. If you want to change the port, you can do so by modifying the standalone.xml file located at $WILDFLY_HOME/standalone/configuration. Look for the following XML snippet:

<socket-binding-group name="standard-sockets" default-interface="public">
<socket-binding name="http" port="8080"/>

You can change the value of the port attribute to the desired port number. Make sure the port is not already in use by another application.

READ ALSO  The Best Free Server Hosting Minecraft for Dev

Creating a New Host

If you want to serve requests for multiple domains or IP addresses, you can create a new host. Here are the steps:

  1. Create a new XML file in the $WILDFLY_HOME/standalone/configuration directory. Name the file after your host, for example, “myhost.xml”.
  2. Add the following XML snippet to the file:
<server xmlns="urn:jboss:domain:4.2">
<extensions>
<extension module="org.jboss.as.clustering.infinispan"/>
</extensions>
<profile>
<subsystem xmlns="urn:jboss:domain:undertow:4.0">
<server name="myhost">
<http-listener name="default" socket-binding="http" redirect-socket="https" enable-http2="true" />
<host name="myhost" alias="mydomain.com">
<location name="/" handler="welcome-content"/>
</host>
<http-invoker security-realm="ManagementRealm"/>
<static-resources>
<external-location name="myhost" path="/opt/static-files/myhost"/>
</static-resources>
</server>
</subsystem>
</profile>
</server>

This XML snippet defines a new server with the name “myhost” and a new HTTP listener with the name “default” and the socket-binding “http”. It also defines a new host with the name “myhost” and the alias “mydomain.com”. Finally, it defines a static resource that serves files from the directory /opt/static-files/myhost.

Once you have created the XML file, start WildFly with the following command:

./bin/standalone.sh -c myhost.xml

WildFly will start with the new host and you can deploy your applications on it as usual.

FAQ

What is the difference between server and host in Undertow?

A server represents an instance of Undertow that is running on a specific port, while a host represents a virtual server that can serve requests for multiple domains or IP addresses.

How do I deploy my application on multiple hosts?

To deploy your application on multiple hosts, you need to create a new XML file for each host and define the host configuration in it. You can then start WildFly with the appropriate XML file for each host.

How do I configure SSL on Undertow?

You can configure SSL on Undertow by adding a security realm, a keystore, and an SSL listener to your server configuration. You can find more information in the Undertow documentation.

Can I use Undertow as a standalone web server?

Yes, you can use Undertow as a standalone web server. You need to download the Undertow distribution from the WildFly website and start it with the appropriate configuration file.

Is Undertow suitable for high-traffic websites?

Undertow is designed to handle high traffic and can be scaled horizontally by adding more servers or hosts. However, performance depends on many factors, including the hardware, the application design, and the traffic patterns.

That’s all for now, Dev. We hope this article has helped you understand how to deploy applications on the default server and default host in Undertow. Let us know if you have any questions!