Skip to content

Commit e6c033b

Browse files
authored
Merge pull request IQSS#8826 from poikilotherm/7000-mpconfig-fqdn
7000 mpconfig fqdn & siteUrl
2 parents 880ec33 + 5cdca67 commit e6c033b

11 files changed

Lines changed: 156 additions & 154 deletions

File tree

doc/sphinx-guides/source/installation/config.rst

Lines changed: 45 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1435,32 +1435,63 @@ It's also possible to change these values by stopping Payara, editing ``payara5/
14351435
dataverse.fqdn
14361436
++++++++++++++
14371437

1438-
If the Dataverse installation has multiple DNS names, this option specifies the one to be used as the "official" hostname. For example, you may want to have ``dataverse.example.edu``, and not the less appealing ``server-123.example.edu`` to appear exclusively in all the registered global identifiers, etc.
1439-
1440-
The password reset feature requires ``dataverse.fqdn`` to be configured.
1441-
1442-
Configuring ``dataverse.fqdn`` is not enough. Read on for the importance of also setting ``dataverse.siteUrl``.
1438+
If the Dataverse installation has multiple DNS names, this option specifies the one to be used as the "official"
1439+
hostname. For example, you may want to have ``dataverse.example.edu``, and not the less appealing
1440+
``server-123.example.edu`` to appear exclusively in all the registered global identifiers, etc.
1441+
1442+
- Email confirmation links
1443+
- Password reset links
1444+
- Generating a Private URL
1445+
- PID minting
1446+
- Exporting to Schema.org format (and showing JSON-LD in HTML's <meta/> tag)
1447+
- Exporting to DDI format
1448+
- Which Dataverse installation an "external tool" should return to
1449+
- URLs embedded in SWORD API responses
1450+
- ...
1451+
1452+
Usually it will follow the pattern ``https://<full-qualified-domain-name>/<some-place-to-go-to>``.
1453+
*Only* the FQDN part of your Dataverse installation URL can be determined by setting ``dataverse.fqdn``.
1454+
1455+
**Notes:**
1456+
1457+
- The URL will default to using ``https://`` and no additional port information. If that does not suit your setup, you
1458+
can define an additional option, ``dataverse.siteUrl``, :ref:`explained below <dataverse.siteUrl>`, which always
1459+
takes precedence.
1460+
- Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_FQDN``.
1461+
Defaults to ``localhost`` when used with ``mp.config.profile=ct``
14431462

14441463
.. _dataverse.siteUrl:
14451464

14461465
dataverse.siteUrl
14471466
+++++++++++++++++
14481467

1449-
``dataverse.siteUrl`` is used to configure the URL for your Dataverse installation that you plan to advertise to your users. As explained in the :ref:`installation <importance-of-siteUrl>` docs, this setting is critical for the correct operation of your installation.
1450-
1451-
For example, your site URL could be https://dataverse.example.edu
1468+
``dataverse.siteUrl`` is used to configure the URL for your Dataverse installation that you plan to advertise to your
1469+
users. As explained in the :ref:`installation <importance-of-siteUrl>` docs, this setting is critical for the correct
1470+
operation of your installation. For example, your site URL could be https://dataverse.example.edu . That is, even though
1471+
the server might also be available at uglier URLs such as https://server-123.example.edu, the site URL is the
1472+
"official" URL.
14521473

1453-
That is, even though the server might also be available at uglier URLs such as https://server-123.example.edu the site URL is the "official" URL.
1474+
That said, some environments may require using a different URL pattern to access your installation. You might need to
1475+
use HTTP without "S", a non-standard port and so on. This is especially useful in development or testing environments.
14541476

1455-
The ``dataverse.siteUrl`` JVM option can be configured by following the procedure under :ref:`jvm-options` or by editing ``domain.xml`` directly. You can specify the protocol, host, and port number. Your ``domain.xml`` file could look like this, for example:
1477+
You can provide any custom tailored site URL via ``dataverse.siteUrl``, which always takes precedence.
1478+
Example: ``dataverse.siteUrl=http://localhost:8080``
14561479

1457-
``<jvm-options>-Ddataverse.siteUrl=https://dataverse.example.edu</jvm-options>``
1480+
If you wish to change your site URL by changing the domain configuration, you should edit your ``domain.xml`` directly
1481+
to avoid problems with colons in commands. Find a line similar to
1482+
``<jvm-options>-Ddataverse.siteUrl=https://dataverse.example.edu</jvm-options>`` and change it. You can specify the
1483+
protocol, host, and port number and should not include a trailing slash.
14581484

1459-
Note that it's also possible to use the ``dataverse.fqdn`` as a variable, if you wish. Here's an example of this as well as a custom port (which is usually not necessary):
1485+
**Notes:**
14601486

1461-
``<jvm-options>-Ddataverse.siteUrl=https://${dataverse.fqdn}:444</jvm-options>``
1487+
- This setting may be used in combination with variable replacement, referencing :ref:`dataverse.fqdn` with
1488+
``./asadmin create-jvm-options "\-Ddataverse.siteUrl=http\://\${dataverse.fqdn}\:8080"``
1489+
- Remember to restart Payara after editing ``domain.xml``.
1490+
- Can also be set via *MicroProfile Config API* sources, e.g. the environment variable ``DATAVERSE_SITEURL``.
1491+
Defaults to ``http://${dataverse.fqdn}:8080`` when used with ``mp.config.profile=ct``
1492+
- We are absolutely aware that it's confusing to have both ``dataverse.fqdn`` and ``dataverse.siteUrl``.
1493+
https://github.com/IQSS/dataverse/issues/6636 is about resolving this confusion.
14621494

1463-
We are absolutely aware that it's confusing to have both ``dataverse.fqdn`` and ``dataverse.siteUrl``. https://github.com/IQSS/dataverse/issues/6636 is about resolving this confusion.
14641495

14651496
.. _dataverse.files.directory:
14661497

src/main/java/edu/harvard/iq/dataverse/HandlenetServiceBean.java

Lines changed: 2 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,6 @@
2424

2525
import java.io.File;
2626
import java.io.FileInputStream;
27-
import java.net.InetAddress;
28-
import java.net.UnknownHostException;
2927
import java.util.*;
3028
import java.util.logging.Level;
3129
import java.util.logging.Logger;
@@ -34,6 +32,7 @@
3432
import java.security.PrivateKey;
3533

3634
/* Handlenet imports: */
35+
import edu.harvard.iq.dataverse.util.SystemConfig;
3736
import net.handle.hdllib.AbstractMessage;
3837
import net.handle.hdllib.AbstractResponse;
3938
import net.handle.hdllib.AdminRecord;
@@ -247,21 +246,7 @@ private String getRegistrationUrl(DvObject dvObject) {
247246
}
248247

249248
public String getSiteUrl() {
250-
logger.log(Level.FINE,"getSiteUrl");
251-
String hostUrl = System.getProperty("dataverse.siteUrl");
252-
if (hostUrl != null && !"".equals(hostUrl)) {
253-
return hostUrl;
254-
}
255-
String hostName = System.getProperty("dataverse.fqdn");
256-
if (hostName == null) {
257-
try {
258-
hostName = InetAddress.getLocalHost().getCanonicalHostName();
259-
} catch (UnknownHostException e) {
260-
return null;
261-
}
262-
}
263-
hostUrl = "https://" + hostName;
264-
return hostUrl;
249+
return SystemConfig.getDataverseSiteUrlStatic();
265250
}
266251

267252
private byte[] readKey(final String file) {

src/main/java/edu/harvard/iq/dataverse/api/Info.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package edu.harvard.iq.dataverse.api;
22

3+
import edu.harvard.iq.dataverse.settings.JvmSettings;
34
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
45
import edu.harvard.iq.dataverse.util.SystemConfig;
56
import javax.ejb.EJB;
@@ -44,7 +45,7 @@ public Response getInfo() {
4445
@GET
4546
@Path("server")
4647
public Response getServer() {
47-
return response( req -> ok(systemConfig.getDataverseServer()));
48+
return response( req -> ok(JvmSettings.FQDN.lookup()));
4849
}
4950

5051
@GET

src/main/java/edu/harvard/iq/dataverse/export/ddi/DdiExportUtil.java

Lines changed: 4 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,15 @@
3232
import edu.harvard.iq.dataverse.export.DDIExporter;
3333
import edu.harvard.iq.dataverse.settings.SettingsServiceBean;
3434

35-
import static edu.harvard.iq.dataverse.util.SystemConfig.FQDN;
36-
import static edu.harvard.iq.dataverse.util.SystemConfig.SITE_URL;
3735

3836
import edu.harvard.iq.dataverse.util.BundleUtil;
3937
import edu.harvard.iq.dataverse.util.FileUtil;
38+
import edu.harvard.iq.dataverse.util.SystemConfig;
4039
import edu.harvard.iq.dataverse.util.json.JsonUtil;
4140
import edu.harvard.iq.dataverse.util.xml.XmlPrinter;
4241
import java.io.ByteArrayOutputStream;
4342
import java.io.IOException;
4443
import java.io.OutputStream;
45-
import java.net.InetAddress;
46-
import java.net.UnknownHostException;
4744
import java.nio.file.Files;
4845
import java.nio.file.Path;
4946
import java.nio.file.Paths;
@@ -1292,7 +1289,7 @@ private static void writeNotesElement(XMLStreamWriter xmlw, DatasetVersionDTO da
12921289
// harvesting *all* files are encoded as otherMats; even tabular ones.
12931290
private static void createOtherMats(XMLStreamWriter xmlw, List<FileDTO> fileDtos) throws XMLStreamException {
12941291
// The preferred URL for this dataverse, for cooking up the file access API links:
1295-
String dataverseUrl = getDataverseSiteUrl();
1292+
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();
12961293

12971294
for (FileDTO fileDTo : fileDtos) {
12981295
// We'll continue using the scheme we've used before, in DVN2-3: non-tabular files are put into otherMat,
@@ -1339,7 +1336,7 @@ private static void createOtherMats(XMLStreamWriter xmlw, List<FileDTO> fileDtos
13391336

13401337
private static void createOtherMatsFromFileMetadatas(XMLStreamWriter xmlw, List<FileMetadata> fileMetadatas) throws XMLStreamException {
13411338
// The preferred URL for this dataverse, for cooking up the file access API links:
1342-
String dataverseUrl = getDataverseSiteUrl();
1339+
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();
13431340

13441341
for (FileMetadata fileMetadata : fileMetadatas) {
13451342
// We'll continue using the scheme we've used before, in DVN2-3: non-tabular files are put into otherMat,
@@ -1555,33 +1552,6 @@ private static void saveJsonToDisk(String datasetVersionAsJson) throws IOExcepti
15551552
Files.write(Paths.get("/tmp/out.json"), datasetVersionAsJson.getBytes());
15561553
}
15571554

1558-
/**
1559-
* The "official", designated URL of the site;
1560-
* can be defined as a complete URL; or derived from the
1561-
* "official" hostname. If none of these options is set,
1562-
* defaults to the InetAddress.getLocalHOst() and https;
1563-
*/
1564-
private static String getDataverseSiteUrl() {
1565-
String hostUrl = System.getProperty(SITE_URL);
1566-
if (hostUrl != null && !"".equals(hostUrl)) {
1567-
return hostUrl;
1568-
}
1569-
String hostName = System.getProperty(FQDN);
1570-
if (hostName == null) {
1571-
try {
1572-
hostName = InetAddress.getLocalHost().getCanonicalHostName();
1573-
} catch (UnknownHostException e) {
1574-
hostName = null;
1575-
}
1576-
}
1577-
1578-
if (hostName != null) {
1579-
return "https://" + hostName;
1580-
}
1581-
1582-
return "http://localhost:8080";
1583-
}
1584-
15851555

15861556

15871557

@@ -1893,7 +1863,7 @@ private static void createVarDDI(XMLStreamWriter xmlw, DataVariable dv, FileMeta
18931863
}
18941864

18951865
private static void createFileDscr(XMLStreamWriter xmlw, DatasetVersion datasetVersion) throws XMLStreamException {
1896-
String dataverseUrl = getDataverseSiteUrl();
1866+
String dataverseUrl = SystemConfig.getDataverseSiteUrlStatic();
18971867
for (FileMetadata fileMetadata : datasetVersion.getFileMetadatas()) {
18981868
DataFile dataFile = fileMetadata.getDataFile();
18991869

src/main/java/edu/harvard/iq/dataverse/harvest/server/web/servlet/OAIServlet.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ public void init(ServletConfig config) throws ServletException {
123123
}
124124

125125
setRepository = new DataverseXoaiSetRepository(setService);
126-
itemRepository = new DataverseXoaiItemRepository(recordService, datasetService, systemConfig.getDataverseSiteUrl());
126+
itemRepository = new DataverseXoaiItemRepository(recordService, datasetService, SystemConfig.getDataverseSiteUrlStatic());
127127

128128
repositoryConfiguration = createRepositoryConfiguration();
129129

src/main/java/edu/harvard/iq/dataverse/settings/JvmSettings.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,8 @@ public enum JvmSettings {
4141
// GENERAL SETTINGS
4242
VERSION(PREFIX, "version"),
4343
BUILD(PREFIX, "build"),
44+
FQDN(PREFIX, "fqdn"),
45+
SITE_URL(PREFIX, "siteUrl"),
4446

4547
// API SETTINGS
4648
SCOPE_API(PREFIX, "api"),

0 commit comments

Comments
 (0)