From cdd73b09cca5a85e902c11cce99940d2f1428fe0 Mon Sep 17 00:00:00 2001 From: Dennis Heimbigner Date: Fri, 3 Nov 2023 20:30:57 -0600 Subject: [PATCH] ## Description of Changes re: Issue The DAP4 code was improperly handling the use of the "dap4:" protocol in a url. This PR fixes it by detecting that protocol and doing two actions: 1. Convert the protocol to "https:". 2. Add the fragment "#dap4" to end of the url. Note that in \#1, this should really be https, but test.opendap.org still uses http; one hopes that other servers are setup to redirect http: to https: ## PR Checklist - [X] Link to any issues that the PR addresses - [X] Add labels - [X] Open as a [draft PR](https://github.blog/2019-02-14-introducing-draft-pull-requests/) until ready for review - [X] Make sure GitHub tests pass - [X] Mark PR as "Ready for Review" --- dap4/build.gradle | 2 -- dap4/src/main/java/dap4/core/util/XURI.java | 13 +++++++++++++ .../java/dap4/dap4lib/cdm/nc2/DapNetcdfFile.java | 7 +++++++ 3 files changed, 20 insertions(+), 2 deletions(-) diff --git a/dap4/build.gradle b/dap4/build.gradle index 287a259f88..5956343144 100644 --- a/dap4/build.gradle +++ b/dap4/build.gradle @@ -32,11 +32,9 @@ test { include 'dap4/test/TestParserCE.class' include 'dap4/test/TestRaw.class' include 'dap4/test/TestDap4Url.class' -if(false) { // disable selected dap4 tests for now include 'dap4/test/TestRemote.class' include 'dap4/test/TestConstraints.class' include 'dap4/test/TestHyrax.class' -} dependsOn('farmBeforeIntegrationTest') finalizedBy('farmAfterIntegrationTest') diff --git a/dap4/src/main/java/dap4/core/util/XURI.java b/dap4/src/main/java/dap4/core/util/XURI.java index 02fde56bd1..74a0a55129 100644 --- a/dap4/src/main/java/dap4/core/util/XURI.java +++ b/dap4/src/main/java/dap4/core/util/XURI.java @@ -265,6 +265,19 @@ public void insertQueryField(String key, String newval) { rebuildQuery(); } + /** + * Allow fragment fields to be inserted + * + * @param key + * @param newval + * @return previous value or this value if key not set + */ + public void insertFragmentField(String key, String newval) { + // Watch out in case there is no query + this.fragfields = insertAmpField(key, newval, parent.getFragment()); + rebuildQuery(); + } + /** * Allow queryfields to be removed * diff --git a/dap4/src/main/java/dap4/dap4lib/cdm/nc2/DapNetcdfFile.java b/dap4/src/main/java/dap4/dap4lib/cdm/nc2/DapNetcdfFile.java index 22c9d7c954..ecd04674ce 100644 --- a/dap4/src/main/java/dap4/dap4lib/cdm/nc2/DapNetcdfFile.java +++ b/dap4/src/main/java/dap4/dap4lib/cdm/nc2/DapNetcdfFile.java @@ -128,6 +128,13 @@ public DapNetcdfFile(String location, CancelTask cancelTask) throws IOException } catch (URISyntaxException use) { throw new IOException(use); } + // We need to convert the protocol to #dap4 + if ("dap4".equalsIgnoreCase(xuri.getScheme())) { + xuri.setScheme("https"); // Note that this should be https, but + // test.opendap.org still uses http; one + // hopes that other servers are setup to + // redirect http: to https: + } this.dsplocation = xuri.assemble(XURI.URLQUERY); cancel = (cancelTask == null ? nullcancel : cancelTask);