diff --git a/build.gradle b/build.gradle index 1b792794bb0..ee78e564bd3 100644 --- a/build.gradle +++ b/build.gradle @@ -159,7 +159,7 @@ dependencies { compile 'org.controlsfx:controlsfx:11.0.0' compile 'org.jsoup:jsoup:1.12.1' - compile 'com.mashape.unirest:unirest-java:1.4.9' + compile 'com.konghq:unirest-java:3.1.03' compile 'org.slf4j:slf4j-api:2.0.0-alpha1' compile group: 'org.apache.logging.log4j', name: 'log4j-jcl', version: '3.0.0-SNAPSHOT' diff --git a/external-libraries.txt b/external-libraries.txt index 385d4d18217..996d126c839 100644 --- a/external-libraries.txt +++ b/external-libraries.txt @@ -50,9 +50,9 @@ Project: pgjdbc-ng URL: http://impossibl.github.io/pgjdbc-ng License: BSD-3-Clause -Id: com.mashape.unirest +Id: com.konghq.unirest Project: Unirest for Java -URL: https://github.com/Mashape/unirest-java +URL: https://github.com/Kong/unirest-java License: MIT Id: com.microsoft.azure:applicationinsights-core diff --git a/src/main/java/module-info.java b/src/main/java/module-info.java index 791e2e50698..327ce26d480 100644 --- a/src/main/java/module-info.java +++ b/src/main/java/module-info.java @@ -55,7 +55,6 @@ requires org.apache.pdfbox; requires reactfx; requires commons.cli; - requires httpclient; requires com.github.tomtung.latex2unicode; requires jbibtex; requires citeproc.java; @@ -65,4 +64,6 @@ requires de.saxsys.mvvmfx.validation; requires richtextfx; requires unirest.java; + requires org.apache.httpcomponents.httpclient; + requires org.jsoup; } diff --git a/src/main/java/org/jabref/Globals.java b/src/main/java/org/jabref/Globals.java index f65daeb27e6..bf5e00d33e7 100644 --- a/src/main/java/org/jabref/Globals.java +++ b/src/main/java/org/jabref/Globals.java @@ -1,7 +1,6 @@ package org.jabref; import java.awt.GraphicsEnvironment; -import java.io.IOException; import java.util.Optional; import java.util.UUID; @@ -26,11 +25,11 @@ import org.jabref.preferences.JabRefPreferences; import com.google.common.base.StandardSystemProperty; -import com.mashape.unirest.http.Unirest; import com.microsoft.applicationinsights.TelemetryClient; import com.microsoft.applicationinsights.TelemetryConfiguration; import com.microsoft.applicationinsights.internal.shutdown.SDKShutdownActivity; import com.microsoft.applicationinsights.telemetry.SessionState; +import kong.unirest.Unirest; public class Globals { @@ -127,9 +126,7 @@ public static void shutdownThreadPools() { public static void stopBackgroundTasks() { stopTelemetryClient(); - try { - Unirest.shutdown(); - } catch (IOException ignore) { } + Unirest.shutDown(); } public static Optional getTelemetryClient() { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java index 70f81f095dd..fcf2750dd79 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/AstrophysicsDataSystem.java @@ -34,10 +34,10 @@ import org.jabref.model.strings.StringUtil; import org.jabref.model.util.DummyFileUpdateMonitor; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; /** * Fetches data from the SAO/NASA Astrophysics Data System (https://ui.adsabs.harvard.edu/) diff --git a/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java b/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java index 50e9da651ac..aca7a6b3397 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java @@ -27,10 +27,10 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.util.OptionalUtil; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; /** * A class for fetching DOIs from CrossRef diff --git a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java index 074c47cff62..96f9d4f4140 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java @@ -23,9 +23,9 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.model.strings.StringUtil; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONArray; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -153,25 +153,6 @@ public static BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry, Character k return entry; } - @Override - public String getName() { - return "DOAJ"; - } - - @Override - public Optional getHelpPage() { - return Optional.of(HelpFile.FETCHER_DOAJ); - } - - @Override - public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException { - URIBuilder uriBuilder = new URIBuilder(SEARCH_URL); - DOAJFetcher.addPath(uriBuilder, query); - uriBuilder.addParameter("pageSize", "30"); // Number of results - //uriBuilder.addParameter("page", "1"); // Page (not needed so far) - return uriBuilder.build().toURL(); - } - /** * @implNote slightly altered version based on https://gist.github.com/enginer/230e2dc2f1d213a825d5 */ @@ -196,6 +177,25 @@ private static String appendSegmentToPath(String path, String segment) { return path + "/" + segment; } + @Override + public String getName() { + return "DOAJ"; + } + + @Override + public Optional getHelpPage() { + return Optional.of(HelpFile.FETCHER_DOAJ); + } + + @Override + public URL getURLForQuery(String query) throws URISyntaxException, MalformedURLException, FetcherException { + URIBuilder uriBuilder = new URIBuilder(SEARCH_URL); + DOAJFetcher.addPath(uriBuilder, query); + uriBuilder.addParameter("pageSize", "30"); // Number of results + //uriBuilder.addParameter("page", "1"); // Page (not needed so far) + return uriBuilder.build().toURL(); + } + @Override public Parser getParser() { return inputStream -> { diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java index 79b03b83d71..0ffd58376ae 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IEEE.java @@ -28,9 +28,9 @@ import org.jabref.model.entry.identifier.DOI; import org.jabref.model.entry.types.StandardEntryType; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONArray; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcher.java index e3f84536f86..068f039c8b6 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/IsbnViaChimboriFetcher.java @@ -13,14 +13,15 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.strings.StringUtil; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; +import kong.unirest.RawResponse; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; /** * Fetcher for ISBN using https://bibtex.chimbori.com/, which in turn uses Amazon's API. */ public class IsbnViaChimboriFetcher extends AbstractIsbnFetcher { + private RawResponse postResponse; public IsbnViaChimboriFetcher(ImportFormatPreferences importFormatPreferences) { super(importFormatPreferences); @@ -47,21 +48,21 @@ public Optional performSearchById(String identifier) throws FetcherExc this.ensureThatIsbnIsValid(identifier); - HttpResponse postResponse; + postResponse = null; try { - postResponse = Unirest.post("https://bibtex.chimbori.com/isbn-bibtex") - .field("isbn", identifier) - .asString(); + Unirest.post("https://bibtex.chimbori.com/isbn-bibtex") + .field("isbn", identifier) + .thenConsume(rawResponse -> postResponse = rawResponse); } catch (UnirestException e) { throw new FetcherException("Could not retrieve data from chimbori.com", e); } if (postResponse.getStatus() != 200) { - throw new FetcherException("Error while retrieving data from chimbori.com: " + postResponse.getBody()); + throw new FetcherException("Error while retrieving data from chimbori.com: " + postResponse.getContentAsString()); } List fetchedEntries; try { - fetchedEntries = getParser().parseEntries(postResponse.getRawBody()); + fetchedEntries = getParser().parseEntries(postResponse.getContent()); } catch (ParseException e) { throw new FetcherException("An internal parser error occurred", e); } diff --git a/src/main/java/org/jabref/logic/importer/fetcher/OpenAccessDoi.java b/src/main/java/org/jabref/logic/importer/fetcher/OpenAccessDoi.java index 64e3ab046e6..7bb7a5125e1 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/OpenAccessDoi.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/OpenAccessDoi.java @@ -11,11 +11,11 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import org.json.JSONObject; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; +import kong.unirest.json.JSONObject; /** * A fulltext fetcher that uses oaDOI. @@ -49,8 +49,8 @@ public TrustLevel getTrustLevel() { public Optional findFullText(DOI doi) throws UnirestException, MalformedURLException { HttpResponse jsonResponse = Unirest.get(API_URL + doi.getDOI() + "?email=developers@jabref.org") - .header("accept", "application/json") - .asJson(); + .header("accept", "application/json") + .asJson(); JSONObject root = jsonResponse.getBody().getObject(); Optional url = Optional.ofNullable(root.optJSONObject("best_oa_location")) .map(location -> location.optString("url")); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java b/src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java index 4b66f6d49e4..56e27018273 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java @@ -11,13 +11,13 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import org.json.JSONArray; -import org.json.JSONException; -import org.json.JSONObject; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; import org.jsoup.Jsoup; import org.jsoup.nodes.Document; import org.jsoup.nodes.Element; @@ -28,7 +28,7 @@ /** * FulltextFetcher implementation that attempts to find a PDF URL at ScienceDirect. * - * @see http://dev.elsevier.com/ + * @see 'https://dev.elsevier.com/' */ public class ScienceDirect implements FulltextFetcher { private static final Logger LOGGER = LoggerFactory.getLogger(ScienceDirect.class); @@ -50,9 +50,9 @@ public Optional findFullText(BibEntry entry) throws IOException { // scrape the web page not as mobile client! if (!sciLink.isEmpty()) { Document html = Jsoup.connect(sciLink) - .userAgent(URLDownload.USER_AGENT) - .referrer("http://www.google.com") - .ignoreHttpErrors(true).get(); + .userAgent(URLDownload.USER_AGENT) + .referrer("http://www.google.com") + .ignoreHttpErrors(true).get(); // Retrieve PDF link from meta data (most recent) Elements metaLinks = html.getElementsByAttributeValue("name", "citation_pdf_url"); @@ -98,9 +98,9 @@ private String getUrlByDoi(String doi) throws UnirestException { try { String request = API_URL + doi; HttpResponse jsonResponse = Unirest.get(request) - .header("X-ELS-APIKey", API_KEY) - .queryString("httpAccept", "application/json") - .asJson(); + .header("X-ELS-APIKey", API_KEY) + .queryString("httpAccept", "application/json") + .asJson(); JSONObject json = jsonResponse.getBody().getObject(); JSONArray links = json.getJSONObject("full-text-retrieval-response").getJSONObject("coredata").getJSONArray("link"); diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java index fd38b2e61b1..8d9221709a0 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerFetcher.java @@ -22,9 +22,9 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.types.StandardEntryType; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONArray; -import org.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java b/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java index 73722330ccd..28f2357efc5 100644 --- a/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java +++ b/src/main/java/org/jabref/logic/importer/fetcher/SpringerLink.java @@ -10,11 +10,11 @@ import org.jabref.model.entry.field.StandardField; import org.jabref.model.entry.identifier.DOI; -import com.mashape.unirest.http.HttpResponse; -import com.mashape.unirest.http.JsonNode; -import com.mashape.unirest.http.Unirest; -import com.mashape.unirest.http.exceptions.UnirestException; -import org.json.JSONObject; +import kong.unirest.HttpResponse; +import kong.unirest.JsonNode; +import kong.unirest.Unirest; +import kong.unirest.UnirestException; +import kong.unirest.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -42,9 +42,9 @@ public Optional findFullText(BibEntry entry) throws IOException { // Available in catalog? try { HttpResponse jsonResponse = Unirest.get(API_URL) - .queryString("api_key", API_KEY) - .queryString("q", String.format("doi:%s", doi.get().getDOI())) - .asJson(); + .queryString("api_key", API_KEY) + .queryString("q", String.format("doi:%s", doi.get().getDOI())) + .asJson(); JSONObject json = jsonResponse.getBody().getObject(); int results = json.getJSONArray("result").getJSONObject(0).getInt("total"); diff --git a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java index 659ee8da831..37c7676307b 100644 --- a/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java +++ b/src/main/java/org/jabref/logic/importer/fileformat/MrDLibImporter.java @@ -17,8 +17,8 @@ import org.jabref.model.entry.BibEntry; import org.jabref.model.entry.field.StandardField; -import org.json.JSONException; -import org.json.JSONObject; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/java/org/jabref/logic/importer/util/JsonReader.java b/src/main/java/org/jabref/logic/importer/util/JsonReader.java index ea46bb7f756..7bfd02986b1 100644 --- a/src/main/java/org/jabref/logic/importer/util/JsonReader.java +++ b/src/main/java/org/jabref/logic/importer/util/JsonReader.java @@ -8,7 +8,7 @@ import org.jabref.logic.importer.ParseException; -import org.json.JSONObject; +import kong.unirest.json.JSONObject; /** * Converts an {@link InputStream} into a {@link JSONObject}. diff --git a/src/main/java/org/jabref/logic/importer/util/ShortDOIService.java b/src/main/java/org/jabref/logic/importer/util/ShortDOIService.java index bbb3dc7b4c6..a74745f0021 100644 --- a/src/main/java/org/jabref/logic/importer/util/ShortDOIService.java +++ b/src/main/java/org/jabref/logic/importer/util/ShortDOIService.java @@ -10,14 +10,14 @@ import org.jabref.logic.net.URLDownload; import org.jabref.model.entry.identifier.DOI; +import kong.unirest.json.JSONException; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONException; -import org.json.JSONObject; /** * Class for obtaining shortened DOI names. * - * @see http://shortdoi.org + * @see 'https://shortdoi.org' */ public class ShortDOIService { diff --git a/src/main/java/org/jabref/logic/net/URLDownload.java b/src/main/java/org/jabref/logic/net/URLDownload.java index 0eb2508cf13..34fc9537f51 100644 --- a/src/main/java/org/jabref/logic/net/URLDownload.java +++ b/src/main/java/org/jabref/logic/net/URLDownload.java @@ -41,7 +41,7 @@ import org.jabref.logic.util.io.FileUtil; import org.jabref.model.util.FileHelper; -import com.mashape.unirest.http.Unirest; +import kong.unirest.Unirest; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -131,7 +131,7 @@ public URL getSource() { } public String getMimeType() { - Unirest.setDefaultHeader("User-Agent", "Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); + Unirest.config().setDefaultHeader("User-Agent", "Mozilla/5.0 (Windows; U; WindowsNT 5.1; en-US; rv1.8.1.6) Gecko/20070725 Firefox/2.0.0.6"); String contentType; // Try to use HEAD request to avoid downloading the whole file diff --git a/src/main/java/org/jabref/logic/util/Version.java b/src/main/java/org/jabref/logic/util/Version.java index e288c718064..0775fd6a0fb 100644 --- a/src/main/java/org/jabref/logic/util/Version.java +++ b/src/main/java/org/jabref/logic/util/Version.java @@ -12,8 +12,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; -import org.json.JSONArray; -import org.json.JSONObject; +import kong.unirest.json.JSONArray; +import kong.unirest.json.JSONObject; import org.slf4j.Logger; import org.slf4j.LoggerFactory; diff --git a/src/main/resources/csl-styles b/src/main/resources/csl-styles index c11d9747ac2..c3fd4bdeadb 160000 --- a/src/main/resources/csl-styles +++ b/src/main/resources/csl-styles @@ -1 +1 @@ -Subproject commit c11d9747ac24fc675ce220fffe8004c8b9de2a70 +Subproject commit c3fd4bdeadbfc4a713284ad15cca64c8198a7dc7 diff --git a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java index a5c81f98570..68ea36fafa0 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/DOAJFetcherTest.java @@ -10,8 +10,8 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.testutils.category.FetcherTest; +import kong.unirest.json.JSONObject; import org.apache.http.client.utils.URIBuilder; -import org.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java index 063b561a4cf..c4db21ec256 100644 --- a/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java +++ b/src/test/java/org/jabref/logic/importer/fetcher/SpringerFetcherTest.java @@ -9,7 +9,7 @@ import org.jabref.model.entry.types.StandardEntryType; import org.jabref.testutils.category.FetcherTest; -import org.json.JSONObject; +import kong.unirest.json.JSONObject; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test;