@Test public void testPassUnspecifiedWithTransform() { outgoing.put("passUnspecifiedOut", true); String[][] transforms = { {"str","message"}, {"str", "place.loc"}, {"str","invalid","nope"}, {"str"} }; List<List> transformations = new ArrayList<>(); for (String[] t : transforms) { List list = new ArrayList(Arrays.asList(t)); transformations.add(list); } outgoing.put("transformations", transformations); pHandler = new UDPPublishHandler(outgoing, fakeSocket, sourceName); String expectedAddress = "127.0.0.1"; int expectedPort = port; Map<String,Object> testMap = new LinkedHashMap<>(); testMap.put("str", "msg"); testMap.put("stay","here"); Map<String,Object> expectedData = new LinkedHashMap<>(); Map<String,Object> subMap = new LinkedHashMap<>(); subMap.put("loc","msg"); expectedData.put("place",subMap); expectedData.put("message","msg"); expectedData.put("stay","here"); createMessage(testMap); pHandler.handleMessage(extMsg); assert fakeSocket.compareData(expectedData); assert fakeSocket.compareAddress(expectedAddress); assert fakeSocket.comparePort(expectedPort); }
@Override public void handleMessage(ExtensionServiceMessage message) { Map receivedMsg = (Map) message.getObject(); Map sendMsg = new LinkedHashMap<String,Object>(); byte[] sendBytes = null; if (formatLocations != null) { sendBytes = getFormattedOutput(receivedMsg); } else if (csvSource != null) { String str = buildCsv(receivedMsg); sendBytes = str.getBytes(); } else if (bytesLocation != null) { sendBytes = ((String)receivedMsg.get(bytesLocation)).getBytes(); } else if (passingPureMap) { sendMsg = receivedMsg; } else if (passingUnspecified) { sendMsg = receivedMsg; if (this.transformer != null) { this.transformer.transform(receivedMsg, sendMsg, true); } } else if (transformer == null) { sendMsg = new LinkedHashMap<String,Object>(); } else { this.transformer.transform(receivedMsg, sendMsg, false); } try { if (sendBytes == null) { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, sendMsg); sendBytes = writer.writeValueAsBytes(sendMsg); } else { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, new String(sendBytes)); } DatagramPacket packet = new DatagramPacket(sendBytes, sendBytes.length, address, port); socket.send(packet); } catch (Exception e) { log.warn("Failed trying to translate and send the message.", e); } }
UDPPublishHandler extends Handler<ExtensionServiceMessage> { @Override public void handleMessage(ExtensionServiceMessage message) { Map receivedMsg = (Map) message.getObject(); Map sendMsg = new LinkedHashMap<String,Object>(); byte[] sendBytes = null; if (formatLocations != null) { sendBytes = getFormattedOutput(receivedMsg); } else if (csvSource != null) { String str = buildCsv(receivedMsg); sendBytes = str.getBytes(); } else if (bytesLocation != null) { sendBytes = ((String)receivedMsg.get(bytesLocation)).getBytes(); } else if (passingPureMap) { sendMsg = receivedMsg; } else if (passingUnspecified) { sendMsg = receivedMsg; if (this.transformer != null) { this.transformer.transform(receivedMsg, sendMsg, true); } } else if (transformer == null) { sendMsg = new LinkedHashMap<String,Object>(); } else { this.transformer.transform(receivedMsg, sendMsg, false); } try { if (sendBytes == null) { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, sendMsg); sendBytes = writer.writeValueAsBytes(sendMsg); } else { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, new String(sendBytes)); } DatagramPacket packet = new DatagramPacket(sendBytes, sendBytes.length, address, port); socket.send(packet); } catch (Exception e) { log.warn("Failed trying to translate and send the message.", e); } } }
UDPPublishHandler extends Handler<ExtensionServiceMessage> { @Override public void handleMessage(ExtensionServiceMessage message) { Map receivedMsg = (Map) message.getObject(); Map sendMsg = new LinkedHashMap<String,Object>(); byte[] sendBytes = null; if (formatLocations != null) { sendBytes = getFormattedOutput(receivedMsg); } else if (csvSource != null) { String str = buildCsv(receivedMsg); sendBytes = str.getBytes(); } else if (bytesLocation != null) { sendBytes = ((String)receivedMsg.get(bytesLocation)).getBytes(); } else if (passingPureMap) { sendMsg = receivedMsg; } else if (passingUnspecified) { sendMsg = receivedMsg; if (this.transformer != null) { this.transformer.transform(receivedMsg, sendMsg, true); } } else if (transformer == null) { sendMsg = new LinkedHashMap<String,Object>(); } else { this.transformer.transform(receivedMsg, sendMsg, false); } try { if (sendBytes == null) { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, sendMsg); sendBytes = writer.writeValueAsBytes(sendMsg); } else { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, new String(sendBytes)); } DatagramPacket packet = new DatagramPacket(sendBytes, sendBytes.length, address, port); socket.send(packet); } catch (Exception e) { log.warn("Failed trying to translate and send the message.", e); } } UDPPublishHandler(Map outgoing, DatagramSocket socket, String sourceName); }
UDPPublishHandler extends Handler<ExtensionServiceMessage> { @Override public void handleMessage(ExtensionServiceMessage message) { Map receivedMsg = (Map) message.getObject(); Map sendMsg = new LinkedHashMap<String,Object>(); byte[] sendBytes = null; if (formatLocations != null) { sendBytes = getFormattedOutput(receivedMsg); } else if (csvSource != null) { String str = buildCsv(receivedMsg); sendBytes = str.getBytes(); } else if (bytesLocation != null) { sendBytes = ((String)receivedMsg.get(bytesLocation)).getBytes(); } else if (passingPureMap) { sendMsg = receivedMsg; } else if (passingUnspecified) { sendMsg = receivedMsg; if (this.transformer != null) { this.transformer.transform(receivedMsg, sendMsg, true); } } else if (transformer == null) { sendMsg = new LinkedHashMap<String,Object>(); } else { this.transformer.transform(receivedMsg, sendMsg, false); } try { if (sendBytes == null) { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, sendMsg); sendBytes = writer.writeValueAsBytes(sendMsg); } else { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, new String(sendBytes)); } DatagramPacket packet = new DatagramPacket(sendBytes, sendBytes.length, address, port); socket.send(packet); } catch (Exception e) { log.warn("Failed trying to translate and send the message.", e); } } UDPPublishHandler(Map outgoing, DatagramSocket socket, String sourceName); @Override void handleMessage(ExtensionServiceMessage message); }
UDPPublishHandler extends Handler<ExtensionServiceMessage> { @Override public void handleMessage(ExtensionServiceMessage message) { Map receivedMsg = (Map) message.getObject(); Map sendMsg = new LinkedHashMap<String,Object>(); byte[] sendBytes = null; if (formatLocations != null) { sendBytes = getFormattedOutput(receivedMsg); } else if (csvSource != null) { String str = buildCsv(receivedMsg); sendBytes = str.getBytes(); } else if (bytesLocation != null) { sendBytes = ((String)receivedMsg.get(bytesLocation)).getBytes(); } else if (passingPureMap) { sendMsg = receivedMsg; } else if (passingUnspecified) { sendMsg = receivedMsg; if (this.transformer != null) { this.transformer.transform(receivedMsg, sendMsg, true); } } else if (transformer == null) { sendMsg = new LinkedHashMap<String,Object>(); } else { this.transformer.transform(receivedMsg, sendMsg, false); } try { if (sendBytes == null) { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, sendMsg); sendBytes = writer.writeValueAsBytes(sendMsg); } else { log.debug("Sending message to address {} and port {} with contents: {}" , address.getHostAddress(), port, new String(sendBytes)); } DatagramPacket packet = new DatagramPacket(sendBytes, sendBytes.length, address, port); socket.send(packet); } catch (Exception e) { log.warn("Failed trying to translate and send the message.", e); } } UDPPublishHandler(Map outgoing, DatagramSocket socket, String sourceName); @Override void handleMessage(ExtensionServiceMessage message);  }