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/07/11 15:03:41 UTC

[1/2] camel git commit: CAMEL-11423 Make camel-olingo2/4 ACCEPT headers RFC-7231 compliant.

Repository: camel
Updated Branches:
  refs/heads/camel-2.19.x 78851c0a1 -> 300974fde
  refs/heads/master e60c9c122 -> 958f7f33f


CAMEL-11423 Make camel-olingo2/4 ACCEPT headers RFC-7231 compliant.

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

Branch: refs/heads/camel-2.19.x
Commit: 300974fde9c7b5494dd37d0e1d9cd8dea2444607
Parents: 78851c0
Author: Sean Haynes <s....@ieee.org>
Authored: Tue Jul 11 09:13:43 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 11 17:01:32 2017 +0200

----------------------------------------------------------------------
 .../olingo2/api/impl/Olingo2AppImpl.java        | 24 +++++++++++++----
 .../olingo4/api/impl/Olingo4AppImpl.java        | 27 +++++++++++++++-----
 2 files changed, 39 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/300974fd/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 9cfe7c7..af06775 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
@@ -766,7 +766,12 @@ public final class Olingo2AppImpl implements Olingo2App {
         }
 
         // Olingo is sensitive to batch part charset case!!
-        headers.put(HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toString().toLowerCase());
+        final ContentType contentType = getResourceContentType(uriInfo);
+        headers.put(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
+        final Charset charset = contentType.getCharset();
+        if (null != charset) {
+            headers.put(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
+        }
         if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
             headers.put(HttpHeaders.CONTENT_TYPE, getContentType());
         }
@@ -788,10 +793,16 @@ public final class Olingo2AppImpl implements Olingo2App {
     private BatchQueryPart createBatchQueryPart(UriInfoWithType uriInfo, Olingo2BatchQueryRequest batchRequest) {
 
         final Map<String, String> headers = new HashMap<String, String>(batchRequest.getHeaders());
+        final ContentType contentType = getResourceContentType(uriInfo);
+        final Charset charset = contentType.getCharset();
         if (!headers.containsKey(HttpHeaders.ACCEPT)) {
             // Olingo is sensitive to batch part charset case!!
-            headers.put(HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toString().toLowerCase());
+            headers.put(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
+        }
+        if (!headers.containsKey(HttpHeaders.ACCEPT_CHARSET) && (null != charset)) {
+            headers.put(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
         }
+        
 
         return BatchQueryPart.method("GET")
             .uri(createBatchUri(batchRequest))
@@ -1013,16 +1024,19 @@ public final class Olingo2AppImpl implements Olingo2App {
                         FutureCallback<HttpResponse> callback) {
 
         // add accept header when its not a form or multipart
-        final String contentTypeString = contentType.toString();
         if (!ContentType.APPLICATION_FORM_URLENCODED.getMimeType().equals(contentType.getMimeType())
             && !contentType.getMimeType().startsWith(MULTIPART_MIME_TYPE)) {
             // otherwise accept what is being sent
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
         }
         // is something being sent?
         if (httpUriRequest instanceof HttpEntityEnclosingRequestBase
             && httpUriRequest.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
-            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
+            final Charset charset = contentType.getCharset();
+            if (null != charset) {
+                httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
+            }
         }
 
         // set user specified custom headers

http://git-wip-us.apache.org/repos/asf/camel/blob/300974fd/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 d3afcee..980c409 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
@@ -567,7 +567,12 @@ public final class Olingo4AppImpl implements Olingo4App {
 
                     batchRequestHeaderOutputStream.write((HttpGet.METHOD_NAME + " " + batchQueryUri + " " + HttpVersion.HTTP_1_1).getBytes(Constants.UTF8));
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toContentTypeString());
+                    final ContentType acceptType = getResourceContentType(uriInfo);
+                    final String acceptCharset = acceptType.getParameter(ContentType.PARAMETER_CHARSET);
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, acceptType.getType().toLowerCase());
+                    if (null != acceptCharset) {
+                        writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+                    }
 
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
                     batchRequestHeaderOutputStream.write(boundary.getBytes(Constants.UTF8));
@@ -587,8 +592,13 @@ public final class Olingo4AppImpl implements Olingo4App {
                         .write((batchChangePart.getOperation().getHttpMethod() + " " + batchChangeUri + " " + HttpVersion.HTTP_1_1).getBytes(Constants.UTF8));
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
                     writeHttpHeader(batchRequestHeaderOutputStream, HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toContentTypeString());
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.CONTENT_TYPE, getResourceContentType(uriInfo).toContentTypeString());
+                    final ContentType acceptType = getResourceContentType(uriInfo);
+                    final String acceptCharset = acceptType.getParameter(ContentType.PARAMETER_CHARSET);
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, acceptType.getType().toLowerCase());
+                    if (null != acceptCharset) {
+                        writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+                    }
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.CONTENT_TYPE, acceptType.toContentTypeString());
 
                     if (batchChangePart.getOperation() != Operation.DELETE) {
                         batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
@@ -798,15 +808,18 @@ public final class Olingo4AppImpl implements Olingo4App {
 
     public void execute(HttpUriRequest httpUriRequest, ContentType contentType, FutureCallback<HttpResponse> callback) {
         // add accept header when its not a form or multipart
-        final String contentTypeString = contentType.toString();
         if (!ContentType.APPLICATION_FORM_URLENCODED.equals(contentType) && !contentType.toContentTypeString().startsWith(MULTIPART_MIME_TYPE)) {
             // otherwise accept what is being sent
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentType.getType().toLowerCase());
+            final String acceptCharset = contentType.getParameter(ContentType.PARAMETER_CHARSET);
+            if (null != acceptCharset) {
+                httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+            }
         }
 
         // is something being sent?
         if (httpUriRequest instanceof HttpEntityEnclosingRequestBase && httpUriRequest.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
-            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
         }
 
         // set user specified custom headers
@@ -819,7 +832,7 @@ public final class Olingo4AppImpl implements Olingo4App {
         // add 'Accept-Charset' header to avoid BOM marker presents inside
         // response stream
         if (!httpUriRequest.containsHeader(HttpHeaders.ACCEPT_CHARSET)) {
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, Constants.UTF8);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, Constants.UTF8.toLowerCase());
         }
 
         // add client protocol version if not specified


[2/2] camel git commit: CAMEL-11423 Make camel-olingo2/4 ACCEPT headers RFC-7231 compliant.

Posted by da...@apache.org.
CAMEL-11423 Make camel-olingo2/4 ACCEPT headers RFC-7231 compliant.

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

Branch: refs/heads/master
Commit: 958f7f33fa40868dec6a878f1c97f6d7339a9b3b
Parents: e60c9c1
Author: Sean Haynes <s....@ieee.org>
Authored: Tue Jul 11 09:13:43 2017 -0400
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 11 17:03:28 2017 +0200

----------------------------------------------------------------------
 .../olingo2/api/impl/Olingo2AppImpl.java        | 24 +++++++++++++----
 .../olingo4/api/impl/Olingo4AppImpl.java        | 27 +++++++++++++++-----
 2 files changed, 39 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/958f7f33/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 9cfe7c7..af06775 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
@@ -766,7 +766,12 @@ public final class Olingo2AppImpl implements Olingo2App {
         }
 
         // Olingo is sensitive to batch part charset case!!
-        headers.put(HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toString().toLowerCase());
+        final ContentType contentType = getResourceContentType(uriInfo);
+        headers.put(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
+        final Charset charset = contentType.getCharset();
+        if (null != charset) {
+            headers.put(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
+        }
         if (!headers.containsKey(HttpHeaders.CONTENT_TYPE)) {
             headers.put(HttpHeaders.CONTENT_TYPE, getContentType());
         }
@@ -788,10 +793,16 @@ public final class Olingo2AppImpl implements Olingo2App {
     private BatchQueryPart createBatchQueryPart(UriInfoWithType uriInfo, Olingo2BatchQueryRequest batchRequest) {
 
         final Map<String, String> headers = new HashMap<String, String>(batchRequest.getHeaders());
+        final ContentType contentType = getResourceContentType(uriInfo);
+        final Charset charset = contentType.getCharset();
         if (!headers.containsKey(HttpHeaders.ACCEPT)) {
             // Olingo is sensitive to batch part charset case!!
-            headers.put(HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toString().toLowerCase());
+            headers.put(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
+        }
+        if (!headers.containsKey(HttpHeaders.ACCEPT_CHARSET) && (null != charset)) {
+            headers.put(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
         }
+        
 
         return BatchQueryPart.method("GET")
             .uri(createBatchUri(batchRequest))
@@ -1013,16 +1024,19 @@ public final class Olingo2AppImpl implements Olingo2App {
                         FutureCallback<HttpResponse> callback) {
 
         // add accept header when its not a form or multipart
-        final String contentTypeString = contentType.toString();
         if (!ContentType.APPLICATION_FORM_URLENCODED.getMimeType().equals(contentType.getMimeType())
             && !contentType.getMimeType().startsWith(MULTIPART_MIME_TYPE)) {
             // otherwise accept what is being sent
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentType.withCharset("").toString().toLowerCase());
         }
         // is something being sent?
         if (httpUriRequest instanceof HttpEntityEnclosingRequestBase
             && httpUriRequest.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
-            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
+            final Charset charset = contentType.getCharset();
+            if (null != charset) {
+                httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, charset.name().toLowerCase());
+            }
         }
 
         // set user specified custom headers

http://git-wip-us.apache.org/repos/asf/camel/blob/958f7f33/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 d3afcee..980c409 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
@@ -567,7 +567,12 @@ public final class Olingo4AppImpl implements Olingo4App {
 
                     batchRequestHeaderOutputStream.write((HttpGet.METHOD_NAME + " " + batchQueryUri + " " + HttpVersion.HTTP_1_1).getBytes(Constants.UTF8));
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toContentTypeString());
+                    final ContentType acceptType = getResourceContentType(uriInfo);
+                    final String acceptCharset = acceptType.getParameter(ContentType.PARAMETER_CHARSET);
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, acceptType.getType().toLowerCase());
+                    if (null != acceptCharset) {
+                        writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+                    }
 
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
                     batchRequestHeaderOutputStream.write(boundary.getBytes(Constants.UTF8));
@@ -587,8 +592,13 @@ public final class Olingo4AppImpl implements Olingo4App {
                         .write((batchChangePart.getOperation().getHttpMethod() + " " + batchChangeUri + " " + HttpVersion.HTTP_1_1).getBytes(Constants.UTF8));
                     batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
                     writeHttpHeader(batchRequestHeaderOutputStream, HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, getResourceContentType(uriInfo).toContentTypeString());
-                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.CONTENT_TYPE, getResourceContentType(uriInfo).toContentTypeString());
+                    final ContentType acceptType = getResourceContentType(uriInfo);
+                    final String acceptCharset = acceptType.getParameter(ContentType.PARAMETER_CHARSET);
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT, acceptType.getType().toLowerCase());
+                    if (null != acceptCharset) {
+                        writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+                    }
+                    writeHttpHeader(batchRequestHeaderOutputStream, HttpHeaders.CONTENT_TYPE, acceptType.toContentTypeString());
 
                     if (batchChangePart.getOperation() != Operation.DELETE) {
                         batchRequestHeaderOutputStream.write(ODataStreamer.CRLF);
@@ -798,15 +808,18 @@ public final class Olingo4AppImpl implements Olingo4App {
 
     public void execute(HttpUriRequest httpUriRequest, ContentType contentType, FutureCallback<HttpResponse> callback) {
         // add accept header when its not a form or multipart
-        final String contentTypeString = contentType.toString();
         if (!ContentType.APPLICATION_FORM_URLENCODED.equals(contentType) && !contentType.toContentTypeString().startsWith(MULTIPART_MIME_TYPE)) {
             // otherwise accept what is being sent
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT, contentType.getType().toLowerCase());
+            final String acceptCharset = contentType.getParameter(ContentType.PARAMETER_CHARSET);
+            if (null != acceptCharset) {
+                httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, acceptCharset.toLowerCase());
+            }
         }
 
         // is something being sent?
         if (httpUriRequest instanceof HttpEntityEnclosingRequestBase && httpUriRequest.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) {
-            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentTypeString);
+            httpUriRequest.addHeader(HttpHeaders.CONTENT_TYPE, contentType.toString());
         }
 
         // set user specified custom headers
@@ -819,7 +832,7 @@ public final class Olingo4AppImpl implements Olingo4App {
         // add 'Accept-Charset' header to avoid BOM marker presents inside
         // response stream
         if (!httpUriRequest.containsHeader(HttpHeaders.ACCEPT_CHARSET)) {
-            httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, Constants.UTF8);
+            httpUriRequest.addHeader(HttpHeaders.ACCEPT_CHARSET, Constants.UTF8.toLowerCase());
         }
 
         // add client protocol version if not specified