@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; } }
@ApiOperation(value = "Export recipe", response = Recipe.class, authorizations = @Authorization(value = "master_key") ) @GET @Path("/export") public void exportRecipe(@HeaderParam("Accept") String contentType, @Named("project") RequestContext context, RakamHttpRequest request) throws JsonProcessingException { request.bodyHandler(s -> { Recipe export = installer.export(context.project); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) .findAny() .orElse(YAML); ByteBuf buffer; try { buffer = Unpooled.wrappedBuffer(exportType.mapper.writeValueAsBytes(export)); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse response = new DefaultFullHttpResponse(HTTP_1_1, OK, buffer); response.headers().add(CONTENT_TYPE, exportType.contentType); if (request.headers().contains(ORIGIN)) { response.headers().set(ACCESS_CONTROL_ALLOW_ORIGIN, request.headers().get(ORIGIN)); } request.response(response).end(); }); }
@ApiOperation(value = "Install recipe", authorizations = @Authorization(value = "master_key"), response = SuccessMessage.class