Author: alessio.soldano(a)jboss.com
Date: 2012-06-24 13:20:25 -0400 (Sun, 24 Jun 2012)
New Revision: 434
Added:
core/trunk/core/src/main/java/org/jboss/wise/core/utils/LoggingOutputStream.java
Modified:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/consumer/impl/WSConsumerTest.java
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java
core/trunk/core/src/main/java/org/jboss/wise/core/consumer/impl/jbossws/DefaultWSImportImpl.java
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/smooks/WiseIntegrationSmooksTest.java
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/wsdlResolver/WSDLResolverIntegrationTest.java
Log:
[WISE-178] default to log4j for consumer output unless verbose is on + fixing some
client/test logging
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/client/impl/reflection/builder/ReflectionBasedWSDynamicClientBuilder.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -37,6 +37,7 @@
import org.apache.commons.io.FileUtils;
import org.apache.commons.lang.StringUtils;
+import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.jboss.wise.core.client.WSDynamicClient;
import org.jboss.wise.core.client.builder.WSDynamicClientBuilder;
@@ -45,6 +46,7 @@
import org.jboss.wise.core.client.impl.wsdlResolver.WSDLResolver;
import org.jboss.wise.core.exception.WiseRuntimeException;
import org.jboss.wise.core.utils.IDGenerator;
+import org.jboss.wise.core.utils.LoggingOutputStream;
/**
* @author stefano.maestri(a)javalinux.it
@@ -54,6 +56,7 @@
public class ReflectionBasedWSDynamicClientBuilder implements WSDynamicClientBuilder {
private static Logger logger =
Logger.getLogger(ReflectionBasedWSDynamicClientBuilder.class);
+ private static PrintStream ps = new PrintStream(new LoggingOutputStream(logger,
Level.INFO), true);
@GuardedBy("this")
private String wsdlURL;
@@ -95,7 +98,7 @@
private String clientSpecificTmpDir;
@GuardedBy("this")
- private PrintStream messageStream = System.out;
+ private PrintStream messageStream = ps;
@GuardedBy("this")
private int maxThreadPoolSize = MAX_THREAD_POOL_SIZE.getIntValue();
Modified:
core/trunk/core/src/main/java/org/jboss/wise/core/consumer/impl/jbossws/DefaultWSImportImpl.java
===================================================================
---
core/trunk/core/src/main/java/org/jboss/wise/core/consumer/impl/jbossws/DefaultWSImportImpl.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/consumer/impl/jbossws/DefaultWSImportImpl.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -70,13 +70,15 @@
wsImporter.setGenerateSource(this.isKeepSource());
wsImporter.setOutputDirectory(outputDir);
wsImporter.setSourceDirectory(sourceDir);
+
+ if (this.isVerbose()) {
+ wsImporter.setMessageStream(System.out);
+ }
+
if (messageStream != null) {
wsImporter.setMessageStream(messageStream);
}
- if (this.isVerbose()) {
- wsImporter.setMessageStream(System.out);
- }
wsImporter.setAdditionalCompilerClassPath(defineAdditionalCompilerClassPath());
if (bindingFiles != null && bindingFiles.size() > 0) {
Added: core/trunk/core/src/main/java/org/jboss/wise/core/utils/LoggingOutputStream.java
===================================================================
--- core/trunk/core/src/main/java/org/jboss/wise/core/utils/LoggingOutputStream.java
(rev 0)
+++
core/trunk/core/src/main/java/org/jboss/wise/core/utils/LoggingOutputStream.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -0,0 +1,91 @@
+package org.jboss.wise.core.utils;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
+
+/**
+ * An OutputStream that flushes out to a Logger
+ */
+public class LoggingOutputStream extends OutputStream {
+
+ public static final int DEFAULT_BUFFER_LENGTH = 2048;
+
+ protected boolean hasBeenClosed = false;
+ protected byte[] buf;
+ protected int count;
+ private int bufLength;
+ protected Logger logger;
+ protected Level level;
+
+ public LoggingOutputStream(Logger log, Level level) throws IllegalArgumentException
{
+ if (log == null) {
+ throw new IllegalArgumentException("Null category!");
+ }
+ if (level == null) {
+ throw new IllegalArgumentException("Null priority!");
+ }
+ this.level = level;
+ logger = log;
+ bufLength = DEFAULT_BUFFER_LENGTH;
+ buf = new byte[DEFAULT_BUFFER_LENGTH];
+ count = 0;
+ }
+
+ public void close() {
+ flush();
+ hasBeenClosed = true;
+ }
+
+ public void write(final int b) throws IOException {
+ if (hasBeenClosed) {
+ throw new IOException("The stream has been closed.");
+ }
+ // would this be writing past the buffer?
+ if (count == bufLength) {
+ // grow the buffer
+ final int newBufLength = bufLength + DEFAULT_BUFFER_LENGTH;
+ final byte[] newBuf = new byte[newBufLength];
+ System.arraycopy(buf, 0, newBuf, 0, bufLength);
+ buf = newBuf;
+ bufLength = newBufLength;
+ }
+ buf[count] = (byte) b;
+ count++;
+ }
+
+ public void flush() {
+ if (count == 0) {
+ return;
+ }
+ // don't print out blank lines; flushing from PrintStream puts
+ // out these
+ // For linux system
+ if (count == 1 && ((char) buf[0]) == '\n') {
+ reset();
+ return;
+ }
+ // For mac system
+ if (count == 1 && ((char) buf[0]) == '\r') {
+ reset();
+ return;
+ }
+ // On windows system
+ if (count == 2 && (char) buf[0] == '\r' && (char) buf[1] ==
'\n') {
+ reset();
+ return;
+ }
+ final byte[] theBytes = new byte[count];
+ System.arraycopy(buf, 0, theBytes, 0, count);
+ logger.log(level, new String(theBytes));
+ reset();
+ }
+
+ private void reset() {
+ // not resetting the buffer -- assuming that if it grew then it
+ // will likely grow similarly again
+ count = 0;
+ }
+}
Modified:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java
===================================================================
---
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/client/jaxrs/ClientServerJaxrsTest.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -1,9 +1,11 @@
package org.jboss.wise.core.client.jaxrs;
import java.io.InputStream;
+
import org.apache.cxf.helpers.IOUtils;
import org.apache.cxf.io.CachedOutputStream;
import org.apache.cxf.testutil.common.AbstractClientServerTestBase;
+import org.apache.log4j.Logger;
import org.jboss.wise.core.client.InvocationResult;
import org.jboss.wise.core.client.factories.WSDynamicClientFactory;
import org.junit.BeforeClass;
@@ -11,6 +13,8 @@
public class ClientServerJaxrsTest extends AbstractClientServerTestBase {
+ private Logger logger = Logger.getLogger(ClientServerJaxrsTest.class);
+
@BeforeClass
public static void startServers() throws Exception {
assertTrue("server did not launch correctly",
launchServer(JaxrsServer.class));
@@ -41,7 +45,7 @@
InvocationResult result = client.invoke(request, null);
String response = (String)result.getResult().get(InvocationResult.RESPONSE);
- System.out.println("-------------" + response);
+ logger.debug("-------------" + response);
String expected =
getStringFromInputStream(getClass().getResourceAsStream("/jaxrs/expected_add_book.txt"));
Modified:
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/consumer/impl/WSConsumerTest.java
===================================================================
---
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/consumer/impl/WSConsumerTest.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/core-cxf/src/test/java/org/jboss/wise/core/consumer/impl/WSConsumerTest.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -27,12 +27,16 @@
import static org.junit.matchers.JUnitMatchers.hasItem;
import java.io.File;
+import java.io.PrintStream;
import java.net.URL;
import java.util.List;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.jboss.wise.core.client.SpiLoader;
import org.jboss.wise.core.consumer.WSConsumer;
import org.jboss.wise.core.exception.WiseRuntimeException;
+import org.jboss.wise.core.utils.LoggingOutputStream;
import org.junit.Test;
/**
@@ -40,6 +44,8 @@
* @author alessio.soldano(a)jboss.com
*/
public class WSConsumerTest {
+
+ private PrintStream testPrintStream = new PrintStream(new
LoggingOutputStream(Logger.getLogger(this.getClass()), Level.INFO), true);
@Test
public void parseHelloGreetingWSDLShouldWorkWithoutPackage() throws Exception {
@@ -47,7 +53,7 @@
File outputDir = new File(url.getFile());
URL wsdURL =
Thread.currentThread().getContextClassLoader().getResource("./hello_world.wsdl");
WSConsumer importer = newConsumer();
- importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir, null, null,
System.out, null);
+ importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir, null, null,
testPrintStream, null);
}
@Test()
@@ -60,7 +66,7 @@
List<File> bindings = new java.util.ArrayList<File>();
bindings.add(bindFile);
WSConsumer importer = newConsumer();
- importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir, null,
bindings, System.out, null);
+ importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir, null,
bindings, testPrintStream, null);
File generatedClass = new File(url.getFile(), "org/mytest");
assertTrue(generatedClass.exists());
}
@@ -71,7 +77,7 @@
File outputDir = new File(url.getFile());
URL wsdURL =
Thread.currentThread().getContextClassLoader().getResource("./hello_world.wsdl");
WSConsumer importer = newConsumer();
- importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir,
"org.jboss.wise", null, System.out, null);
+ importer.importObjectFromWsdl(wsdURL.toExternalForm(), outputDir, outputDir,
"org.jboss.wise", null, testPrintStream, null);
}
@Test()
Modified:
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/smooks/WiseIntegrationSmooksTest.java
===================================================================
---
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/smooks/WiseIntegrationSmooksTest.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/smooks/WiseIntegrationSmooksTest.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -30,6 +30,8 @@
import java.util.Date;
import java.util.Map;
+import org.apache.log4j.Level;
+import org.apache.log4j.Logger;
import org.jboss.wise.core.client.InvocationResult;
import org.jboss.wise.core.client.WSDynamicClient;
import org.jboss.wise.core.client.WSMethod;
@@ -64,7 +66,7 @@
.toString()).build();
WSMethod method = client.getWSMethod("ComplexWSService",
"ComplexWSPort", "ping");
- method.getEndpoint().addHandler(new LoggingHandler());
+ method.getEndpoint().addHandler(new LoggingHandler(Logger.getLogger(this.getClass()),
Level.DEBUG));
InternalObject internal = new InternalObject();
internal.setNumber(new Integer(1));
internal.setText("aa");
Modified:
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/wsdlResolver/WSDLResolverIntegrationTest.java
===================================================================
---
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/wsdlResolver/WSDLResolverIntegrationTest.java 2012-06-24
15:31:23 UTC (rev 433)
+++
core/trunk/integration-testsuite/common/src/test/java/org/jboss/wise/test/integration/wsdlResolver/WSDLResolverIntegrationTest.java 2012-06-24
17:20:25 UTC (rev 434)
@@ -29,6 +29,7 @@
import net.jcip.annotations.Immutable;
+import org.apache.log4j.Logger;
import org.jboss.wise.core.client.impl.wsdlResolver.Connection;
import org.jboss.wise.core.client.impl.wsdlResolver.WSDLResolver;
import org.jboss.wise.core.test.WiseTest;
@@ -110,7 +111,7 @@
@Before
public void createTmpDir() throws IOException
{
- System.out.println("Creating tmp dir: " + tmpDir.getPath());
+ Logger.getLogger(this.getClass()).debug("Creating tmp dir: " +
tmpDir.getPath());
if (tmpDir.exists()) {
tmpDir.delete();
}