Change to best effort If the annotation is present it will use this information to try to read the entity with this class, otherwise it will use the default String
Project: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/commit/1e2887d9 Tree: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/tree/1e2887d9 Diff: http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/diff/1e2887d9 Branch: refs/heads/master Commit: 1e2887d9d3cb153c17621d7c120300a1da79a1cc Parents: 4d7505a Author: Robert Moss <[email protected]> Authored: Tue Jun 16 11:27:08 2015 +0100 Committer: Robert Moss <[email protected]> Committed: Tue Jun 16 11:27:08 2015 +0100 ---------------------------------------------------------------------- usage/rest-client/pom.xml | 4 ++-- .../java/brooklyn/rest/client/BrooklynApi.java | 20 ++++++++++++++++---- 2 files changed, 18 insertions(+), 6 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1e2887d9/usage/rest-client/pom.xml ---------------------------------------------------------------------- diff --git a/usage/rest-client/pom.xml b/usage/rest-client/pom.xml index af001aa..30796b3 100644 --- a/usage/rest-client/pom.xml +++ b/usage/rest-client/pom.xml @@ -114,14 +114,14 @@ <groupId>org.apache.brooklyn</groupId> <artifactId>brooklyn-core</artifactId> <version>${project.version}</version> + <classifier>tests</classifier> <scope>test</scope> </dependency> <dependency> <groupId>org.apache.brooklyn</groupId> <artifactId>brooklyn-core</artifactId> <version>${project.version}</version> - <classifier>tests</classifier> - <scope>test</scope> + <scope>compile</scope> </dependency> <dependency> <groupId>org.apache.brooklyn</groupId> http://git-wip-us.apache.org/repos/asf/incubator-brooklyn/blob/1e2887d9/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 c003d63..f8d9dfb 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 @@ -59,6 +59,7 @@ import brooklyn.rest.api.UsageApi; import brooklyn.rest.api.VersionApi; import brooklyn.util.exceptions.Exceptions; import brooklyn.util.http.BuiltResponsePreservingError; +import brooklyn.util.http.HttpTool; import com.wordnik.swagger.core.ApiOperation; @@ -124,12 +125,12 @@ public class BrooklynApi { Object result1 = method.invoke(result0, args); Class<?> type = String.class; if (result1 instanceof Response) { - if(((Response)result1).getStatus()/100 == 2) { - String responseClass = method.getAnnotation(ApiOperation.class).responseClass(); - type = Class.forName(responseClass); + Response resp = (Response)result1; + if(HttpTool.isStatusCodeHealthy(resp.getStatus()) && method.isAnnotationPresent(ApiOperation.class)) { + type = getClassFromMethodAnnotationOrDefault(resp, method, type); } // wrap the original response so it self-closes - result1 = BuiltResponsePreservingError.copyResponseAndClose((Response) result1, type); + result1 = BuiltResponsePreservingError.copyResponseAndClose(resp, type); } return result1; } catch (Throwable e) { @@ -140,6 +141,17 @@ public class BrooklynApi { throw Exceptions.propagate(e); } } + + private Class<?> getClassFromMethodAnnotationOrDefault(Response resp, Method method, Class<?> def){ + Class<?> type; + try{ + String responseClass = method.getAnnotation(ApiOperation.class).responseClass(); + type = Class.forName(responseClass); + } catch (Exception e) { + type = def; + } + return type; + } }); }
