aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/org/traccar/notification/EventForwarder.java9
-rw-r--r--src/org/traccar/notification/MultiPartEventForwarder.java19
2 files changed, 14 insertions, 14 deletions
diff --git a/src/org/traccar/notification/EventForwarder.java b/src/org/traccar/notification/EventForwarder.java
index cc83aefbc..1354901a7 100644
--- a/src/org/traccar/notification/EventForwarder.java
+++ b/src/org/traccar/notification/EventForwarder.java
@@ -20,6 +20,7 @@ import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
import java.util.Arrays;
import java.util.List;
+import org.apache.commons.lang3.StringUtils;
import org.traccar.Context;
import org.traccar.helper.Log;
import org.traccar.model.Device;
@@ -39,7 +40,7 @@ public abstract class EventForwarder {
public EventForwarder() {
url = Context.getConfig().getString("event.forward.url", "http://localhost/");
- header = Context.getConfig().getString("event.forward.header", "");
+ header = Context.getConfig().getString("event.forward.header");
}
private static final String KEY_POSITION = "position";
@@ -54,9 +55,9 @@ public abstract class EventForwarder {
requestBuilder.addHeader("Content-Type", getContentType());
- if (!header.equals("")) {
+ if (StringUtils.isNotEmpty(header)) {
FluentCaseInsensitiveStringsMap params = new FluentCaseInsensitiveStringsMap();
- params.putAll(splitParams(header, ":"));
+ params.putAll(splitIntoKeyValues(header, ":"));
requestBuilder.setHeaders(params);
}
@@ -64,7 +65,7 @@ public abstract class EventForwarder {
requestBuilder.execute();
}
- protected Map<String, List<String>> splitParams(String params, String separator) {
+ protected Map<String, List<String>> splitIntoKeyValues(String params, String separator) {
String[] splitedLine;
Map<String, List<String>> paramsMap = new HashMap<>();
diff --git a/src/org/traccar/notification/MultiPartEventForwarder.java b/src/org/traccar/notification/MultiPartEventForwarder.java
index a77ad5975..6a3baecb3 100644
--- a/src/org/traccar/notification/MultiPartEventForwarder.java
+++ b/src/org/traccar/notification/MultiPartEventForwarder.java
@@ -1,10 +1,11 @@
package org.traccar.notification;
-import java.nio.charset.StandardCharsets;
+import static java.nio.charset.StandardCharsets.UTF_8;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
+import org.apache.commons.lang3.StringUtils;
import org.traccar.Context;
import org.traccar.model.Event;
import org.traccar.model.Position;
@@ -19,7 +20,7 @@ public class MultiPartEventForwarder extends EventForwarder {
public MultiPartEventForwarder() {
payloadParamName = Context.getConfig().getString("event.forward.paramMode.payloadParamName", "payload");
- additionalParams = Context.getConfig().getString("event.forward.paramMode.additionalParams", "");
+ additionalParams = Context.getConfig().getString("event.forward.paramMode.additionalParams");
}
@Override
@@ -30,18 +31,16 @@ public class MultiPartEventForwarder extends EventForwarder {
@Override
protected void setContent(Event event, Position position, BoundRequestBuilder requestBuilder) {
- if (!additionalParams.equals("")) {
- Map<String, List<String>> paramsToAdd = splitParams(additionalParams, "=");
+ if (StringUtils.isNotEmpty(additionalParams)) {
+ Map<String, List<String>> paramsToAdd = splitIntoKeyValues(additionalParams, "=");
- for (Entry<String, List<String>> en : paramsToAdd.entrySet()) {
- for (String value : en.getValue()) {
- requestBuilder.addBodyPart(new StringPart(en.getKey(), value, null, StandardCharsets.UTF_8));
+ for (Entry<String, List<String>> param : paramsToAdd.entrySet()) {
+ for (String singleParamValue : param.getValue()) {
+ requestBuilder.addBodyPart(new StringPart(param.getKey(), singleParamValue, null, UTF_8));
}
}
}
requestBuilder.addBodyPart(new StringPart(payloadParamName,
- prepareJsonPayload(event, position),
- "application/json",
- StandardCharsets.UTF_8));
+ prepareJsonPayload(event, position), "application/json", UTF_8));
}
}