From e7c04c8dfaa67e5bef2d3b9c5ba8924e85045ffc Mon Sep 17 00:00:00 2001 From: Vitaliy Gergel Date: Wed, 4 Mar 2020 21:18:14 +0200 Subject: Fix code review comments and repace url variables for post request as well --- src/main/java/org/traccar/WebDataHandler.java | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) (limited to 'src/main/java') diff --git a/src/main/java/org/traccar/WebDataHandler.java b/src/main/java/org/traccar/WebDataHandler.java index c8bb9b461..858b00aad 100644 --- a/src/main/java/org/traccar/WebDataHandler.java +++ b/src/main/java/org/traccar/WebDataHandler.java @@ -192,7 +192,7 @@ public class WebDataHandler extends BaseDataHandler { String formattedUrl; try { - formattedUrl = json ? url : formatRequest(position); + formattedUrl = formatRequest(position); } catch (UnsupportedEncodingException | JsonProcessingException e) { throw new RuntimeException("Forwarding formatting error", e); } @@ -203,9 +203,10 @@ public class WebDataHandler extends BaseDataHandler { String[] values = line.split(":", 2); String headerName = values[0].trim(); String headerValue = values[1].trim(); - requestBuilder.header(headerName, headerValue); if (headerName.equals(HttpHeaders.CONTENT_TYPE)) { mediaType = MediaType.valueOf(headerValue); + } else { + requestBuilder.header(headerName, headerValue); } } } @@ -220,9 +221,10 @@ public class WebDataHandler extends BaseDataHandler { private void send() { if (json) { try { - requestBuilder.async().post(Entity.entity(objectMapper.writeValueAsString(payload), mediaType), this); + Entity entity = Entity.entity(objectMapper.writeValueAsString(payload), mediaType); + requestBuilder.async().post(entity, this); } catch (JsonProcessingException e) { - throw new RuntimeException("Failed to serialize payload to json: " + payload); + throw new RuntimeException("Failed to serialize location to json", e); } } else { requestBuilder.async().get(this); -- cgit v1.2.3