aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVitaliy Gergel <vitaliy.gergel@zoomdata.com>2020-03-04 16:38:50 +0200
committerVitaliy Gergel <vitaliy.gergel@zoomdata.com>2020-03-04 16:38:50 +0200
commitdd23d3becaf50ad4cdaf0064712f1f104e1c5967 (patch)
treed4c5b9555c4921719bce4a4db656ddb9f478639c
parenta48c68d4b5fb522081c9182713a4088a66317964 (diff)
downloadtrackermap-server-dd23d3becaf50ad4cdaf0064712f1f104e1c5967.tar.gz
trackermap-server-dd23d3becaf50ad4cdaf0064712f1f104e1c5967.tar.bz2
trackermap-server-dd23d3becaf50ad4cdaf0064712f1f104e1c5967.zip
Allowing custom content type header in location forward
-rw-r--r--src/main/java/org/traccar/WebDataHandler.java16
1 files changed, 14 insertions, 2 deletions
diff --git a/src/main/java/org/traccar/WebDataHandler.java b/src/main/java/org/traccar/WebDataHandler.java
index 39e54616b..c8bb9b461 100644
--- a/src/main/java/org/traccar/WebDataHandler.java
+++ b/src/main/java/org/traccar/WebDataHandler.java
@@ -33,6 +33,8 @@ import org.traccar.model.Position;
import org.traccar.model.Group;
import javax.inject.Inject;
+import javax.ws.rs.core.HttpHeaders;
+import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.client.Client;
import javax.ws.rs.client.Entity;
@@ -184,6 +186,7 @@ public class WebDataHandler extends BaseDataHandler {
private int retries = 0;
private Map<String, Object> payload;
private Invocation.Builder requestBuilder;
+ private MediaType mediaType = MediaType.APPLICATION_JSON_TYPE;
AsyncRequestAndCallback(Position position) {
@@ -198,7 +201,12 @@ public class WebDataHandler extends BaseDataHandler {
if (header != null && !header.isEmpty()) {
for (String line: header.split("\\r?\\n")) {
String[] values = line.split(":", 2);
- requestBuilder.header(values[0].trim(), values[1].trim());
+ String headerName = values[0].trim();
+ String headerValue = values[1].trim();
+ requestBuilder.header(headerName, headerValue);
+ if (headerName.equals(HttpHeaders.CONTENT_TYPE)) {
+ mediaType = MediaType.valueOf(headerValue);
+ }
}
}
@@ -211,7 +219,11 @@ public class WebDataHandler extends BaseDataHandler {
private void send() {
if (json) {
- requestBuilder.async().post(Entity.json(payload), this);
+ try {
+ requestBuilder.async().post(Entity.entity(objectMapper.writeValueAsString(payload), mediaType), this);
+ } catch (JsonProcessingException e) {
+ throw new RuntimeException("Failed to serialize payload to json: " + payload);
+ }
} else {
requestBuilder.async().get(this);
}