aboutsummaryrefslogtreecommitdiff
path: root/src/org/traccar/notification/MultiPartEventForwarder.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/org/traccar/notification/MultiPartEventForwarder.java')
-rw-r--r--src/org/traccar/notification/MultiPartEventForwarder.java47
1 files changed, 47 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..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));
+ }
+}