<chapter id="Installation_Configuration">
    <title>Installation/Configuration</title>

    <para>
        RESTEasy is installed and configured in different ways depending on which environment you are running in.
        If you are running in WildFly, RESTEasy is already bundled and integrated completely
        so there is very little you have to do. If you are running in a different environment, there is some manual
        installation and configuration you will have to do.
    </para>

    <section id="resteasy_modules_in_wildfly">
        <title>RESTEasy modules in WildFly</title>
        <para>
            In WildFly, RESTEasy and the &REST-API; API are automatically loaded into your deployment's classpath
            if and only if you are deploying a &REST-API; application (as determined by the presence
            of &REST-API; annotations). However, only some RESTEasy features are automatically loaded. See Table 3.1.
            If you need any of those libraries which are not loaded automatically, you'll have to bring them in
            with a jboss-deployment-structure.xml file in the WEB-INF directory of your WAR file.  Here's an example:
        </para>
        <programlisting><![CDATA[
<jboss-deployment-structure>
    <deployment>
        <dependencies>
            <module name="org.jboss.resteasy.resteasy-jackson2-provider" services="import"/>
        </dependencies>
    </deployment>
</jboss-deployment-structure>]]></programlisting>
        <para>The <literal>services</literal> attribute must be set to "import" for modules that have default providers
            in a META-INF/services/jakarta.ws.rs.ext.Providers file.
        </para>
        <para>
            To get an idea of which RESTEasy modules are loaded by default when &REST-API; services are deployed, please
            see the table below, which refers to a recent WildFly ditribution patched with the current RESTEasy
            distribution. Clearly, future and unpatched WildFly distributions might differ a bit in terms of modules
            enabled by default, as the container actually controls this too.
        </para>
        <para>
            <table>
            <tgroup cols="3" rowsep="1" colsep="1">
            <thead>
                <row>
                    <entry>
                        Module Name
                    </entry>
                    <entry>
                        Loaded by Default
                    </entry>
                    <entry>
                        Description
                    </entry>

                 </row>
            </thead>
            <tbody>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-atom-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        RESTEasy's atom library
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-cdi
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        RESTEasy CDI integration
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-crypto
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        S/MIME, DKIM, and support for other security formats.
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-jackson2-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        Integration with the JSON parser and object mapper Jackson 2
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-jaxb-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        &XML-BIND-API; integration.
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-core
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        Core RESTEasy libraries for server.
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-client
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        Core RESTEasy libraries for client.
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.jose-jwt
                    </entry>
                    <entry>
                        no
                    </entry>
                    <entry>
                        JSON Web Token support.
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-jsapi
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        RESTEasy's Javascript API
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-json-p-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        JSON parsing API
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-json-binding-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        JSON binding API
                    </entry>
                </row>
                <row>
                    <entry>
                        jakarta.json.bind-api
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        JSON binding API
                    </entry>
                </row>
                <row>
                    <entry>
                        org.eclipse.yasson
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        RI implementation of JSON binding API
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-multipart-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        Support for multipart formats
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-spring
                    </entry>
                    <entry>
                        no
                    </entry>
                    <entry>
                        Spring provider
                    </entry>
                </row>
                <row>
                    <entry>
                        org.jboss.resteasy.resteasy-validator-provider
                    </entry>
                    <entry>
                        yes
                    </entry>
                    <entry>
                        RESTEasy's interface to Hibernate Bean Validation
                    </entry>
                </row>
            </tbody>
            </tgroup>
            </table>
        </para>

        <section id="other_resteasy_modules">
        <title>Other RESTEasy modules</title>
            <para>
                Not all RESTEasy modules are bundled with WildFly. For example,
                <code>resteasy-fastinfoset-provider</code> and <code>resteasy-wadl</code> are not included among the
                modules listed in <xref linkend="resteasy_modules_in_wildfly"/>. If you want
                to use them in your application, you can include them in your WAR as you would if you were
                deploying outside of WildFly. See <xref linkend="standalone_resteasy"/> for more information.
        </para>
        </section>
	    <section id="upgrading-wildfly">
	        <title>Upgrading RESTEasy within WildFly</title>
	        <para>
                RESTEasy is bundled with WildFly. However you may wish to upgrade to the latest version. With
                <ulink url="https://docs.wildfly.org/24/Galleon_Guide.html">Galleon</ulink> this makes upgrading RESTEasy
                in WildFly quite easy.
	        </para>
            <para>
                The first requirement is the WildFly installation is provisioned with Galleon. The simplest way to do
                this for a local installation is with <ulink url="https://docs.wildfly.org/galleon/#_galleon_cli_tool">Galleon CLI</ulink>.
                <programlisting><![CDATA[$ galleon.sh install wildfly:current]]></programlisting>

                To install the RESTEasy upgrade on top of that you simply need to use the tool again with the Maven GAV:
                <programlisting><![CDATA[$ galleon.sh install org.jboss.resteasy:galleon-feature-pack:6.1.0.Beta3]]></programlisting>
            </para>
            <para>
                If you are using Maven to provision WildFly you can simply add the feature pack to your plugin configuration.
                <programlisting><![CDATA[
<plugin>
    <groupId>org.jboss.galleon</groupId>
    <artifactId>galleon-maven-plugin</artifactId>
    <configuration>
        <install-dir>${jboss.home}</install-dir>
        <record-state>true</record-state>
        <log-time>true</log-time>
        <offline>false</offline>
        <feature-packs>
            <feature-pack>
                <groupId>org.jboss.resteasy</groupId>
                <artifactId>galleon-feature-pack</artifactId>
                <version>6.1.0.Beta3</version>
            </feature-pack>
        </feature-packs>
    </configuration>
    <executions>
        <execution>
            <id>server-provisioning</id>
            <phase>generate-test-resources</phase>
            <goals>
                <goal>provision</goal>
            </goals>
        </execution>
    </executions>
</plugin>]]>
                </programlisting>
            </para>
	    </section>
    </section>
    <section>
        <title>Deploying a RESTEasy application to WildFly</title>
        <para>
            RESTEasy is bundled with WildFly and completely integrated as per the requirements of Jakarta EE.
            A &REST-API; application can contain &ENTERPRISE-BEANS; and CDI.
            WildFly scans the WAR file for the &REST-API; services and provider classes packaged in the
            WAR either as POJOs, CDI beans, or &ENTERPRISE-BEANS;.
        </para>
        <para>
            <programlisting><![CDATA[
<web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
</web-app>]]></programlisting>
        </para>
        <para>
            The web.xml can supply to RESTEasy init-params and context-params (see <xref linkend="configuration_switches"/>)
            if you want to tweak or turn on/off any specific RESTEasy feature.
        </para>
        <para>
            When a &lt;servlet-mapping&gt; element is not declared in the web.xml, then a class must be provided
            that implements
            <classname>jakarta.ws.rs.core.Application</classname> class (see <xref linkend="jakarta.ws.rs.core.Application"/>).
            This class must be annotated with the <classname>jakarta.ws.rs.ApplicationPath</classname> annotation.
            If this implementation class returns an empty set for classes and singletons, the WAR will
            be scanned for resource and provider classes as indicated by the presence of &REST-API; annotations.
        </para>
        <programlisting>
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

@ApplicationPath("/root-path")
public class MyApplication extends Application
{
}       </programlisting>

        <para>
            <emphasis role="bold">Note.</emphasis> If the application WAR contains an
            <classname>Application</classname> class (or a subclass thereof)
            which is annotated with an <classname>ApplicationPath</classname> annotation, a web.xml
            file is not required.
            If the application WAR contains an <classname>Application</classname> class but the
            class doesn't have an declare a <classname>@ApplicationPath</classname> annotation, then
            the web.xml must at least a declare a &lt;servlet-mapping&gt; element.
        </para>

        <para>
            <emphasis role="bold">Note.</emphasis> As mentioned in <xref linkend="other_resteasy_modules"/>,
            not all RESTEasy modules are bundled with WildFly. For example,
            resteasy-fastinfoset-provider and resteasy-wadl are not included among the
            modules listed in <xref linkend="resteasy_modules_in_wildfly"/>. If they are required by
            the application, they can be included in the WAR as is done if you were
            deploying outside of WildFly. See <xref linkend="standalone_resteasy"/> for more information.
        </para>

</section>
    <section id="standalone_resteasy">
        <title>Deploying to other servlet containers</title>
        <para>
            If you are using RESTEasy outside of WildFly, in a standalone servlet container like Tomcat or Jetty, for example,
            you will need to include the appropriate RESTEasy jars in your WAR file.  You will need the core classes
            in the resteasy-core and resteasy-client modules, and you may need additional facilities like the resteasy-jaxb-provider module.
            We strongly suggest that you use Maven to build your WAR files as RESTEasy is split into
            a bunch of different modules:
        </para>
        <programlisting><![CDATA[
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-core</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxb-provider</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
]]></programlisting>
        <para>
            You can see sample Maven projects in
            <ulink url="https://github.com/resteasy/resteasy-examples">https://github.com/resteasy/resteasy-examples</ulink>.
        </para>
        <para>
            If you are not using Maven, you can include the necessary jars by hand. If you download
            RESTEasy (from <ulink url="http://resteasy.jboss.org/downloads.html">http://resteasy.jboss.org/downloads.html</ulink>,
            for example) you will get a file like resteasy-&lt;version&gt;-all.zip.
            If you unzip it you will see a lib/ directory that contains the libraries needed by RESTEasy.
            Copy these, as needed, into your /WEB-INF/lib directory. Place your &REST-API; annotated class resources and providers
            within one or more jars within /WEB-INF/lib or your raw class files within /WEB-INF/classes.
        </para>

        <section>
        <title>Servlet 3.0 containers</title>
        <para>
            RESTEasy provides an implementation of the Servlet 3.0 <literal>ServletContainerInitializer</literal>
            integration interface for containers to use in initializing an application.
            The container calls this interface during the application's startup phase.
            The RESTEasy implementation performs automatic scanning for resources and providers,
            and programmatic registration of a servlet.

            RESTEasy's implementation is provided in maven artifact, <literal>resteasy-servlet-initializer</literal>.
            Add this artifact dependency to your project's pom.xml file so the JAR file will be included
            in your WAR file.
        </para>
        <programlisting><![CDATA[
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
]]></programlisting>
        </section>

        <section>
        <title>Older servlet containers</title>
        <para>
            The <literal>resteasy-servlet-initializer</literal> artifact will not work in Servlet versions older than
            3.0.  You'll then have to manually declare the RESTEasy servlet in your WEB-INF/web.xml file of your WAR project,
            and you'll have to use an <classname>Application</classname> class (see <xref linkend="jakarta.ws.rs.core.Application"/>)
            which explicitly lists resources and providers. For example:
        </para>
        <para>
            <programlisting><![CDATA[
<web-app>
    <display-name>Archetype Created Web Application</display-name>

    <servlet>
        <servlet-name>Resteasy</servlet-name>
        <servlet-class>
            org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
        </servlet-class>
        <init-param>
            <param-name>jakarta.ws.rs.Application</param-name>
            <param-value>com.restfully.shop.services.ShoppingApplication</param-value>
        </init-param>
    </servlet>

    <servlet-mapping>
        <servlet-name>Resteasy</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>

</web-app>]]></programlisting>
        </para>
        <para>
            The RESTEasy servlet is responsible for initializing some basic components of RESTEasy.
        </para>
        <para>
            <emphasis role="bold">Note.</emphasis> It is likely that support for pre-3.0 Servlet specifications
            will be deprecated and eliminated eventually.
        </para>
        </section>
    </section>
   <section id="microprofile_config">
        <title>Configuration</title>
        
        <para>
        RESTEasy has two mutually exclusive mechanisms for retrieving configuration parameters
        (see <xref linkend="configuration_switches"/>).
        The classic mechanism depends on context-params and init-params in a web.xml file.
        Alternatively, the Eclipse MicroProfile Config project
        (<ulink url="https://github.com/eclipse/microprofile-config">https://github.com/eclipse/microprofile-config</ulink>)
        provides a flexible parameter retrieval mechanism that RESTEasy will use if the necessary
        dependencies are available. See <xref linkend="configuring_mp_config"/> for more about that. If 
        they are not available, it will fall back to an extended form of the classic mechanism.
        </para>
        
        <section id="resteasy_microprofile_config">
        <title>RESTEasy with MicroProfile Config</title>
        <para>
            In the presence of the Eclipse MicroProfile Config API jar and an implementation
            of the API (see <xref linkend="configuring_mp_config"/>), RESTEasy will use the facilities
            of MicroProfile Config for accessing configuration properties (see <xref linkend="configuration_switches"/>). 
            MicroProfile Config offers to both RESTEasy users and RESTEasy developers a great deal of
            flexibility in controlling runtime configuration.	
        </para>
        
        <para>
            In MicroProfile Config, a <classname>ConfigSource</classname> represents a <classname>Map&lt;String, String&gt;</classname>
            of property names to values, and a <classname>Config</classname> represents a sequence of <classname>ConfigSource</classname>s,
            ordered by priority. The priority of a <classname>ConfigSource</classname> is given by an ordinal (represented by an
            <classname>int</classname>), with a higher value indicating a higher priority. For a given property name, the
            <classname>ConfigSource</classname>s are searched in order until a value is found.
        </para>
        <para>
            MicroProfile Config mandates the presence of the following <classname>ConfigSource</classname>s:
        </para>
        <orderedlist>
            <listitem>a <classname>ConfigSource</classname> based on System.getProperties() (ordinal = 400)</listitem>
            <listitem>a <classname>ConfigSource</classname> based on System.getenv() (ordinal = 300)</listitem>
            <listitem>a <classname>ConfigSource</classname> for each META-INF/microprofile-config.properties file on the ClassPath,
            separately configurable via a config_ordinal property inside each file (default ordinal = 100)</listitem>
        </orderedlist>
        <para>
            Note that a property which is found among the System properties and which is also in the System environment will be assigned
            the System property value because of the relative priorities of the <classname>ConfigSource</classname>s.
        </para>
        <para>
            The set of <classname>ConfigSources</classname> is extensible. For example, smallrye-config
            (<ulink url="https://github.com/smallrye/smallrye-config">https://github.com/smallrye/smallrye-config</ulink>),
            the implementation of the MicroProfile Config specification currently used by RESTEasy, adds the following
            kinds of <classname>ConfigSource</classname>s:
        </para>
        <orderedlist>
            <listitem><classname>PropertiesConfigSource</classname> creates a <classname>ConfigSource</classname> from a
            Java <classname>Properties</classname> object or a Map&lt;String, String&gt; object or a properties file
            (referenced by its URL) (default ordinal = 100).</listitem>
            <listitem><classname>DirConfigSource</classname> creates a <classname>ConfigSource</classname> that will look into a directory
            where each file corresponds to a property (the file name is the property key and its textual content is the property value).
            This <classname>ConfigSource</classname> can be used to read configuration from Kubernetes ConfigMap (default ordinal = 100).</listitem>
            <listitem><classname>ZkMicroProfileConfig</classname> creates a <classname>ConfigSource</classname>ConfigSource that is backed by Apache Zookeeper
            (ordinal = 150).</listitem>
        </orderedlist>
        <para>
            These can be registered programmatically by using an instance of <classname>ConfigProviderResolver</classname>:
        </para>
        <programlisting>
Config config = new PropertiesConfigSource("file:/// ...");
ConfigProviderResolver.instance().registerConfig(config, getClass().getClassLoader());
        </programlisting>
        <para>where <classname>ConfigProviderResolver</classname> is part of the Eclipse API.</para>
        <para>
            If the application is running in Wildfly, then Wildfly provides another set of <classname>ConfigSource</classname>s,
            as described in the "MicroProfile Config Subsystem Configuration" section of the WildFly Admin guide
            (<ulink url="https://docs.wildfly.org/21/Admin_Guide.html#MicroProfile_Config_SmallRye">https://docs.wildfly.org/21/Admin_Guide.html#MicroProfile_Config_SmallRye</ulink>).
        </para>
        <para>
            Finally, RESTEasy automatically provides three more <classname>ConfigSource</classname>s:
        </para>
        <itemizedlist>
            <listitem><classname>org.jboss.resteasy.microprofile.config.ServletConfigSource</classname> represents
            a servlet's &lt;init-param&gt;s from web.xml (ordinal = 60).</listitem>
            <listitem><classname>org.jboss.resteasy.microprofile.config.FilterConfigSource</classname> represents
            a filter's &lt;init-param&gt;s from web.xml (ordinal = 50). (See <xref linkend="filter"/> for more information.)
            </listitem>
            <listitem><classname>org.jboss.resteasy.microprofile.config.ServletContextConfigSource</classname> represents
            &lt;context-param&gt;s from web.xml (ordinal = 40).</listitem>
        </itemizedlist>
        <para>
            <emphasis role="bold">Note. </emphasis>As stated by the MicroProfile Config specification, a special property
            <classname>config_ordinal</classname> can be set within any RESTEasy built-in <classname>ConfigSource</classname>s.
            The default implementation of getOrdinal() will attempt to read this value. If found and a valid integer, the value
            will be used. Otherwise the respective default value will be used.
        </para>
        </section>

        <section>
            <title>Using pure MicroProfile Config</title>
            
            <para>
                The MicroProfile Config API is very simple. A <classname>Config</classname> may be obtained either
                programatically:
            </para>
            
            <programlisting>
Config config = ConfigProvider.getConfig();
            </programlisting>
            
            <para>
                or, in the presence of CDI, by way of injection:
            </para>
            
            <programlisting>
@Inject Config config;
            </programlisting>
            
            <para>
                Once a <classname>Config</classname> has been obtained, a property can be queried. For example,
            </para>
            
            <programlisting>
String s = config.getValue("prop_name", String.class);
            </programlisting>
            
            <para>
                or
            </para>
            
            <programlisting>
String s = config.getOptionalValue("prop_name", String.class).orElse("d'oh");
            </programlisting>
            
            <para>
                Now, consider a situation in which "prop_name" has been set by <code>System.setProperty("prop_name", "system")</code>
                and also by
            </para>
            
            <programlisting>
   &lt;context-param&gt;
      &lt;param-name&gt;prop_name&lt;/param-name&gt;
      &lt;param-value&gt;context&lt;/param-value&gt;
   &lt;/context-param&gt;
            </programlisting>
               
            <para>
                Then, since the system parameter <classname>ConfigSource</classname> has precedence over (has a higher ordinal than)
                <classname>ServletContextConfigSource</classname>, <code>config.getValue("prop_name", String.class)</code> will
                return "system" rather than "context".
            </para>

        </section>
        <section>
            <title>Using RESTEasy's extension of MicroProfile Config</title>
            
            <para>
            RESTEasy offers a general purpose parameter retrieval mechanism which incorporates MicroProfile Config if the necessary
            dependencies are available, and which falls back to an extended version of the classic RESTEasy mechanism 
            (see <xref linkend="classic_config"/>) otherwise.
            </para>
            
            <para>Calling</para>
            
            <programlisting>
ConfigurationFactory.getInstance().getConfiguration()
            </programlisting>
            
            <para>
            will return an instance of org.jboss.resteasy.spi.config.Configuration:
            </para>
            
            <programlisting>
public interface Configuration {

    /**
     * Returns the resolved value for the specified type of the named property.
     *
     * @param name the name of the parameter
     * @param type the type to convert the value to
     * @param &lt;T&gt;  the property type
     *
     * @return the resolved optional value
     *
     * @throws IllegalArgumentException if the type is not supported
     */
    &lt;T&gt; Optional&lt;T&gt; getOptionalValue(String name, Class&lt;T&gt; type);

    /**
     * Returns the resolved value for the specified type of the named property.
     *
     * @param name the name of the parameter
     * @param type the type to convert the value to
     * @param &lt;T&gt;  the property type
     *
     * @return the resolved value
     *
     * @throws IllegalArgumentException         if the type is not supported
     * @throws java.util.NoSuchElementException if there is no property associated with the name
     */
    &lt;T&gt; T getValue(String name, Class&lt;T&gt; type);
}
            </programlisting>
            
        <para>
        For example,
        </para>
        
        <programlisting>
String value = ConfigurationFactory.getInstance().getConfiguration().getOptionalValue("prop_name", String.class).orElse("d'oh");
        </programlisting>
        
        <para>
        If MicroProfile Config is available, that would be equivalent to
        </para>
        
        <programlisting>
String value = ConfigProvider.getConfig().getOptionalValue("prop_name", String.class).orElse("d'oh");
        </programlisting>
        
        <para>
        If MicroProfile Config is not available, then an attempt is made to retrieve the parameter from
        the following sources:
        </para>
        
        <orderedlist>
          <listitem>system variables, followed by</listitem>
          <listitem>environment variables, followed by</listitem>
          <listitem>web.xml parameters, as described in <xref linkend="classic_config"/> </listitem>
        </orderedlist>
        </section>
                
        <section id="configuring_mp_config">
            <title>Configuring MicroProfile Config</title>
            
            <para>
                If an application is running inside Wildfly, then all of the dependencies are automatically available. Outside of
                Wildfly, an application will need the Eclipse MicroProfile API at compile time. In maven, for example, use
            </para>

            <para>
                As of RESTEasy 5.0 you will first need to add the RESTEasy MicroProfile Config dependency.
            </para>

            <programlisting>
        &lt;dependency&gt;
          &lt;groupId&gt;org.jboss.resteasy.microprofile&lt;/groupId&gt;
          &lt;artifactId&gt;microprofile-config&lt;/artifactId&gt;
          &lt;scope&gt;compile&lt;/scope&gt;
        &lt;/dependency&gt;
            </programlisting>

            <para>
                You will also need the MicroProfile Config API and an Implementation, in our case SmallRye.
            </para>
            
            <programlisting>
        &lt;dependency&gt;
            &lt;groupId&gt;org.eclipse.microprofile.config&lt;/groupId&gt;
            &lt;artifactId&gt;microprofile-config-api&lt;/artifactId&gt;
            &lt;scope&gt;compile&lt;/scope&gt;
        &lt;/dependency&gt;
            </programlisting>
            
            <programlisting>
        &lt;dependency&gt;
            &lt;groupId&gt;io.smallrye&lt;/groupId&gt;
            &lt;artifactId&gt;smallrye-config&lt;/artifactId&gt;
            &lt;scope&gt;runtime&lt;/scope&gt;
        &lt;/dependency&gt;
            </programlisting>
        </section>
       
    <section id="classic_config">
    <title>RESTEasy's classic configuration mechanism</title>
    
    <para>
    Prior to the incorporation of MicroProfile Config, nearly all of RESTEasy's parameters were retrieved from
    servlet init-params and context-params. Which ones are available depends on how a web application invokes RESTEasy.
    </para>
    
    <para>
    If RESTEasy is invoked as a servlet, as in
    </para>
    
<programlisting>
&lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;

   &lt;context-param&gt;
      &lt;param-name&gt;system&lt;/param-name&gt;
      &lt;param-value&gt;system-context&lt;/param-value&gt;
   &lt;/context-param&gt;
   
   &lt;servlet&gt;
      &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
      &lt;servlet-class&gt;org.jboss.resteasy.plugins.server.servlet.HttpServlet30Dispatcher&lt;/servlet-class&gt;

      &lt;init-param&gt;
         &lt;param-name&gt;system&lt;/param-name&gt;
         &lt;param-value&gt;system-init&lt;/param-value&gt;
      &lt;/init-param&gt;
      
   &lt;/servlet&gt;

   &lt;servlet-mapping&gt;
      &lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
      &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
   &lt;/servlet-mapping&gt;
&lt;/web-app&gt;
</programlisting>

   <para>
   then the servlet specific init-params and the general context-params are available,
   with the former taking precedence over the latter. For example, the property "system" would
   have the value "system-init".
   </para>

   <para>
   If RESTEasy is invoked by way of a filter (see <xref linkend="filter"/>), as in
   </para>
   
   <programlisting>
&lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;

   &lt;context-param&gt;
      &lt;param-name&gt;system&lt;/param-name&gt;
      &lt;param-value&gt;system-context&lt;/param-value&gt;
   &lt;/context-param&gt;

   &lt;filter&gt;
      &lt;filter-name&gt;Resteasy&lt;/filter-name&gt;
      &lt;filter-class&gt;org.jboss.resteasy.plugins.server.servlet.FilterDispatcher&lt;/filter-class&gt;

      &lt;init-param&gt;
         &lt;param-name&gt;system&lt;/param-name&gt;
         &lt;param-value&gt;system-filter&lt;/param-value&gt;
      &lt;/init-param&gt;

    &lt;/filter&gt;

    &lt;filter-mapping&gt;
        &lt;filter-name&gt;Resteasy&lt;/filter-name&gt;
        &lt;url-pattern&gt;/*&lt;/url-pattern&gt;
    &lt;/filter-mapping&gt;

&lt;/web-app&gt;
   </programlisting>

   <para>
   then the filter specific init-params and the general context-params are available,
   with the former taking precedence over the latter. For example, the property "system" would
   have the value "system-filter".
   </para>

   <para>
   Finally, if RESTEasy is invoked by way of a ServletContextListener (see <xref linkend="listener"/>), as in
   </para>

<programlisting>
&lt;web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee"
         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"&gt;

   &lt;listener&gt;
      &lt;listener-class&gt;
         org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
      &lt;/listener-class&gt;
   &lt;/listener&gt;

   &lt;context-param&gt;
      &lt;param-name&gt;system&lt;/param-name&gt;
      &lt;param-value&gt;system-context&lt;/param-value&gt;
   &lt;/context-param&gt;
&lt;/web-app&gt;
</programlisting>
 
    <para>
    where <classname>ResteasyBootstrap</classname> is a <classname>ServletContextListener</classname>,
    then the context-params are available.
    </para>
    </section>
   
    <section id="overriding_config">
    <title>Overriding RESTEasy's configuration mechanism</title>
    
    <para>
    Before adopting the default behavior, with or without MicroProfile Config, as described in 
    previous sections, RESTEasy will use service loading to look for one or more implementations of
    the interface <classname>org.jboss.resteasy.spi.config.ConfigurationFactory</classname>, selecting one
    with the highest priority as determined by the value returned by 
    <methodname>ConfigurationFactory.priority()</methodname>. Smaller numbers indicate higher priority.
    The default <classname>ConfigurationFactory</classname> is
    <classname>org.jboss.resteasy.core.config.DefaultConfigurationFactory</classname> with a priority of 500.
    </para>
    </section>
    </section>
     
    <section id="configuration_switches">
        <title>Configuration switches</title>
        <para>RESTEasy can receive the following configuration options from any <classname>ConfigSource</classname>s
        that are available at runtime:
        </para>
        <para>
            <table frame="topbot">
                <tgroup cols="3" rowsep="1" colsep="1">
                    <thead>
                        <row>
                            <entry>
                                Option Name
                            </entry>
                            <entry>
                                Default Value
                            </entry>
                            <entry>
                                Description
                            </entry>
                        </row>
                    </thead>
                    <tbody>
                        <row>
                            <entry>
                                resteasy.servlet.mapping.prefix
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                If the url-pattern for the RESTEasy servlet-mapping is not /*
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.providers
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                A comma delimited list of fully qualified @Provider class names you want to register
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.use.builtin.providers
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                Whether or not to register default, built-in @Provider classes
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.resources
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                A comma delimited list of fully qualified &REST-API; resource class names you want to
                                register
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.jndi.resources
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                A comma delimited list of JNDI names which reference objects you want to register as
                                &REST-API; resources
                            </entry>
                        </row>
                        <row>
                            <entry>
                                jakarta.ws.rs.Application
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                Fully qualified name of Application class to bootstrap in a spec portable way
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.media.type.mappings
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                Replaces the need for an Accept header by mapping file name extensions (like .xml or
                                .txt) to a media type. Used when the client
                                is unable to use an Accept header to choose a representation (i.e. a browser). See
                                <xref linkend="Jakarta_REST_Content_Negotiation"/> for more details.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.language.mappings
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                Replaces the need for an Accept-Language header by mapping file name extensions (like
                                .en or .fr) to a language. Used when the client
                                is unable to use an Accept-Language header to choose a language (i.e. a browser). See
                                <xref linkend="Jakarta_REST_Content_Negotiation"/> for more details.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.media.type.param.mapping
                            </entry>
                            <entry>
                                no default
                            </entry>
                            <entry>
                                Names a query parameter that can be set to an acceptable media type,
                                enabling content negotiation without an Accept header. See
                                <xref linkend="Jakarta_REST_Content_Negotiation"/> for more details.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.role.based.security
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Enables role based security. See <xref linkend="Securing_Jakarta_REST_and_RESTeasy"/>
                                for more details.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.document.expand.entity.references
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Expand external entities in org.w3c.dom.Document documents
                                and &XML-BIND-API; object representations
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.document.secure.processing.feature
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                Impose security constraints in processing org.w3c.dom.Document documents
                                and &XML-BIND-API; object representations
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.document.secure.disableDTDs
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                Prohibit DTDs in org.w3c.dom.Document documents
                                and &XML-BIND-API; object representations
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.wider.request.matching
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Turns off the &REST-API; spec defined class-level expression filtering and instead
                                tries to match version every method's full path.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.use.container.form.params
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Obtain form parameters by using HttpServletRequest.getParameterMap().
                                Use this switch if you are calling this method within a servlet filter or eating
                                the input stream within the filter.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.rfc7232preconditions
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Enables <link linkend='Http_Precondition'>RFC7232 compliant HTTP preconditions handling</link>.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.gzip.max.input
                            </entry>
                            <entry>
                                10000000
                            </entry>
                            <entry>
                                Imposes maximum size on decompressed gzipped .
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.secure.random.max.use
                            </entry>
                            <entry>
                                100
                            </entry>
                            <entry>
                                The number of times a SecureRandom can be used before reseeding.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.buffer.exception.entity
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                Upon receiving an exception, the client side buffers any response
                                entity before closing the connection.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.add.charset
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                If a resource method returns a text/* or application/xml* media type without
                                an explicit charset, RESTEasy will add "charset=UTF-8" to the returned
                                Content-Type header. Note that the charset defaults to UTF-8 in this case,
                                independent of the setting of this parameter.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.disable.html.sanitizer
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Normally, a response with media type "text/html" and a status of 400 will be processed
                                so that the characters "/", "&lt;", "&gt;", "&amp;", """ (double quote), and "'" (single quote)
                                are escaped to prevent an XSS attack. If this parameter is set to "true", escaping
                                will not occur.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.patchfilter.disabled
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                Turns off the default patch filter to handle JSON patch and JSON Merge Patch request. 
                                A customerized patch method filter can be provided to serve the JSON patch and JSON merge
                                patch request instead.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.patchfilter.legacy
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                Set this value to false, the jsonp provider will be activated to provide
                                PatchFilter for Json patch or Json Merge patch functionalities. By default(true value),
                                the Jackson provider will be used.
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.original.webapplicationexception.behavior
                            </entry>
                            <entry>
                                false
                            </entry>
                            <entry>
                                When set to "true", this parameter will restore the original behavior in which
                                a Client running in a resource method will throw a &REST-API; WebApplicationException
                                instead of a Resteasy version with a sanitized <classname>Response</classname>. For more information,
                                see section <link linkend='ResteasyWebApplicationException'>Resteasy WebApplicationExceptions</link>
                            </entry>
                        </row>
                    </tbody>
                </tgroup>
            </table>
        </para>
        <para>
            <emphasis role="bold">Note. </emphasis>
            The resteasy.servlet.mapping.prefix &lt;context param&gt; variable must be set if your servlet-mapping for
            the RESTEasy servlet has a url-pattern other than /*. For example, if the url-pattern is
        </para>
        <para>
            <programlisting>
&lt;servlet-mapping&gt;
&lt;servlet-name&gt;Resteasy&lt;/servlet-name&gt;
&lt;url-pattern&gt;/restful-services/*&lt;/url-pattern&gt;
&lt;/servlet-mapping&gt;</programlisting>
        </para>
        <para>
            Then the value of resteasy.servlet.mapping.prefix must be:
        </para>
        <para>
            <programlisting>
&lt;context-param&gt;
&lt;param-name&gt;resteasy.servlet.mapping.prefix&lt;/param-name&gt;
&lt;param-value&gt;/restful-services&lt;/param-value&gt;
&lt;/context-param&gt;</programlisting>
        </para>

        <para>
            Resteasy internally uses a cache to find the resource invoker for the request url. This cache
            size and enablement can be controlled with these system properties.
        </para>
        <para>
            <table frame="topbot">
                <tgroup cols="3" rowsep="1" colsep="1">
                    <thead>
                        <row>
                            <entry>
                                System Property Name
                            </entry>
                            <entry>
                                Default Value
                            </entry>
                            <entry>
                                Description
                            </entry>
                        </row>
                    </thead>
                    <tbody>
                        <row>
                            <entry>
                                resteasy.match.cache.enabled
                            </entry>
                            <entry>
                                true
                            </entry>
                            <entry>
                                If the match cache is enabled or not
                            </entry>
                        </row>
                        <row>
                            <entry>
                                resteasy.match.cache.size
                            </entry>
                            <entry>
                                2048
                            </entry>
                            <entry>
                                The size of this match cache
                            </entry>
                        </row>
                    </tbody>
                </tgroup>
            </table>
        </para>
    </section>
    <section id="jakarta.ws.rs.core.Application">
        <title>jakarta.ws.rs.core.Application</title>

        <para>

            The <classname>jakarta.ws.rs.core.Application</classname> class is a standard &REST-API; class that you may implement to provide
            information on your deployment. It is simply a class the lists all &REST-API; root resources and providers.
        </para>
        <para>

            <programlisting>
/**
* Defines the components of a &REST-API; application and supplies additional
* metadata. A &REST-API; application or implementation supplies a concrete
* subclass of this abstract class.
*/
public abstract class Application
{
    private static final Set&lt;Object&gt; emptySet = Collections.emptySet();

    /**
    * Get a set of root resource and provider classes. The default lifecycle
    * for resource class instances is per-request. The default lifecycle for
    * providers is singleton.
    * &lt;p/&gt;
    * &lt;p&gt;Implementations should warn about and ignore classes that do not
    * conform to the requirements of root resource or provider classes.
    * Implementations should warn about and ignore classes for which
    * {@link #getSingletons()} returns an instance. Implementations MUST
    * NOT modify the returned set.&lt;/p&gt;
    *
    * @return a set of root resource and provider classes. Returning null
    * is equivalent to returning an empty set.
    */
    public abstract Set&lt;Class&lt;?&gt;&gt; getClasses();

    /**
    * Get a set of root resource and provider instances. Fields and properties
    * of returned instances are injected with their declared dependencies
    * (see {@link Context}) by the runtime prior to use.
    * &lt;p/&gt;
    * &lt;p&gt;Implementations should warn about and ignore classes that do not
    * conform to the requirements of root resource or provider classes.
    * Implementations should flag an error if the returned set includes
    * more than one instance of the same class. Implementations MUST
    * NOT modify the returned set.&lt;/p&gt;
    * &lt;p/&gt;
    * &lt;p&gt;The default implementation returns an empty set.&lt;/p&gt;
    *
    * @return a set of root resource and provider instances. Returning null
    * is equivalent to returning an empty set.
    */
    public Set&lt;Object&gt; getSingletons()
    {
        return emptySet;
    }

}            </programlisting>
        </para>
        <para>


        </para>

        <para>

        </para>
        <para>
            <emphasis role="bold">Note. </emphasis>If your web.xml file does not have a
            &lt;servlet-mapping&gt; element, you must use an <classname>Application</classname> class
            annotated with <classname>@ApplicationPath</classname>.

        </para>
    </section>

    <section id="listener">
        <title>RESTEasy as a ServletContextListener</title>

        <para>
            This section is pretty much deprecated if you are using a Servlet 3.0 container or higher.  Skip it if
            you are and read the configuration section above on installing in Servlet 3.0.
            The initialization of RESTEasy can be performed within a ServletContextListener instead of within the
            Servlet. You may need this if you are writing custom Listeners that need to interact with RESTEasy at boot
            time. An example of this is the RESTEasy Spring integration that requires a Spring ServletContextListener.
            The org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap class is a ServletContextListener that
            configures an instance of an ResteasyProviderFactory and Registry. You can obtain instances of a
            ResteasyProviderFactory and Registry from the ServletContext attributes
            org.jboss.resteasy.spi.ResteasyProviderFactory and org.jboss.resteasy.spi.Registry. From these instances you
            can programmatically interact with RESTEasy registration interfaces.
        </para>

        <programlisting><![CDATA[
<web-app>
   <listener>
      <listener-class>
         org.jboss.resteasy.plugins.server.servlet.ResteasyBootstrap
      </listener-class>
   </listener>

  <!-- ** INSERT YOUR LISTENERS HERE!!!! -->

   <servlet>
      <servlet-name>Resteasy</servlet-name>
      <servlet-class>
         org.jboss.resteasy.plugins.server.servlet.HttpServletDispatcher
      </servlet-class>
   </servlet>

   <servlet-mapping>
      <servlet-name>Resteasy</servlet-name>
      <url-pattern>/Resteasy/*</url-pattern>
   </servlet-mapping>

</web-app>]]></programlisting>
    </section>
    <section id="filter">
        <title>RESTEasy as a Servlet Filter</title>

        <para>
            This section is pretty much deprecated if you are using a Servlet 3.0 container or higher.  Skip it if
            you are and read the configuration section above on installing in Servlet 3.0.
            The downside of running RESTEasy as a Servlet is that you cannot have static resources like .html and .jpeg
            files in the
            same path as your &REST-API; services. RESTEasy allows you to run as a Filter instead. If a &REST-API; resource is
            not
            found under the URL requested, RESTEasy will delegate back to the base servlet container to resolve URLs.
        </para>

        <programlisting><![CDATA[
<web-app>
    <filter>
        <filter-name>Resteasy</filter-name>
        <filter-class>
            org.jboss.resteasy.plugins.server.servlet.FilterDispatcher
        </filter-class>
        <init-param>
            <param-name>jakarta.ws.rs.Application</param-name>
            <param-value>com.restfully.shop.services.ShoppingApplication</param-value>
        </init-param>
    </filter>

    <filter-mapping>
        <filter-name>Resteasy</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

</web-app>]]></programlisting>
    </section>

    <section>
    <title>Client side</title>

    <para>
        &REST-API; conforming implementations, such as RESTEasy, support a client side framework which simplifies
        communicating with restful applications. In RESTEasy, the minimal set of modules needed for the client framework
        consists of resteasy-core and resteasy-client. You can access them by way of maven:
    </para>

<programlisting><![CDATA[
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-core</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>6.1.0.Beta3</version>
</dependency>
]]></programlisting>

    <para>
        Other modules, such as resteasy-jaxb-provider, may be brought in as needed.
    </para>

    </section>
</chapter>

