You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ha...@apache.org on 2012/04/11 22:05:18 UTC
svn commit: r1324970 - in /camel/branches/camel-2.9.x: ./
components/camel-jsch/
components/camel-jsch/src/main/java/org/apache/camel/component/jsch/
Author: hadrian
Date: Wed Apr 11 20:05:18 2012
New Revision: 1324970
URL: http://svn.apache.org/viewvc?rev=1324970&view=rev
Log:
Merged revisions 1310959 via svnmerge from
https://svn.apache.org/repos/asf/camel/trunk
........
r1310959 | davsclaus | 2012-04-08 03:50:37 -0400 (Sun, 08 Apr 2012) | 1 line
CAMEL-5020: Fixed failing tests. And ensure streams is closed after usage.
........
Modified:
camel/branches/camel-2.9.x/ (props changed)
camel/branches/camel-2.9.x/components/camel-jsch/ (props changed)
camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpConfiguration.java
camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpOperations.java
Propchange: camel/branches/camel-2.9.x/
------------------------------------------------------------------------------
Binary property 'svnmerge-integrated' - no diff available.
Propchange: camel/branches/camel-2.9.x/components/camel-jsch/
------------------------------------------------------------------------------
--- svn:ignore (added)
+++ svn:ignore Wed Apr 11 20:05:18 2012
@@ -0,0 +1,16 @@
+.pmd
+.checkstyle
+.ruleset
+target
+.settings
+.classpath
+.project
+.wtpmodules
+prj.el
+.jdee_classpath
+.jdee_sources
+velocity.log
+eclipse-classes
+*.ipr
+*.iml
+*.iws
Modified: camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpConfiguration.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpConfiguration.java?rev=1324970&r1=1324969&r2=1324970&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpConfiguration.java (original)
+++ camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpConfiguration.java Wed Apr 11 20:05:18 2012
@@ -33,7 +33,7 @@ public class ScpConfiguration extends Re
private String strictHostKeyChecking = "no";
private int serverAliveInterval;
private int serverAliveCountMax = 1;
- private String chmod;
+ private String chmod = DEFAULT_MOD;
// comma separated list of ciphers.
// null means default jsch list will be used
private String ciphers;
Modified: camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpOperations.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpOperations.java?rev=1324970&r1=1324969&r2=1324970&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpOperations.java (original)
+++ camel/branches/camel-2.9.x/components/camel-jsch/src/main/java/org/apache/camel/component/jsch/ScpOperations.java Wed Apr 11 20:05:18 2012
@@ -32,7 +32,6 @@ import com.jcraft.jsch.JSchException;
import com.jcraft.jsch.Session;
import com.jcraft.jsch.UIKeyboardInteractive;
import com.jcraft.jsch.UserInfo;
-
import org.apache.camel.Exchange;
import org.apache.camel.InvalidPayloadException;
import org.apache.camel.component.file.GenericFileEndpoint;
@@ -40,6 +39,7 @@ import org.apache.camel.component.file.G
import org.apache.camel.component.file.remote.RemoteFileConfiguration;
import org.apache.camel.component.file.remote.RemoteFileOperations;
import org.apache.camel.util.ExchangeHelper;
+import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -227,10 +227,11 @@ public class ScpOperations implements Re
OutputStream os = c.getOutputStream();
InputStream is = c.getInputStream();
- writeFile(name, data, os, is, cfg);
-
- os.close();
- is.close();
+ try {
+ writeFile(name, data, os, is, cfg);
+ } finally {
+ IOHelper.close(is, os);
+ }
}
private void writeFile(String filename, InputStream data, OutputStream os, InputStream is, ScpConfiguration cfg) throws IOException {
@@ -257,32 +258,36 @@ public class ScpOperations implements Re
readAck(is, false);
} else {
int count = 0;
- int read = 0;
+ int read;
int size = endpoint.getBufferSize();
byte[] reply = new byte[size];
// figure out the stream size as we need to pass it in the header
BufferedInputStream buffer = new BufferedInputStream(data, size);
- buffer.mark(Integer.MAX_VALUE);
- while ((read = buffer.read(reply)) != -1) {
- count += read;
- }
-
- // send the header
- bytes = "C0" + cfg.getChmod() + " " + count + " " + filename;
- LOG.trace("[scp:sink] {}", bytes);
- os.write(bytes.getBytes());
- os.write(lineFeed);
- os.flush();
- readAck(is, false);
-
- // now send the stream
- buffer.reset();
- while ((read = buffer.read(reply)) != -1) {
- os.write(reply, 0, read);
+ try {
+ buffer.mark(Integer.MAX_VALUE);
+ while ((read = buffer.read(reply)) != -1) {
+ count += read;
+ }
+
+ // send the header
+ bytes = "C0" + cfg.getChmod() + " " + count + " " + filename;
+ LOG.trace("[scp:sink] {}", bytes);
+ os.write(bytes.getBytes());
+ os.write(lineFeed);
+ os.flush();
+ readAck(is, false);
+
+ // now send the stream
+ buffer.reset();
+ while ((read = buffer.read(reply)) != -1) {
+ os.write(reply, 0, read);
+ }
+ writeAck(os);
+ readAck(is, false);
+ } finally {
+ IOHelper.close(buffer);
}
- writeAck(os);
- readAck(is, false);
}
}
@@ -298,17 +303,15 @@ public class ScpOperations implements Re
case -1:
if (failOnEof) {
message = "[scp] Unexpected end of stream";
- LOG.info(message);
throw new EOFException(message);
}
break;
case 1:
message = "[scp] WARN " + readLine(is);
- LOG.info(message);
+ LOG.warn(message);
break;
case 2:
message = "[scp] NACK " + readLine(is);
- LOG.info(message);
throw new IOException(message);
default:
// case 0:
@@ -319,16 +322,20 @@ public class ScpOperations implements Re
private String readLine(InputStream is) throws IOException {
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
- int c = 0;
- do {
- c = is.read();
- if (c == '\n') {
- return bytes.toString();
- }
- bytes.write(c);
- } while (c != -1);
+ try {
+ int c;
+ do {
+ c = is.read();
+ if (c == '\n') {
+ return bytes.toString();
+ }
+ bytes.write(c);
+ } while (c != -1);
+ } finally {
+ IOHelper.close(bytes);
+ }
+
String message = "[scp] Unexpected end of stream";
- LOG.info(message);
throw new IOException(message);
}
@@ -368,7 +375,7 @@ public class ScpOperations implements Re
@Override
public String getPassphrase() {
- LOG.info("Private Key authentication not supported");
+ LOG.warn("Private Key authentication not supported");
return null;
}
@Override