@Override public void incoming(Request request) { requestSizeHistogram .ifPresent(histogram -> request.payload() .ifPresent(payload -> histogram.update(payload.size()))); }
private <E> Either<Response<?>, E> deserialize(RequestContext rc, Class<? extends E> entityClass) { final Optional<ByteString> payloadOpt = rc.request().payload(); if (!payloadOpt.isPresent()) { return Either.left(Response.forStatus( Status.BAD_REQUEST .withReasonPhrase("Missing payload"))); } final E entity; try { entity = codec.read(payloadOpt.get(), entityClass, rc); } catch (Throwable e) { LOG.warn("error", e); return Either.left(Response.forStatus( Status.BAD_REQUEST .withReasonPhrase("Payload parsing failed: " + e.getMessage()))); } return Either.right(entity); }
Optional<com.spotify.apollo.Request> apolloIncomingRequest) { final Optional<RequestBody> requestBody = apolloRequest.payload().map(payload -> { final MediaType contentType = apolloRequest.header("Content-Type") .map(MediaType::parse)
public static <T> Middleware<AsyncHandler<Response<T>>, AsyncHandler<Response<T>>> httpLogger( Logger log, RequestAuthenticator authenticator) { return innerHandler -> requestContext -> { final Request request = requestContext.request(); log.info("{}{} {} by {} with headers {} parameters {} and payload {}", "GET".equals(request.method()) ? "" : "[AUDIT] ", request.method(), request.uri(), // TODO: pass in auth context instead of authenticating twice auth(requestContext, authenticator).user().map(idToken -> idToken.getPayload() .getEmail()) .orElse("anonymous"), hideSensitiveHeaders(request.headers()), request.parameters(), request.payload().map(ByteString::utf8).orElse("") .replaceAll("\n", " ")); return innerHandler.invoke(requestContext); }; }
private <E> Either<Response<?>, E> deserialize(RequestContext rc, Class<? extends E> entityClass) { final Optional<ByteString> payloadOpt = rc.request().payload(); if (!payloadOpt.isPresent()) { return Either.left(Response.forStatus( Status.BAD_REQUEST .withReasonPhrase("Missing payload"))); } final E entity; try { entity = codec.read(payloadOpt.get(), entityClass, rc); } catch (Throwable e) { LOG.warn("error", e); return Either.left(Response.forStatus( Status.BAD_REQUEST .withReasonPhrase("Payload parsing failed: " + e.getMessage()))); } return Either.right(entity); }
private Response<Workflow> createOrUpdateWorkflow(String componentId, RequestContext rc, AuthContext ac) { final Optional<ByteString> payload = rc.request().payload(); if (!payload.isPresent()) { return Response.forStatus(Status.BAD_REQUEST.withReasonPhrase("Missing payload."));
private Response<WorkflowState> patchState(String componentId, String id, Request request, AuthContext ac) { final Optional<ByteString> payload = request.payload(); if (!payload.isPresent()) { return Response.forStatus(Status.BAD_REQUEST.withReasonPhrase("Missing payload."));