You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@brooklyn.apache.org by robertgmoss <gi...@git.apache.org> on 2015/06/15 17:47:14 UTC

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

GitHub user robertgmoss opened a pull request:

    https://github.com/apache/incubator-brooklyn/pull/690

    Determine type of entity in rest response from api annotation

    Previously the Response was read into a String, which makes it difficult
    to convert back into the domain object.

You can merge this pull request into a Git repository by running:

    $ git pull https://github.com/robertgmoss/incubator-brooklyn fix/rest-client-response

Alternatively you can review and apply these changes as the patch at:

    https://github.com/apache/incubator-brooklyn/pull/690.patch

To close this pull request, make a commit to your master/trunk branch
with (at least) the following in the commit message:

    This closes #690
    
----
commit 7262741265566da944ec648ce35a3c59664adef7
Author: Robert Moss <ro...@gmail.com>
Date:   2015-06-15T15:31:21Z

    Determine type of entity in rest response from api annotation
    
    Previously the Response was read into a String, which makes it difficult
    to convert back into the domain object.

----


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-113437432
  
    Looks good. Only a couple of very minor points. 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823145
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +124,39 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        Response resp = (Response)result1;
    +                        if(HttpTool.isStatusCodeHealthy(resp.getStatus()) && method.isAnnotationPresent(ApiOperation.class)) {
    +                           type = getClassFromMethodAnnotationOrDefault(method, type);
    +                        }
    +                        // wrap the original response so it self-closes
    +                        result1 = BuiltResponsePreservingError.copyResponseAndClose(resp, type);
    +                    }
    +                    return result1;
                     } catch (Throwable e) {
                         if (e instanceof InvocationTargetException) {
                             // throw the original exception
                             e = ((InvocationTargetException)e).getTargetException();
                         }
                         throw Exceptions.propagate(e);
    +                }  
    +            }
    +            
    +            private Class<?> getClassFromMethodAnnotationOrDefault(Method method, Class<?> def){
    +                Class<?> type;
    +                try{
    +                    String responseClass = method.getAnnotation(ApiOperation.class).responseClass();
    +                    type = Class.forName(responseClass);
    +                } catch (Exception e) {
    +                    type = def;
    +                    LOG.info("Unable to get class from annotation: {}.  Defaulting to {}", e.getMessage(), def.getName());
    --- End diff --
    
    debug might be better?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32812240
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +120,37 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        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(resp, type);
    +                    }
    +                    return result1;
                     } catch (Throwable e) {
                         if (e instanceof InvocationTargetException) {
                             // throw the original exception
                             e = ((InvocationTargetException)e).getTargetException();
                         }
                         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;
    --- End diff --
    
    Agree, will do


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32465480
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +119,26 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    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();
    --- End diff --
    
    Looks like `responseClass` is used purely for documentation, can't rely on it for the exact return type. Better get the return type from the method handle.
    For example:
      * `CatalogApi` doesn't include the fully qualified names
      * Some methods return collections, indicated by `multiValueResponse` in the annotation
      * Some have atomic values, not including a `responseClass`
      * Some methods have complex return types, but don't have `responseClass`
      * etc.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823085
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -34,12 +34,16 @@
     import org.apache.http.auth.Credentials;
     import org.apache.http.auth.UsernamePasswordCredentials;
     import org.apache.http.impl.client.DefaultHttpClient;
    +import org.eclipse.jetty.util.log.Log;
    --- End diff --
    
    wrong `Log` no?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by mikezaccardo <gi...@git.apache.org>.
Github user mikezaccardo commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-112475512
  
    LGTM


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32812175
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -197,6 +216,11 @@ public AccessApi getAccessApi() {
         }
     
         public static <T> T getEntity(Response response, Class<T> type) {
    --- End diff --
    
    This is called later by consumers of the api, which still returns a Response Object (which has had its contents read from one Response into another reflectively).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823799
  
    --- Diff: 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>
    --- End diff --
    
    i see.  just bring in the method as private static rather than add `core` as a dependency?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by mikezaccardo <gi...@git.apache.org>.
Github user mikezaccardo commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32534673
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +120,37 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        Response resp = (Response)result1;
    +                        if(HttpTool.isStatusCodeHealthy(resp.getStatus()) && method.isAnnotationPresent(ApiOperation.class)) {
    --- End diff --
    
    Is a healthy response the only case in which we care about the specific type?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-113444449
  
    Thanks @aledsage, comments addressed


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by ahgittin <gi...@git.apache.org>.
Github user ahgittin commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823340
  
    --- Diff: 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>
    --- End diff --
    
    why do we need to add `<scope>compile</scope>`?
    
    previously both dependencies, regular and `<classifier>tests</classifier>` were only brought in for `test` scope I think which lowers the footprint for someone using the REST client.  also the ordering of the regular classifier first is cleaner i think.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32811436
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +120,37 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        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(resp, type);
    +                    }
    +                    return result1;
                     } catch (Throwable e) {
                         if (e instanceof InvocationTargetException) {
                             // throw the original exception
                             e = ((InvocationTargetException)e).getTargetException();
                         }
                         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;
    --- End diff --
    
    Worth a log statement, rather than swallowing the exception, to explain (in the debug log) why it defaulted to a String?
    
    I also like to do `Exceptions.propagateIfFatal()`. This mainly is for handing InterruptedExceptions and RuntimeInterruptedExceptions right, which should never happen in the calls within the try block (so not important here).


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32534702
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +119,26 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    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();
    --- End diff --
    
    @neykov That will fall back to String because it isn't a FQN


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-112487037
  
    LGTM as well.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823507
  
    --- Diff: 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>
    --- End diff --
    
    was brought in to use `HttpTool.isStatusCodeHealthy()`.  It wouldn't
    compile without the `compile` scope.
    
    On 19 June 2015 at 13:15, Alex Heneveld <no...@github.com> wrote:
    
    > In usage/rest-client/pom.xml
    > <https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32823340>
    > :
    >
    > >              <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>
    >
    > why do we need to add <scope>compile</scope>?
    >
    > previously both dependencies, regular and <classifier>tests</classifier>
    > were only brought in for test scope I think which lowers the footprint
    > for someone using the REST client. also the ordering of the regular
    > classifier first is cleaner i think.
    >
    > —
    > Reply to this email directly or view it on GitHub
    > <https://github.com/apache/incubator-brooklyn/pull/690/files#r32823340>.
    >
    
    -- 
    Cloudsoft Corporation Limited, Registered in Scotland No: SC349230. 
     Registered Office: 13 Dryden Place, Edinburgh, EH9 1RP
     
    This e-mail message is confidential and for use by the addressee only. If 
    the message is received by anyone other than the addressee, please return 
    the message to the sender by replying to it and then delete the message 
    from your computer. Internet e-mails are not necessarily secure. Cloudsoft 
    Corporation Limited does not accept responsibility for changes made to this 
    message after it was sent.
    
    Whilst all reasonable care has been taken to avoid the transmission of 
    viruses, it is the responsibility of the recipient to ensure that the 
    onward transmission, opening or use of this message and any attachments 
    will not adversely affect its systems or data. No responsibility is 
    accepted by Cloudsoft Corporation Limited in this regard and the recipient 
    should carry out such virus and other checks as it considers appropriate.



---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32533391
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +119,26 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    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();
    --- End diff --
    
    Good point. Then there's only one case where I am not clear what happens - in `brooklyn.rest.api.CatalogApi.create(String)` the annotation is `responseClass = "Response"`, it will probably fall back?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-112408406
  
    This failure appears not to be to do with this PR (failure to access ports)


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-113112002
  
    Can this be merged?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by mikezaccardo <gi...@git.apache.org>.
Github user mikezaccardo commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32535501
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +120,37 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        Response resp = (Response)result1;
    +                        if(HttpTool.isStatusCodeHealthy(resp.getStatus()) && method.isAnnotationPresent(ApiOperation.class)) {
    --- End diff --
    
    Roger that, thanks


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by aledsage <gi...@git.apache.org>.
Github user aledsage commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32811590
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -197,6 +216,11 @@ public AccessApi getAccessApi() {
         }
     
         public static <T> T getEntity(Response response, Class<T> type) {
    --- End diff --
    
    It looks like this method isn't called (or is it reflective)?
    
    If it's not useful, but are concerned about API compatibility, then could mark as deprecated and delete in 0.8.0-SNAPSHOT?


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by neykov <gi...@git.apache.org>.
Github user neykov commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32464170
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +119,26 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        if(((Response)result1).getStatus()/100 == 2) {
    --- End diff --
    
    Better use `HttpTool.isStatusCodeHealthy`


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by asfgit <gi...@git.apache.org>.
Github user asfgit closed the pull request at:

    https://github.com/apache/incubator-brooklyn/pull/690


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#issuecomment-113504554
  
    @ahgittin done


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32508752
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +119,26 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    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();
    --- End diff --
    
    @neykov I've changed it to best effort now.  We can't use the return type because in this case it is wrapped in a `Response` object.  The other cases you list are also not a problem because we are only looking at those that return a `Response`.


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---

[GitHub] incubator-brooklyn pull request: Determine type of entity in rest ...

Posted by robertgmoss <gi...@git.apache.org>.
Github user robertgmoss commented on a diff in the pull request:

    https://github.com/apache/incubator-brooklyn/pull/690#discussion_r32534946
  
    --- Diff: usage/rest-client/src/main/java/brooklyn/rest/client/BrooklynApi.java ---
    @@ -116,22 +120,37 @@ public BrooklynApi(URL endpoint, ClientExecutor clientExecutor) {
             final T result0 = ProxyFactory.create(clazz, target, clientExecutor);
             return (T) Proxy.newProxyInstance(clazz.getClassLoader(), new Class<?>[] { clazz }, new InvocationHandler() {
                 @Override
    -            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
    -                Object result1;
    +            public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {                 
                     try {
    -                    result1 = method.invoke(result0, args);
    +                    Object result1 = method.invoke(result0, args);
    +                    Class<?> type = String.class;
    +                    if (result1 instanceof Response) {
    +                        Response resp = (Response)result1;
    +                        if(HttpTool.isStatusCodeHealthy(resp.getStatus()) && method.isAnnotationPresent(ApiOperation.class)) {
    --- End diff --
    
    @mikezaccardo yes, because an unhealthy one cannot be converted to a domain object so should just be serialized as a String


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastructure@apache.org or file a JIRA ticket
with INFRA.
---