@Override @ApiOperation(value = "Realtime mailbox notification service", notes = "Websocket service for sending and receiving mail noti fication", response = WSMessage.class, request = String.class, responseContainer = "List", authorizations = {@Authorization(value = "write_key"), @Authorization(value = "read_key")} ) public void onMessage(ChannelHandlerContext ctx, String data) { Integer jsonStart = data.indexOf("\n"); Operation op = Operation.valueOf(data.substring(0, jsonStart)); String jsonStr = data.substring(jsonStart); switch (op) { case msg: try { UserMessage message = JsonHelper.readSafe(jsonStr, UserMessage.class); storage.send(ctx.attr(PROJECT_ID).get(), ctx.attr(USER_ID).get(), message.toUser, message.parent, message.content, Instant.now()); } catch (IOException e) { ctx.close(); } break; case typing: break; } }
final ExportQuery read; try { read = JsonHelper.readSafe(body, ExportQuery.class); } catch (IOException e) { HttpServer.returnError(request, "Couldn't parse body: " + e.getMessage(), BAD_REQUEST);
@JsonRequest @ApiOperation(value = "Set user properties once", request = User.class, response = Integer.class) @ApiResponses(value = {@ApiResponse(code = 404, message = "User does not exist.")}) @Path("/set_properties_once") public void setPropertiesOnce(RakamHttpRequest request) { request.bodyHandler(s -> { User req; try { req = JsonHelper.readSafe(s, User.class); } catch (IOException e) { returnError(request, e.getMessage(), BAD_REQUEST); return; } String project = apiKeyService.getProjectOfApiKey(req.api.apiKey, WRITE_KEY); DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, wrappedBuffer(OK_MESSAGE)); response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, request.headers().get(ORIGIN)); List<Cookie> cookies = mapProperties(project, req, request); if (cookies != null) { response.headers().add(SET_COOKIE, STRICT.encode(cookies)); } String headerList = getHeaderList(response.headers().iterator()); if (headerList != null) { response.headers().set(ACCESS_CONTROL_EXPOSE_HEADERS, headerList); } // TODO: we may cache these values and reduce the db hit. service.setUserPropertiesOnce(project, req.id, req.properties); request.response(OK_MESSAGE).end(); }); }
query = JsonHelper.readSafe(data.get(0), StreamQuery.class); } catch (IOException e) { response.send("error", encode(errorMessage("JSON couldn't parsed: " + e.getMessage(), BAD_REQUEST)));
User req; try { req = JsonHelper.readSafe(s, User.class); } catch (IOException e) { returnError(request, e.getMessage(), BAD_REQUEST);
query = JsonHelper.readSafe(data.get(0), clazz); } catch (Exception e) { response.send("result", encode(errorMessage("JSON couldn't parsed: " + e.getMessage(), BAD_REQUEST))).end();