Created
January 20, 2021 15:25
-
-
Save BoboTiG/521ac322deca9c3f6f00c7d9d111c868 to your computer and use it in GitHub Desktop.
Medium - The Mystery of the Endless HTTPS Call
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
# pre-requisites | |
$ brew install java11 | |
$ echo 'export PATH="/usr/local/opt/openjdk@11/bin:$PATH"' >> ~/.zshrc | |
# exec | |
$ javac SimpleHttpsClient.java | |
$ java SimpleHttpsClient | |
# debug | |
$ jmap -dump:live,file=dump-jmap.hprof PID | |
$ jstack -l PID >dump-jstack | |
*/ | |
import java.net.URI; | |
import java.net.URLEncoder; | |
import java.net.http.HttpClient; | |
import java.net.http.HttpRequest; | |
import java.net.http.HttpResponse; | |
public class SimpleHttpsClient { | |
public static void main(String[] args) throws Exception { | |
HttpClient httpClient = HttpClient.newBuilder() | |
.version(HttpClient.Version.HTTP_1_1) | |
.build(); | |
HttpRequest request = HttpRequest.newBuilder() | |
.POST(HttpRequest.BodyPublishers.ofString("{\"context\": {\"currentDocument\": \"/default-domain/UserWorkspaces/<USER>\"}}")) | |
.uri(URI.create("https://<HOST>/nuxeo/api/v1/upload/<BATCH_ID>/0/execute/FileManager.Import")) | |
.header("X-Batch-No-Drop", "true") | |
.header("Content-Type", "application/json") | |
.header("X-Authentication-Token", "<TOKEN>") | |
.build(); | |
HttpResponse<String> response = httpClient.send(request, HttpResponse.BodyHandlers.ofString()); | |
System.out.println(response.body()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment