Skip to content

Commit

Permalink
MIR-1242 make MIR compatible with Java 21 (#902)
Browse files Browse the repository at this point in the history
Fixed URL and dependency.

---------

Co-authored-by: Antoniafriedrich <[email protected]>
  • Loading branch information
yagee-de and Antoniafriedrich authored Oct 10, 2023
1 parent 9d73393 commit 5409514
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
package org.mycore.mir.orcid;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
Expand Down Expand Up @@ -55,10 +56,10 @@ public class MIROrcidServlet extends MCRServlet {
private static final String SEARCH_ORCID_XPATH = "/search:search/search:result/common:orcid-identifier/common:path";

private static List<MIROrcidPersonEntry> getPersonList(String query)
throws MalformedURLException, UnsupportedEncodingException {
String encodedQuery = URLEncoder.encode(query, "UTF-8");
throws MalformedURLException, URISyntaxException {
String encodedQuery = URLEncoder.encode(query, StandardCharsets.UTF_8);

URL url = new URL(ORCID_REQUEST_BASE + "search/?q=" + encodedQuery + "&rows=" + ORCID_FETCH_SIZE * 2);
URL url = new URI(ORCID_REQUEST_BASE + "search/?q=" + encodedQuery + "&rows=" + ORCID_FETCH_SIZE * 2).toURL();

try {
Document document = new SAXBuilder().build(url);
Expand Down Expand Up @@ -88,7 +89,7 @@ private static List<String> getOrcidsFromDocument(Document document) {

private static MIROrcidPersonEntry getEntry(String orcid) {
try {
URL url = new URL(ORCID_REQUEST_BASE + orcid + "/personal-details");
URL url = new URI(ORCID_REQUEST_BASE + orcid + "/personal-details").toURL();
Document document = new SAXBuilder().build(url);
Element element = document.getRootElement();

Expand All @@ -105,7 +106,7 @@ private static MIROrcidPersonEntry getEntry(String orcid) {
}

return new MIROrcidPersonEntry(givenName.getTextTrim(), familyName.getTextTrim(), ORCID_URL + orcid);
} catch (JDOMException | IOException e) {
} catch (JDOMException | IOException | URISyntaxException e) {
throw new MCRException(e);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.Optional;

Expand Down Expand Up @@ -64,17 +66,15 @@ public Response retrieve(@PathParam("type") String type, @QueryParam("filter") S
urlStr+="&filter="+filter;
}
try {
URL url = new URL(urlStr);
try(InputStream is = url.openStream()){
try(ByteArrayOutputStream bos = new ByteArrayOutputStream()){
is.transferTo(bos);
return Response.ok(bos.toByteArray()).build();
}
URL url = new URI(urlStr).toURL();
try (InputStream is = url.openStream(); ByteArrayOutputStream bos = new ByteArrayOutputStream()) {
is.transferTo(bos);
return Response.ok(bos.toByteArray()).build();
} catch (IOException e) {
LOGGER.error("Error while performing request!", e);
return Response.serverError().build();
}
} catch (MalformedURLException e) {
} catch (MalformedURLException | URISyntaxException e) {
LOGGER.error("Error while building URL " + urlStr, e);
return Response.serverError().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;

import org.apache.logging.log4j.LogManager;
Expand Down Expand Up @@ -30,16 +32,16 @@ public static String validateSDNB(String sdnb) {
public static boolean validatePPN(String ppn) {
String database = MCRConfiguration2.getString("MIR.PPN.DatabaseList").orElse("gvk");
try {
URL url = new URL("http://uri.gbv.de/document/" + database + ":ppn:" + ppn);
URL url = new URI("http://uri.gbv.de/document/" + database + ":ppn:" + ppn).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();
int resCode = connection.getResponseCode();
if (resCode == 200 || resCode == 302) {
return true;
}
} catch (IOException e) {
LogManager.getLogger().error("IOException while validating PPN.", e);
} catch (IOException | URISyntaxException e) {
LogManager.getLogger().error("Exception while validating PPN.", e);
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -338,7 +338,7 @@
<xsl:param name="label"/>

<xsl:variable name="hitsSortList" xmlns:encoder="xalan://java.net.URLEncoder"
select="document(concat('solr:q=',encoder:encode($query), '&amp;rows=1000&amp;sort=mods.part.order.', $objectID, ' desc,mods.dateIssued desc, mods.dateIssued.host desc,', $modsPart, ' desc, mods.title.main desc&amp;group=true&amp;group.limit=1000&amp;group.field=mods.yearIssued'))/response/lst[@name='grouped']/lst[@name='mods.yearIssued']" />
select="document(concat('solr:q=',encoder:encode($query), '&amp;rows=1000&amp;sort=mods.part.order.', $objectID, '%20desc,mods.dateIssued%20desc,%20mods.dateIssued.host%20desc,', $modsPart, '%20desc,%20mods.title.main%20desc&amp;group=true&amp;group.limit=1000&amp;group.field=mods.yearIssued'))/response/lst[@name='grouped']/lst[@name='mods.yearIssued']" />
<xsl:if test="$hitsSortList/int[@name='matches'] &gt; 0">
<xsl:call-template name="listRelatedItems">
<xsl:with-param name="hits" select="$hitsSortList"/>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
package org.mycore.mir.wizard.command;

import java.io.File;
import java.net.URL;
import java.net.URI;

import org.apache.commons.io.FileUtils;
import org.apache.commons.io.FilenameUtils;
Expand Down Expand Up @@ -63,7 +63,7 @@ public void doExecute() {
File file = new File(libDir + File.separator + fname);
try {

FileUtils.copyURLToFile(new URL(url), file);
FileUtils.copyURLToFile(new URI(url).toURL(), file);
MCRConfigurationDirSetup.loadExternalLibs();

success = true;
Expand Down
6 changes: 0 additions & 6 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -334,12 +334,6 @@
<version>${tomcat.version}</version>
<type>tar.gz</type>
</artifactInstaller>
<dependencies>
<dependency>
<groupId>com.sun.activation</groupId>
<artifactId>jakarta.activation</artifactId>
</dependency>
</dependencies>
</container>
<configuration>
<home>${project.build.directory}/catalina-base</home>
Expand Down

0 comments on commit 5409514

Please sign in to comment.