diff options
author | Harald Musum <musum@yahoo-inc.com> | 2016-10-19 14:15:58 +0200 |
---|---|---|
committer | Harald Musum <musum@yahoo-inc.com> | 2016-10-19 14:15:58 +0200 |
commit | dad97716ae3a0e9a0e777bc18871640bc0a13009 (patch) | |
tree | 96d85be17fe38b779e99174a0454cc1df392e8b6 | |
parent | 1df00b8a64b73218ca2412535398e1e76129ae2a (diff) |
Set content-type to application/json for all requests
-rw-r--r-- | node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutor.java | 19 |
1 files changed, 16 insertions, 3 deletions
diff --git a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutor.java b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutor.java index 78b01177099..8740ff12dcf 100644 --- a/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutor.java +++ b/node-admin/src/main/java/com/yahoo/vespa/hosted/node/admin/util/ConfigServerHttpRequestExecutor.java @@ -4,11 +4,13 @@ package com.yahoo.vespa.hosted.node.admin.util; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.apache.http.HttpEntity; +import org.apache.http.HttpHeaders; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpDelete; import org.apache.http.client.methods.HttpGet; import org.apache.http.client.methods.HttpPatch; import org.apache.http.client.methods.HttpPut; +import org.apache.http.client.methods.HttpRequestBase; import org.apache.http.client.methods.HttpUriRequest; import org.apache.http.entity.StringEntity; import org.apache.http.impl.client.CloseableHttpClient; @@ -25,7 +27,8 @@ import java.util.Set; import java.util.stream.Collectors; /** - * Retries request on config server a few times before giving up. + * Retries request on config server a few times before giving up. Assumes that all requests should be sent with + * content-type application/json * * @author dybdahl */ @@ -115,6 +118,7 @@ public class ConfigServerHttpRequestExecutor { public <T> T put(String path, int port, Optional<Object> bodyJsonPojo, Class<T> wantedReturnType) { return tryAllConfigServers(configServer -> { HttpPut put = new HttpPut("http://" + configServer + ":" + port + path); + setContentTypeToApplicationJson(put); if (bodyJsonPojo.isPresent()) { put.setEntity(new StringEntity(mapper.writeValueAsString(bodyJsonPojo.get()))); } @@ -125,6 +129,7 @@ public class ConfigServerHttpRequestExecutor { public <T> T patch(String path, int port, Object bodyJsonPojo, Class<T> wantedReturnType) { return tryAllConfigServers(configServer -> { HttpPatch patch = new HttpPatch("http://" + configServer + ":" + port + path); + setContentTypeToApplicationJson(patch); patch.setEntity(new StringEntity(mapper.writeValueAsString(bodyJsonPojo))); return patch; }, wantedReturnType); @@ -132,13 +137,17 @@ public class ConfigServerHttpRequestExecutor { public <T> T delete(String path, int port, Class<T> wantedReturnType) { return tryAllConfigServers(configServer -> { - return new HttpDelete("http://" + configServer + ":" + port + path); + HttpDelete delete = new HttpDelete("http://" + configServer + ":" + port + path); + setContentTypeToApplicationJson(delete); + return delete; }, wantedReturnType); } public <T> T get(String path, int port, Class<T> wantedReturnType) { return tryAllConfigServers(configServer -> { - return new HttpGet("http://" + configServer + ":" + port + path); + HttpGet get = new HttpGet("http://" + configServer + ":" + port + path); + setContentTypeToApplicationJson(get); + return get; }, wantedReturnType); } @@ -151,4 +160,8 @@ public class ConfigServerHttpRequestExecutor { return "Failed reading stream: " + e.getMessage(); } } + + private void setContentTypeToApplicationJson(HttpRequestBase request) { + request.setHeader(HttpHeaders.CONTENT_TYPE, "application/json"); + } }
\ No newline at end of file |