@Override public String getPathTranslated() { return request.path(); }
@Override public String getContextPath() { return request.path(); }
@Override public String getPathInfo() { return request.path(); }
@Override public String getRequestURI() { return request.path(); }
@GET @ApiOperation(value = "Show webhook images", response = Integer.class) @Path("/image/*") public void image(RakamHttpRequest request) { String substring = request.path().substring("/ui/webhook/image".length() + 1); if (!substring.matches("^[A-Za-z0-9-]+$")) { throw new RakamException(FORBIDDEN); } URL resource = getClass().getResource("/webhook/" + substring + "/image.png"); if (resource == null) { throw new RakamException(NOT_FOUND); } byte[] script; try { script = ByteStreams.toByteArray(resource.openStream()); } catch (IOException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(script)); resp.headers().add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); resp.headers().add(CACHE_CONTROL, "private, max-age=86400"); HttpHeaders.setContentLength(resp, script.length); resp.headers().set(CONTENT_TYPE, "image/png"); request.response(resp).end(); }
@GET @IgnoreApi @ApiOperation(value = "Collect event", response = Integer.class) @Path("/collect/*") public void collectGet(RakamHttpRequest request) { String identifier = request.path().substring(20); List<String> writeKeyList = request.params().get("write_key"); if (writeKeyList == null || writeKeyList.isEmpty()) { throw new RakamException("write_key query parameter is null", FORBIDDEN); } String project = apiKeyService.getProjectOfApiKey(writeKeyList.get(0), WRITE_KEY); call(request, project, identifier, request.params(), request.headers(), null); }
@GET @ApiOperation(value = "List custom event mappers", response = Integer.class) @Path("/image/*") public void image(RakamHttpRequest request) { String substring = request.path().substring("/ui/custom-event-mapper/image".length() + 1); if (!substring.matches("^[A-Za-z0-9-]+$")) { throw new RakamException(FORBIDDEN); } URL resource = getClass().getResource("/custom-event-mapper/" + substring + "/image.png"); if (resource == null) { throw new RakamException(NOT_FOUND); } byte[] script; try { script = toByteArray(resource.openStream()); } catch (IOException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse resp = new DefaultFullHttpResponse(HTTP_1_1, OK, Unpooled.wrappedBuffer(script)); resp.headers().add(ACCESS_CONTROL_ALLOW_ORIGIN, "*"); resp.headers().add(CACHE_CONTROL, "private, max-age=86400"); HttpHeaders.setContentLength(resp, script.length); resp.headers().set(CONTENT_TYPE, "image/png"); request.response(resp).end(); }
@POST @IgnoreApi @ApiOperation(value = "Collect event", response = Integer.class) @Path("/collect/*") public void collectPost(RakamHttpRequest request) { String identifier = request.path().substring(20); List<String> writeKeyList = request.params().get("write_key"); if (writeKeyList == null || writeKeyList.isEmpty()) { throw new RakamException("write_key query parameter is null", FORBIDDEN); } String project = apiKeyService.getProjectOfApiKey(writeKeyList.get(0), WRITE_KEY); request.bodyHandler(inputStream -> { String data; try { data = new String(ByteStreams.toByteArray(inputStream), CharsetUtil.UTF_8); } catch (IOException e) { throw new RakamException("Unable to parse data: " + e.getMessage(), INTERNAL_SERVER_ERROR); } call(request, project, identifier, request.params(), request.headers(), data); }); }
@Path("/display/*") @GET public void display(RakamHttpRequest request) { if (!database.isPresent()) { throw new RakamException("Custom page feature is not implemented", NOT_IMPLEMENTED); } String path = request.path().substring(21); String[] projectCustomPage = path.split("/", 3); byte[] bytes; try { InputStream file = database.get().getFile(Integer.parseInt(projectCustomPage[0]), projectCustomPage[1], projectCustomPage[2]); if (file == null) { request.response(NOT_FOUND.reasonPhrase(), NOT_FOUND).end(); } bytes = ByteStreams.toByteArray(file); } catch (IOException e) { throw Throwables.propagate(e); } HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); response.headers().set(CONTENT_TYPE, "text/html"); HttpHeaders.setContentLength(response, bytes.length); request.context().write(response); request.context().write(Unpooled.wrappedBuffer(bytes)); ChannelFuture lastContentFuture = request.context().writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); if (!HttpHeaders.isKeepAlive(request)) { lastContentFuture.addListener(ChannelFutureListener.CLOSE); } }
public void main(RakamHttpRequest request) { if (!request.getDecoderResult().isSuccess()) { sendError(request, BAD_REQUEST); return; } if (request.getMethod() != GET) { sendError(request, NOT_FOUND); return; } final String uri = request.path(); int idx = uri.indexOf("/static/"); File file; if (idx > -1) { final String path = sanitizeUri(uri); if (path == null) { sendError(request, FORBIDDEN); return; } file = new File(path); } else { file = new File(directory.getPath(), "index.html"); } sendFile(request, file); }
public void handle(RakamHttpRequest request) { String path = cleanPath(request.path()); int lastIndex = path.length() - 1; if (lastIndex > 0 && path.charAt(lastIndex) == '/') { path = path.substring(0, lastIndex); } HttpMethod method = request.getMethod(); final HttpRequestHandler handler = routes.get(new PatternBinding(method, path)); if (handler != null) { if (handler instanceof WebSocketService) { request.context().attr(PATH).set(path); } handler.handle(request); } else { for (Map.Entry<PatternBinding, HttpRequestHandler> prefixRoute : prefixRoutes) { if (method.equals(prefixRoute.getKey().method) && path.startsWith(prefixRoute.getKey().pattern)) { prefixRoute.getValue().handle(request); return; } } noMatch.handle(request); } }