You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2014/03/07 04:18:50 UTC
[1/2] git commit: CAMEL-7277 camel-ssh should close the session when
execution is finished.
Repository: camel
Updated Branches:
refs/heads/master 44cad623a -> 1b0f11626
CAMEL-7277 camel-ssh should close the session when execution is finished.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1b0f1162
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1b0f1162
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1b0f1162
Branch: refs/heads/master
Commit: 1b0f116267fad8830069874b627d1f2aa5bf3eaa
Parents: 1155961
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Mar 7 11:17:34 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Mar 7 11:17:53 2014 +0800
----------------------------------------------------------------------
.../apache/camel/component/ssh/SshEndpoint.java | 109 +++++++++++--------
1 file changed, 61 insertions(+), 48 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1b0f1162/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
----------------------------------------------------------------------
diff --git a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
index 2465e96..b5bd60e 100644
--- a/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
+++ b/components/camel-ssh/src/main/java/org/apache/camel/component/ssh/SshEndpoint.java
@@ -98,55 +98,68 @@ public class SshEndpoint extends ScheduledPollEndpoint {
log.debug("Connected to {}:{}", getHost(), getPort());
- AuthFuture authResult;
- ClientSession session = connectFuture.getSession();
-
- KeyPairProvider keyPairProvider;
- final String certResource = getCertResource();
- if (certResource != null) {
- log.debug("Attempting to authenticate using ResourceKey '{}'...", certResource);
- keyPairProvider = new ResourceHelperKeyPairProvider(new String[]{certResource}, getCamelContext().getClassResolver());
- } else {
- keyPairProvider = getKeyPairProvider();
+ ClientChannel channel = null;
+ ClientSession session = null;
+
+ try {
+ AuthFuture authResult;
+ session = connectFuture.getSession();
+
+ KeyPairProvider keyPairProvider;
+ final String certResource = getCertResource();
+ if (certResource != null) {
+ log.debug("Attempting to authenticate using ResourceKey '{}'...", certResource);
+ keyPairProvider = new ResourceHelperKeyPairProvider(new String[]{certResource}, getCamelContext().getClassResolver());
+ } else {
+ keyPairProvider = getKeyPairProvider();
+ }
+
+ if (keyPairProvider != null) {
+ log.debug("Attempting to authenticate username '{}' using Key...", getUsername());
+ KeyPair pair = keyPairProvider.loadKey(getKeyType());
+ authResult = session.authPublicKey(getUsername(), pair);
+ } else {
+ log.debug("Attempting to authenticate username '{}' using Password...", getUsername());
+ authResult = session.authPassword(getUsername(), getPassword());
+ }
+
+ authResult.await(getTimeout());
+
+ if (!authResult.isDone() || authResult.isFailure()) {
+ log.debug("Failed to authenticate");
+ throw new RuntimeCamelException("Failed to authenticate username " + getUsername());
+ }
+
+ channel = session.createChannel(ClientChannel.CHANNEL_EXEC, command);
+
+ ByteArrayInputStream in = new ByteArrayInputStream(new byte[]{0});
+ channel.setIn(in);
+
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ channel.setOut(out);
+
+ ByteArrayOutputStream err = new ByteArrayOutputStream();
+ channel.setErr(err);
+ OpenFuture openFuture = channel.open();
+ openFuture.await(getTimeout());
+ if (openFuture.isOpened()) {
+ channel.waitFor(ClientChannel.CLOSED, 0);
+ result = new SshResult(command, channel.getExitStatus(),
+ new ByteArrayInputStream(out.toByteArray()),
+ new ByteArrayInputStream(err.toByteArray()));
+
+ }
+ return result;
+ } finally {
+ if (channel != null) {
+ channel.close(true);
+ }
+ // need to make sure the session is closed
+ if (session != null) {
+ session.close(false);
+ }
}
-
- if (keyPairProvider != null) {
- log.debug("Attempting to authenticate username '{}' using Key...", getUsername());
- KeyPair pair = keyPairProvider.loadKey(getKeyType());
- authResult = session.authPublicKey(getUsername(), pair);
- } else {
- log.debug("Attempting to authenticate username '{}' using Password...", getUsername());
- authResult = session.authPassword(getUsername(), getPassword());
- }
-
- authResult.await(getTimeout());
-
- if (!authResult.isDone() || authResult.isFailure()) {
- log.debug("Failed to authenticate");
- throw new RuntimeCamelException("Failed to authenticate username " + getUsername());
- }
-
- ClientChannel channel = session.createChannel(ClientChannel.CHANNEL_EXEC, command);
-
- ByteArrayInputStream in = new ByteArrayInputStream(new byte[]{0});
- channel.setIn(in);
-
- ByteArrayOutputStream out = new ByteArrayOutputStream();
- channel.setOut(out);
-
- ByteArrayOutputStream err = new ByteArrayOutputStream();
- channel.setErr(err);
- OpenFuture openFuture = channel.open();
- openFuture.await(getTimeout());
- if (openFuture.isOpened()) {
- channel.waitFor(ClientChannel.CLOSED, 0);
- result = new SshResult(command, channel.getExitStatus(),
- new ByteArrayInputStream(out.toByteArray()),
- new ByteArrayInputStream(err.toByteArray()));
-
- }
-
- return result;
+
}
@Override
[2/2] git commit: Added a warning log when we get the exception from
xmlrpc server
Posted by ni...@apache.org.
Added a warning log when we get the exception from xmlrpc server
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/11559611
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/11559611
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/11559611
Branch: refs/heads/master
Commit: 11559611b43cc7e58c5bdfad42935b1c0dece8c8
Parents: 44cad62
Author: Willem Jiang <wi...@gmail.com>
Authored: Fri Mar 7 11:16:34 2014 +0800
Committer: Willem Jiang <wi...@gmail.com>
Committed: Fri Mar 7 11:17:53 2014 +0800
----------------------------------------------------------------------
.../camel/component/xmlrpc/XmlRpcProducer.java | 17 +++++++++++------
1 file changed, 11 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/11559611/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcProducer.java
----------------------------------------------------------------------
diff --git a/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcProducer.java b/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcProducer.java
index 04be300..1dd2c8b 100644
--- a/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcProducer.java
+++ b/components/camel-xmlrpc/src/main/java/org/apache/camel/component/xmlrpc/XmlRpcProducer.java
@@ -44,12 +44,17 @@ public class XmlRpcProducer extends DefaultProducer implements AsyncProcessor {
LOG.trace("Process exchange: {} in the sync way.", exchange);
Message in = exchange.getIn();
String operationName = in.getHeader(XmlRpcConstants.METHOD_NAME, String.class);
- //TODO need to use the binding to handle the requests
- Object result = client.execute(operationName, in.getBody(List.class));
- //TODO what if the request is one way operation
- // copy the in message header to the out message
- exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
- exchange.getOut().setBody(result);
+ try {
+ //TODO need to use the binding to handle the requests
+ Object result = client.execute(operationName, in.getBody(List.class));
+ //TODO what if the request is one way operation
+ // copy the in message header to the out message
+ exchange.getOut().getHeaders().putAll(exchange.getIn().getHeaders());
+ exchange.getOut().setBody(result);
+ } catch (Exception ex) {
+ LOG.warn("Got an exception {0} when invoke the XMLRPC service", ex);
+ exchange.setException(ex);
+ }
}
public boolean process(Exchange exchange, AsyncCallback callback) {