You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@karaf.apache.org by jb...@apache.org on 2015/04/15 13:53:36 UTC
karaf-cellar git commit: [KARAF-3664] Added support for DOSGi
exception pass through between client and services
Repository: karaf-cellar
Updated Branches:
refs/heads/master 100c3278c -> b4a250411
[KARAF-3664] Added support for DOSGi exception pass through between client and services
Project: http://git-wip-us.apache.org/repos/asf/karaf-cellar/repo
Commit: http://git-wip-us.apache.org/repos/asf/karaf-cellar/commit/b4a25041
Tree: http://git-wip-us.apache.org/repos/asf/karaf-cellar/tree/b4a25041
Diff: http://git-wip-us.apache.org/repos/asf/karaf-cellar/diff/b4a25041
Branch: refs/heads/master
Commit: b4a250411ff664ee559121dac026550b4348bab4
Parents: 100c327
Author: Alberto São Marcos <al...@gmail.com>
Authored: Tue Apr 14 15:45:29 2015 +0100
Committer: Alberto São Marcos <al...@gmail.com>
Committed: Tue Apr 14 15:45:29 2015 +0100
----------------------------------------------------------------------
.../RemoteServiceInvocationException.java | 37 ++++++++++++++++++++
.../cellar/dosgi/RemoteServiceCallHandler.java | 12 +++++--
.../dosgi/RemoteServiceInvocationHandler.java | 12 +++++++
3 files changed, 58 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/b4a25041/core/src/main/java/org/apache/karaf/cellar/core/exception/RemoteServiceInvocationException.java
----------------------------------------------------------------------
diff --git a/core/src/main/java/org/apache/karaf/cellar/core/exception/RemoteServiceInvocationException.java b/core/src/main/java/org/apache/karaf/cellar/core/exception/RemoteServiceInvocationException.java
new file mode 100644
index 0000000..219b514
--- /dev/null
+++ b/core/src/main/java/org/apache/karaf/cellar/core/exception/RemoteServiceInvocationException.java
@@ -0,0 +1,37 @@
+/*
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.karaf.cellar.core.exception;
+
+/**
+ * Exception raised when remote service call invocation raises an exception.
+ */
+public class RemoteServiceInvocationException extends Exception {
+
+ public RemoteServiceInvocationException() {
+ // nothing to do
+ }
+
+ public RemoteServiceInvocationException(String message) {
+ super(message);
+ }
+
+ public RemoteServiceInvocationException(String message, Throwable cause) {
+ super(message, cause);
+ }
+
+ public RemoteServiceInvocationException(Throwable cause) {
+ super(cause);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/b4a25041/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceCallHandler.java
----------------------------------------------------------------------
diff --git a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceCallHandler.java b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceCallHandler.java
index dc0f37e..c6f5732 100644
--- a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceCallHandler.java
+++ b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceCallHandler.java
@@ -21,6 +21,7 @@ import org.apache.karaf.cellar.core.control.SwitchStatus;
import org.apache.karaf.cellar.core.event.EventHandler;
import org.apache.karaf.cellar.core.event.EventProducer;
import org.apache.karaf.cellar.core.event.EventTransportFactory;
+import org.apache.karaf.cellar.core.exception.RemoteServiceInvocationException;
import org.osgi.framework.BundleContext;
import org.osgi.framework.InvalidSyntaxException;
import org.osgi.framework.ServiceReference;
@@ -84,6 +85,8 @@ public class RemoteServiceCallHandler extends CellarSupport implements EventHand
}
}
+ RemoteServiceResult result = new RemoteServiceResult(event.getId());
+ EventProducer producer = eventTransportFactory.getEventProducer(Constants.RESULT_PREFIX + Constants.SEPARATOR + event.getSourceNode().getId() + event.getEndpointId(), false);
try {
Method method;
if (classes.length > 0) {
@@ -93,18 +96,21 @@ public class RemoteServiceCallHandler extends CellarSupport implements EventHand
}
Object obj = method.invoke(targetService, event.getArguments().toArray());
- RemoteServiceResult result = new RemoteServiceResult(event.getId());
result.setResult(obj);
-
- EventProducer producer = eventTransportFactory.getEventProducer(Constants.RESULT_PREFIX + Constants.SEPARATOR + event.getSourceNode().getId() + event.getEndpointId(), false);
producer.produce(result);
} catch (NoSuchMethodException e) {
LOGGER.error("CELLAR DOSGI: unable to find remote method for service", e);
+ result.setResult(new RemoteServiceInvocationException(e));
+ producer.produce(result);
} catch (InvocationTargetException e) {
LOGGER.error("CELLAR DOSGI: unable to invoke remote method for service", e);
+ result.setResult(new RemoteServiceInvocationException(e.getCause()));
+ producer.produce(result);
} catch (IllegalAccessException e) {
LOGGER.error("CELLAR DOSGI: unable to access remote method for service", e);
+ result.setResult(new RemoteServiceInvocationException(e));
+ producer.produce(result);
}
}
}
http://git-wip-us.apache.org/repos/asf/karaf-cellar/blob/b4a25041/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceInvocationHandler.java
----------------------------------------------------------------------
diff --git a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceInvocationHandler.java b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceInvocationHandler.java
index fc82ed4..79099f8 100644
--- a/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceInvocationHandler.java
+++ b/dosgi/src/main/java/org/apache/karaf/cellar/dosgi/RemoteServiceInvocationHandler.java
@@ -16,6 +16,7 @@ package org.apache.karaf.cellar.dosgi;
import org.apache.karaf.cellar.core.ClusterManager;
import org.apache.karaf.cellar.core.Node;
import org.apache.karaf.cellar.core.command.ExecutionContext;
+import org.apache.karaf.cellar.core.exception.RemoteServiceInvocationException;
import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;
@@ -60,6 +61,17 @@ public class RemoteServiceInvocationHandler implements InvocationHandler {
if(results != null) {
for(Map.Entry<Node,RemoteServiceResult> entry:results.entrySet()) {
RemoteServiceResult result = entry.getValue();
+
+ // an exception being thrown by the remote service call must be raised locally
+ if (result != null && result.getResult() != null && result.getResult() instanceof RemoteServiceInvocationException) {
+ RemoteServiceInvocationException ute = (RemoteServiceInvocationException) result.getResult();
+ if (ute.getCause() != null) {
+ throw ute.getCause();
+ } else {
+ throw ute;
+ }
+ }
+
return result.getResult();
}
}