9 Replies Latest reply on Dec 4, 2015 12:29 AM by khantariquealam

    Global valve-like construction in Wildfly

    ht-arosii

      Hi,

       

      We have enjoyed the JBoss 6 concept of a global valve. This feature enabled us to log certain attributes from HTTP requests. We were able to setup a valve in such a way, that parts of the body along with headers could be parsed and logged without interfering with what the deployed application saw.

       

      We are now considering upgrading to Wildfly, but we would like to have a similar mechanism for logging. So the question is: does Wildfly have a similar concept or other means of achieving the same functionality. One solution would be to modify the Wildfly Undertow extension, but I rather not have a patched version of Wildfly running.

       

      We would also like not to have to modify the deployed applications. These are delivered from various contractors, and this would create an overhead for us on each new release of these applications.

        • 1. Re: Global valve-like construction in Wildfly
          ctomc

          Hey,

           

          in undertow now you can write your own HttpHandler which is similar to what Valve used to be in jbossweb/tomcat times.

           

          Easiest way to modify the deployment to add your own ServletExtension http://undertow.io/documentation/servlet/using-non-blocking-handlers-with-servlet.html

          that can then add as many handlers as you want and much more.

           

          Given that we currently do not have support for defining global handlers / servlet extensions for all deployments, you would need to do a trick to make it work for your case.

          At least until we do have such capability in undertow subsystem.

           

          Create your http handler(s) and ServletExtension, package it into jboss module, then define your module as global module, but make sure that you also enable meta inf and services from it.

           

          something along this lines:

           

          <global-modules>

                <module name="my.module.name" meta-inf="true" services="true"/>

          </global-modules>

           

          this will expose your module to all deployments and when deployments will be processed ServletExtension will be loaded.

           

          Let me know if this works for you.

           

          --

          tomaz

          • 2. Re: Global valve-like construction in Wildfly
            ht-arosii

            Hi,

             

            Thank you very much for the answer. The proposed solution does indeed work for me.

             

            Here are some items I noted when trying out the solution:

             

            • The addPath method on the PathHandler is deprecated.
            • The <global-modules> was put under the parent element <subsystem xmlns="urn:jboss:domain:ee:2.0"> in the standalone.xml file.
            • The extension class (ServletExtension) is loaded only once even in the presence of multiple deployed applications (I am not very familiar with jboss modules, so this might be obvious to others)
            • The extension class is however instantiated once for each deployed application.

             

            This is exactly was I was looking for. Porting the old valve implementation will now be an easy task.

            • 3. Re: Global valve-like construction in Wildfly
              kbabu

              Hi Henrik,

              I am working on similar one,  trying to configure valves in wildFly8 (from http://jamonapi.sourceforge.net/http_monitoring.html). I have placed module.xml and jamon.jar at D:\wildfly-8.1.0.Final\modules\system\layers\base\com\jamonapi\http\main. could you please help me out to set further of the following?

               

                • JBoss 4.0.5/4.2 - Other versions may work too.
                  • Add the following Valve line to Tomcat's server.xml file (i.e. jbossweb-tomcat55.sar/server.xml). The 'Engine' line is used to show context.

              <Engine name="Catalina" defaultHost="localhost">
              <Valve className="com.jamonapi.http.JAMonTomcatValve"/>

               

              My module.xml contains the following :

               

              <module xmlns="urn:jboss:module:1.3" name="com.jamonapi.http">

                  <properties>

                      <property name="jboss.api" value="private"/>

                  </properties>

                  <resources>

                      <resource-root path="jamon-2.79.jar"/>

                  </resources>

              </module>

              • 4. Re: Global valve-like construction in Wildfly
                ctomc

                As an update, support for configuring global handlers was added to 9 and 8.2 for more details see [WFLY-3697] Custom http handlers support - JBoss Issue Tracker

                • 5. Re: Global valve-like construction in Wildfly
                  valsaraj007

                  Great!

                  • 6. Re: Global valve-like construction in Wildfly
                    nitin.shukla

                    Hello Tomaz,

                     

                    Can you please point me to some documentation on how to configure global handlers which is considered as replacement of valve in JBoss/Tomcat? I have a similar need as I am migrating my application currently on JBOSS AS 7.1 to WildFly 8.2, where we have used valve to negotiate authentication. Basically we have modified waffle.apache.NegotiateAuthenticator valve used for NTLM authentication and I need it to work on WildFly 8.2. Any pointers to documentation/tutorials to get me started is appreciated.

                     

                    Thanks.

                    • 7. Re: Global valve-like construction in Wildfly
                      khantariquealam

                      Hello Tomaz,

                      We are migrating from JBOSS5 to Wildfly 8.2.1 and currently have a valve implementation use as below

                      <Valve className="be.belgacom.tv.common.log4j.BtaAccessLogValve"

                                      prefix="localhost_access_log." suffix=".log"

                                      pattern='%h %l %u %t %{logID}r %{deviceIdentifier}r %{deviceAddress}r "%r" %s %b %D' directory="${jboss.server.log.dir}"

                                      resolveHosts="false" />

                      Same we want to implement in Wildfly but unable to achieve this.

                       

                      Regards,

                      Tarique

                      • 8. Re: Global valve-like construction in Wildfly
                        valsaraj007

                        Just add this in configuration file:

                        <host name="default-host" >
                          
                        <location name="/" handler="welcome-content">
                          .... 
                          
                        <access-log />
                        </host>


                        After restart, the access_log.log will be there along with server.log in the same directory.


                        • 9. Re: Global valve-like construction in Wildfly
                          khantariquealam

                          Thanks viswanathan for your reply.

                           

                          Actually our requirement is not for inbuild access-log implementation.

                          We have implemented custom access log which use lucene to write logID on file.

                          See below

                          <Valve className="be.belgacom.tv.common.log4j.BtaAccessLogValve"

                                          prefix="localhost_access_log." suffix=".log"

                                          pattern='%h %l %u %t %{logID}r %{deviceIdentifier}r %{deviceAddress}r "%r" %s %b %D' directory="${jboss.server.log.dir}"

                                          resolveHosts="false" />

                          BtaAccessLogValve is our custom valve which was working in Jboss5.

                          Now same implementation we want for Wildfly. As per suggested by Tomaz on Re: web access logs to syslog (in wildfly 8.2) to use ServletExtension.

                          We can not use servlet extension as we need to provide wildfly admin to configure prefix, pattern and directory.

                           

                          If you have some other approach please let us know as we are stuck completely on it.

                           

                          Regards,

                          Tarique