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:14 UTC

[3/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/a64cc311
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/a64cc311
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/a64cc311

Branch: refs/heads/camel-2.19.x
Commit: a64cc311ae4797719dea69ca06b5261197b0185b
Parents: 07d0455
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Jun 15 11:44:48 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Jun 15 13:15:56 2017 +0200

----------------------------------------------------------------------
 .../api/impl/AbstractFutureCallback.java        |  5 ++-
 .../olingo4/api/impl/Olingo4AppImpl.java        |  4 +-
 .../olingo4/api/impl/Olingo4Helper.java         | 42 ++++++++++++++++++++
 3 files changed, 48 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/a64cc311/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/AbstractFutureCallback.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/AbstractFutureCallback.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/AbstractFutureCallback.java
index 1a206fa..b710f04 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/AbstractFutureCallback.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/AbstractFutureCallback.java
@@ -37,6 +37,8 @@ import org.apache.olingo.commons.api.ex.ODataException;
 import org.apache.olingo.commons.api.format.ContentType;
 import org.apache.olingo.commons.api.http.HttpStatusCode;
 
+import static org.apache.camel.component.olingo4.api.impl.Olingo4Helper.getContentTypeHeader;
+
 /**
 * Helper implementation of {@link org.apache.http.concurrent.FutureCallback}
  * for {@link org.apache.camel.component.olingo4.api.impl.Olingo4AppImpl}
@@ -58,8 +60,7 @@ public abstract class AbstractFutureCallback<T> implements FutureCallback<HttpRe
         if (HttpStatusCode.BAD_REQUEST.getStatusCode() <= httpStatusCode.getStatusCode() && httpStatusCode.getStatusCode() <= NETWORK_CONNECT_TIMEOUT_ERROR) {
             if (response.getEntity() != null) {
                 try {
-                    final ContentType responseContentType = ContentType.parse(
-                        response.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+                    final ContentType responseContentType = getContentTypeHeader(response);
                               
                     if (ODATA_MIME_TYPE_PATTERN.matcher(responseContentType.toContentTypeString()).matches()) {
                         final ODataReader reader = ODataClientFactory.getClient().getReader();

http://git-wip-us.apache.org/repos/asf/camel/blob/a64cc311/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
index 7dffd1c..bea94b5 100644
--- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java
@@ -108,6 +108,8 @@ import org.apache.olingo.server.core.uri.parser.Parser;
 import org.apache.olingo.server.core.uri.parser.UriParserException;
 import org.apache.olingo.server.core.uri.validator.UriValidationException;
 
+import static org.apache.camel.component.olingo4.api.impl.Olingo4Helper.getContentTypeHeader;
+
 /**
  * Application API used by Olingo4 Component.
  */
@@ -640,7 +642,7 @@ public final class Olingo4AppImpl implements Olingo4App {
                     final UriInfo uriInfo = parseUri(edm, batchPartQueryRequest.getResourcePath(), null);
 
                     if (HttpStatusCode.BAD_REQUEST.getStatusCode() <= batchPartLineStatusCode && batchPartLineStatusCode <= AbstractFutureCallback.NETWORK_CONNECT_TIMEOUT_ERROR) {
-                        final ContentType responseContentType = ContentType.parse(batchPartHttpResponse.getFirstHeader(HttpHeaders.CONTENT_TYPE).getValue());
+                        final ContentType responseContentType = getContentTypeHeader(batchPartHttpResponse);
                         content = odataReader.readError(batchPartHttpResponse.getEntity().getContent(), responseContentType);
                     } else if (batchPartLineStatusCode == HttpStatusCode.NO_CONTENT.getStatusCode()) {
                         // nothing to do if NO_CONTENT returning

http://git-wip-us.apache.org/repos/asf/camel/blob/a64cc311/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4Helper.java
----------------------------------------------------------------------
diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4Helper.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4Helper.java
new file mode 100644
index 0000000..d68aab0
--- /dev/null
+++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/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.olingo4.api.impl;
+
+import org.apache.http.HttpHeaders;
+import org.apache.http.HttpResponse;
+import org.apache.olingo.commons.api.format.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;
+        }
+    }
+
+}