diff --git a/src/main/java/io/cryostat/net/web/WebServer.java b/src/main/java/io/cryostat/net/web/WebServer.java index 3773efbcdf..b5bc435d6c 100644 --- a/src/main/java/io/cryostat/net/web/WebServer.java +++ b/src/main/java/io/cryostat/net/web/WebServer.java @@ -90,6 +90,7 @@ public class WebServer extends AbstractVerticle { // Use X- prefix so as to not trigger web-browser auth dialogs public static final String AUTH_SCHEME_HEADER = "X-WWW-Authenticate"; + public static final String DATASOURCE_FILENAME = "cryostat-analysis.jfr"; private final HttpServer server; private final NetworkConfiguration netConf; diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandler.java index 6d33709476..55488afbee 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandler.java @@ -55,6 +55,7 @@ import io.cryostat.core.sys.Environment; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; +import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.HttpModule; import io.cryostat.net.web.http.api.ApiVersion; @@ -188,13 +189,14 @@ private ResponseMessage doPost(String subdirectoryName, String recordingName, UR MultipartForm.create() .binaryFileUpload( "file", - recordingName, + WebServer.DATASOURCE_FILENAME, recordingPath.toString(), HttpMimeType.OCTET_STREAM.toString()); CompletableFuture future = new CompletableFuture<>(); webClient .postAbs(uploadUrl.toURI().resolve("/load").normalize().toString()) + .addQueryParam("overwrite", "true") .timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds)) .sendMultipartForm( form, diff --git a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandler.java b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandler.java index dcbae79f33..cd6204a07a 100644 --- a/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandler.java @@ -55,6 +55,7 @@ import io.cryostat.core.sys.Environment; import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; +import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.HttpModule; import io.cryostat.net.web.http.api.ApiVersion; @@ -188,13 +189,14 @@ private ResponseMessage doPost(String sourceTarget, String recordingName, URL up MultipartForm.create() .binaryFileUpload( "file", - recordingName, + WebServer.DATASOURCE_FILENAME, recordingPath.toString(), HttpMimeType.OCTET_STREAM.toString()); CompletableFuture future = new CompletableFuture<>(); webClient .postAbs(uploadUrl.toURI().resolve("/load").normalize().toString()) + .addQueryParam("overwrite", "true") .timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds)) .sendMultipartForm( form, diff --git a/src/main/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandler.java b/src/main/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandler.java index eb54503ac5..3e92b363c5 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandler.java @@ -57,6 +57,7 @@ import io.cryostat.net.AuthManager; import io.cryostat.net.security.ResourceAction; import io.cryostat.net.web.DeprecatedApi; +import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.HttpModule; @@ -179,13 +180,14 @@ private ResponseMessage doPost(String recordingName, URL uploadUrl) throws Excep MultipartForm.create() .binaryFileUpload( "file", - recordingName, + WebServer.DATASOURCE_FILENAME, recordingPath.toString(), HttpMimeType.OCTET_STREAM.toString()); CompletableFuture future = new CompletableFuture<>(); webClient .postAbs(uploadUrl.toURI().resolve("/load").normalize().toString()) + .addQueryParam("overwrite", "true") .timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds)) .sendMultipartForm( form, diff --git a/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandler.java b/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandler.java index f781af5c10..43f7172885 100644 --- a/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandler.java +++ b/src/main/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandler.java @@ -61,6 +61,7 @@ import io.cryostat.net.AuthManager; import io.cryostat.net.TargetConnectionManager; import io.cryostat.net.security.ResourceAction; +import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.AbstractAuthenticatedRequestHandler; import io.cryostat.net.web.http.HttpMimeType; import io.cryostat.net.web.http.HttpModule; @@ -185,7 +186,7 @@ private ResponseMessage doPost(RoutingContext ctx, URL uploadUrl) throws Excepti MultipartForm.create() .binaryFileUpload( "file", - recordingName, + WebServer.DATASOURCE_FILENAME, recordingPath.toString(), HttpMimeType.OCTET_STREAM.toString()); @@ -193,6 +194,7 @@ private ResponseMessage doPost(RoutingContext ctx, URL uploadUrl) throws Excepti try { webClient .postAbs(uploadUrl.toURI().resolve("/load").normalize().toString()) + .addQueryParam("overwrite", "true") .timeout(TimeUnit.SECONDS.toMillis(httpTimeoutSeconds)) .sendMultipartForm( form, diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java index 0d9fc74492..89f8d0cc2c 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostFromPathHandlerTest.java @@ -222,6 +222,8 @@ void shouldDoUpload() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -275,6 +277,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception { HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.doAnswer( new Answer() { @Override @@ -333,6 +337,8 @@ void shouldHandleNullStatusMessage() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -392,6 +398,8 @@ void shouldHandleNullResponseBody() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { diff --git a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandlerTest.java index fb2a320940..dd7277fa75 100644 --- a/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/beta/RecordingUploadPostHandlerTest.java @@ -215,6 +215,8 @@ void shouldDoUpload() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -264,6 +266,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -320,6 +324,8 @@ void shouldHandleNullStatusMessage() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -376,6 +382,8 @@ void shouldHandleNullResponseBody() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandlerTest.java index 77fad75d59..71f1f4e2a3 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/RecordingUploadPostHandlerTest.java @@ -195,6 +195,8 @@ void shouldDoUpload() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -251,6 +253,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -316,6 +320,8 @@ void shouldHandleNullStatusMessage() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -374,6 +380,8 @@ void shouldHandleNullResponseBody() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { diff --git a/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandlerTest.java b/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandlerTest.java index fefd14530d..6b03ca36b8 100644 --- a/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandlerTest.java +++ b/src/test/java/io/cryostat/net/web/http/api/v1/TargetRecordingUploadPostHandlerTest.java @@ -232,6 +232,8 @@ void shouldDoUpload() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -301,6 +303,8 @@ void shouldHandleInvalidResponseStatusCode() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -373,6 +377,8 @@ void shouldHandleNullStatusMessage() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { @@ -445,6 +451,8 @@ void shouldHandleNullResponseBody() throws Exception { HttpRequest httpReq = Mockito.mock(HttpRequest.class); HttpResponse httpResp = Mockito.mock(HttpResponse.class); Mockito.when(webClient.postAbs(Mockito.anyString())).thenReturn(httpReq); + Mockito.when(httpReq.addQueryParam(Mockito.anyString(), Mockito.anyString())) + .thenReturn(httpReq); Mockito.when(httpReq.timeout(Mockito.anyLong())).thenReturn(httpReq); Mockito.doAnswer( new Answer() { diff --git a/src/test/java/itest/UploadRecordingIT.java b/src/test/java/itest/UploadRecordingIT.java index bac98cbf40..9efa408ca0 100644 --- a/src/test/java/itest/UploadRecordingIT.java +++ b/src/test/java/itest/UploadRecordingIT.java @@ -45,6 +45,7 @@ import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeoutException; +import io.cryostat.net.web.WebServer; import io.cryostat.net.web.http.HttpMimeType; import io.vertx.core.MultiMap; @@ -131,7 +132,9 @@ public void shouldLoadRecordingToDatasource() throws Exception { }); final String expectedUploadResponse = - String.format("Uploaded: %s\nSet: %s", RECORDING_NAME, RECORDING_NAME); + String.format( + "Uploaded: %s\nSet: %s", + WebServer.DATASOURCE_FILENAME, WebServer.DATASOURCE_FILENAME); MatcherAssert.assertThat( uploadRespFuture.get().trim(), Matchers.equalTo(expectedUploadResponse)); @@ -154,7 +157,7 @@ public void shouldLoadRecordingToDatasource() throws Exception { MatcherAssert.assertThat( getRespFuture.get().trim(), - Matchers.equalTo(String.format("**%s**", RECORDING_NAME))); + Matchers.equalTo(String.format("**%s**", WebServer.DATASOURCE_FILENAME))); // Query Data Source for recording metrics final CompletableFuture queryRespFuture = new CompletableFuture<>();