@Override
    @VisibleForTesting
    public CompletableFuture<JarUploadResponseBody> handleRequest(
            @Nonnull final HandlerRequest<EmptyRequestBody> request,
            @Nonnull final RestfulGateway gateway)
            throws RestHandlerException {
        Collection<File> uploadedFiles = request.getUploadedFiles();
        if (uploadedFiles.size() != 1) {
            throw new RestHandlerException(
                    "Exactly 1 file must be sent, received " + uploadedFiles.size() + '.',
                    HttpResponseStatus.BAD_REQUEST);
        }
        final Path fileUpload = uploadedFiles.iterator().next().toPath();
        return CompletableFuture.supplyAsync(
                () -> {
                    if (!fileUpload.getFileName().toString().endsWith(".jar")) {
                        throw new CompletionException(
                                new RestHandlerException(
                                        "Only Jar files are allowed.",
                                        HttpResponseStatus.BAD_REQUEST));
                    } else {
                        final Path destination =
                                jarDir.resolve(UUID.randomUUID() + "_" + fileUpload.getFileName());
                        try {
                            Files.move(fileUpload, destination);
                        } catch (IOException e) {
                            throw new CompletionException(
                                    new RestHandlerException(
                                            String.format(
                                                    "Could not move uploaded jar file [%s] to [%s].",
                                                    fileUpload, destination),
                                            HttpResponseStatus.INTERNAL_SERVER_ERROR,
                                            e));
                        }
                        return new JarUploadResponseBody(destination.normalize().toString());
                    }
                },
                executor);
    }
@Test
    void testRejectNonJarFiles() throws Exception {
        final Path uploadedFile = Files.createFile(jarDir.resolve("katrin.png"));
        final HandlerRequest<EmptyRequestBody> request = createRequest(uploadedFile);

        assertThatThrownBy(
                        () -> jarUploadHandler.handleRequest(request, mockDispatcherGateway).get())
                .satisfies(
                        e -> {
                            final Throwable throwable =
                                    ExceptionUtils.stripCompletionException(e.getCause());
                            assertThat(throwable).isInstanceOf(RestHandlerException.class);
                            final RestHandlerException restHandlerException =
                                    (RestHandlerException) throwable;
                            assertThat(restHandlerException.getHttpResponseStatus())
                                    .isEqualTo(HttpResponseStatus.BAD_REQUEST);
                        });
    }