fix case where error is thrown by api

Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo
Commit: 
http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/4d7505a0
Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/4d7505a0
Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/4d7505a0

Branch: refs/heads/master
Commit: 4d7505a0b437f4294576e19d491673c57e5c808a
Parents: 7262741
Author: Robert Moss <[email protected]>
Authored: Mon Jun 15 17:42:37 2015 +0100
Committer: Robert Moss <[email protected]>
Committed: Mon Jun 15 17:42:37 2015 +0100

----------------------------------------------------------------------
 .../src/main/java/brooklyn/rest/client/BrooklynApi.java       | 7 +++++--
 .../java/brooklyn/util/http/BuiltResponsePreservingError.java | 1 -
 2 files changed, 5 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d7505a0/usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java
----------------------------------------------------------------------
diff --git 
a/usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java 
b/usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java
index fb2322c..c003d63 100644
--- a/usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java
+++ b/usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java
@@ -122,9 +122,12 @@ public class BrooklynApi {
             public Object invoke(Object proxy, Method method, Object[] args) 
throws Throwable {                 
                 try {
                     Object result1 = method.invoke(result0, args);
+                    Class<?> type = String.class;
                     if (result1 instanceof Response) {
-                        String responseClass = 
method.getAnnotation(ApiOperation.class).responseClass();
-                        Class<?> type = Class.forName(responseClass);
+                        if(((Response)result1).getStatus()/100 == 2) {
+                           String responseClass = 
method.getAnnotation(ApiOperation.class).responseClass();
+                           type = Class.forName(responseClass);
+                        }
                         // wrap the original response so it self-closes
                         result1 = 
BuiltResponsePreservingError.copyResponseAndClose((Response) result1, type);
                     }

http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/4d7505a0/usage/rest-client/src/main/java/brooklyn/util/http/BuiltResponsePreservingError.java
----------------------------------------------------------------------
diff --git 
a/usage/rest-client/src/main/java/brooklyn/util/http/BuiltResponsePreservingError.java
 
b/usage/rest-client/src/main/java/brooklyn/util/http/BuiltResponsePreservingError.java
index de21dc9..c3ad96a 100644
--- 
a/usage/rest-client/src/main/java/brooklyn/util/http/BuiltResponsePreservingError.java
+++ 
b/usage/rest-client/src/main/java/brooklyn/util/http/BuiltResponsePreservingError.java
@@ -53,7 +53,6 @@ public class BuiltResponsePreservingError extends 
BuiltResponse {
             status = source.getStatus();
             headers.putAll(source.getHeaders());
             if (source instanceof org.jboss.resteasy.client.ClientResponse) {
-                // ClientResponse requires strong type info, which we don't 
yet have
                 entity = 
((org.jboss.resteasy.client.ClientResponse<?>)source).getEntity(type);
             } else {
                 entity = source.getEntity();

Reply via email to