Using Windup's xpath-value rule to check for non-default values.
Posted by rsearls in JBoss AS on Oct 16, 2013 10:30:00 AMHere is an example of a Windup xpath-value rule checking XML statements for non-default values. Most users only write rules to flag a statement when a specific value is found. The example is doing the opposite.
Here is the XML that the rule will evaluate.
<Server>
<Service>
<!-- +++ This element is using all the default values. +++ -->
<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />
<!-- +++ This element is using a non-default port number. +++ -->
<Connector port="5995" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />
</Service>
</Server>
The first connector statement is using all the default values of the element. The second connector is using a custom port. I am going to provide a rule that determines that the first connector is using all the default settings and therefore will not be flagged, but flags the second connector as needing attention because a non-default value was found.
Here is the rule. It uses a fairly complex XPath construct but it does the job.
<windup:xpath-value
description="A custom connector attribute setting has been detected."
xpath="//Server/Service/Connector[@protocol = 'AJP/1.3'
and @port != '8009'
or @address != '${jboss.bind.address}'
or @emptySessionPath != 'true'
or @enableLookups != 'false'
or @redirectPort != '8443']"
inline="true" effort="1">
</windup:xpath-value>
If I was only interested in the connectors in a named service?
<Server>
<Service name="jboss.web">
<!-- +++ This element is using all the default values. +++ -->
<Connector port="8009" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />
<!-- +++ This element is using a non-default port number. +++ -->
<Connector port="5995" address="${jboss.bind.address}" protocol="AJP/1.3"
emptySessionPath="true" enableLookups="false" redirectPort="8443" />
</Service>
</Server>
The rule would be
<windup:xpath-value
description="A custom connector attribute setting has been detected."
xpath="//Server/Service[@name = 'jboss.web']/Connector[@protocol = 'AJP/1.3'
and @port != '8009'
or @address != '${jboss.bind.address}'
or @emptySessionPath != 'true'
or @enableLookups != 'false'
or @redirectPort != '8443']"
inline="true" effort="1">
</windup:xpath-value>
If I was interested only in services not named 'jboss.web'?
<Server>
<Service name="my.new.web">
.....
</Service>
</Server>
The rule would be
<windup:xpath-value
description="A custom connector attribute setting has been detected."
xpath="//Server/Service[@name != 'jboss.web']/Connector[@protocol = 'AJP/1.3'
and @port != '8009'
or @address != '${jboss.bind.address}'
or @emptySessionPath != 'true'
or @enableLookups != 'false'
or @redirectPort != '8443']"
inline="true" effort="1">
</windup:xpath-value>
Comments