[jboss-cvs] JBossAS SVN: r96446 - in branches/Branch_5_x/testsuite: src/main/org/jboss/test/web/servlets and 3 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon Nov 16 13:29:35 EST 2009


Author: jaikiran
Date: 2009-11-16 13:29:34 -0500 (Mon, 16 Nov 2009)
New Revision: 96446

Added:
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/servlets/JBAS6532LoggingServlet.java
   branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/PerApplicationLoggingTestCase.java
   branches/Branch_5_x/testsuite/src/resources/web/logging/
   branches/Branch_5_x/testsuite/src/resources/web/logging/log4j.xml
   branches/Branch_5_x/testsuite/src/resources/web/logging/web.xml
Modified:
   branches/Branch_5_x/testsuite/imports/sections/web.xml
Log:
JBAS-6532 Fixed application specific logging to separate files. A newly introduced org.jboss.logging.filter.TCLMCFilter should be used

Modified: branches/Branch_5_x/testsuite/imports/sections/web.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/web.xml	2009-11-16 18:18:01 UTC (rev 96445)
+++ branches/Branch_5_x/testsuite/imports/sections/web.xml	2009-11-16 18:29:34 UTC (rev 96446)
@@ -919,5 +919,24 @@
            <include name="**"/>
          </fileset>
       </jar>
+      
+      <!-- build jbas-6532 war -->
+      <war warfile="${build.lib}/jbas-6532-app-one.war"
+	   webxml="${build.resources}/web/logging/web.xml">
+	      <lib dir="${apache.log4j.lib}">
+		      <include name="log4j.jar" />
+	      </lib>
+	      <lib dir="${jboss.common.logging.log4j.lib}">
+		      <include name="jboss-logging-log4j.jar" />
+         	</lib>
+	      <classes dir="${build.classes}">
+		      <include name="org/jboss/test/web/servlets/JBAS6532LoggingServlet.class"/>
+	      </classes>
+	      <classes dir="${build.resources}/web/logging/">
+		      <include name="log4j.xml"/>
+	      </classes>
+	      
+      </war>
+      
    </target>
 </project>

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/servlets/JBAS6532LoggingServlet.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/servlets/JBAS6532LoggingServlet.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/servlets/JBAS6532LoggingServlet.java	2009-11-16 18:29:34 UTC (rev 96446)
@@ -0,0 +1,100 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.web.servlets;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+
+import org.jboss.test.web.test.PerApplicationLoggingTestCase;
+
+/**
+ * JBAS6532LoggingServlet
+ * Used in {@link PerApplicationLoggingTestCase} for JBAS-6532
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class JBAS6532LoggingServlet extends HttpServlet
+{
+
+   /**
+    * Logger
+    */
+   private static org.apache.log4j.Logger logger = org.apache.log4j.Logger.getLogger("jbas-6532-logger");
+   
+   /**
+    * Process GET request
+    */
+   protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+   {
+      // we do the same thing as POST
+      doPost(request, response);
+   }
+
+   /**
+    * Process POST
+    */
+   protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
+   {
+      // first log the message to this application's log file
+      String action = request.getParameter("action");
+      if (action.equals("write-log"))
+      {
+         // write the log message. Internally, it will be directed to the 
+         // correct appender (in this case, the application specific log file)
+         String logMessage = request.getParameter("log-message");
+         logger.info(logMessage);
+         return;
+      }
+      else if (action.equals("read-log"))
+      {
+         // read the contents of the application specific log file
+         String jbossLogDir = System.getProperty("jboss.server.log.dir");
+         File logDir = new File (jbossLogDir);
+         String logFileName = request.getParameter("log-file-name");
+         File appLogFile = new File (logDir, logFileName);
+         if (!appLogFile.exists())
+         {
+            // indicates an error
+            response.addHeader("X-JBAS6532-Error", appLogFile + " does not exist");
+            return;
+         }
+         BufferedReader bufferedReader = new BufferedReader(new FileReader(appLogFile));
+         StringBuffer contents = new StringBuffer();
+         String line = null;
+         while ( (line = bufferedReader.readLine()) != null)
+         {
+            contents.append(line);
+         }
+         // return the log file contents
+         response.addHeader("X-JBAS6532-Log", contents.toString());
+         return;
+      }
+
+   }
+}

Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/PerApplicationLoggingTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/PerApplicationLoggingTestCase.java	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/web/test/PerApplicationLoggingTestCase.java	2009-11-16 18:29:34 UTC (rev 96446)
@@ -0,0 +1,99 @@
+/*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2006, Red Hat Middleware LLC, and individual contributors
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+package org.jboss.test.web.test;
+
+import java.net.URL;
+
+import junit.framework.Test;
+
+import org.apache.commons.httpclient.Header;
+import org.apache.commons.httpclient.HttpMethodBase;
+import org.jboss.logging.Logger;
+import org.jboss.test.JBossTestCase;
+import org.jboss.test.util.web.HttpUtils;
+
+/**
+ * PerApplicationLoggingTestCase
+ * 
+ * Tests that the per application logging filter as explained here 
+ * http://www.jboss.org/community/wiki/SeparatingApplicationLogs
+ * works
+ *
+ * @see JBAS-6532
+ * @author Jaikiran Pai
+ * @version $Revision: $
+ */
+public class PerApplicationLoggingTestCase extends JBossTestCase
+{
+
+   /**
+    * Logger
+    */
+   private static Logger logger = Logger.getLogger(PerApplicationLoggingTestCase.class);
+
+   /**
+    * Constructor
+    * @param name
+    */
+   public PerApplicationLoggingTestCase(String name)
+   {
+      super(name);
+   }
+
+   /**
+    * Test that the log messages from an app are directed to the app specific log file 
+    * @throws Exception
+    */
+   public void testPerApplicationLogging() throws Exception
+   {
+
+      // first write a log message from app-one
+      String baseURL = "http://" + getServerHost() + ":" + Integer.getInteger("web.port", 8080) + '/';
+      String appOneLogMessage = "AppOneLogMessage";
+      URL appOneServletURL = new URL(baseURL + "jbas-6532-app-one/JBAS6532LoggingServlet?action=write-log&log-message="
+            + appOneLogMessage);
+      HttpUtils.accessURL(appOneServletURL);
+
+      // now check that the app-one log file contains log from only app-one
+      String appOneLogFileName = "jbas-6532-app-one.log";
+      appOneServletURL = new URL(baseURL + "jbas-6532-app-one/JBAS6532LoggingServlet?action=read-log&log-file-name="
+            + appOneLogFileName);
+      HttpMethodBase request = HttpUtils.accessURL(appOneServletURL);
+      
+      Header errorHeader = request.getResponseHeader("X-JBAS6532-Error");
+      // make sure there were no errors
+      assertNull("Error reading log file of app one: " + errorHeader, errorHeader);
+      // check the log file contents
+      Header appOneLogFileContents = request.getResponseHeader("X-JBAS6532-Log");
+      assertEquals("Unexpected content in app one log file", appOneLogMessage, appOneLogFileContents.getValue());
+
+   }
+
+   /**
+    * Setup the test suite.
+    */
+   public static Test suite() throws Exception
+   {
+      return getDeploySetup(PerApplicationLoggingTestCase.class, "jbas-6532-app-one.war");
+   }
+
+}

Added: branches/Branch_5_x/testsuite/src/resources/web/logging/log4j.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/web/logging/log4j.xml	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/web/logging/log4j.xml	2009-11-16 18:29:34 UTC (rev 96446)
@@ -0,0 +1,37 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE log4j:configuration SYSTEM "log4j.dtd">
+
+<log4j:configuration xmlns:log4j="http://jakarta.apache.org/log4j/" debug="false">
+
+
+  <appender name="APP1_LOG_FILE" class="org.apache.log4j.RollingFileAppender">
+	<param name="File" value="${jboss.server.log.dir}/jbas-6532-app-one.log"/>
+	<param name="Append" value="false"/>
+	<param name="MaxFileSize" value="5000KB"/>
+	<param name="MaxBackupIndex" value="1"/>
+	<layout class="org.apache.log4j.PatternLayout">
+		<param name="ConversionPattern" value="%m%n"/>
+	</layout>	
+	<!-- The tcl filter -->
+	<filter class="org.jboss.logging.filter.TCLMCFilter">
+		<param name="AcceptOnMatch" value="true"/>
+		<param name="DeployURL" value="jbas-6532-app-one"/>
+	</filter>    
+	
+	<!-- end the filter chain here -->
+	<filter class="org.apache.log4j.varia.DenyAllFilter"></filter>
+		
+		
+   </appender>
+   
+ 
+   <!-- ======================= -->
+   <!-- Setup the Root category -->
+   <!-- ======================= -->
+
+   <root>
+	<appender-ref ref="APP1_LOG_FILE"></appender-ref>	   
+   </root>
+
+
+</log4j:configuration>

Added: branches/Branch_5_x/testsuite/src/resources/web/logging/web.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/web/logging/web.xml	                        (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/web/logging/web.xml	2009-11-16 18:29:34 UTC (rev 96446)
@@ -0,0 +1,18 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
+   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+   xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
+   http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
+   <description>Simple web app for JBAS-6532 testcase</description>
+   
+   <servlet>
+	   <servlet-name>JBAS6532LoggingServlet</servlet-name>
+	   <servlet-class>org.jboss.test.web.servlets.JBAS6532LoggingServlet</servlet-class>
+   </servlet>
+   
+   <servlet-mapping>
+	   <servlet-name>JBAS6532LoggingServlet</servlet-name>
+	   <url-pattern>/JBAS6532LoggingServlet</url-pattern>
+   </servlet-mapping>
+
+</web-app>


Property changes on: branches/Branch_5_x/testsuite/src/resources/web/logging/web.xml
___________________________________________________________________
Name: svn:executable
   + *




More information about the jboss-cvs-commits mailing list