diff options
author | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-08 15:08:33 +1300 |
---|---|---|
committer | Anton Tananaev <anton.tananaev@gmail.com> | 2015-10-08 15:08:33 +1300 |
commit | eb4ee7a9d4d0f132546b164c3483d62eb9e9f0db (patch) | |
tree | 29bc56f0f67cd49bac31a50e415c614ed4b1c5dc /src | |
parent | 320d41863864485c5675c9bf8332ff0845e5e812 (diff) | |
download | traccar-server-eb4ee7a9d4d0f132546b164c3483d62eb9e9f0db.tar.gz traccar-server-eb4ee7a9d4d0f132546b164c3483d62eb9e9f0db.tar.bz2 traccar-server-eb4ee7a9d4d0f132546b164c3483d62eb9e9f0db.zip |
Clean up reported PMD issues
Diffstat (limited to 'src')
40 files changed, 168 insertions, 143 deletions
diff --git a/src/org/traccar/BasePipelineFactory.java b/src/org/traccar/BasePipelineFactory.java index 7e27d8db6..404cab2ba 100644 --- a/src/org/traccar/BasePipelineFactory.java +++ b/src/org/traccar/BasePipelineFactory.java @@ -64,7 +64,7 @@ public abstract class BasePipelineFactory implements ChannelPipelineFactory { msg.append("[").append(String.format("%08X", e.getChannel().getId())).append(": "); msg.append(((InetSocketAddress) e.getChannel().getLocalAddress()).getPort()); - msg.append((e instanceof DownstreamMessageEvent) ? " > " : " < "); + msg.append(e instanceof DownstreamMessageEvent ? " > " : " < "); msg.append(((InetSocketAddress) event.getRemoteAddress()).getAddress().getHostAddress()).append("]"); diff --git a/src/org/traccar/BaseProtocolDecoder.java b/src/org/traccar/BaseProtocolDecoder.java index 3509ec4cf..c47c0dc69 100644 --- a/src/org/traccar/BaseProtocolDecoder.java +++ b/src/org/traccar/BaseProtocolDecoder.java @@ -31,7 +31,7 @@ public abstract class BaseProtocolDecoder extends ExtendedObjectDecoder { private long deviceId; public boolean hasDeviceId() { - return (deviceId != 0); + return deviceId != 0; } public long getDeviceId() { diff --git a/src/org/traccar/FilterHandler.java b/src/org/traccar/FilterHandler.java index 9eb92135f..870132fe0 100644 --- a/src/org/traccar/FilterHandler.java +++ b/src/org/traccar/FilterHandler.java @@ -88,7 +88,7 @@ public class FilterHandler extends BaseDataHandler { } private boolean filterFuture(Position position) { - return filterFuture && (position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT); + return filterFuture && position.getFixTime().getTime() > System.currentTimeMillis() + FILTER_FUTURE_LIMIT; } private boolean filterDistance(Position position) { diff --git a/src/org/traccar/MainEventHandler.java b/src/org/traccar/MainEventHandler.java index 933d0d975..8b94a68c9 100644 --- a/src/org/traccar/MainEventHandler.java +++ b/src/org/traccar/MainEventHandler.java @@ -30,24 +30,22 @@ public class MainEventHandler extends IdleStateAwareChannelHandler { @Override public void messageReceived(ChannelHandlerContext ctx, MessageEvent e) { - if (e.getMessage() != null) { - if (e.getMessage() instanceof Position) { + if (e.getMessage() != null && e.getMessage() instanceof Position) { - Position position = (Position) e.getMessage(); + Position position = (Position) e.getMessage(); - // Log position - StringBuilder s = new StringBuilder(); - s.append(formatChannel(e.getChannel())).append(" "); - s.append("id: ").append(position.getDeviceId()).append(", "); - s.append("time: ").append(position.getFixTime()).append(", "); - s.append("lat: ").append(position.getLatitude()).append(", "); - s.append("lon: ").append(position.getLongitude()).append(", "); - s.append("speed: ").append(position.getSpeed()).append(", "); - s.append("course: ").append(position.getCourse()); - Log.info(s.toString()); + // Log position + StringBuilder s = new StringBuilder(); + s.append(formatChannel(e.getChannel())).append(" "); + s.append("id: ").append(position.getDeviceId()).append(", "); + s.append("time: ").append(position.getFixTime()).append(", "); + s.append("lat: ").append(position.getLatitude()).append(", "); + s.append("lon: ").append(position.getLongitude()).append(", "); + s.append("speed: ").append(position.getSpeed()).append(", "); + s.append("course: ").append(position.getCourse()); + Log.info(s.toString()); - Context.getConnectionManager().update(position); - } + Context.getConnectionManager().update(position); } } diff --git a/src/org/traccar/database/DataManager.java b/src/org/traccar/database/DataManager.java index 1cd8ebb32..7f30fc6f3 100644 --- a/src/org/traccar/database/DataManager.java +++ b/src/org/traccar/database/DataManager.java @@ -118,7 +118,7 @@ public class DataManager implements IdentityManager { @Override public Device getDeviceByUniqueId(String uniqueId) throws SQLException { - if ((System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay) || !devicesByUniqueId.containsKey(uniqueId)) { + if (System.currentTimeMillis() - devicesLastUpdate > devicesRefreshDelay || !devicesByUniqueId.containsKey(uniqueId)) { devicesById.clear(); devicesByUniqueId.clear(); diff --git a/src/org/traccar/database/QueryBuilder.java b/src/org/traccar/database/QueryBuilder.java index 09fb19d13..11dbcd1b9 100644 --- a/src/org/traccar/database/QueryBuilder.java +++ b/src/org/traccar/database/QueryBuilder.java @@ -37,6 +37,7 @@ import javax.json.JsonReader; import javax.json.stream.JsonParsingException; import javax.sql.DataSource; import org.traccar.Context; +import org.traccar.helper.Log; import org.traccar.model.Factory; import org.traccar.model.MiscFormatter; @@ -258,6 +259,7 @@ public class QueryBuilder { } } } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } } @@ -319,6 +321,7 @@ public class QueryBuilder { try { method.invoke(object, resultSet.getBoolean(name)); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -329,6 +332,7 @@ public class QueryBuilder { try { method.invoke(object, resultSet.getInt(name)); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -339,6 +343,7 @@ public class QueryBuilder { try { method.invoke(object, resultSet.getLong(name)); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -349,6 +354,7 @@ public class QueryBuilder { try { method.invoke(object, resultSet.getDouble(name)); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -359,6 +365,7 @@ public class QueryBuilder { try { method.invoke(object, resultSet.getString(name)); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -369,6 +376,7 @@ public class QueryBuilder { try { method.invoke(object, new Date(resultSet.getTimestamp(name).getTime())); } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } }); @@ -379,6 +387,7 @@ public class QueryBuilder { try (JsonReader reader = Json.createReader(new StringReader(resultSet.getString(name)))) { method.invoke(object, MiscFormatter.fromJson(reader.readObject())); } catch (IllegalAccessException | InvocationTargetException | JsonParsingException error) { + Log.warning(error); } } }); diff --git a/src/org/traccar/geocode/BingMapsReverseGeocoder.java b/src/org/traccar/geocode/BingMapsReverseGeocoder.java index 34c3e4922..8c47febef 100644 --- a/src/org/traccar/geocode/BingMapsReverseGeocoder.java +++ b/src/org/traccar/geocode/BingMapsReverseGeocoder.java @@ -29,7 +29,7 @@ public class BingMapsReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("resourceSets"); if (result != null) { JsonObject location = result.getJsonObject(0).getJsonArray("resources").getJsonObject(0).getJsonObject("address"); diff --git a/src/org/traccar/geocode/FactualReverseGeocoder.java b/src/org/traccar/geocode/FactualReverseGeocoder.java index 8f32cf624..6e5a48423 100644 --- a/src/org/traccar/geocode/FactualReverseGeocoder.java +++ b/src/org/traccar/geocode/FactualReverseGeocoder.java @@ -28,7 +28,7 @@ public class FactualReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonObject result = json.getJsonObject("response").getJsonObject("data"); if (result != null) { Address address = new Address(); diff --git a/src/org/traccar/geocode/GisgraphyReverseGeocoder.java b/src/org/traccar/geocode/GisgraphyReverseGeocoder.java index 59c4de723..ef9209fca 100644 --- a/src/org/traccar/geocode/GisgraphyReverseGeocoder.java +++ b/src/org/traccar/geocode/GisgraphyReverseGeocoder.java @@ -28,7 +28,7 @@ public class GisgraphyReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { Address address = new Address(); JsonObject result = json.getJsonArray("result").getJsonObject(0); diff --git a/src/org/traccar/geocode/GoogleReverseGeocoder.java b/src/org/traccar/geocode/GoogleReverseGeocoder.java index ade49a38b..ca1d42000 100644 --- a/src/org/traccar/geocode/GoogleReverseGeocoder.java +++ b/src/org/traccar/geocode/GoogleReverseGeocoder.java @@ -30,7 +30,7 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonArray results = json.getJsonArray("results"); if (!results.isEmpty()) { @@ -43,35 +43,31 @@ public class GoogleReverseGeocoder extends JsonReverseGeocoder { String value = component.getString("short_name"); - for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) { + typesLoop: for (JsonString type : component.getJsonArray("types").getValuesAs(JsonString.class)) { switch (type.getString()) { case "street_number": address.setHouse(value); - break; + break typesLoop; case "route": address.setStreet(value); - break; + break typesLoop; case "locality": address.setSettlement(value); - break; + break typesLoop; case "administrative_area_level_2": address.setDistrict(value); - break; + break typesLoop; case "administrative_area_level_1": address.setState(value); - break; + break typesLoop; case "country": address.setCountry(value); - break; + break typesLoop; case "postal_code": address.setPostcode(value); - break; - default: - continue; + break typesLoop; } - - break; } } diff --git a/src/org/traccar/geocode/JsonReverseGeocoder.java b/src/org/traccar/geocode/JsonReverseGeocoder.java index 25b8e7853..88150a299 100644 --- a/src/org/traccar/geocode/JsonReverseGeocoder.java +++ b/src/org/traccar/geocode/JsonReverseGeocoder.java @@ -18,14 +18,10 @@ package org.traccar.geocode; import com.ning.http.client.AsyncCompletionHandler; import com.ning.http.client.Response; import org.traccar.Context; -import org.traccar.helper.Log; import javax.json.Json; import javax.json.JsonObject; import javax.json.JsonReader; -import java.io.InputStreamReader; -import java.net.HttpURLConnection; -import java.net.URL; import java.util.AbstractMap; import java.util.Collections; import java.util.LinkedHashMap; @@ -84,6 +80,6 @@ public abstract class JsonReverseGeocoder implements ReverseGeocoder { }); } - protected abstract Address parseAddress(JsonObject json); + public abstract Address parseAddress(JsonObject json); } diff --git a/src/org/traccar/geocode/MapQuestReverseGeocoder.java b/src/org/traccar/geocode/MapQuestReverseGeocoder.java index 7141ea020..be3f51b04 100644 --- a/src/org/traccar/geocode/MapQuestReverseGeocoder.java +++ b/src/org/traccar/geocode/MapQuestReverseGeocoder.java @@ -29,7 +29,7 @@ public class MapQuestReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("results"); if (result != null) { JsonArray locations = result.getJsonObject(0).getJsonArray("locations"); diff --git a/src/org/traccar/geocode/NominatimReverseGeocoder.java b/src/org/traccar/geocode/NominatimReverseGeocoder.java index 763987eae..933d9389c 100644 --- a/src/org/traccar/geocode/NominatimReverseGeocoder.java +++ b/src/org/traccar/geocode/NominatimReverseGeocoder.java @@ -28,7 +28,7 @@ public class NominatimReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonObject result = json.getJsonObject("address"); if (result != null) { diff --git a/src/org/traccar/geocode/OpenCageReverseGeocoder.java b/src/org/traccar/geocode/OpenCageReverseGeocoder.java index 1ad4aaf91..3104cb56a 100644 --- a/src/org/traccar/geocode/OpenCageReverseGeocoder.java +++ b/src/org/traccar/geocode/OpenCageReverseGeocoder.java @@ -29,7 +29,7 @@ public class OpenCageReverseGeocoder extends JsonReverseGeocoder { } @Override - protected Address parseAddress(JsonObject json) { + public Address parseAddress(JsonObject json) { JsonArray result = json.getJsonArray("results"); if (result != null) { JsonObject location = result.getJsonObject(0).getJsonObject("components"); diff --git a/src/org/traccar/geocode/ReverseGeocoder.java b/src/org/traccar/geocode/ReverseGeocoder.java index 1367e82dc..5d985fb31 100644 --- a/src/org/traccar/geocode/ReverseGeocoder.java +++ b/src/org/traccar/geocode/ReverseGeocoder.java @@ -17,7 +17,7 @@ package org.traccar.geocode; public interface ReverseGeocoder { - public interface ReverseGeocoderCallback { + interface ReverseGeocoderCallback { void onResult(String address); diff --git a/src/org/traccar/helper/BitUtil.java b/src/org/traccar/helper/BitUtil.java index e8a55c0a8..6dceb52d7 100644 --- a/src/org/traccar/helper/BitUtil.java +++ b/src/org/traccar/helper/BitUtil.java @@ -25,7 +25,7 @@ public class BitUtil { } public static int range(int number, int index) { - return (number >> index); + return number >> index; } public static int range(int number, int index, int length) { @@ -33,7 +33,7 @@ public class BitUtil { } public static long range(long number, int index) { - return (number >> index); + return number >> index; } public static long range(long number, int index, int length) { diff --git a/src/org/traccar/helper/Checksum.java b/src/org/traccar/helper/Checksum.java index 69c9dd499..d3cec3880 100644 --- a/src/org/traccar/helper/Checksum.java +++ b/src/org/traccar/helper/Checksum.java @@ -168,7 +168,7 @@ public class Checksum { for (int i = 0; remain != 0; i++) { long digit = remain % 10; - if ((i % 2) == 0) { + if (i % 2 == 0) { digit *= 2; if (digit >= 10) { digit = 1 + (digit % 10); diff --git a/src/org/traccar/helper/DistanceCalculator.java b/src/org/traccar/helper/DistanceCalculator.java index 072f3d7a8..7ba5044bc 100644 --- a/src/org/traccar/helper/DistanceCalculator.java +++ b/src/org/traccar/helper/DistanceCalculator.java @@ -17,16 +17,16 @@ package org.traccar.helper; public class DistanceCalculator { - private static final double equatorialEarthRadius = 6378.1370D; - private static final double deg2rad = (Math.PI / 180); + private static final double EQUATORIAL_EARTH_RADIUS = 6378.1370; + private static final double DEG_TO_RAD = Math.PI / 180; public static double distance(double lat1, double lon1, double lat2, double lon2) { - double dlong = (lon2 - lon1) * deg2rad; - double dlat = (lat2 - lat1) * deg2rad; + double dlong = (lon2 - lon1) * DEG_TO_RAD; + double dlat = (lat2 - lat1) * DEG_TO_RAD; double a = Math.pow(Math.sin(dlat / 2), 2) + - Math.cos(lat1 * deg2rad) * Math.cos(lat2 * deg2rad) * Math.pow(Math.sin(dlong / 2), 2); + Math.cos(lat1 * DEG_TO_RAD) * Math.cos(lat2 * DEG_TO_RAD) * Math.pow(Math.sin(dlong / 2), 2); double c = 2 * Math.atan2(Math.sqrt(a), Math.sqrt(1 - a)); - double d = equatorialEarthRadius * c; + double d = EQUATORIAL_EARTH_RADIUS * c; return d * 1000; } diff --git a/src/org/traccar/helper/PatternUtil.java b/src/org/traccar/helper/PatternUtil.java index e129a1438..4fa212200 100644 --- a/src/org/traccar/helper/PatternUtil.java +++ b/src/org/traccar/helper/PatternUtil.java @@ -31,7 +31,8 @@ public class PatternUtil { if (matcher.matches()) { match = pattern.substring(0, i); } - } catch (PatternSyntaxException e) { + } catch (PatternSyntaxException error) { + Log.warning(error); } } diff --git a/src/org/traccar/model/Device.java b/src/org/traccar/model/Device.java index 09d9ce0ab..7622f78cd 100644 --- a/src/org/traccar/model/Device.java +++ b/src/org/traccar/model/Device.java @@ -56,10 +56,42 @@ public class Device implements Factory { private String status; + public String getStatus() { + return status; + } + + public void setStatus(String status) { + this.status = status; + } + private Date lastUpdate; + public Date getLastUpdate() { + return lastUpdate; + } + + public void setLastUpdate(Date lastUpdate) { + this.lastUpdate = lastUpdate; + } + private long positionId; + public long getPositionId() { + return positionId; + } + + public void setPositionId(long positionId) { + this.positionId = positionId; + } + private long dataId; + public long getDataId() { + return dataId; + } + + public void setDataId(long dataId) { + this.dataId = dataId; + } + } diff --git a/src/org/traccar/model/User.java b/src/org/traccar/model/User.java index 05437dd97..f9534b87d 100644 --- a/src/org/traccar/model/User.java +++ b/src/org/traccar/model/User.java @@ -57,6 +57,14 @@ public class User implements Factory { private boolean readonly; + public boolean getReadonly() { + return readonly; + } + + public void setReadonly(boolean readonly) { + this.readonly = readonly; + } + private boolean admin; public boolean getAdmin() { diff --git a/src/org/traccar/protocol/ApelProtocolDecoder.java b/src/org/traccar/protocol/ApelProtocolDecoder.java index 3bfed1ebb..865a34e99 100644 --- a/src/org/traccar/protocol/ApelProtocolDecoder.java +++ b/src/org/traccar/protocol/ApelProtocolDecoder.java @@ -109,7 +109,7 @@ public class ApelProtocolDecoder extends BaseProtocolDecoder { } if (type == MSG_TRACKER_ID_EXT) { - long id = buf.readUnsignedInt(); + buf.readUnsignedInt(); // id int length = buf.readUnsignedShort(); buf.skipBytes(length); length = buf.readUnsignedShort(); diff --git a/src/org/traccar/protocol/CalAmpProtocolDecoder.java b/src/org/traccar/protocol/CalAmpProtocolDecoder.java index 7c6a45f18..0648dd29f 100644 --- a/src/org/traccar/protocol/CalAmpProtocolDecoder.java +++ b/src/org/traccar/protocol/CalAmpProtocolDecoder.java @@ -44,9 +44,9 @@ public class CalAmpProtocolDecoder extends BaseProtocolDecoder { public static final int MSG_MINI_EVENT_REPORT = 10; public static final int MSG_MINI_USER_DATA = 11; - private static final int SERVICE_UNACKNOWLEDGED = 0; - private static final int SERVICE_ACKNOWLEDGED = 1; - private static final int SERVICE_RESPONSE = 2; + public static final int SERVICE_UNACKNOWLEDGED = 0; + public static final int SERVICE_ACKNOWLEDGED = 1; + public static final int SERVICE_RESPONSE = 2; private void sendResponse(Channel channel, SocketAddress remoteAddress, int type, int index, int result) { if (channel != null) { diff --git a/src/org/traccar/protocol/CastelProtocolDecoder.java b/src/org/traccar/protocol/CastelProtocolDecoder.java index d7c6bbf46..dcfa2868b 100644 --- a/src/org/traccar/protocol/CastelProtocolDecoder.java +++ b/src/org/traccar/protocol/CastelProtocolDecoder.java @@ -111,22 +111,20 @@ public class CastelProtocolDecoder extends BaseProtocolDecoder { return null; - } else if (type == MSG_LOGIN) { - - if (channel != null) { - ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 41); - response.writeByte(0x40); response.writeByte(0x40); - response.writeShort(response.capacity()); - response.writeByte(version); - response.writeBytes(id); - response.writeShort(ChannelBuffers.swapShort(MSG_LOGIN_RESPONSE)); - response.writeInt(0xFFFFFFFF); - response.writeShort(0); - response.writeInt((int) (System.currentTimeMillis() / 1000)); - response.writeShort(Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex()))); - response.writeByte(0x0D); response.writeByte(0x0A); - channel.write(response, remoteAddress); - } + } else if (type == MSG_LOGIN && channel != null) { + + ChannelBuffer response = ChannelBuffers.directBuffer(ByteOrder.LITTLE_ENDIAN, 41); + response.writeByte(0x40); response.writeByte(0x40); + response.writeShort(response.capacity()); + response.writeByte(version); + response.writeBytes(id); + response.writeShort(ChannelBuffers.swapShort(MSG_LOGIN_RESPONSE)); + response.writeInt(0xFFFFFFFF); + response.writeShort(0); + response.writeInt((int) (System.currentTimeMillis() / 1000)); + response.writeShort(Checksum.crc16(Checksum.CRC16_X25, response.toByteBuffer(0, response.writerIndex()))); + response.writeByte(0x0D); response.writeByte(0x0A); + channel.write(response, remoteAddress); } diff --git a/src/org/traccar/protocol/CityeasyProtocolDecoder.java b/src/org/traccar/protocol/CityeasyProtocolDecoder.java index 158d84ea3..d4235c191 100644 --- a/src/org/traccar/protocol/CityeasyProtocolDecoder.java +++ b/src/org/traccar/protocol/CityeasyProtocolDecoder.java @@ -71,10 +71,8 @@ public class CityeasyProtocolDecoder extends BaseProtocolDecoder { buf.readUnsignedShort(); // length String imei = ChannelBufferTools.readHexString(buf, 14); - if (!identify(imei, channel, null, false)) { - if (!identify(imei + Checksum.luhn(Long.parseLong(imei)), channel)) { - return null; - } + if (!identify(imei, channel, null, false) && !identify(imei + Checksum.luhn(Long.parseLong(imei)), channel)) { + return null; } int type = buf.readUnsignedShort(); diff --git a/src/org/traccar/protocol/FlextrackProtocolDecoder.java b/src/org/traccar/protocol/FlextrackProtocolDecoder.java index 04eed5734..e89e31aaf 100644 --- a/src/org/traccar/protocol/FlextrackProtocolDecoder.java +++ b/src/org/traccar/protocol/FlextrackProtocolDecoder.java @@ -88,10 +88,8 @@ public class FlextrackProtocolDecoder extends BaseProtocolDecoder { String id = parser.group(index++); String iccid = parser.group(index++); - if (!identify(iccid, channel, null, false)) { - if (!identify(id, channel)) { - return null; - } + if (!identify(iccid, channel, null, false) && !identify(id, channel)) { + return null; } } else if (sentence.contains("UNITSTAT") && hasDeviceId()) { diff --git a/src/org/traccar/protocol/H02FrameDecoder.java b/src/org/traccar/protocol/H02FrameDecoder.java index 0e3f78737..ce27b406f 100644 --- a/src/org/traccar/protocol/H02FrameDecoder.java +++ b/src/org/traccar/protocol/H02FrameDecoder.java @@ -49,12 +49,10 @@ public class H02FrameDecoder extends FrameDecoder { return buf.readBytes(index + 1 - buf.readerIndex()); } - } else if (marker.equals("$")) { + } else if (marker.equals("$") && buf.readableBytes() >= MESSAGE_LENGTH) { // Return binary message - if (buf.readableBytes() >= MESSAGE_LENGTH) { - return buf.readBytes(MESSAGE_LENGTH); - } + return buf.readBytes(MESSAGE_LENGTH); } diff --git a/src/org/traccar/protocol/Jt600ProtocolDecoder.java b/src/org/traccar/protocol/Jt600ProtocolDecoder.java index e8cfd8631..6ce282988 100644 --- a/src/org/traccar/protocol/Jt600ProtocolDecoder.java +++ b/src/org/traccar/protocol/Jt600ProtocolDecoder.java @@ -50,7 +50,7 @@ public class Jt600ProtocolDecoder extends BaseProtocolDecoder { // Protocol and type int version = ChannelBufferTools.readHexInteger(buf, 1); - int type = buf.readUnsignedByte() & 0xf; + buf.readUnsignedByte(); // type buf.readBytes(2); // length diff --git a/src/org/traccar/protocol/MegastekProtocolDecoder.java b/src/org/traccar/protocol/MegastekProtocolDecoder.java index 37bf5a0d4..17e9dc6d7 100644 --- a/src/org/traccar/protocol/MegastekProtocolDecoder.java +++ b/src/org/traccar/protocol/MegastekProtocolDecoder.java @@ -128,7 +128,7 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { private Position decodeOld(Channel channel, String sentence) { // Detect type - boolean simple = (sentence.charAt(3) == ',' || sentence.charAt(6) == ','); + boolean simple = sentence.charAt(3) == ',' || sentence.charAt(6) == ','; // Split message String id; @@ -189,10 +189,8 @@ public class MegastekProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_ALARM, parser.group(index++)); // IMEI - if (!identify(parser.group(index++), channel, null, false)) { - if (!identify(id, channel)) { - return null; - } + if (!identify(parser.group(index++), channel, null, false) && !identify(id, channel)) { + return null; } position.setDeviceId(getDeviceId()); diff --git a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java index f5ad46885..4584c1862 100644 --- a/src/org/traccar/protocol/MeiligaoProtocolDecoder.java +++ b/src/org/traccar/protocol/MeiligaoProtocolDecoder.java @@ -92,17 +92,15 @@ public class MeiligaoProtocolDecoder extends BaseProtocolDecoder { id += d1; // Second digit - int d2 = (b & 0x0f); + int d2 = b & 0x0f; if (d2 == 0xf) break; id += d2; } - if (id.length() == 14) { - // Try to recreate full IMEI number - // Sometimes first digit is cut, so this won't work - if (identify(id + Checksum.luhn(Long.parseLong(id)), channel, null, false)) { - return true; - } + // Try to recreate full IMEI number + // Sometimes first digit is cut, so this won't work + if (id.length() == 14 && identify(id + Checksum.luhn(Long.parseLong(id)), channel, null, false)) { + return true; } return identify(id, channel); diff --git a/src/org/traccar/protocol/Mta6ProtocolDecoder.java b/src/org/traccar/protocol/Mta6ProtocolDecoder.java index 8827393dc..055e4278c 100644 --- a/src/org/traccar/protocol/Mta6ProtocolDecoder.java +++ b/src/org/traccar/protocol/Mta6ProtocolDecoder.java @@ -34,6 +34,7 @@ import org.traccar.BaseProtocolDecoder; import org.traccar.Protocol; import org.traccar.helper.BitUtil; import org.traccar.helper.ChannelBufferTools; +import org.traccar.helper.Log; import org.traccar.model.Event; import org.traccar.model.Position; @@ -195,6 +196,7 @@ public class Mta6ProtocolDecoder extends BaseProtocolDecoder { positions.add(position); } } catch (IndexOutOfBoundsException error) { + Log.warning(error); } return positions; diff --git a/src/org/traccar/protocol/MxtProtocolDecoder.java b/src/org/traccar/protocol/MxtProtocolDecoder.java index e35973654..9151d9672 100644 --- a/src/org/traccar/protocol/MxtProtocolDecoder.java +++ b/src/org/traccar/protocol/MxtProtocolDecoder.java @@ -20,7 +20,6 @@ import java.util.Calendar; import java.util.Date; import java.util.TimeZone; import org.jboss.netty.buffer.ChannelBuffer; -import org.jboss.netty.buffer.ChannelBuffers; import org.jboss.netty.channel.Channel; import org.traccar.BaseProtocolDecoder; import org.traccar.helper.BitUtil; @@ -100,7 +99,7 @@ public class MxtProtocolDecoder extends BaseProtocolDecoder { position.setSpeed(UnitsConverter.knotsFromKph(buf.readUnsignedByte())); - int inputMask = buf.readUnsignedByte(); + buf.readUnsignedByte(); // input mask if (BitUtil.check(infoGroups, 0)) { buf.skipBytes(8); // waypoints diff --git a/src/org/traccar/protocol/NoranProtocolDecoder.java b/src/org/traccar/protocol/NoranProtocolDecoder.java index ddfa4cba6..62f0b4219 100644 --- a/src/org/traccar/protocol/NoranProtocolDecoder.java +++ b/src/org/traccar/protocol/NoranProtocolDecoder.java @@ -76,13 +76,10 @@ public class NoranProtocolDecoder extends BaseProtocolDecoder { type == MSG_ALARM) { boolean newFormat = false; - /*if (((type == MSG_UPLOAD_POSITION || type == MSG_ALARM) && buf.readableBytes() == 30) || - ((type == MSG_CONTROL_RESPONSE) && buf.readableBytes() == 39)) { - newFormat = false; - }*/ - if (((type == MSG_UPLOAD_POSITION || type == MSG_ALARM) && buf.readableBytes() == 48) || - ((type == MSG_CONTROL_RESPONSE) && buf.readableBytes() == 57) || - ((type == MSG_UPLOAD_POSITION_NEW))) { + if (type == MSG_UPLOAD_POSITION && buf.readableBytes() == 48 || + type == MSG_ALARM && buf.readableBytes() == 48 || + type == MSG_CONTROL_RESPONSE && buf.readableBytes() == 57 || + type == MSG_UPLOAD_POSITION_NEW) { newFormat = true; } diff --git a/src/org/traccar/protocol/OrionFrameDecoder.java b/src/org/traccar/protocol/OrionFrameDecoder.java index 033dbd1d5..3babda175 100644 --- a/src/org/traccar/protocol/OrionFrameDecoder.java +++ b/src/org/traccar/protocol/OrionFrameDecoder.java @@ -34,34 +34,33 @@ public class OrionFrameDecoder extends FrameDecoder { int type = buf.getUnsignedByte(buf.readerIndex() + 2) & 0x0f; - if (type == OrionProtocolDecoder.MSG_USERLOG) { - if (buf.readableBytes() >= length + 5) { + if (type == OrionProtocolDecoder.MSG_USERLOG && buf.readableBytes() >= length + 5) { - int index = buf.readerIndex() + 3; - int count = buf.getUnsignedByte(index) & 0x0f; - index += 5; - length += 5; + int index = buf.readerIndex() + 3; + int count = buf.getUnsignedByte(index) & 0x0f; + index += 5; + length += 5; - for (int i = 0; i < count; i++) { - if (buf.readableBytes() < length) { - return null; - } - int logLength = buf.getUnsignedByte(index + 1); - index += logLength; - length += logLength; + for (int i = 0; i < count; i++) { + if (buf.readableBytes() < length) { + return null; } + int logLength = buf.getUnsignedByte(index + 1); + index += logLength; + length += logLength; + } - if (buf.readableBytes() >= length) { - return buf.readBytes(length); - } + if (buf.readableBytes() >= length) { + return buf.readBytes(length); } - } else if (type == OrionProtocolDecoder.MSG_SYSLOG) { - if (buf.readableBytes() >= length + 12) { - length += buf.getUnsignedShort(buf.readerIndex() + 8); - if (buf.readableBytes() >= length) { - return buf.readBytes(length); - } + + } else if (type == OrionProtocolDecoder.MSG_SYSLOG && buf.readableBytes() >= length + 12) { + + length += buf.getUnsignedShort(buf.readerIndex() + 8); + if (buf.readableBytes() >= length) { + return buf.readBytes(length); } + } } diff --git a/src/org/traccar/protocol/ProgressProtocolDecoder.java b/src/org/traccar/protocol/ProgressProtocolDecoder.java index 0eaa66411..fa7b1e3a9 100644 --- a/src/org/traccar/protocol/ProgressProtocolDecoder.java +++ b/src/org/traccar/protocol/ProgressProtocolDecoder.java @@ -173,7 +173,7 @@ public class ProgressProtocolDecoder extends BaseProtocolDecoder { for (int i = buf.readerIndex(); i < buf.readerIndex() + size; i++) { byte b = buf.getByte(i); hex.append(HEX_CHARS.charAt((b & 0xf0) >> 4)); - hex.append(HEX_CHARS.charAt((b & 0x0F))); + hex.append(HEX_CHARS.charAt(b & 0x0F)); } position.set("passenger", hex.toString()); diff --git a/src/org/traccar/protocol/XexunProtocolDecoder.java b/src/org/traccar/protocol/XexunProtocolDecoder.java index 32d8eb427..5c719ece7 100644 --- a/src/org/traccar/protocol/XexunProtocolDecoder.java +++ b/src/org/traccar/protocol/XexunProtocolDecoder.java @@ -103,8 +103,8 @@ public class XexunProtocolDecoder extends BaseProtocolDecoder { Double longitude = Double.parseDouble(parser.group(index++)); longitude += Double.parseDouble(parser.group(index++)) / 60; String hemisphere = parser.group(index++); - if (hemisphere != null) { - if (hemisphere.compareTo("W") == 0) longitude = -longitude; + if (hemisphere != null && hemisphere.compareTo("W") == 0) { + longitude = -longitude; } position.setLongitude(longitude); diff --git a/src/org/traccar/protocol/YwtProtocolDecoder.java b/src/org/traccar/protocol/YwtProtocolDecoder.java index be76d1d86..d4e402185 100644 --- a/src/org/traccar/protocol/YwtProtocolDecoder.java +++ b/src/org/traccar/protocol/YwtProtocolDecoder.java @@ -136,11 +136,10 @@ public class YwtProtocolDecoder extends BaseProtocolDecoder { position.set(Event.KEY_STATUS, parser.group(index++)); // Send response - if (type.equals("KP") || type.equals("EP") || type.equals("EP")) { - if (channel != null) { - channel.write("%AT+" + type + "=" + reportId + "\r\n"); - } + if ((type.equals("KP") || type.equals("EP") || type.equals("EP")) && channel != null) { + channel.write("%AT+" + type + "=" + reportId + "\r\n"); } + return position; } diff --git a/src/org/traccar/web/AsyncServlet.java b/src/org/traccar/web/AsyncServlet.java index eaab7abe8..9d68c959c 100644 --- a/src/org/traccar/web/AsyncServlet.java +++ b/src/org/traccar/web/AsyncServlet.java @@ -124,10 +124,8 @@ public class AsyncServlet extends BaseServlet { public void run(Timeout tmt) throws Exception { synchronized (AsyncSession.this) { logEvent("requestTimeout"); - if (!destroyed) { - if (activeContext != null) { - response(); - } + if (!destroyed && activeContext != null) { + response(); } } } diff --git a/src/org/traccar/web/JsonConverter.java b/src/org/traccar/web/JsonConverter.java index 6b52fac20..5dc879ab8 100644 --- a/src/org/traccar/web/JsonConverter.java +++ b/src/org/traccar/web/JsonConverter.java @@ -34,6 +34,7 @@ import javax.json.JsonValue; import org.joda.time.DateTime; import org.joda.time.format.DateTimeFormatter; import org.joda.time.format.ISODateTimeFormat; +import org.traccar.helper.Log; import org.traccar.model.Factory; import org.traccar.model.MiscFormatter; @@ -81,6 +82,7 @@ public class JsonConverter { method.invoke(object, MiscFormatter.fromJson(json.getJsonObject(name))); } } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } } @@ -123,6 +125,7 @@ public class JsonConverter { json.add(name, MiscFormatter.toJson((Map) method.invoke(object))); } } catch (IllegalAccessException | InvocationTargetException error) { + Log.warning(error); } } } diff --git a/src/org/traccar/web/ServerServlet.java b/src/org/traccar/web/ServerServlet.java index e2305bba4..7ed096bc6 100644 --- a/src/org/traccar/web/ServerServlet.java +++ b/src/org/traccar/web/ServerServlet.java @@ -27,7 +27,7 @@ public class ServerServlet extends BaseServlet { switch (command) { case "/get": - get(req, resp); + get(resp); break; case "/update": update(req, resp); @@ -38,7 +38,7 @@ public class ServerServlet extends BaseServlet { return true; } - private void get(HttpServletRequest req, HttpServletResponse resp) throws Exception { + private void get(HttpServletResponse resp) throws Exception { sendResponse(resp.getWriter(), JsonConverter.objectToJson( Context.getDataManager().getServer())); } |