diff --git a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java index 33cf9c1..39d81f8 100644 --- a/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java +++ b/src/main/java/de/ctdo/bunti/artnet/ByteUtils.java @@ -28,7 +28,7 @@ public class ByteUtils { private final byte[] data; public ByteUtils(byte[] data) { - this.data = data; + this.data = data.clone(); } public static final int byteToUint(byte b) { @@ -40,7 +40,7 @@ public class ByteUtils { } public final byte[] getBytes() { - return data; + return data.clone(); } public final int getInt16(int offset) { diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java b/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java index a63e753..2beaae6 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/ArtNetPacket.java @@ -37,7 +37,7 @@ public abstract class ArtNetPacket { } public final void setData(byte[] data) { - this.data = new ByteUtils(data); + this.data = new ByteUtils(data.clone()); } public final PacketType getType() { diff --git a/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java b/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java index 874e8d3..a5c3dd8 100644 --- a/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java +++ b/src/main/java/de/ctdo/bunti/artnet/packets/PacketType.java @@ -19,6 +19,9 @@ package de.ctdo.bunti.artnet.packets; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + public enum PacketType { ART_POLL(0x2000, null), @@ -47,6 +50,8 @@ public enum PacketType { private final int opCode; private final Class packetClass; + private static final Logger LOGGER = LoggerFactory.getLogger(PacketType.class); + private PacketType(int code, Class clazz) { opCode = code; @@ -59,9 +64,9 @@ public enum PacketType { try { p = packetClass.newInstance(); } catch (InstantiationException e) { - e.printStackTrace(); + LOGGER.error("Could not instanciate ArtNetPacket: ",e); } catch (IllegalAccessException e) { - e.printStackTrace(); + LOGGER.error("Could not instanciate ArtNetPacket: ",e); } } return p; diff --git a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java index 4d1665b..ddfa819 100644 --- a/src/main/java/de/ctdo/bunti/model/BuntiDevice.java +++ b/src/main/java/de/ctdo/bunti/model/BuntiDevice.java @@ -22,12 +22,12 @@ public abstract class BuntiDevice { */ @SuppressWarnings("UnusedDeclaration") public final String getType() { - String FQClassName = this.getClass().getName(); - int firstChar = FQClassName.lastIndexOf ('.') + 1; + String fqClassName = this.getClass().getName(); + int firstChar = fqClassName.lastIndexOf ('.') + 1; if ( firstChar > 0 ) { - FQClassName = FQClassName.substring ( firstChar ); + fqClassName = fqClassName.substring ( firstChar ); } - return FQClassName; + return fqClassName; } /** diff --git a/src/main/java/de/ctdo/bunti/web/RestController.java b/src/main/java/de/ctdo/bunti/web/RestController.java index bc68cb3..da6a236 100644 --- a/src/main/java/de/ctdo/bunti/web/RestController.java +++ b/src/main/java/de/ctdo/bunti/web/RestController.java @@ -8,35 +8,26 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.*; -import javax.validation.Validator; import java.util.Collection; import java.util.Map; @Controller public class RestController { private static final Logger LOGGER = LoggerFactory.getLogger(RestController.class); - private Validator validator; + + @Autowired private BuntiController controller; - @Autowired - public void setValidator(Validator validator) { - this.validator = validator; - } - - @Autowired - public final void setController(BuntiController controller) { - this.controller = controller; - } - - @RequestMapping(value = "/devices", method = RequestMethod.GET) - public @ResponseBody Collection getAll() { + @ResponseBody + public Collection getAll() { LOGGER.info("handle GET /devices request"); return controller.getAllDevices(); } @RequestMapping(value = "/devices/{id}", method = RequestMethod.GET) - public @ResponseBody BuntiDevice getDeviceById(@PathVariable("id") int id) { + @ResponseBody + public BuntiDevice getDeviceById(@PathVariable("id") int id) { LOGGER.info("handle GET /devices/" + id + " request"); return controller.getDeviceById(id); } diff --git a/src/main/java/de/ctdo/bunti/websocket/AtmosphereResourceArgumentResolver.java b/src/main/java/de/ctdo/bunti/websocket/AtmosphereResourceArgumentResolver.java index fe14b33..671b4ab 100644 --- a/src/main/java/de/ctdo/bunti/websocket/AtmosphereResourceArgumentResolver.java +++ b/src/main/java/de/ctdo/bunti/websocket/AtmosphereResourceArgumentResolver.java @@ -17,7 +17,7 @@ public class AtmosphereResourceArgumentResolver implements WebArgumentResolver { * @see org.springframework.web.bind.support.WebArgumentResolver#resolveArgument(org.springframework.core.MethodParameter, org.springframework.web.context.request.NativeWebRequest) */ @Override - public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) throws Exception { + public Object resolveArgument(MethodParameter methodParameter, NativeWebRequest webRequest) { if (AtmosphereResource.class.isAssignableFrom(methodParameter.getParameterType())) { return AtmosphereUtils.getAtmosphereResource(webRequest.getNativeRequest(HttpServletRequest.class)); diff --git a/src/main/java/de/ctdo/bunti/websocket/AtmosphereUtils.java b/src/main/java/de/ctdo/bunti/websocket/AtmosphereUtils.java index b3f56f1..502e296 100644 --- a/src/main/java/de/ctdo/bunti/websocket/AtmosphereUtils.java +++ b/src/main/java/de/ctdo/bunti/websocket/AtmosphereUtils.java @@ -9,8 +9,9 @@ import org.springframework.util.Assert; public final class AtmosphereUtils { + private AtmosphereUtils() { } - public static AtmosphereResource getAtmosphereResource( + public static AtmosphereResource getAtmosphereResource( HttpServletRequest request) { AtmosphereResource resource = diff --git a/src/main/java/de/ctdo/bunti/websocket/WebSocketController.java b/src/main/java/de/ctdo/bunti/websocket/WebSocketController.java index 30c51df..780e2e1 100644 --- a/src/main/java/de/ctdo/bunti/websocket/WebSocketController.java +++ b/src/main/java/de/ctdo/bunti/websocket/WebSocketController.java @@ -1,11 +1,5 @@ package de.ctdo.bunti.websocket; -import java.util.concurrent.Callable; -import java.util.concurrent.TimeUnit; - -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.atmosphere.cpr.AtmosphereResource; import org.atmosphere.cpr.Broadcaster; import org.codehaus.jackson.map.ObjectMapper; @@ -16,6 +10,12 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.ResponseBody; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.util.concurrent.Callable; +import java.util.concurrent.TimeUnit; + @Controller public class WebSocketController { private static final Logger LOGGER = LoggerFactory.getLogger(WebSocketController.class); @@ -40,10 +40,8 @@ public class WebSocketController { bc.scheduleFixedBroadcast(new Callable() { - private long sinceId = 0; - @Override - public String call() throws Exception { + public String call() throws IOException { LOGGER.debug("call was called"); return mapper.writeValueAsString("blafaselblubb");