@Override public HttpHeaders headers() { return request.headers(); } }
@Override public Object nextElement() { return request.headers().get(s); } };
@Override public String getHeader(String s) { return request.headers().get(s); }
@Override public Enumeration<String> getHeaderNames() { return new Vector(request.headers().names()).elements(); }
@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); }
@ApiOperation(value = "Export recipe", response = UIRecipe.class, authorizations = @Authorization(value = "master_key") ) @GET @Path("/export") public void exportUIRecipe(@HeaderParam("Accept") String contentType, @Named("user_id") Project project, RakamHttpRequest request) throws JsonProcessingException { request.bodyHandler(s -> { UIRecipe export = installer.export(project.userId, project.project); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) .findAny() .orElse(ExportType.YAML); ByteBuf buffer; try { buffer = Unpooled.wrappedBuffer(exportType.mapper.writeValueAsBytes(export)); } catch (JsonProcessingException e) { throw Throwables.propagate(e); } DefaultFullHttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.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 = "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", 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); } }); }
ImmutableMap.<String, Object>builder() .put("remote_address", Optional.ofNullable(request.getRemoteAddress())) .put("origin", Optional.ofNullable(request.headers().get(HttpHeaders.Names.ORIGIN))) .put("limit", Optional.ofNullable(query.limit)) .put("timezone", Optional.ofNullable(query.timezone).map(e -> e.getId()))
@Path("/install") public void installRecipe(RakamHttpRequest request) { String contentType = request.headers().get(CONTENT_TYPE); ExportType exportType = Arrays.stream(ExportType.values()) .filter(f -> f.contentType.equals(contentType)) String master_key = request.headers().get("master_key"); String project = apiKeyService.getProjectOfApiKey(master_key, MASTER_KEY);
@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); }); }
@Override public Object extract(ObjectNode node, RakamHttpRequest request) { String apiKey = request.headers().get(type.getKey()); if (apiKey == null) { List<String> apiKeyList = request.params().get(type.getKey());
String masterKey = Optional.ofNullable(request.params().get("master_key")) .map((v) -> v.get(0)) .orElseGet(() -> request.headers().get("master_key")); String project = apiKeyService.getProjectOfApiKey(masterKey, MASTER_KEY); } else if (query.type == CSV) { CsvSchema.Builder builder = CsvSchema.builder(); if (request.headers().get("column_separator") != null) { String column_seperator = request.headers().get("column_separator"); if (column_seperator.length() != 1) { throw new RakamException("Invalid column separator", BAD_REQUEST); if (request.headers().get("use_header") != null) { useHeader = Boolean.valueOf(request.headers().get("use_header"));
String ifModifiedSince = request.headers().get(IF_MODIFIED_SINCE); if (ifModifiedSince != null && !ifModifiedSince.isEmpty()) { SimpleDateFormat dateFormatter = new SimpleDateFormat(HTTP_DATE_FORMAT, Locale.US);
@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(); }); }
String projectString = request.headers().get("project"); if (projectString == null && requiresProject) { throw new RakamException("Project header is null", BAD_REQUEST);
Object scoped = engine.invokeFunction("$$module", request.params(), body, request.headers());
public <T> void handleServerSentQueryExecution(RakamHttpRequest request, Class<T> clazz, BiFunction<String, T, QueryExecution> executorFunction, ApiKeyService.AccessKeyType keyType, boolean killOnConnectionClose, Optional<BiConsumer<T, QueryResult>> exceptionCallback) { if (!Objects.equals(request.headers().get(ACCEPT), "text/event-stream")) { request.response("The endpoint only supports text/event-stream as Accept header", HttpResponseStatus.NOT_ACCEPTABLE).end(); return;