From bc3b09e48efb9a58d9aef111d4316dcd9c0a7038 Mon Sep 17 00:00:00 2001 From: Anton Tananaev Date: Sun, 13 Dec 2020 15:51:33 -0800 Subject: Improve forwarding logging --- .../org/traccar/notification/EventForwarder.java | 28 ++++++++++++++++------ .../notification/JsonTypeEventForwarder.java | 18 -------------- 2 files changed, 21 insertions(+), 25 deletions(-) delete mode 100644 src/main/java/org/traccar/notification/JsonTypeEventForwarder.java (limited to 'src/main/java/org/traccar/notification') 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() { + @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 preparePayload(Event event, Position position, Set users) { @@ -85,7 +102,4 @@ public abstract class EventForwarder { return data; } - protected abstract void executeRequest( - Event event, Position position, Set 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 users, AsyncInvoker invoker) { - invoker.post(Entity.json(preparePayload(event, position, users))); - } - -} -- cgit v1.2.3