@Override public List<IDecodedDeviceRequest<?>> decode(byte[] payload, Map<String, Object> metadata) throws EventDecodeException { LOGGER.info("=== EVENT DATA BEGIN ==="); LOGGER.info(new String(payload)); LOGGER.info("(hex) " + DataUtils.bytesToHex(payload)); LOGGER.info("=== EVENT DATA END ==="); return new ArrayList<IDecodedDeviceRequest<?>>(); }
/** * Parse a byte[] containing SiteWhere XML configuration for JSON * representation. * * @param config * @return * @throws SiteWhereException */ public static ElementContent parse(byte[] config) throws SiteWhereException { try { DocumentBuilderFactory factory = DataUtils.getDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new ByteArrayInputStream(config))); Element element = document.getDocumentElement(); ElementContent content = parse(element); return content; } catch (Exception e) { throw new SiteWhereException("Unable to parse configuration content.", e); } }
/** * Parse a date argument from a string and send a "bad request" code if date * can not be parsed. * * @param dateString * @param response * @return */ protected static Date parseDateOrSendBadResponse(String dateString, HttpServletResponse response) { try { if (StringUtils.isBlank(dateString)) { return null; } ZonedDateTime zdt = DataUtils.parseDateInMutipleFormats(dateString); return Date.from(zdt.toInstant()); } catch (DateTimeParseException e) { try { response.sendError(HttpServletResponse.SC_BAD_REQUEST); } catch (IOException e1) { LOGGER.error(e); } } return null; }
@Override public byte[] encode(IDeviceCommandExecution execution, IDeviceNestingContext nested, IDeviceAssignment assignment) throws SiteWhereException { byte[] encoded = ProtobufMessageBuilder.createMessage(execution, nested, assignment, getTenant()); LOGGER.debug("Protobuf message: 0x" + DataUtils.bytesToHex(encoded)); return encoded; }
/** * Parse a byte[] containing SiteWhere XML configuration for JSON * representation. * * @param config * @param configurationModel * @return * @throws SiteWhereException */ public static ElementContent parse(byte[] config, IConfigurationModel configurationModel) throws SiteWhereException { try { DocumentBuilderFactory factory = DataUtils.getDocumentBuilderFactory(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new InputSource(new ByteArrayInputStream(config))); Element element = document.getDocumentElement(); ElementContent content = parse(element, configurationModel); return content; } catch (Exception e) { throw new SiteWhereException("Unable to parse configuration content.", e); } }
@Override public List<IDecodedDeviceRequest<?>> decode(byte[] payload, Map<String, Object> metadata) throws EventDecodeException { getLogger().info("=== EVENT DATA BEGIN ==="); getLogger().info(new String(payload)); getLogger().info("(hex) " + DataUtils.bytesToHex(payload)); getLogger().info("=== EVENT DATA END ==="); return new ArrayList<IDecodedDeviceRequest<?>>(); } }
@Override public byte[] encode(IDeviceCommandExecution execution, IDeviceNestingContext nested, IDeviceAssignment assignment) throws SiteWhereException { byte[] encoded = ProtobufMessageBuilder.createMessage(execution, nested, assignment, getTenantEngine().getTenant(), getDeviceManagement()); getLogger().debug("Protobuf message: 0x" + DataUtils.bytesToHex(encoded)); return encoded; }