You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/06/15 11:16:13 UTC

[2/4] camel git commit: CAMEL-11413: camel-olingo - Potential NPE in getting content-type header

CAMEL-11413: camel-olingo - Potential NPE in getting content-type header


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

Branch: refs/heads/master
Commit: cbeb8496512fec459b85e1d7a6d144b2c5a22971
Parents: e951622
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 15 13:14:06 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 15 13:14:06 2017 +0200

----------------------------------------------------------------------
 .../api/impl/AbstractFutureCallback.java        |  5 ++-
 .../olingo2/api/impl/Olingo2AppImpl.java        |  6 ++-
 .../olingo2/api/impl/Olingo4Helper.java         | 42 ++++++++++++++++++++
 3 files changed, 49 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/cbeb8496/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/AbstractFutureCallback.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/AbstractFutureCallback.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/AbstractFutureCallback.java
index 1ad332e..04e22b1 100644
--- a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/AbstractFutureCallback.java
+++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/AbstractFutureCallback.java
@@ -33,6 +33,8 @@ import org.apache.olingo.odata2.api.exception.ODataApplicationException;
 import org.apache.olingo.odata2.api.exception.ODataException;
 import org.apache.olingo.odata2.api.processor.ODataErrorContext;
 
+import static org.apache.camel.component.olingo2.api.impl.Olingo4Helper.getContentTypeHeader;
+
 /**
 * Helper implementation of {@link org.apache.http.concurrent.FutureCallback}
  * for {@link org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl}
@@ -52,8 +54,7 @@ public abstract class AbstractFutureCallback<T> implements FutureCallback<HttpRe
         if (400 <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= 599) {
             if (response.getEntity() != null) {
                 try {
-                    final ContentType responseContentType = ContentType.parse(
-                        response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+                    final ContentType responseContentType = getContentTypeHeader(response);
 
                     final String mimeType = responseContentType.getMimeType();
                     if (ODATA_MIME_TYPE.matcher(mimeType).matches()) {

http://git-wip-us.apache.org/repos/asf/camel/blob/cbeb8496/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 e641162..7b3e0ed 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
@@ -91,6 +91,8 @@ import org.apache.olingo.odata2.api.processor.ODataResponse;
 import org.apache.olingo.odata2.api.uri.PathSegment;
 import org.apache.olingo.odata2.api.uri.UriParser;
 
+import static org.apache.camel.component.olingo2.api.impl.Olingo4Helper.getContentTypeHeader;
+
 /**
  * Application API used by Olingo2 Component.
  */
@@ -486,9 +488,9 @@ public final class Olingo2AppImpl implements Olingo2App {
                         switch (uriInfo.getUriType()) {
                         case URI9:
                             // $batch
+                            String type = result.containsHeader(HttpHeaders.CONTENT_TYPE) ? result.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue() : null;
                             final List<BatchSingleResponse> singleResponses = EntityProvider.parseBatchResponse(
-                                result.getEntity().getContent(),
-                                result.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+                                result.getEntity().getContent(), type);
 
                             // parse batch response bodies
                             final List<Olingo2BatchResponse> responses = new ArrayList<Olingo2BatchResponse>();

http://git-wip-us.apache.org/repos/asf/camel/blob/cbeb8496/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo4Helper.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo4Helper.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo4Helper.java
new file mode 100644
index 0000000..749ea6b
--- /dev/null
+++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo4Helper.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.camel.component.olingo2.api.impl;
+
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.http.entity.ContentType;
+
+/**
+ * Helper
+ */
+public final class Olingo4Helper {
+
+    private Olingo4Helper() {
+    }
+
+    /**
+     * Gets the content type header in a safe way
+     */
+    public static ContentType getContentTypeHeader(HttpResponse response) {
+        if (response.containsHeader(HttpHeaders.CONTENT_TYPE)) {
+            return ContentType.parse(response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+        } else {
+            return null;
+        }
+    }
+
+}