aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2018-08-07 22:00:53 +1200
committerAnton Tananaev <anton.tananaev@gmail.com>2018-08-07 22:00:53 +1200
commitb800c16dff17f18b5c079e3403904d61bda86e88 (patch)
tree269e5e515f891789f67fd99e8aedc826599a17d3 /src
parent3ed2536aae70188fb6c7f20ff7a6a8ab7dfbba80 (diff)
downloadtrackermap-server-b800c16dff17f18b5c079e3403904d61bda86e88.tar.gz
trackermap-server-b800c16dff17f18b5c079e3403904d61bda86e88.tar.bz2
trackermap-server-b800c16dff17f18b5c079e3403904d61bda86e88.zip
Encode device name (fix #3995)
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/WebDataHandler.java28
1 files changed, 12 insertions, 16 deletions
diff --git a/src/org/traccar/WebDataHandler.java b/src/org/traccar/WebDataHandler.java
index 763493437..65b272df4 100644
--- a/src/org/traccar/WebDataHandler.java
+++ b/src/org/traccar/WebDataHandler.java
@@ -80,12 +80,12 @@ public class WebDataHandler extends BaseDataHandler {
}
}
- public String formatRequest(Position position) {
+ public String formatRequest(Position position) throws UnsupportedEncodingException, JsonProcessingException {
Device device = Context.getIdentityManager().getById(position.getDeviceId());
String request = url
- .replace("{name}", device.getName())
+ .replace("{name}", URLEncoder.encode(device.getName(), StandardCharsets.UTF_8.name()))
.replace("{uniqueId}", device.getUniqueId())
.replace("{status}", device.getStatus())
.replace("{deviceId}", String.valueOf(position.getDeviceId()))
@@ -102,22 +102,14 @@ public class WebDataHandler extends BaseDataHandler {
.replace("{statusCode}", calculateStatus(position));
if (position.getAddress() != null) {
- try {
- request = request.replace(
- "{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name()));
- } catch (UnsupportedEncodingException error) {
- Log.warning(error);
- }
+ request = request.replace(
+ "{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name()));
}
if (request.contains("{attributes}")) {
- try {
- String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes());
- request = request.replace(
- "{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name()));
- } catch (UnsupportedEncodingException | JsonProcessingException error) {
- Log.warning(error);
- }
+ String attributes = Context.getObjectMapper().writeValueAsString(position.getAttributes());
+ request = request.replace(
+ "{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name()));
}
if (request.contains("{gprmc}")) {
@@ -132,7 +124,11 @@ public class WebDataHandler extends BaseDataHandler {
if (json) {
Context.getClient().target(url).request().async().post(Entity.json(prepareJsonPayload(position)));
} else {
- Context.getClient().target(formatRequest(position)).request().async().get();
+ try {
+ Context.getClient().target(formatRequest(position)).request().async().get();
+ } catch (UnsupportedEncodingException | JsonProcessingException e) {
+ Log.warning(e);
+ }
}
return position;
}