You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2020/01/10 11:19:15 UTC
[camel] branch master updated: Camel-Exec: Fixed deprecation
This is an automated email from the ASF dual-hosted git repository.
acosentino pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 8912e15 Camel-Exec: Fixed deprecation
8912e15 is described below
commit 8912e15525cd85fde2367781c8236816aa70ba22
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Fri Jan 10 12:18:34 2020 +0100
Camel-Exec: Fixed deprecation
---
.../apache/camel/component/exec/ExecResultConverter.java | 5 +----
.../component/exec/ExecJavaProcessRecipientListTest.java | 11 ++++++-----
.../apache/camel/component/exec/ExecJavaProcessTest.java | 13 +++++++------
.../org/apache/camel/component/exec/ExecOutFileTest.java | 7 ++++---
.../org/apache/camel/component/exec/ExecProducerTest.java | 3 ++-
.../exec/impl/ExecDocumentationExamplesTest.java | 15 ++++++++-------
6 files changed, 28 insertions(+), 26 deletions(-)
diff --git a/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java b/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java
index 5b3cd75..7a2b5ca 100644
--- a/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java
+++ b/components/camel-exec/src/main/java/org/apache/camel/component/exec/ExecResultConverter.java
@@ -53,11 +53,8 @@ public final class ExecResultConverter {
@Converter
public static byte[] convertToByteArray(ExecResult result, Exchange exchange) throws FileNotFoundException, IOException {
- InputStream stream = toInputStream(result);
- try {
+ try (InputStream stream = toInputStream(result)) {
return IOUtils.toByteArray(stream);
- } finally {
- IOUtils.closeQuietly(stream);
}
}
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
index 46fdb1e..d1caa98 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessRecipientListTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.exec;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -104,7 +105,7 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
ExecResult inBody = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout()));
+ assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout(), Charset.defaultCharset()));
}
@Test
@@ -176,7 +177,7 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
output.assertIsSatisfied();
InputStream out = e.getIn().getBody(InputStream.class);
- assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out));
+ assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out, Charset.defaultCharset()));
}
@Test
@@ -199,9 +200,9 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
output.setExpectedMessageCount(1);
Exchange exchange = sendExchange(THREADS, NO_TIMEOUT);
- String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class));
+ String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class), Charset.defaultCharset());
ExecResult result = exchange.getIn().getBody(ExecResult.class);
- String[] outs = IOUtils.toString(result.getStdout()).split(LINE_SEPARATOR);
+ String[] outs = IOUtils.toString(result.getStdout(), Charset.defaultCharset()).split(LINE_SEPARATOR);
String[] errs = err.split(LINE_SEPARATOR);
output.assertIsSatisfied();
@@ -240,7 +241,7 @@ public class ExecJavaProcessRecipientListTest extends CamelTestSupport {
Exchange e = sendExchange(READ_INPUT_LINES_AND_PRINT_THEM, 20000, whiteSpaceSeparatedLines, false);
ExecResult inBody = e.getIn().getBody(ExecResult.class);
- assertEquals(expected, IOUtils.toString(inBody.getStdout()));
+ assertEquals(expected, IOUtils.toString(inBody.getStdout(), Charset.defaultCharset()));
}
protected Exchange sendExchange(final String endpoint, final Object commandArgument, final long timeout) {
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
index e00e5e1..059453c 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecJavaProcessTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.exec;
import java.io.InputStream;
+import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.List;
@@ -117,7 +118,7 @@ public class ExecJavaProcessTest extends CamelTestSupport {
ExecResult inBody = e.getIn().getBody(ExecResult.class);
output.assertIsSatisfied();
- assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout()));
+ assertEquals(PRINT_IN_STDOUT, IOUtils.toString(inBody.getStdout(), Charset.defaultCharset()));
}
@Test
@@ -199,7 +200,7 @@ public class ExecJavaProcessTest extends CamelTestSupport {
Exchange e = sendExchange(commandArgument, NO_TIMEOUT);
output.assertIsSatisfied();
InputStream out = e.getIn().getBody(InputStream.class);
- assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out));
+ assertEquals(PRINT_IN_STDOUT, IOUtils.toString(out, Charset.defaultCharset()));
}
@Test
@@ -213,7 +214,7 @@ public class ExecJavaProcessTest extends CamelTestSupport {
output.assertIsSatisfied();
byte[] out = e.getIn().getBody(byte[].class);
assertNotNull(out);
- assertEquals(PRINT_IN_STDOUT, new String(out));
+ assertEquals(PRINT_IN_STDOUT, new String(out, Charset.defaultCharset()));
}
@Test
@@ -244,9 +245,9 @@ public class ExecJavaProcessTest extends CamelTestSupport {
output.setExpectedMessageCount(1);
Exchange exchange = sendExchange(THREADS, NO_TIMEOUT);
- String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class));
+ String err = IOUtils.toString(exchange.getIn().getHeader(EXEC_STDERR, InputStream.class), Charset.defaultCharset());
ExecResult result = exchange.getIn().getBody(ExecResult.class);
- String[] outs = IOUtils.toString(result.getStdout()).split(LINE_SEPARATOR);
+ String[] outs = IOUtils.toString(result.getStdout(), Charset.defaultCharset()).split(LINE_SEPARATOR);
String[] errs = err.split(LINE_SEPARATOR);
output.assertIsSatisfied();
@@ -389,7 +390,7 @@ public class ExecJavaProcessTest extends CamelTestSupport {
Exchange e = sendExchange(READ_INPUT_LINES_AND_PRINT_THEM, 20000, whiteSpaceSeparatedLines, false);
ExecResult inBody = e.getIn().getBody(ExecResult.class);
- assertEquals(expected, IOUtils.toString(inBody.getStdout()));
+ assertEquals(expected, IOUtils.toString(inBody.getStdout(), Charset.defaultCharset()));
}
/**
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
index 51be879..1f2ce43 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecOutFileTest.java
@@ -19,6 +19,7 @@ package org.apache.camel.component.exec;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.nio.charset.Charset;
import org.w3c.dom.Document;
@@ -53,7 +54,7 @@ public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
@Before
public void setUp() throws IOException {
FILE.createNewFile();
- FileUtils.writeStringToFile(FILE, FILE_CONTENT);
+ FileUtils.writeStringToFile(FILE, FILE_CONTENT, Charset.defaultCharset());
}
@After
@@ -69,7 +70,7 @@ public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
assertNotNull(result);
File outFile = result.getCommand().getOutFile();
assertNotNull(outFile);
- assertEquals(FILE_CONTENT, FileUtils.readFileToString(outFile));
+ assertEquals(FILE_CONTENT, FileUtils.readFileToString(outFile, Charset.defaultCharset()));
}
@Test
@@ -78,7 +79,7 @@ public class ExecOutFileTest extends AbstractJUnit4SpringContextTests {
Exchange e = sendWithMockedExecutor();
InputStream body = e.getIn().getBody(InputStream.class);
assertNotNull(body);
- assertEquals(FILE_CONTENT, IOUtils.toString(body));
+ assertEquals(FILE_CONTENT, IOUtils.toString(body, Charset.defaultCharset()));
}
@Test
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
index 97c58f6..9cc1f0e 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/ExecProducerTest.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.exec;
import java.io.IOException;
+import java.nio.charset.Charset;
import java.util.Arrays;
import java.util.List;
@@ -122,7 +123,7 @@ public class ExecProducerTest extends AbstractJUnit4SpringContextTests {
exchange.getIn().setBody(input);
}
});
- assertEquals(input, IOUtils.toString(execCommandExecutorMock.lastCommandResult.getCommand().getInput()));
+ assertEquals(input, IOUtils.toString(execCommandExecutorMock.lastCommandResult.getCommand().getInput(), Charset.defaultCharset()));
}
@Test
diff --git a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
index f645dbe..8f728f5 100644
--- a/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
+++ b/components/camel-exec/src/test/java/org/apache/camel/component/exec/impl/ExecDocumentationExamplesTest.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.exec.impl;
import java.io.File;
import java.io.InputStream;
+import java.nio.charset.Charset;
import org.apache.camel.Exchange;
import org.apache.camel.Processor;
@@ -84,7 +85,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
// Strange that Sun Java 1.5 writes the -version in the syserr
assertNull(out);
assertNotNull(err);
- String outString = IOUtils.toString(err);
+ String outString = IOUtils.toString(err, Charset.defaultCharset());
log.info("Received stdout: " + outString);
assertTrue(outString.contains("java version"));
}
@@ -98,7 +99,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
// Strange that Sun Java 1.5 writes the -version in the syserr
assertNull(out);
assertNotNull(err);
- String outerr = IOUtils.toString(err);
+ String outerr = IOUtils.toString(err, Charset.defaultCharset());
log.info("Received stderr: " + outerr);
assertTrue(outerr.contains("java version"));
}
@@ -111,10 +112,10 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
public void testExecWinAnt() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
- FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT);
+ FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT, Charset.defaultCharset());
assertTrue("You must create a sample build file!", f.exists());
ExecResult body = templateExecAnt.requestBody((Object)"test", ExecResult.class);
- String stdout = IOUtils.toString(body.getStdout());
+ String stdout = IOUtils.toString(body.getStdout(), Charset.defaultCharset());
assertNull(body.getStderr());
assertTrue("The ant script should print" + TEST_MSG, stdout.contains(TEST_MSG));
f.delete();
@@ -128,11 +129,11 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
public void testExecWinAntWithOutFile() throws Exception {
File f = new File(ANT_BUILD_FILE_NAME);
f.createNewFile();
- FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT);
+ FileUtils.writeStringToFile(f, ANT_BUILD_FILE_CONTENT, Charset.defaultCharset());
assertTrue("You must create a sample build file!", f.exists());
// use type conversion here
InputStream body = templateExecAntWithOutFile.requestBody((Object)"test", InputStream.class);
- String bodyString = IOUtils.toString(body);
+ String bodyString = IOUtils.toString(body, Charset.defaultCharset());
assertTrue("The ant script should print" + TEST_MSG, bodyString.contains(TEST_MSG));
f.delete();
}
@@ -171,7 +172,7 @@ public class ExecDocumentationExamplesTest extends CamelTestSupport {
public void process(Exchange exchange) throws Exception {
InputStream outFile = exchange.getIn().getBody(InputStream.class);
// do something with the out file here
- log.info(IOUtils.toString(outFile));
+ log.info(IOUtils.toString(outFile, Charset.defaultCharset()));
}
});