Quarkus includes the "undertow" extension which can be easily triggered as you include a JAXRS dependency in your project. We will see in this tutorial which are the most common settings you can apply to a Quarkus application to configure the embedded Undertow server.

First of all let's specify how you can set configuration parameters on Quarkus. You have two main options:

  • Pass parameters on the Command Line using -D
  • Include parameters in the the application.properties file

Configuring HTTP Port

The most basic setting is the default HTTP Port, which can be overridden as follows in the application.properties file:

quarkus.http.port=9080

Configuring Host name

Here is how you can configure in the application.properties file the Host where the application will be bound ("Default is 0.0.0.0"):

quarkus.http.host=acme.com

Configuring HTTPS Port

In order to configure the secure port used for https connections, you can use this setting:

quarkus.http.ssl-port=8443

Configuring HTTP Test Port

Quarkus tests by default run on port 8081 to avoid conflict with the HTT Port. You can can configure the port used by tests by setting quarkus.http.test-port as follows:

quarkus.http.test-port=8088

Configuring the Context Path

Another common setting is the Context Path, which defaults to the Root Context ("/"). Here is how to set it to a custom value:

quarkus.servlet.context-path=/webcontext

Configuring CORS 

Cross-origin resource sharing is a mechanism that allows some restricted resources on a web page to be requested from another domain outside the domain from which the first resource was served. In order to enable Cross-origin resource sharing you need to set the quarkus.http.cors property to true, which enables it through a Servlet Filter. Then, you can fine tune the CORS policy to allow specific headers or HTTP methods to be allowed.

Here is a fully configured application.properties which allows all HTTP methods from the site acme.com:

quarkus.http.cors=true
quarkus.http.cors.origins=http://foo.com,http://www.acme.com
quarkus.http.cors.methods=GET,PUT,POST,DELETE
quarkus.http.cors.headers=X-Custom
quarkus.http.cors.exposed-headers=Content-Disposition

Configuring IO Threads

The number if IO threads used to perform IO in Quarkus will be automatically set to a reasonable value based on the number of CPU cores. You can configure it using the following property:

quarkus.http.io-threads=5

Configuring HTTPS with Quarkus

You can configure secure connections for Web applications either with a PEM certificate or using a Keystore. Let's see how to configure a keystore. First generate a self-signed keystore:

keytool -genkey -keyalg RSA -alias demo -keystore keystore.jks -storepass mypassword -validity 365 -keysize 2048

Then, provide in your configuration file a reference to the keystore and its password:

quarkus.http.ssl.certificate.key-store-file=/path/to/keystore.jks
quarkus.http.ssl.certificate.key-store-password=mypassword

In order to configure the secure port used for https connections, you can use this setting:

quarkus.http.ssl-port=8443

 

 

0
0
0
s2sdefault