Author: veithen
Date: Mon Oct 6 14:23:34 2008
New Revision: 702272
URL: http://svn.apache.org/viewvc?rev=702272&view=rev
Log:
Transport testkit: Added an AspectJ advice that intercepts and logs the message
when it enters a message builder.
Modified:
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/axis2/client/LogAspect.java
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/util/LogManager.java
Modified:
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/axis2/client/LogAspect.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/axis2/client/LogAspect.java?rev=702272&r1=702271&r2=702272&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/axis2/client/LogAspect.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/axis2/client/LogAspect.java
Mon Oct 6 14:23:34 2008
@@ -28,6 +28,7 @@
import org.apache.axis2.context.MessageContext;
import org.apache.axis2.transport.testkit.util.LogManager;
import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.TeeInputStream;
import org.apache.commons.io.output.TeeOutputStream;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -76,4 +77,22 @@
log.error("Unable to dump message", ex);
}
}
+
+ @Around("call(org.apache.axiom.om.OMElement
org.apache.axis2.builder.Builder.processDocument(" +
+ " java.io.InputStream, java.lang.String,
org.apache.axis2.context.MessageContext))" +
+ " && args(in, contentType, msgContext)")
+ public Object aroundProcessDocument(ProceedingJoinPoint
proceedingJoinPoint,
+ InputStream in, String contentType, MessageContext msgContext)
throws Throwable {
+ InputStream tee;
+ if (in == null) {
+ tee = null;
+ } else {
+ OutputStream log = LogManager.INSTANCE.createLog("builder");
+ // Note: We can't close the log right after the method execution
because the
+ // message builder may use streaming. LogManager will take
care of closing the
+ // log for us if anything goes wrong.
+ tee = new TeeInputStream(in, log, true);
+ }
+ return proceedingJoinPoint.proceed(new Object[] { tee, contentType,
msgContext });
+ }
}
Modified:
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/util/LogManager.java
URL:
http://svn.apache.org/viewvc/webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/util/LogManager.java?rev=702272&r1=702271&r2=702272&view=diff
==============================================================================
---
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/util/LogManager.java
(original)
+++
webservices/commons/trunk/modules/transport/modules/testkit/src/main/java/org/apache/axis2/transport/testkit/util/LogManager.java
Mon Oct 6 14:23:34 2008
@@ -23,8 +23,11 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;
+import java.util.LinkedList;
+import java.util.List;
import org.apache.axis2.transport.testkit.tests.TransportTestCase;
+import org.apache.commons.io.IOUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Logger;
import org.apache.log4j.TTCCLayout;
@@ -37,6 +40,7 @@
private File testCaseDir;
private WriterAppender appender;
private int sequence;
+ private List<OutputStream> logs;
private LogManager() {
logDir = new File("target" + File.separator + "testkit-logs");
@@ -48,11 +52,18 @@
appender.close();
appender = null;
}
+ if (logs != null) {
+ for (OutputStream log : logs) {
+ IOUtils.closeQuietly(log);
+ }
+ logs = null;
+ }
if (testCase == null) {
testCaseDir = null;
} else {
File testSuiteDir = new File(logDir,
testCase.getTestClass().getName());
testCaseDir = new File(testSuiteDir, testCase.getId());
+ logs = new LinkedList<OutputStream>();
sequence = 1;
appender = new WriterAppender(new TTCCLayout(),
createLog("debug"));
Logger.getRootLogger().addAppender(appender);
@@ -61,6 +72,8 @@
public synchronized OutputStream createLog(String name) throws IOException
{
testCaseDir.mkdirs();
- return new FileOutputStream(new File(testCaseDir,
StringUtils.leftPad(String.valueOf(sequence++), 2, '0') + "-" + name + ".log"));
+ OutputStream log = new FileOutputStream(new File(testCaseDir,
StringUtils.leftPad(String.valueOf(sequence++), 2, '0') + "-" + name + ".log"));
+ logs.add(log);
+ return log;
}
}