1 Reply Latest reply on Feb 3, 2006 4:26 AM by twenckebach

    Using XSLTFileDelegate parameter in binding manager

    twenckebach

      Hello,
      I`d like to pass a parameter other than host or port to a stylesheet in my binding manager xml input file (JBoss4.0.3 SP1). In particular, I want to be able to specify the AJP port explicitely, rather then by computing a difference from HTTP port as in the standard example.
      This should work using the the following syntax (quote from admin guide):


      <delegate-config>
      <xslt-config configName="ConfigurationElement"><![CDATA[
      Any XSL document contents...
      ]]>
      </xslt-config>
      <xslt-param name="param-name">param-value</xslt-param>
      <!-- ... -->
      </delegate-config>

      The parameter name and value is indeed submitted to the transformer as can be seen in XSLTConfigDelegate.java:
       // xslt-param are transform parameters
       for(int a = 0; a < attributes.getLength(); a ++)
       {
       Element attr = (Element) attributes.item(a);
       String name = attr.getAttribute("name");
       if( name.length() == 0 )
       throw new IllegalArgumentException("attribute element #"
       +a+" has no name attribute");
       String attrExp = MetaData.getElementContent(attr);
       String attrValue = StringPropertyReplacer.replaceProperties(attrExp);
       transformer.setParameter(name, attrValue);
      
       log.debug("set "+name+" parameter to:"+attrValue);
       }
      


      However, I found no way of getting the parameter passing to work. Interestingly, I can state that the parameters declared in the script are not totally ignored - this is verified by using a default value via

      <xsl:param name="portAJP" select="9999"/>

      This will always result in usage of port 9999, though, even if I actually pass a parameter. If I don`t use the default, like

      <xsl:param name="portAJP"/>

      the port is assigned to 8009 - my script is pointless.
      My actual xml file looks as follows:

      <service-config name="jboss.web:service=WebServer"
      delegateClass="org.jboss.services.binding.XSLTFileDelegate"
      >
      <delegate-config>
      <xslt-config configName="ConfigFile"><![CDATA[
      <xsl:stylesheet
      xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'>

      <xsl:output method="xml" />
      <xsl:param name="port"/>
      <xsl:param name="portAJP"/>

      <xsl:variable name="portHttps" select="$port + 363"/>

      <xsl:template match="/">
      <xsl:apply-templates/>
      </xsl:template>

      <xsl:template match = "Connector">
      <Connector>
      <xsl:for-each select="@*">
      <xsl:choose>
      <xsl:when test="(name() = 'port' and . = '8080')">
      <xsl:attribute name="port"><xsl:value-of select="$port" /></xsl:attribute>
      </xsl:when>
      <xsl:when test="(name() = 'port' and . = '8009')">
      <xsl:attribute name="port"><xsl:value-of select="$portAJP" /></xsl:attribute>
      </xsl:when>
      <xsl:when test="(name() = 'redirectPort')">
      <xsl:attribute name="redirectPort"><xsl:value-of select="$portHttps" /></xsl:attribute>
      </xsl:when>
      <xsl:when test="(name() = 'port' and . = '8443')">
      <xsl:attribute name="port"><xsl:value-of select="$portHttps" /></xsl:attribute>
      </xsl:when>
      <xsl:otherwise>
      <xsl:attribute name="{name()}"><xsl:value-of select="." /></xsl:attribute>
      </xsl:otherwise>
      </xsl:choose>
      </xsl:for-each>
      <xsl:apply-templates/>
      </Connector>
      </xsl:template>

      <xsl:template match="*|@*">
      <xsl:copy>
      <xsl:apply-templates select="@*|node()"/>
      </xsl:copy>
      </xsl:template>
      </xsl:stylesheet>
      ]]>
      </xslt-config>
      <xslt-param name="portAJP">9999</xslt-param>
      </delegate-config>
      <binding port="5555"/>
      </service-config>


      Thanks a lot
      - regards, Thomas

        • 1. Re: Using XSLTFileDelegate parameter in binding manager
          twenckebach

          Hello,
          in the meantime I looked into the sources more closely. I discovered that in contrast to the statement in the adminguide text, the binding-manager example for manipulating tomcat`s server.xml does NOT use XSLTConfigDelegate but XSLTFileDelegate. The latter is structured very similar but the processing of xslt-param is simply missing. For testing purposes, I completed the code to contain the following passage:

           // [...]
           if (host != null)
           {
           transformer.setParameter("host", host);
           }
          
           // +++++++++++++ MY TEST BEGIN
           // Check for any arbitrary attributes
           NodeList attributes = delegateConfig.getElementsByTagName("xslt-param");
           // xslt-param are transform parameters
           for(int a = 0; a < attributes.getLength(); a ++)
           {
           Element attr = (Element) attributes.item(a);
           String name = attr.getAttribute("name");
           if( name.length() == 0 )
           throw new IllegalArgumentException("attribute element #"
           +a+" has no name attribute");
           String attrExp = MetaData.getElementContent(attr);
           String attrValue = StringPropertyReplacer.replaceProperties(attrExp);
           transformer.setParameter(name, attrValue);
          
           log.debug("set "+name+" parameter to:"+attrValue);
           }
           // +++++++++++++ MY TEST END
          
          
           transformer.transform(xmlSource, xmlResult);
           // [...]
          

          I will submit these results (both code and adminguide) as a bug.

          Regards, Thomas