Review fix. Do try .. catch of Exceptions in the producer Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/b1f7ea62 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/b1f7ea62 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/b1f7ea62
Branch: refs/heads/master Commit: b1f7ea623da2748537d6349ebbea4ed3f220a31a Parents: 3bc8d1b Author: Preben Asmussen <preben.asmus...@gmail.com> Authored: Wed Apr 12 17:25:22 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Apr 12 21:56:07 2017 +0200 ---------------------------------------------------------------------- .../camel/component/pubnub/PubNubProducer.java | 83 ++++++++++---------- 1 file changed, 43 insertions(+), 40 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/b1f7ea62/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java ---------------------------------------------------------------------- diff --git a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java index 4e688d4..bb20e1b 100644 --- a/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java +++ b/components/camel-pubnub/src/main/java/org/apache/camel/component/pubnub/PubNubProducer.java @@ -20,6 +20,7 @@ import java.util.Arrays; import com.pubnub.api.PubNubException; import com.pubnub.api.callbacks.PNCallback; +import com.pubnub.api.models.consumer.PNErrorData; import com.pubnub.api.models.consumer.PNPublishResult; import com.pubnub.api.models.consumer.PNStatus; import com.pubnub.api.models.consumer.history.PNHistoryResult; @@ -56,43 +57,41 @@ public class PubNubProducer extends DefaultAsyncProducer { Operation operation = getOperation(exchange); LOG.debug("Executing {} operation", operation); - - switch (operation) { - case PUBLISH: { - doPublish(exchange, callback); - break; - } - case FIRE: { - doFire(exchange, callback); - break; - } - case GETHISTORY: { - doGetHistory(exchange, callback); - break; - } - case GETSTATE: { - doGetState(exchange, callback); - break; - } - case HERENOW: { - doHereNow(exchange, callback); - break; - } - case SETSTATE: { - doSetState(exchange, callback); - break; - } - case WHERENOW: { - doWhereNow(exchange, callback); - break; - } - default: - throw new UnsupportedOperationException(operation.toString()); - } - if (exchange.getException() != null) { - if (exchange.getException() instanceof PubNubException) { - LOG.error("Exception from PubNub : {}", exchange.getException(PubNubException.class).getPubnubError().getMessage()); + try { + switch (operation) { + case PUBLISH: { + doPublish(exchange, callback); + break; + } + case FIRE: { + doFire(exchange, callback); + break; } + case GETHISTORY: { + doGetHistory(exchange, callback); + break; + } + case GETSTATE: { + doGetState(exchange, callback); + break; + } + case HERENOW: { + doHereNow(exchange, callback); + break; + } + case SETSTATE: { + doSetState(exchange, callback); + break; + } + case WHERENOW: { + doWhereNow(exchange, callback); + break; + } + default: + throw new UnsupportedOperationException(operation.toString()); + } + } catch (Exception e) { + exchange.setException(e); callback.done(true); return true; } @@ -103,8 +102,7 @@ public class PubNubProducer extends DefaultAsyncProducer { private void doPublish(Exchange exchange, AsyncCallback callback) { Object body = exchange.getIn().getBody(); if (ObjectHelper.isEmpty(body)) { - exchange.setException(new CamelException("Can not publish empty message")); - callback.done(true); + throw new RuntimeException("Can not publish empty message"); } LOG.debug("Sending message [{}] to channel [{}]", body, getChannel(exchange)); endpoint.getPubnub() @@ -222,9 +220,14 @@ public class PubNubProducer extends DefaultAsyncProducer { private void processMessage(Exchange exchange, AsyncCallback callback, PNStatus status, Object body) { if (status.isError()) { - exchange.setException(status.getErrorData().getThrowable()); + PNErrorData errorData = status.getErrorData(); callback.done(false); - return; + exchange.setException(errorData.getThrowable()); + if (errorData != null && errorData.getThrowable() instanceof PubNubException) { + PubNubException pubNubException = (PubNubException) errorData.getThrowable(); + throw new RuntimeException(pubNubException.getPubnubError().getMessage(), errorData.getThrowable()); + } + throw new RuntimeException(status.getErrorData().getThrowable()); } if (exchange.getPattern().isOutCapable()) { exchange.getOut().copyFrom(exchange.getIn());