diff options
author | Srk <watertext@hotmail.it> | 2017-11-22 19:50:19 +0100 |
---|---|---|
committer | Srk <watertext@hotmail.it> | 2017-11-22 19:50:19 +0100 |
commit | 906d376b4f8c199b36064a0cd58cdf9c3ccb712f (patch) | |
tree | 18a706a9e96898d9a3486ab99f2420ac65a5902f | |
parent | 07eae46acf26e2d978655f8ec0e5fd09c47c1546 (diff) | |
download | traccar-server-906d376b4f8c199b36064a0cd58cdf9c3ccb712f.tar.gz traccar-server-906d376b4f8c199b36064a0cd58cdf9c3ccb712f.tar.bz2 traccar-server-906d376b4f8c199b36064a0cd58cdf9c3ccb712f.zip |
Changing form method
-rw-r--r-- | src/org/traccar/Context.java | 4 | ||||
-rw-r--r-- | src/org/traccar/notification/FormTypeEventForwarder.java | 33 | ||||
-rw-r--r-- | src/org/traccar/notification/MultiPartEventForwarder.java | 47 |
3 files changed, 49 insertions, 35 deletions
diff --git a/src/org/traccar/Context.java b/src/org/traccar/Context.java index d77b6878f..3681cc2cc 100644 --- a/src/org/traccar/Context.java +++ b/src/org/traccar/Context.java @@ -71,8 +71,8 @@ import org.traccar.geolocation.GeolocationProvider; import org.traccar.geolocation.MozillaGeolocationProvider; import org.traccar.geolocation.OpenCellIdGeolocationProvider; import org.traccar.notification.EventForwarder; -import org.traccar.notification.FormTypeEventForwarder; import org.traccar.notification.JsonTypeEventForwarder; +import org.traccar.notification.MultiPartEventForwarder; import org.traccar.reports.model.TripsConfig; import org.traccar.smpp.SmppClient; import org.traccar.web.WebServer; @@ -375,7 +375,7 @@ public final class Context { if (config.getBoolean("event.forward.enable")) { if (Context.getConfig().getBoolean("event.forward.payloadAsParamMode")) { - eventForwarder = new FormTypeEventForwarder(); + eventForwarder = new MultiPartEventForwarder(); } else { eventForwarder = new JsonTypeEventForwarder(); } diff --git a/src/org/traccar/notification/FormTypeEventForwarder.java b/src/org/traccar/notification/FormTypeEventForwarder.java deleted file mode 100644 index 1478faa03..000000000 --- a/src/org/traccar/notification/FormTypeEventForwarder.java +++ /dev/null @@ -1,33 +0,0 @@ -package org.traccar.notification;
-
-import org.traccar.Context;
-import org.traccar.model.Event;
-import org.traccar.model.Position;
-
-import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder;
-
-public class FormTypeEventForwarder extends EventForwarder {
-
- private final String payloadParamName;
- private final String additionalParams;
-
- public FormTypeEventForwarder() {
- payloadParamName = Context.getConfig().getString("event.forward.paramMode.payloadParamName", "payload");
- additionalParams = Context.getConfig().getString("event.forward.paramMode.additionalParams", "");
- }
-
- @Override
- protected String getContentType() {
- return "application/x-www-form-urlencoded; charset=UTF-8";
- }
-
- @Override
- protected void setContent(Event event, Position position, BoundRequestBuilder requestBuilder) {
- if (!additionalParams.equals("")) {
- requestBuilder.setFormParams(splitParams(additionalParams, "="));
- }
-
- requestBuilder.addFormParam(payloadParamName, prepareJsonPayload(event, position));
- }
-
-}
diff --git a/src/org/traccar/notification/MultiPartEventForwarder.java b/src/org/traccar/notification/MultiPartEventForwarder.java new file mode 100644 index 000000000..a77ad5975 --- /dev/null +++ b/src/org/traccar/notification/MultiPartEventForwarder.java @@ -0,0 +1,47 @@ +package org.traccar.notification; + +import java.nio.charset.StandardCharsets; +import java.util.List; +import java.util.Map; +import java.util.Map.Entry; + +import org.traccar.Context; +import org.traccar.model.Event; +import org.traccar.model.Position; + +import com.ning.http.client.AsyncHttpClient.BoundRequestBuilder; +import com.ning.http.client.multipart.StringPart; + +public class MultiPartEventForwarder extends EventForwarder { + + private final String payloadParamName; + private final String additionalParams; + + public MultiPartEventForwarder() { + payloadParamName = Context.getConfig().getString("event.forward.paramMode.payloadParamName", "payload"); + additionalParams = Context.getConfig().getString("event.forward.paramMode.additionalParams", ""); + } + + @Override + protected String getContentType() { + return "multipart/form-data"; + } + + @Override + protected void setContent(Event event, Position position, BoundRequestBuilder requestBuilder) { + + if (!additionalParams.equals("")) { + Map<String, List<String>> paramsToAdd = splitParams(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)); + } + } + } + requestBuilder.addBodyPart(new StringPart(payloadParamName, + prepareJsonPayload(event, position), + "application/json", + StandardCharsets.UTF_8)); + } +} |