@SuppressWarnings("unchecked")
    public Output run(RunContext runContext) throws Exception {
        Logger logger = runContext.logger();

        try (HttpClient client = this.client(runContext, this.method)) {
            HttpRequest<String> request = this.request(runContext);
            HttpResponse<String> response;

            try {
                response = client
                    .toBlocking()
                    .exchange(request, Argument.STRING, Argument.STRING);

                // check that the string is a valid Unicode string
                if (response.getBody().isPresent()) {
                    OptionalInt illegalChar = response.body().chars().filter(c -> !Character.isDefined(c)).findFirst();
                    if (illegalChar.isPresent()) {
                        throw new IllegalArgumentException("Illegal unicode code point in request body: " + illegalChar.getAsInt() +
                            ", the Request task only support valid Unicode strings as body.\n" +
                            "You can try using the Download task instead.");
                    }
                }
            } catch (HttpClientResponseException e) {
                if (!allowFailed) {
                    throw e;
                }

                //noinspection unchecked
                response = (HttpResponse<String>) e.getResponse();
            }

            logger.debug("Request '{}' with the response code '{}'", request.getUri(), response.getStatus().getCode());

            return this.output(runContext, request, response);
        }
    }
@Test
    void failed() throws Exception {
        try (
            ApplicationContext applicationContext = ApplicationContext.run();
            EmbeddedServer server = applicationContext.getBean(EmbeddedServer.class).start();

        ) {
            Request task = Request.builder()
                .id(RequestTest.class.getSimpleName())
                .type(RequestTest.class.getName())
                .uri(server.getURL().toString() + "/hello417")
                .allowFailed(true)
                .build();

            RunContext runContext = TestsUtils.mockRunContext(this.runContextFactory, task, ImmutableMap.of());

            Request.Output output = task.run(runContext);

            assertThat(output.getBody(), is("{ \"hello\": \"world\" }"));
            assertThat(output.getCode(), is(417));
        }
    }