You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by dh...@apache.org on 2014/09/16 22:46:39 UTC

git commit: CAMEL-7829 Added support for OK responses for PUT, also support for handling updated resource values for patch and merge

Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x 922e849e1 -> 4d2b14c25


CAMEL-7829 Added support for OK responses for PUT, also support for handling updated resource values for patch and merge


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

Branch: refs/heads/camel-2.14.x
Commit: 4d2b14c252db49e23fd0d5349c5f6d2aa25857aa
Parents: 922e849
Author: Dhiraj Bokde <dh...@yahoo.com>
Authored: Tue Sep 16 13:46:22 2014 -0700
Committer: Dhiraj Bokde <dh...@yahoo.com>
Committed: Tue Sep 16 13:46:33 2014 -0700

----------------------------------------------------------------------
 .../olingo2/api/impl/Olingo2AppImpl.java        | 69 ++++++++++++++++++--
 1 file changed, 63 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/4d2b14c2/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
index ecb7d96..2c41453 100644
--- a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
+++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java
@@ -415,9 +415,14 @@ public final class Olingo2AppImpl implements Olingo2App {
 
                     // if a entity is created (via POST request) the response body contains the new created entity
                     HttpStatusCodes statusCode = HttpStatusCodes.fromStatusCode(result.getStatusLine().getStatusCode());
-                    if (statusCode != HttpStatusCodes.NO_CONTENT) {
 
-                        // TODO do we need to handle response based on other UriTypes???
+                    // look for no content, or no response body!!!
+                    final boolean noEntity = result.getEntity() == null || result.getEntity().getContentLength() == 0;
+                    if (statusCode == HttpStatusCodes.NO_CONTENT || noEntity) {
+                        responseHandler.onResponse(
+                            (T) HttpStatusCodes.fromStatusCode(result.getStatusLine().getStatusCode()));
+                    } else {
+
                         switch (uriInfo.getUriType()) {
                         case URI9:
                             // $batch
@@ -457,18 +462,70 @@ public final class Olingo2AppImpl implements Olingo2App {
                             responseHandler.onResponse((T) responses);
                             break;
 
-                        default:
+                        case URI4:
+                        case URI5:
+                            // simple property
+                            // get the response content as Object for $value or Map<String, Object> otherwise
+                            final List<EdmProperty> simplePropertyPath = uriInfo.getPropertyPath();
+                            final EdmProperty simpleProperty = simplePropertyPath.get(simplePropertyPath.size() - 1);
+                            if (uriInfo.isValue()) {
+                                responseHandler.onResponse(
+                                    (T) EntityProvider.readPropertyValue(simpleProperty,
+                                        result.getEntity().getContent()));
+                            } else {
+                                responseHandler.onResponse(
+                                    (T) EntityProvider.readProperty(getContentType(), simpleProperty,
+                                        result.getEntity().getContent(),
+                                        EntityProviderReadProperties.init().build()));
+                            }
+                            break;
+
+                        case URI3:
+                            // complex property
+                            // get the response content as Map<String, Object>
+                            final List<EdmProperty> complexPropertyPath = uriInfo.getPropertyPath();
+                            final EdmProperty complexProperty = complexPropertyPath.get(complexPropertyPath.size() - 1);
+                            responseHandler.onResponse(
+                                (T) EntityProvider.readProperty(getContentType(), complexProperty,
+                                result.getEntity().getContent(),
+                                EntityProviderReadProperties.init().build()));
+                            break;
+
+                        case URI7A:
+                            // $links with 0..1 cardinality property
+                            // get the response content as String
+                            final EdmEntitySet targetLinkEntitySet = uriInfo.getTargetEntitySet();
+                            responseHandler.onResponse(
+                                (T) EntityProvider.readLink(getContentType(), targetLinkEntitySet,
+                                result.getEntity().getContent()));
+                            break;
+
+                        case URI7B:
+                            // $links with * cardinality property
+                            // get the response content as java.util.List<String>
+                            final EdmEntitySet targetLinksEntitySet = uriInfo.getTargetEntitySet();
+                            responseHandler.onResponse(
+                                (T) EntityProvider.readLinks(getContentType(), targetLinksEntitySet,
+                                result.getEntity().getContent()));
+                            break;
+
+                        case URI1:
+                        case URI2:
+                        case URI6A:
+                        case URI6B:
+                            // Entity
                             // get the response content as an ODataEntry object
                             responseHandler.onResponse((T) EntityProvider.readEntry(response.getContentHeader(),
                                 uriInfo.getTargetEntitySet(),
                                 result.getEntity().getContent(),
                                 EntityProviderReadProperties.init().build()));
                             break;
+
+                        default:
+                            throw new ODataApplicationException("Unsupported resource type " + uriInfo.getTargetType(),
+                                Locale.ENGLISH);
                         }
 
-                    } else {
-                        responseHandler.onResponse(
-                            (T) HttpStatusCodes.fromStatusCode(result.getStatusLine().getStatusCode()));
                     }
                 }
             });