Source:
public String formatRequest(Position position) throws UnsupportedEncodingException, JsonProcessingException { Device device = identityManager.getById(position.getDeviceId()); String request = url .replace("{name}", URLEncoder.encode(device.getName(), StandardCharsets.UTF_8.name())) .replace("{uniqueId}", device.getUniqueId()) .replace("{status}", device.getStatus()) .replace("{deviceId}", String.valueOf(position.getDeviceId())) .replace("{protocol}", String.valueOf(position.getProtocol())) .replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime())) .replace("{fixTime}", String.valueOf(position.getFixTime().getTime())) .replace("{valid}", String.valueOf(position.getValid())) .replace("{latitude}", String.valueOf(position.getLatitude())) .replace("{longitude}", String.valueOf(position.getLongitude())) .replace("{altitude}", String.valueOf(position.getAltitude())) .replace("{speed}", String.valueOf(position.getSpeed())) .replace("{course}", String.valueOf(position.getCourse())) .replace("{accuracy}", String.valueOf(position.getAccuracy())) .replace("{statusCode}", calculateStatus(position)); if (position.getAddress() != null) { request = request.replace( "{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name())); } if (request.contains("{attributes}")) { String attributes = objectMapper.writeValueAsString(position.getAttributes()); request = request.replace( "{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name())); } if (request.contains("{gprmc}")) { request = request.replace("{gprmc}", formatSentence(position)); } String deviceGroupName = ""; if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId()); if (group != null) { deviceGroupName = group.getName(); } } return request.replace("{group}", URLEncoder.encode(deviceGroupName, StandardCharsets.UTF_8.name())); }

Target:
public String formatRequest(Position position) throws UnsupportedEncodingException, JsonProcessingException { Device device = identityManager.getById(position.getDeviceId()); String request = url .replace("{name}", URLEncoder.encode(device.getName(), StandardCharsets.UTF_8.name())) .replace("{uniqueId}", device.getUniqueId()) .replace("{status}", device.getStatus()) .replace("{deviceId}", String.valueOf(position.getDeviceId())) .replace("{protocol}", String.valueOf(position.getProtocol())) .replace("{deviceTime}", String.valueOf(position.getDeviceTime().getTime())) .replace("{fixTime}", String.valueOf(position.getFixTime().getTime())) .replace("{valid}", String.valueOf(position.getValid())) .replace("{latitude}", String.valueOf(position.getLatitude())) .replace("{longitude}", String.valueOf(position.getLongitude())) .replace("{altitude}", String.valueOf(position.getAltitude())) .replace("{speed}", String.valueOf(position.getSpeed())) .replace("{course}", String.valueOf(position.getCourse())) .replace("{accuracy}", String.valueOf(position.getAccuracy())) .replace("{statusCode}", calculateStatus(position)); if (position.getAddress() != null) { request = request.replace( "{address}", URLEncoder.encode(position.getAddress(), StandardCharsets.UTF_8.name())); } if (request.contains("{attributes}")) { String attributes = objectMapper.writeValueAsString(position.getAttributes()); request = request.replace( "{attributes}", URLEncoder.encode(attributes, StandardCharsets.UTF_8.name())); } if (request.contains("{gprmc}")) { request = request.replace("{gprmc}", formatSentence(position)); } if (request.contains("{group}")) { String deviceGroupName = ""; if (device.getGroupId() != 0) { Group group = Context.getGroupsManager().getById(device.getGroupId()); if (group != null) { deviceGroupName = group.getName(); } } request = request.replace("{group}", URLEncoder.encode(deviceGroupName, StandardCharsets.UTF_8.name())); } return request; }