From af49fada37f21df9ed5ceb67504c45b714ec24d4 Mon Sep 17 00:00:00 2001 From: Abyss777 Date: Fri, 2 Feb 2018 13:53:49 +0500 Subject: - Use "media.path" as switch - Handle if MediaManager undefined --- src/org/traccar/protocol/Gt06ProtocolDecoder.java | 8 +++++--- src/org/traccar/protocol/MeitrackProtocolDecoder.java | 4 +++- src/org/traccar/protocol/WatchProtocolDecoder.java | 8 ++++++-- src/org/traccar/web/WebServer.java | 4 ++-- 4 files changed, 16 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/org/traccar/protocol/Gt06ProtocolDecoder.java b/src/org/traccar/protocol/Gt06ProtocolDecoder.java index 4173b4d5b..e1bb6f96c 100644 --- a/src/org/traccar/protocol/Gt06ProtocolDecoder.java +++ b/src/org/traccar/protocol/Gt06ProtocolDecoder.java @@ -703,9 +703,11 @@ public class Gt06ProtocolDecoder extends BaseProtocolDecoder { if (photo.writableBytes() > 0) { sendPhotoRequest(channel, pictureId); } else { - Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId()); - position.set( - Position.KEY_IMAGE, Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg")); + if (Context.getMediaManager() != null) { + Device device = Context.getDeviceManager().getById(deviceSession.getDeviceId()); + position.set(Position.KEY_IMAGE, + Context.getMediaManager().writeFile(device.getUniqueId(), photo, "jpg")); + } photos.remove(pictureId); } diff --git a/src/org/traccar/protocol/MeitrackProtocolDecoder.java b/src/org/traccar/protocol/MeitrackProtocolDecoder.java index 11e38194f..4d42683b1 100644 --- a/src/org/traccar/protocol/MeitrackProtocolDecoder.java +++ b/src/org/traccar/protocol/MeitrackProtocolDecoder.java @@ -477,7 +477,9 @@ public class MeitrackProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); - position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg")); + if (Context.getMediaManager() != null) { + position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(imei, photo, "jpg")); + } photo = null; return position; diff --git a/src/org/traccar/protocol/WatchProtocolDecoder.java b/src/org/traccar/protocol/WatchProtocolDecoder.java index fe62874b5..cc0364094 100644 --- a/src/org/traccar/protocol/WatchProtocolDecoder.java +++ b/src/org/traccar/protocol/WatchProtocolDecoder.java @@ -246,7 +246,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { int timeIndex = buf.indexOf(buf.readerIndex(), buf.writerIndex(), (byte) ','); buf.readerIndex(timeIndex + 12 + 2); - position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg")); + if (Context.getMediaManager() != null) { + position.set(Position.KEY_IMAGE, Context.getMediaManager().writeFile(id, buf, "jpg")); + } return position; @@ -257,7 +259,9 @@ public class WatchProtocolDecoder extends BaseProtocolDecoder { getLastLocation(position, null); - position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, buf, "amr")); + if (Context.getMediaManager() != null) { + position.set(Position.KEY_AUDIO, Context.getMediaManager().writeFile(id, buf, "amr")); + } return position; diff --git a/src/org/traccar/web/WebServer.java b/src/org/traccar/web/WebServer.java index 5c3fc8aaa..06894552d 100644 --- a/src/org/traccar/web/WebServer.java +++ b/src/org/traccar/web/WebServer.java @@ -167,10 +167,10 @@ public class WebServer { servletHandler.addServlet(new ServletHolder(new AsyncSocketServlet()), "/socket"); - if (config.getBoolean("media.web.enable")) { + if (config.hasKey("media.path")) { ServletHolder servletHolder = new ServletHolder("media", DefaultServlet.class); servletHolder.setInitParameter("resourceBase", config.getString("media.path")); - servletHolder.setInitParameter("dirAllowed", config.getString("media.web.directoryAllow", "false")); + servletHolder.setInitParameter("dirAllowed", config.getString("media.directoryAllow", "false")); servletHolder.setInitParameter("pathInfoOnly", "true"); servletHandler.addServlet(servletHolder, "/media/*"); servletHandler.addFilter(MediaFilter.class, "/media/*", EnumSet.allOf(DispatcherType.class)); -- cgit v1.2.3