0 Replies Latest reply on Jan 18, 2016 3:05 PM by Willy Seminario

    Apache CXF LoggingFeature - LoggingInInterceptor issue.

    Willy Seminario Newbie

      I have problem when trying to intercept the requests and responses before printing the log. I would like to intercept the request message before being print in the log, to handle some values and masking them because are sensitive data and don't want to be shown in the log file. What I'm missing or doing wrong?

       

      14:47:57,217 INFO  [org.apache.cxf.services.iws.iwsPort.Iws] (http-localhost/127.0.0.1:8080-1) Inbound Message

      ----------------------------

      ID: 1

      Address: http://localhost:8080/iws-current/iws

      Encoding: UTF-8

      ttp-Method: POST

      ... (some sensitive data to be hidden in logs)

      ...

      14:47:57,218 INFO  [com.test.interceptors.LoggingInInterceptor] (http-localhost/127.0.0.1:8080-1) INSIDE LOG INTERCEPTOR 1

       

      My configuration file and classes.

       

      I have the system-properties tag (standalone.xml file from JBOSS) set as true as the following:

       

      <system-properties>

              <property name="org.apache.cxf.logging.enabled" value="true"/>

      </system-properties>

       

      In my service implementation (for the endpoints) I have the annotation @Features(classes = {CustomLoggingFeature.class}) , referring to this class i create to configure the LoggingInInterceptors and LoggingOutInterceptors

       

      public class CustomLoggingFeature extends AbstractFeature {

          private static final int DEFAULT_LIMIT = 100 * 1024;

          private static final LoggingInInterceptor IN = new LoggingInInterceptor(DEFAULT_LIMIT);

          private static final LoggingOutInterceptor OUT = new LoggingOutInterceptor(DEFAULT_LIMIT);

          private static org.slf4j.Logger logger = LoggerFactory.getLogger(CustomLoggingFeature.class);

          int limit = DEFAULT_LIMIT;

       

          @Override

          protected void initializeProvider(InterceptorProvider provider, Bus bus) {

          logger.info("INSIDE CUSTOM LOG");  (THIS IS NOT PRINTED IN THE LOG)

          if (limit == DEFAULT_LIMIT) {

                  provider.getInInterceptors().add(IN);

                  provider.getInFaultInterceptors().add(IN);

                  provider.getOutInterceptors().add(OUT);

                  provider.getOutFaultInterceptors().add(OUT);

              } else {

                  LoggingInInterceptor in = new LoggingInInterceptor(limit);

                  LoggingOutInterceptor out = new LoggingOutInterceptor(limit);

                  provider.getInInterceptors().add(in);

                  provider.getInFaultInterceptors().add(in);

                  provider.getOutInterceptors().add(out);

                  provider.getOutFaultInterceptors().add(out);

              }

          }

       

          /**

           * This function has no effect at this time.

           * @param lim

           */

          public void setLimit(int lim) {

              limit = lim;

          }

       

          /**

           * Retrieve the value set with {@link #setLimit(int)}.

           * @return

           */

          public int getLimit() {

              return limit;

          }

       

      And then, also have an interceptor called LoggingInInterceptor :

       

      @NoJSR250Annotations

      public class LoggingInInterceptor extends AbstractLoggingInterceptor {

        private static org.slf4j.Logger logger = LoggerFactory.getLogger(LoggingInInterceptor.class);

       

        private static final Logger LOG = LogUtils.getLogger(LoggingInInterceptor.class);

       

        public LoggingInInterceptor() {

              super(Phase.RECEIVE);

              logger.info("INSIDE LOG INTERCEPTOR A");

          }

         

          public LoggingInInterceptor(String phase) {

              super(phase);

              logger.info("INSIDE LOG INTERCEPTOR B");

          }

       

       

          public LoggingInInterceptor(String id, String phase) {

              super(id, phase);

              logger.info("INSIDE LOG INTERCEPTOR C");

          }

       

       

          public LoggingInInterceptor(int lim) {

              this();

              limit = lim;

              logger.info("INSIDE LOG INTERCEPTOR D");

          }

          public LoggingInInterceptor(String id, int lim) {

              this(id, Phase.RECEIVE);

              limit = lim;

              logger.info("INSIDE LOG INTERCEPTOR E");

          }

       

       

          public LoggingInInterceptor(PrintWriter w) {

              this();

              this.writer = w;

              logger.info("INSIDE LOG INTERCEPTOR F");

          }

          public LoggingInInterceptor(String id, PrintWriter w) {

              this(id, Phase.RECEIVE);

              this.writer = w;

              logger.info("INSIDE LOG INTERCEPTOR G");

          }

         

          public void handleMessage(Message message) throws Fault {

          LOG.log(Level.ALL, "INSIDE LOG INTERCEPTOR 1");

          logger.info("INSIDE LOG INTERCEPTOR 1");

          if (writer != null || getLogger().isLoggable(Level.INFO)) {

                  logging(message);

              }

          }

       

       

          protected void logging(Message message) throws Fault {

             

          LOG.log(Level.ALL, "INSIDE LOG INTERCEPTOR 2");

          logger.info("INSIDE LOG INTERCEPTOR 2");

       

          }


        @Override

        protected Logger getLogger() {

        // TODO Auto-generated method stub

        LOG.log(Level.ALL, "INSIDE LOG INTERCEPTOR 4");

        logger.info("INSIDE LOG INTERCEPTOR");

        return LOG;

        }