Specify Content-Type in all HTTP requests 33/67833/1
authormark.j.leonard <mark.j.leonard@gmail.com>
Wed, 19 Sep 2018 17:57:46 +0000 (18:57 +0100)
committermark.j.leonard <mark.j.leonard@gmail.com>
Wed, 19 Sep 2018 18:13:51 +0000 (19:13 +0100)
Explicitly specify all HTTP payload content as JSON, for compatibility
with Elasticsearch 6.x

Change-Id: Ibd6ad7bfd627a5c1bdfb04a950472e4cedfd790d
Issue-ID: AAI-1650
Signed-off-by: mark.j.leonard <mark.j.leonard@gmail.com>
src/main/java/org/onap/aai/sa/searchdbabstraction/elasticsearch/dao/ElasticSearchHttpController.java

index 841f477..a93274e 100644 (file)
@@ -342,7 +342,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn.setRequestMethod("PUT");
-            conn.setRequestProperty("Content-Type", "application/json");
         } catch (ProtocolException e) {
             shutdownConnection(conn);
             throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
@@ -405,7 +404,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn.setRequestMethod("PUT");
-            conn.setRequestProperty("Content-Type", "application/json");
         } catch (ProtocolException e) {
             shutdownConnection(conn);
             throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
@@ -553,7 +551,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
     private void attachDocument(HttpURLConnection conn, DocumentStoreDataEntity doc)
             throws DocumentStoreOperationException {
-        conn.setRequestProperty("Content-Type", "application/json");
         conn.setRequestProperty("Connection", "Close");
         attachContent(conn, doc.getContentInJson());
     }
@@ -640,7 +637,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn.setRequestMethod("PUT");
-            conn.setRequestProperty("Content-Type", "application/json");
         } catch (ProtocolException e) {
             shutdownConnection(conn);
             throw new DocumentStoreOperationException("Failed to set HTTP request method to PUT.", e);
@@ -805,7 +801,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn.setRequestMethod("POST");
-            conn.setRequestProperty("Content-Type", "application/json");
         } catch (ProtocolException e) {
             shutdownConnection(conn);
             throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
@@ -854,7 +849,6 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn.setRequestMethod("POST");
-            conn.setRequestProperty("Content-Type", "application/json");
         } catch (ProtocolException e) {
             shutdownConnection(conn);
             throw new DocumentStoreOperationException("Failed to set HTTP request method to POST.", e);
@@ -913,6 +907,7 @@ public class ElasticSearchHttpController implements DocumentStoreInterface {
 
         try {
             conn = (HttpURLConnection) url.openConnection();
+            conn.setRequestProperty("Content-Type", "application/json");
             conn.setDoOutput(true);
         } catch (IOException e) {
             shutdownConnection(conn);