Skip to content

Commit

Permalink
Merge pull request #5511 from JoHaHu/fixjson
Browse files Browse the repository at this point in the history
Updates unirest and removes org.json dependency
  • Loading branch information
Siedlerchr committed Oct 28, 2019
2 parents 8fe9593 + ae9680c commit 6c48883
Show file tree
Hide file tree
Showing 21 changed files with 90 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
4 changes: 2 additions & 2 deletions external-libraries.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/module-info.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -65,4 +64,6 @@
requires de.saxsys.mvvmfx.validation;
requires richtextfx;
requires unirest.java;
requires org.apache.httpcomponents.httpclient;
requires org.jsoup;
}
7 changes: 2 additions & 5 deletions src/main/java/org/jabref/Globals.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.jabref;

import java.awt.GraphicsEnvironment;
import java.io.IOException;
import java.util.Optional;
import java.util.UUID;

Expand All @@ -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 {

Expand Down Expand Up @@ -127,9 +126,7 @@ public static void shutdownThreadPools() {

public static void stopBackgroundTasks() {
stopTelemetryClient();
try {
Unirest.shutdown();
} catch (IOException ignore) { }
Unirest.shutDown();
}

public static Optional<TelemetryClient> getTelemetryClient() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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/)
Expand Down
6 changes: 3 additions & 3 deletions src/main/java/org/jabref/logic/importer/fetcher/CrossRef.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
42 changes: 21 additions & 21 deletions src/main/java/org/jabref/logic/importer/fetcher/DOAJFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -153,25 +153,6 @@ public static BibEntry parseBibJSONtoBibtex(JSONObject bibJsonEntry, Character k
return entry;
}

@Override
public String getName() {
return "DOAJ";
}

@Override
public Optional<HelpFile> 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
*/
Expand All @@ -196,6 +177,25 @@ private static String appendSegmentToPath(String path, String segment) {
return path + "/" + segment;
}

@Override
public String getName() {
return "DOAJ";
}

@Override
public Optional<HelpFile> 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 -> {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/jabref/logic/importer/fetcher/IEEE.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -47,21 +48,21 @@ public Optional<BibEntry> performSearchById(String identifier) throws FetcherExc

this.ensureThatIsbnIsValid(identifier);

HttpResponse<String> 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<BibEntry> fetchedEntries;
try {
fetchedEntries = getParser().parseEntries(postResponse.getRawBody());
fetchedEntries = getParser().parseEntries(postResponse.getContent());
} catch (ParseException e) {
throw new FetcherException("An internal parser error occurred", e);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 <a href="https://oadoi.org/">oaDOI</a>.
Expand Down Expand Up @@ -49,8 +49,8 @@ public TrustLevel getTrustLevel() {

public Optional<URL> findFullText(DOI doi) throws UnirestException, MalformedURLException {
HttpResponse<JsonNode> 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<String> url = Optional.ofNullable(root.optJSONObject("best_oa_location"))
.map(location -> location.optString("url"));
Expand Down
28 changes: 14 additions & 14 deletions src/main/java/org/jabref/logic/importer/fetcher/ScienceDirect.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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);
Expand All @@ -50,9 +50,9 @@ public Optional<URL> 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");
Expand Down Expand Up @@ -98,9 +98,9 @@ private String getUrlByDoi(String doi) throws UnirestException {
try {
String request = API_URL + doi;
HttpResponse<JsonNode> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -42,9 +42,9 @@ public Optional<URL> findFullText(BibEntry entry) throws IOException {
// Available in catalog?
try {
HttpResponse<JsonNode> 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");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Loading

0 comments on commit 6c48883

Please sign in to comment.