@Test public void postTest() { try { fileSystemTestingUtils.setup(); ioService = fileSystemTestingUtils.getIoService(); final String repoName = "myrepo"; final JGitFileSystem fs = (JGitFileSystem) ioService.newFileSystem(URI.create("git: new HashMap<String, Object>() {{ put("init", Boolean.TRUE); put("internal", Boolean.TRUE); }}); ioService.startBatch(fs); String pom = "target/test-classes/kjar-2-single-resources/pom.xml"; if (!runIntoMavenCLI) { pom = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/pom.xml"; } ioService.write(fs.getPath("/kjar-2-single-resources/pom.xml"), new String(java.nio.file.Files.readAllBytes(new File(pom).toPath()))); String personDotJava = "target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"; if (!runIntoMavenCLI) { personDotJava = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"; } ioService.write(fs.getPath("/kjar-2-single-resources/src/main/java/org/kie/maven/plugin/test/Person.java"), new String(java.nio.file.Files.readAllBytes(new File(personDotJava).toPath()))); String simpleRulesDotDRL = "target/test-classes/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"; if (!runIntoMavenCLI) { simpleRulesDotDRL = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/AllResourceTypes/simple-rules.drl"; } ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/AllResourcesTypes/simple-rules.drl"), new String(java.nio.file.Files.readAllBytes(new File(simpleRulesDotDRL).toPath()))); String kmodule = "target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"; if (!runIntoMavenCLI) { kmodule = "kie-wb-common-services/kie-wb-common-compiler/kie-wb-common-compiler-distribution/target/test-classes/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"; } ioService.write(fs.getPath("/kjar-2-single-resources/src/main/resources/META-INF/kmodule.xml"), new String(java.nio.file.Files.readAllBytes(new File(kmodule).toPath()))); ioService.endBatch(); Path tmpRootCloned = Files.createTempDirectory("cloned"); Path tmpCloned = Files.createDirectories(Paths.get(tmpRootCloned.toString(), "dummy")); final File gitClonedFolder = new File(tmpCloned.toFile(), ".clone.git"); final Git cloned = Git.cloneRepository().setURI(fs.getGit().getRepository().getDirectory().toURI().toString()).setBare(false).setDirectory(gitClonedFolder).call(); assertThat(cloned).isNotNull(); mavenRepoPath = Paths.get(System.getProperty("user.home"), ".m2", "repository"); tmpRoot = Paths.get(gitClonedFolder + "/dummy/"); Client client = ClientBuilder.newClient(); WebTarget target = client.target(deploymentUrl.toString() + "rest/maven/"); MultivaluedMap headersMap = new MultivaluedHashMap(); headersMap.add("project", tmpRoot.toAbsolutePath().toString() + "/dummy"); headersMap.add("mavenrepo", mavenRepoPath.toAbsolutePath().toString()); headersMap.add("settings_xml", mavenSettingsPath); Future<Response> responseFuture = target.request().headers(headersMap).async().post(Entity.entity(String.class, MediaType.TEXT_PLAIN)); Response response = responseFuture.get(); assertThat(response.getStatusInfo().getStatusCode()).isEqualTo(200); InputStream is = response.readEntity(InputStream.class); byte[] serializedCompilationResponse = IOUtils.toByteArray(is); HttpCompilationResponse res = RestUtils.readDefaultCompilationResponseFromBytes(serializedCompilationResponse); assertThat(res).isNotNull(); assertThat(res.getDependencies()).hasSize(4); assertThat(res.getTargetContent()).hasSize(3); tearDown(); } catch (Exception e) { logger.error(e.getMessage()); } finally { fileSystemTestingUtils.cleanup(); } }
public CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url) { final CompletableFuture<KieCompilationResponse> cfInternal = new CompletableFuture<>(); Future<?> future = ClientBuilder.newBuilder().build() .target(url) .request().header("project", projectPath).header("mavenrepo", mavenRepoPath).header("settings_xml",settingsXmlPath) .accept(MediaType.APPLICATION_OCTET_STREAM) .async() .post(null, new InvocationCallback<KieCompilationResponse>() { @Override public void completed(final KieCompilationResponse result) { cfInternal.complete(result); } @Override public void failed(final Throwable throwable) { cfInternal.completeExceptionally(throwable); } }); return cfInternal.whenComplete((result, exception) -> { if (CancellationException.class.isInstance(exception)) { future.cancel(true); } }); }
MavenRestClient { public CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url) { final CompletableFuture<KieCompilationResponse> cfInternal = new CompletableFuture<>(); Future<?> future = ClientBuilder.newBuilder().build() .target(url) .request().header("project", projectPath).header("mavenrepo", mavenRepoPath).header("settings_xml",settingsXmlPath) .accept(MediaType.APPLICATION_OCTET_STREAM) .async() .post(null, new InvocationCallback<KieCompilationResponse>() { @Override public void completed(final KieCompilationResponse result) { cfInternal.complete(result); } @Override public void failed(final Throwable throwable) { cfInternal.completeExceptionally(throwable); } }); return cfInternal.whenComplete((result, exception) -> { if (CancellationException.class.isInstance(exception)) { future.cancel(true); } }); } }
MavenRestClient { public CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url) { final CompletableFuture<KieCompilationResponse> cfInternal = new CompletableFuture<>(); Future<?> future = ClientBuilder.newBuilder().build() .target(url) .request().header("project", projectPath).header("mavenrepo", mavenRepoPath).header("settings_xml",settingsXmlPath) .accept(MediaType.APPLICATION_OCTET_STREAM) .async() .post(null, new InvocationCallback<KieCompilationResponse>() { @Override public void completed(final KieCompilationResponse result) { cfInternal.complete(result); } @Override public void failed(final Throwable throwable) { cfInternal.completeExceptionally(throwable); } }); return cfInternal.whenComplete((result, exception) -> { if (CancellationException.class.isInstance(exception)) { future.cancel(true); } }); }  }
MavenRestClient { public CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url) { final CompletableFuture<KieCompilationResponse> cfInternal = new CompletableFuture<>(); Future<?> future = ClientBuilder.newBuilder().build() .target(url) .request().header("project", projectPath).header("mavenrepo", mavenRepoPath).header("settings_xml",settingsXmlPath) .accept(MediaType.APPLICATION_OCTET_STREAM) .async() .post(null, new InvocationCallback<KieCompilationResponse>() { @Override public void completed(final KieCompilationResponse result) { cfInternal.complete(result); } @Override public void failed(final Throwable throwable) { cfInternal.completeExceptionally(throwable); } }); return cfInternal.whenComplete((result, exception) -> { if (CancellationException.class.isInstance(exception)) { future.cancel(true); } }); }  CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url); }
MavenRestClient { public CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url) { final CompletableFuture<KieCompilationResponse> cfInternal = new CompletableFuture<>(); Future<?> future = ClientBuilder.newBuilder().build() .target(url) .request().header("project", projectPath).header("mavenrepo", mavenRepoPath).header("settings_xml",settingsXmlPath) .accept(MediaType.APPLICATION_OCTET_STREAM) .async() .post(null, new InvocationCallback<KieCompilationResponse>() { @Override public void completed(final KieCompilationResponse result) { cfInternal.complete(result); } @Override public void failed(final Throwable throwable) { cfInternal.completeExceptionally(throwable); } }); return cfInternal.whenComplete((result, exception) -> { if (CancellationException.class.isInstance(exception)) { future.cancel(true); } }); }  CompletableFuture<KieCompilationResponse> call(String projectPath, String mavenRepoPath, String settingsXmlPath, String url);  }