Whitespace in JBoss web.xml is not preserved

Solution Verified - Updated -

Environment

  • JBoss Enterprise Application Platform (EAP)

Issue

  • The org.jboss.metadata.javaee.spec.ParamValueMetaData is annotated as follows:
    <snip>
    
    @XmlType(name="param-valueType", propOrder={"descriptions", "paramName", "paramValue"})
    @JBossXmlType(modelGroup=JBossXmlConstants.MODEL_GROUP_UNORDERED_SEQUENCE)
    public class ParamValueMetaData extends IdMetaDataImplWithDescriptions
    {
      private static final long serialVersionUID = 1;
    
      private String paramName;
      private String paramValue;
    
      public String getParamName()
      {
          return paramName;
      }
      @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
      public void setParamName(String paramName)
      {
          this.paramName = paramName;
      }
      public String getParamValue()
      {
          return paramValue;
      }
      @XmlJavaTypeAdapter(CollapsedStringAdapter.class)
      public void setParamValue(String paramValue)
      {
          this.paramValue = paramValue;
      }
    
    </snip>
    
  • Notice in particular the "@XmlJavaTypeAdapter(CollapsedStringAdapter.class)" annotation on the setParamValue field. Because of this, JBossXB code (used by the AS Tomcat code for web.xml parsing) will actively strip all whitespace, tabs, and LFs from <param-value> element values contained within web.xml (see: org.jboss.xb.builder.runtime.BeanHandler:205).
  • This makes it impossible to preserve significant whitespace/LFs even where desired, appropriate, and valid in terms of XML.
  • An additional side effect of this behavior is that CDATA is not respected.

Resolution

This is per the servlet spec. For example, section 13.2 of the 2.5 spec:

"Web containers must remove all leading and trailing whitespace, which is defined as “S (white space)” in XML 1.0 (http://www.w3.org/TR/2000/WD-xml-2e-20000814), for the element content of the text nodes of a deployment descriptor."

This solution is part of Red Hat’s fast-track publication program, providing a huge library of solutions that Red Hat engineers have created while supporting our customers. To give you the knowledge you need the instant it becomes available, these articles may be presented in a raw and unedited form.

Comments