aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/notification/MultiPartEventForwarder.java
diff options
context:
space:
mode:
authorAnton Tananaev <anton.tananaev@gmail.com>2017-11-24 16:55:15 +1300
committerGitHub <noreply@github.com>2017-11-24 16:55:15 +1300
commit924c28dc7435c7b1f95a3a19d191affb408ce704 (patch)
tree13264afdabb54f08aa786d61fdf3e2c55afde23e /src/org/traccar/notification/MultiPartEventForwarder.java
parenta358302a32872fe9d6def421166703f3a586e337 (diff)
parent00c5cef324ed644ca5cae282864f3bca9629467a (diff)
downloadtrackermap-server-924c28dc7435c7b1f95a3a19d191affb408ce704.tar.gz
trackermap-server-924c28dc7435c7b1f95a3a19d191affb408ce704.tar.bz2
trackermap-server-924c28dc7435c7b1f95a3a19d191affb408ce704.zip
Merge pull request #3624 from Shinryuken/payload-as-form-param
Support for custom params on EventForwarder
Diffstat (limited to 'src/org/traccar/notification/MultiPartEventForwarder.java')
-rw-r--r--src/org/traccar/notification/MultiPartEventForwarder.java46
1 files changed, 46 insertions, 0 deletions
diff --git a/src/org/traccar/notification/MultiPartEventForwarder.java b/src/org/traccar/notification/MultiPartEventForwarder.java
new file mode 100644
index 000000000..f4c36d3e4
--- /dev/null
+++ b/src/org/traccar/notification/MultiPartEventForwarder.java
@@ -0,0 +1,46 @@
+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 != null && !additionalParams.isEmpty()) {
+ Map<String, List<String>> paramsToAdd = splitIntoKeyValues(additionalParams, "=");
+
+ for (Entry<String, List<String>> param : paramsToAdd.entrySet()) {
+ for (String singleParamValue : param.getValue()) {
+ requestBuilder.addBodyPart(new StringPart(param.getKey(), singleParamValue, null,
+ StandardCharsets.UTF_8));
+ }
+ }
+ }
+ requestBuilder.addBodyPart(new StringPart(payloadParamName,
+ prepareJsonPayload(event, position), "application/json", StandardCharsets.UTF_8));
+ }
+}