Search code examples
eclipsewebserverjettyapplication-serverjetty-10

How to modify jetty-home-11.0.6\etc\*.xml files


I am updating Jetty9 to Jetty11 and Understood the concept of Jetty-Home and Jetty-Base directory. and my question is how to modify the below files as Jeety-Home is the read-only directory and should not update in the Jetty-Home directory.

  1. etc\jetty.XML
  2. etc\webdefault.XML
  3. etc\jetty-requestlog.xml
  4. lib\jetty-http-11.0.6.jar\org\eclipse\jetty\http (To add MimeTypes)

I was reading about the custom Jetty module concept but couldn't get much information. Is this the way to do it ? Please share reference docs if any

I used to modify the above-mentioned files directly in jetty-distribution-9.4.43.v20210629.

Exa :- I have to modify the below attributes like

1. jetty.httpConfig.sendServerVersion to false in etc\jetty.xml
2. Increased the query params to 10000 in etc\jetty.xml.
        <Call name="setAttribute">
            <Arg>org.eclipse.jetty.server.Request.maxFormKeys</Arg>
            <Arg>10000</Arg>
        </Call>
3. set development mode to false in etc\webdefault.xml  
<init-param>
 <param-name>development</param-name>
 <param-value>false</param-value>
</init-param>
4. add below MIME Types in mime.properties file under lib\jetty-http-11.0.6.jar\org\eclipse\jetty\http folder
     appcache=text/cache-manifest
     ttf=application/font-sfnt

Solution

  • As you will see, you have changed nothing in your ${jetty.home} directory in order to accomplish your end goals.

    1. jetty.httpConfig.sendServerVersion to false in etc\jetty.xml

    That's a property, just define the value you want in your appropriate ${jetty.base}/start.d/*.ini file.

    1. Increased the query params to 10000 in etc\jetty.xml.
           <Call name="setAttribute">
               <Arg>org.eclipse.jetty.server.Request.maxFormKeys</Arg>
               <Arg>10000</Arg>
           </Call>
    

    That won't work as a Server property or attribute.

    If you want to configure maxFormKeys, you do that for the specific webapp and/or context.

    Use the documented XML deployable for your webapp and set the maxFormKeys

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
      ... other configuration for your webapp ...
      <Set name="maxFormContentSize">400000</Set>
      <Set name="maxFormKeys">400</Set>
    </Configure>
    
    1. set development mode to false in etc\webdefault.xml
    <init-param>
      <param-name>development</param-name>
      <param-value>false</param-value>
    </init-param>
    
    1. add below MIME Types in mime.properties file under lib\jetty-http-11.0.6.jar\org\eclipse\jetty\http folder
        appcache=text/cache-manifest
        ttf=application/font-sfnt
    

    For both of these, the correct place to configure them is your webapp specific descriptor.

    Note: that the mime.properties defines the MimeTypes defaults, and the values in MimeTypes are only used for serving static content from the DefaultServlet.

    For custom descriptor behavior, you configure that in your specific webapp and/or context.

    You can:

    1. declare the entire new default descriptor with <Set name="defaultsDescriptor">...location...</Set>
    2. or provide a replacement descriptor to apply after the default descriptor, which is just a diff of changes from the default descriptor. <Set name="overrideDescriptor">...location...</Set>
    3. or provide that entries you want in your WEB-INF/web.xml descriptor.

    For option 1 (this approach is not recommended, as you are stomping on the version in jetty itself, and wont get fixes/updates/improvements that come with newer versions of Jetty), copy the entire contents of webdefault.xml into a new file in your ${jetty.base}/etc/, and reference it in your XML deployable ${jetty.base}/webapps/<name>.xml like this ...

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
    
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
      ... other configuration for your webapp ...  
      <Set name="defaultsDescriptor"><Property name="jetty.base" default="."/>/etc/custom-default-descriptor.xml</Set>
    </Configure>
    

    For option 2 (best server level option) ${jetty.base}/etc/override-web.xml
    and option 3 (most correct use of servlet spec) WEB-INF/web.xml the descriptor is only the differences from default, and would looks like this...

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app 
       xmlns="http://xmlns.jcp.org/xml/ns/javaee" 
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
       metadata-complete="false"
       version="3.1" >
    
      <servlet id="jsp">
        <servlet-name>jsp</servlet-name>
        <init-param>
          <param-name>development</param-name>
          <param-value>false</param-value>
        </init-param>
      </servlet>
    
      <mime-mapping>
        <extension>appcache</extension>
        <mime-type>text/cache-manifest</mime-type>
      </mime-mapping>
      <mime-mapping>
        <extension>ttf</extension>
        <mime-type>application/font-sfnt</mime-type>
      </mime-mapping>
    </web-app>
    

    For option 2, you reference it in your ${jetty.base}/webapps/<name>.xml like this ...

    <?xml version="1.0"?>
    <!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_10_0.dtd">
    
    <Configure class="org.eclipse.jetty.webapp.WebAppContext">
      ... other configuration for your webapp ...  
      <Set name="overrideDescriptor"><Property name="jetty.base" default="."/>/etc/override-web.xml</Set>
    </Configure>