public static void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String body; // load all if (message.length == 0) { body = user.profile.toString(); } else { // load specific by id int dashId = ParseUtil.parseInt(message.body, message.id); body = user.profile.getDashById(dashId, message.id).toString(); } ctx.writeAndFlush(new LoadProfileMessage(message.id, body)); }
public void messageReceived(ChannelHandlerContext ctx, User user, StringMessage message) { String[] split = message.body.split(BODY_SEPARATOR_STRING, 2); if (split.length < 2) { throw new IllegalCommandException("Wrong income message format."); } int dashId = ParseUtil.parseInt(split[0]); String widgetString = split[1]; if (widgetString == null || widgetString.equals("")) { throw new IllegalCommandException("Income widget message is empty."); } if (widgetString.length() > MAX_WIDGET_SIZE) { throw new NotAllowedException("Widget is larger then limit."); } DashBoard dash = user.profile.getDashById(dashId); Widget newWidget = JsonParser.parseWidget(widgetString); log.debug("Updating widget {}.", widgetString); if (dash == null || newWidget == null) { log.error("Error updating widget {}. Project : {}", widgetString, dash); throw new IllegalCommandException("Empty widget or project."); } int existingWidgetIndex = dash.getWidgetIndex(newWidget.id); if (newWidget instanceof Tabs) { Tabs newTabs = (Tabs) newWidget; DeleteWidgetLogic.deleteTabs(user, dash, newTabs.tabs.length - 1); } // strange issue https://github.com/blynkkk/blynk-server/issues/227 // just log error for now try { dash.widgets[existingWidgetIndex] = newWidget; dash.updatedAt = System.currentTimeMillis(); user.lastModifiedTs = dash.updatedAt; } catch (ArrayIndexOutOfBoundsException e) { throw new BaseServerException( "Error updating widget. " + widgetString, Response.SERVER_EXCEPTION); } ctx.writeAndFlush(ok(message.id), ctx.voidPromise()); }