@Test public void processShouldWorkWhenKnownMethod() throws Exception { ObjectNode parameters = new ObjectNode(new JsonNodeFactory(false)); parameters.put("id", "testId"); parameters.put("name", "testName"); JsonNode[] nodes = new JsonNode[] { new ObjectNode(new JsonNodeFactory(false)).textNode("getTestMethod"), parameters, new ObjectNode(new JsonNodeFactory(false)).textNode("#1")}; List<InvocationResponse> responses = testee.handle(AuthenticatedRequest.decorate(InvocationRequest.deserialize(nodes), session)) .collectList() .block(); assertThat(responses).hasSize(1) .extracting( x -> x.getResults().findValue("id").asText(), x -> x.getResults().findValue("name").asText(), x -> x.getResults().findValue("message").asText()) .containsExactly(tuple("testId", "testName", "works")); }
public Flux<InvocationResponse> handle(AuthenticatedRequest request) { Optional<MailboxSession> mailboxSession = Optional.ofNullable(request.getMailboxSession()); try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.USER, mailboxSession.map(MailboxSession::getUser).map(Username::asString)) .addContext(MDCBuilder.SESSION_ID, mailboxSession.map(MailboxSession::getSessionId)) .addContext(MDCBuilder.ACTION, request.getMethodName().getName()) .build()) { return Optional.ofNullable(methods.get(request.getMethodName())) .map(extractAndProcess(request)) .map(jmapResponseWriter::formatMethodResponse) .orElseThrow(() -> new IllegalStateException("unknown method " + request.getMethodName())); } catch (IOException e) { throw new RuntimeException(e); } }
RequestHandler { public Flux<InvocationResponse> handle(AuthenticatedRequest request) { Optional<MailboxSession> mailboxSession = Optional.ofNullable(request.getMailboxSession()); try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.USER, mailboxSession.map(MailboxSession::getUser).map(Username::asString)) .addContext(MDCBuilder.SESSION_ID, mailboxSession.map(MailboxSession::getSessionId)) .addContext(MDCBuilder.ACTION, request.getMethodName().getName()) .build()) { return Optional.ofNullable(methods.get(request.getMethodName())) .map(extractAndProcess(request)) .map(jmapResponseWriter::formatMethodResponse) .orElseThrow(() -> new IllegalStateException("unknown method " + request.getMethodName())); } catch (IOException e) { throw new RuntimeException(e); } } }
RequestHandler { public Flux<InvocationResponse> handle(AuthenticatedRequest request) { Optional<MailboxSession> mailboxSession = Optional.ofNullable(request.getMailboxSession()); try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.USER, mailboxSession.map(MailboxSession::getUser).map(Username::asString)) .addContext(MDCBuilder.SESSION_ID, mailboxSession.map(MailboxSession::getSessionId)) .addContext(MDCBuilder.ACTION, request.getMethodName().getName()) .build()) { return Optional.ofNullable(methods.get(request.getMethodName())) .map(extractAndProcess(request)) .map(jmapResponseWriter::formatMethodResponse) .orElseThrow(() -> new IllegalStateException("unknown method " + request.getMethodName())); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  RequestHandler(Set<Method> methods, JmapRequestParser jmapRequestParser, JmapResponseWriter jmapResponseWriter); }
RequestHandler { public Flux<InvocationResponse> handle(AuthenticatedRequest request) { Optional<MailboxSession> mailboxSession = Optional.ofNullable(request.getMailboxSession()); try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.USER, mailboxSession.map(MailboxSession::getUser).map(Username::asString)) .addContext(MDCBuilder.SESSION_ID, mailboxSession.map(MailboxSession::getSessionId)) .addContext(MDCBuilder.ACTION, request.getMethodName().getName()) .build()) { return Optional.ofNullable(methods.get(request.getMethodName())) .map(extractAndProcess(request)) .map(jmapResponseWriter::formatMethodResponse) .orElseThrow(() -> new IllegalStateException("unknown method " + request.getMethodName())); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  RequestHandler(Set<Method> methods, JmapRequestParser jmapRequestParser, JmapResponseWriter jmapResponseWriter); Flux<InvocationResponse> handle(AuthenticatedRequest request); ErrorResponse generateInvalidArgumentError(String description); }
RequestHandler { public Flux<InvocationResponse> handle(AuthenticatedRequest request) { Optional<MailboxSession> mailboxSession = Optional.ofNullable(request.getMailboxSession()); try (Closeable closeable = MDCBuilder.create() .addContext(MDCBuilder.USER, mailboxSession.map(MailboxSession::getUser).map(Username::asString)) .addContext(MDCBuilder.SESSION_ID, mailboxSession.map(MailboxSession::getSessionId)) .addContext(MDCBuilder.ACTION, request.getMethodName().getName()) .build()) { return Optional.ofNullable(methods.get(request.getMethodName())) .map(extractAndProcess(request)) .map(jmapResponseWriter::formatMethodResponse) .orElseThrow(() -> new IllegalStateException("unknown method " + request.getMethodName())); } catch (IOException e) { throw new RuntimeException(e); } } @Inject  RequestHandler(Set<Method> methods, JmapRequestParser jmapRequestParser, JmapResponseWriter jmapResponseWriter); Flux<InvocationResponse> handle(AuthenticatedRequest request); ErrorResponse generateInvalidArgumentError(String description);  }