diff options
Diffstat (limited to 'src/main/java/org/traccar/notification')
-rw-r--r-- | src/main/java/org/traccar/notification/EventForwarder.java | 28 | ||||
-rw-r--r-- | src/main/java/org/traccar/notification/JsonTypeEventForwarder.java | 18 |
2 files changed, 21 insertions, 25 deletions
diff --git a/src/main/java/org/traccar/notification/EventForwarder.java b/src/main/java/org/traccar/notification/EventForwarder.java index c0010ebbd..966bff31d 100644 --- a/src/main/java/org/traccar/notification/EventForwarder.java +++ b/src/main/java/org/traccar/notification/EventForwarder.java @@ -1,5 +1,5 @@ /* - * Copyright 2016 - 2019 Anton Tananaev (anton@traccar.org) + * Copyright 2016 - 2020 Anton Tananaev (anton@traccar.org) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,6 +15,8 @@ */ package org.traccar.notification; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.traccar.Context; import org.traccar.model.Device; import org.traccar.model.Event; @@ -22,13 +24,16 @@ import org.traccar.model.Geofence; import org.traccar.model.Maintenance; import org.traccar.model.Position; -import javax.ws.rs.client.AsyncInvoker; +import javax.ws.rs.client.Entity; import javax.ws.rs.client.Invocation; +import javax.ws.rs.client.InvocationCallback; import java.util.HashMap; import java.util.Map; import java.util.Set; -public abstract class EventForwarder { +public class EventForwarder { + + private static final Logger LOGGER = LoggerFactory.getLogger(EventForwarder.class); private final String url; private final String header; @@ -56,7 +61,19 @@ public abstract class EventForwarder { } } - executeRequest(event, position, users, requestBuilder.async()); + LOGGER.debug("Event forwarding initiated"); + requestBuilder.async().post( + Entity.json(preparePayload(event, position, users)), new InvocationCallback<Object>() { + @Override + public void completed(Object o) { + LOGGER.debug("Event forwarding succeeded"); + } + + @Override + public void failed(Throwable throwable) { + LOGGER.warn("Event forwarding failed", throwable); + } + }); } protected Map<String, Object> preparePayload(Event event, Position position, Set<Long> users) { @@ -85,7 +102,4 @@ public abstract class EventForwarder { return data; } - protected abstract void executeRequest( - Event event, Position position, Set<Long> users, AsyncInvoker invoker); - } diff --git a/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java b/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java deleted file mode 100644 index 55d926fc8..000000000 --- a/src/main/java/org/traccar/notification/JsonTypeEventForwarder.java +++ /dev/null @@ -1,18 +0,0 @@ -package org.traccar.notification; - -import java.util.Set; - -import org.traccar.model.Event; -import org.traccar.model.Position; - -import javax.ws.rs.client.AsyncInvoker; -import javax.ws.rs.client.Entity; - -public class JsonTypeEventForwarder extends EventForwarder { - - @Override - protected void executeRequest(Event event, Position position, Set<Long> users, AsyncInvoker invoker) { - invoker.post(Entity.json(preparePayload(event, position, users))); - } - -} |