private static void sendError(RakamHttpRequest request, HttpResponseStatus status) { HttpServer.returnError(request, status.reasonPhrase(), status); }
body = future.get(); } catch (Throwable e) { returnError(request, "Error executing callback code", INTERNAL_SERVER_ERROR); LOGGER.warn(e, "Error executing webhook callback"); String prefix = "webhook." + key.project + "." + key.identifier; } else { if (!(body instanceof ScriptObjectMirror)) { returnError(request, "The script must return an object {collection: '', properties: {}}", BAD_REQUEST); returnError(request, "JSON couldn't parsed: " + message, BAD_REQUEST); return; } catch (IOException e) { returnError(request, "JSON couldn't parsed: " + e.getMessage(), BAD_REQUEST); return; } catch (RakamException e) { LogUtil.logException(request, e); returnError(request, e.getMessage(), e.getStatusCode()); return; } catch (HttpRequestException e) { returnError(request, e.getMessage(), e.getStatusCode()); return; } catch (IllegalArgumentException e) { LogUtil.logException(request, e); returnError(request, e.getMessage(), BAD_REQUEST); return; } catch (Exception e) { LOGGER.error(e, "Error while collecting event");
final List<RequestPreprocessor> preprocessors = getPreprocessorRequest(method); try { if (!preprocessors.isEmpty()) { applyPreprocessors(request, preprocessors); requestError(e, request); return; requestError(e.getCause(), request); return; handleAsyncJsonRequest(mapper, request, apply); handleJsonRequest(mapper, service, request, function); .map(e -> getHandler(e, service, method)) .toArray(IRequestParameter[]::new); int parameterSize = parameters.length + 1; try { if (!preprocessors.isEmpty()) { HttpServer.applyPreprocessors(request, preprocessors); requestError(e, request); return; ObjectNode json = generate(request.params()); Object[] objects = new Object[parameterSize];
json = mapper.readValue(o, jsonClazz); } catch (UnrecognizedPropertyException e) { returnError(request, "Unrecognized field: " + e.getPropertyName(), BAD_REQUEST); return; } catch (InvalidFormatException e) { returnError(request, format("Field value couldn't validated: %s ", e.getOriginalMessage()), BAD_REQUEST); return; } catch (JsonMappingException e) { returnError(request, e.getCause() != null ? e.getCause().getClass().getName() + ": " +e.getCause().getMessage() : e.getMessage(), BAD_REQUEST); return; } catch (JsonParseException e) { returnError(request, format("Couldn't parse json: %s ", e.getOriginalMessage()), BAD_REQUEST); return; }catch (DateTimeParseException e) { returnError(request, format("Couldn't parse date value '%s' in json: %s ", e.getParsedString(), e.getMessage()), BAD_REQUEST); return; } catch (IOException e) { returnError(request, format("Error while mapping json: ", e.getMessage()), BAD_REQUEST); return; httpServer.requestError(e, request); return; apply = (CompletionStage) function.apply(service, json); } catch (Throwable e) { httpServer.requestError(e, request); return; httpServer.handleAsyncJsonRequest(mapper, request, apply);
private HttpRequestHandler getJsonRequestHandler(Method method, HttpService service) final List<RequestPreprocessor> preprocessorRequest = getPreprocessorRequest(method); return new JsonBeanRequestHandler(this, mapper, method, getPreprocessorRequest(method), service); bodyParams.add(getHandler(parameter, service, method)); final List<RequestPreprocessor> preprocessorForJsonRequest = getPreprocessorRequest(method); HttpServer.applyPreprocessors(request, preprocessorRequest); requestError(e.getCause(), request); return; handleRequest(mapper, isAsync, invoke, request); };
request = createRequest(ctx); HttpServer.returnError(request, cause.getMessage(), BAD_REQUEST); server.markProcessing(request); server.routeMatcher.handle(request); server.unmarkProcessing(request); HttpServer.returnError(request, e); String errorMessage = "Body is too large"; server.uncaughtExceptionHandler.handle(request, new HttpRequestException(errorMessage, REQUEST_ENTITY_TOO_LARGE)); HttpServer.returnError(request, "Body is too large.", REQUEST_ENTITY_TOO_LARGE); ctx.close(); server.markProcessing(request); server.routeMatcher.handle(ctx, (WebSocketFrame) msg); server.unmarkProcessing(request);
microRouteMatcher.add(lastPath, POST, getJsonRequestHandler(method, service)); handler = createGetRequestHandler(service, method); else if (isRawRequestMethod(method)) { handler = generateRawRequestHandler(service, method); handler = getJsonRequestHandler(method, service);
build.setNotFoundHandler(requestHandler); build.bind(address.getHostText(), address.getPort()); } catch (InterruptedException e) { addError(e);
private HttpRequestHandler generateRawRequestHandler(HttpService service, Method method) List<RequestPreprocessor> requestPreprocessors = getPreprocessorRequest(method); try { if (!requestPreprocessors.isEmpty()) { HttpServer.applyPreprocessors(request, requestPreprocessors); requestError(e, request); requestError(e, request);
public static void returnError(RakamHttpRequest request, String msg, HttpResponseStatus status) { ByteBuf byteBuf = Unpooled.wrappedBuffer(JsonHelper.encodeAsBytes(errorMessage(msg, status))); DefaultFullHttpResponse errResponse = new DefaultFullHttpResponse(HTTP_1_1, status, byteBuf); setBrowser(request, errResponse); request.response(errResponse).end(); }
public void bindAwait(String host, int port) throws InterruptedException { bind(host, port); channel.closeFuture().sync(); // Wait until the channel is closed. }
public void bind(String host, int port) throws InterruptedException { channel = bindInternal(host, port).channel(); }
customRequestParameters = ImmutableMap.of(); return new HttpServer( httpServices, websocketServices,
LOGGER.error(new RuntimeException(sample.toString(), e), "Error executing EventStore " + (single ? "store" : "batch") + " method."); return completedFuture(new HeaderDefaultFullHttpResponse(HTTP_1_1, INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(encodeAsBytes(errorMessage("An error occurred", INTERNAL_SERVER_ERROR))), responseHeaders));
@ApiOperation(value = "Install recipe", response = SuccessMessage.class) @POST @ProtectEndpoint(writeOperation = true) @Path("/install") public void installUIRecipe(RakamHttpRequest request, @Named("user_id") Project project) { String contentType = request.headers().get(CONTENT_TYPE); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) .findAny() .orElse(ExportType.YAML); boolean override = ImmutableList.of(TRUE.toString()).equals(request.params().get("override")); request.bodyHandler(body -> { UIRecipe recipe; try { recipe = exportType.mapper.readValue(body, UIRecipe.class); } catch (IOException e) { returnError(request, e.getMessage(), HttpResponseStatus.BAD_REQUEST); return; } try { UIRecipeHandler.RecipeResult install = installer.install(recipe, project.userId, project.project, override); request.response(JsonHelper.encode(install)).end(); } catch (Exception e) { returnError(request, "Error loading recipe: " + e.getMessage(), HttpResponseStatus.BAD_REQUEST); } }); }
@Override public void operationComplete(Future<Object> future) throws Exception { if (future.await(1, TimeUnit.SECONDS)) { Object body = future.getNow(); if (body == null) { return; } if (!(body instanceof ScriptObjectMirror)) { returnError(request, "The script must return an object or array {collection: '', properties: {}}", BAD_REQUEST); } ScriptObjectMirror json = (ScriptObjectMirror) ((ScriptObjectMirror) body).eval("JSON"); Object stringify = json.callMember("stringify", body); request.response(stringify.toString()).end(); } else { byte[] bytes = JsonHelper.encodeAsBytes(errorMessage("Webhook code timeouts.", INTERNAL_SERVER_ERROR)); request.response(bytes, INTERNAL_SERVER_ERROR).end(); } } });
"Error while storing event."); return new HeaderDefaultFullHttpResponse(HTTP_1_1, INTERNAL_SERVER_ERROR, Unpooled.wrappedBuffer(encodeAsBytes(errorMessage("An error occurred", INTERNAL_SERVER_ERROR))), responseHeaders);
recipe = exportType.mapper.readValue(body, Recipe.class); } catch (IOException e) { returnError(request, e.getMessage(), HttpResponseStatus.BAD_REQUEST); return; request.response(JsonHelper.encode(SuccessMessage.success())).end(); } catch (Exception e) { returnError(request, "Error loading recipe: " + e.getMessage(), HttpResponseStatus.BAD_REQUEST);
} catch (Exception e) { LogUtil.logException(request, e); returnError(request, e.getMessage(), BAD_REQUEST); return; request.response(JsonHelper.encode(errorMessage("An error occurred", INTERNAL_SERVER_ERROR)), INTERNAL_SERVER_ERROR); LOGGER.error(ex, "Error while performing batch user operation");
@Path("/listen") @GET @ApiImplicitParams({ @ApiImplicitParam(name = "project", dataType = "string", paramType = "query"), }) @ApiOperation(value = "Listen all mailboxes", consumes = "text/event-stream", produces = "text/event-stream", authorizations = @Authorization(value = "read_key") ) @IgnoreApi public void listenMails(RakamHttpRequest request) { RakamHttpRequest.StreamResponse response = request.streamResponse(); List<String> apiKey = request.params().get("api_key"); if (apiKey == null || apiKey.isEmpty()) { response.send("result", encode(HttpServer.errorMessage("api_key query parameter is required", HttpResponseStatus.BAD_REQUEST))).end(); return; } List<String> api_key = request.params().get("read_key"); String project = apiKeyService.getProjectOfApiKey(api_key.get(0), ApiKeyService.AccessKeyType.READ_KEY); UserMailboxStorage.MessageListener update = storage.listenAllUsers(project, data -> response.send("update", data.serialize())); response.listenClose(() -> update.shutdown()); }