Skip to content

Commit

Permalink
Update to Eclipse 2022-03 + dependent libraries
Browse files Browse the repository at this point in the history
  • Loading branch information
buchen committed Apr 23, 2022
1 parent 1a87ac1 commit 9f695b3
Show file tree
Hide file tree
Showing 10 changed files with 131 additions and 196 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
import org.jsoup.Jsoup;
import org.jsoup.safety.Whitelist;
import org.jsoup.safety.Safelist;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand Down Expand Up @@ -130,7 +130,7 @@ protected void createButtonsForButtonBar(Composite parent)
if (rawText.isDisposed())
return;

rawText.setText(Jsoup.clean(rawText.getText(), Whitelist.relaxed()));
rawText.setText(Jsoup.clean(rawText.getText(), Safelist.relaxed()));
}));

}
Expand Down
6 changes: 3 additions & 3 deletions name.abuchen.portfolio/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -63,10 +63,10 @@ Import-Package: com.google.common.base,
Bundle-ClassPath: .
Bundle-Vendor: %Bundle-Vendor
Require-Bundle: org.eclipse.core.runtime,
org.apache.httpcomponents.httpclient,
org.apache.httpcomponents.httpcore,
org.apache.httpcomponents.client5.httpclient5,
org.apache.httpcomponents.core5.httpcore5,
org.apache.pdfbox,
com.jayway.jsonpath.json-path,
json-path,
com.google.gson
Automatic-Module-Name: name.abuchen.portfolio
Eclipse-ExtensibleAPI: true
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.jsoup.UncheckedIOException;
import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element;
import org.jsoup.safety.Whitelist;
import org.jsoup.safety.Safelist;
import org.jsoup.select.Elements;

import name.abuchen.portfolio.Messages;
Expand Down Expand Up @@ -549,7 +549,7 @@ private List<LatestSecurityPrice> parse(String url, Document document, QuoteFeed
if (prices.isEmpty())
{
data.addError(new IOException(MessageFormat.format(Messages.MsgNoQuotesFoundInHTML, url,
Jsoup.clean(document.html(), Whitelist.relaxed()))));
Jsoup.clean(document.html(), Safelist.relaxed()))));
return Collections.emptyList();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,23 @@
import java.util.ArrayList;
import java.util.List;

import org.apache.http.Header;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpStatus;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.entity.ContentType;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpDelete;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpPut;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.ContentType;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpEntity;
import org.apache.hc.core5.http.HttpHeaders;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicHeader;
import org.osgi.framework.FrameworkUtil;

import com.google.gson.Gson;
Expand All @@ -33,10 +35,11 @@
import com.google.gson.reflect.TypeToken;
import com.google.gson.stream.JsonReader;
import com.google.gson.stream.JsonWriter;

import name.abuchen.portfolio.online.impl.PortfolioReportNet;
import name.abuchen.portfolio.util.WebAccess;

@SuppressWarnings("nls")
@SuppressWarnings({ "nls", "restriction" })
public class PRApiClient
{
private String endpoint;
Expand Down Expand Up @@ -148,10 +151,10 @@ private <T> List<T> list(Class<T> type, String path) throws IOException
HttpGet request = new HttpGet(endpoint + path);
CloseableHttpResponse response = client.execute(request);

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
if (response.getCode() != HttpStatus.SC_OK)
throw asError(request, response, null);

return this.gson.fromJson(EntityUtils.toString(response.getEntity()),
return this.gson.fromJson(toString(response.getEntity()),
TypeToken.getParameterized(List.class, type).getType());
}

Expand All @@ -161,10 +164,10 @@ private <T> T create(Class<T> type, String path, T input) throws IOException
request.setEntity(new StringEntity(this.gson.toJson(input), StandardCharsets.UTF_8));
CloseableHttpResponse response = client.execute(request);

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_CREATED)
throw asError(request, response, EntityUtils.toString(request.getEntity()));
if (response.getCode() != HttpStatus.SC_CREATED)
throw asError(request, response, toString(request.getEntity()));

return this.gson.fromJson(EntityUtils.toString(response.getEntity()), type);
return this.gson.fromJson(toString(response.getEntity()), type);
}

private <T> T update(Class<T> type, String path, T input) throws IOException
Expand All @@ -174,28 +177,39 @@ private <T> T update(Class<T> type, String path, T input) throws IOException

CloseableHttpResponse response = client.execute(request);

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
throw asError(request, response, EntityUtils.toString(request.getEntity()));
if (response.getCode() != HttpStatus.SC_OK)
throw asError(request, response, toString(request.getEntity()));

return this.gson.fromJson(EntityUtils.toString(response.getEntity()), type);
return this.gson.fromJson(toString(response.getEntity()), type);
}

private <T> T deleteEntity(Class<T> type, String path) throws IOException
{
HttpDelete request = new HttpDelete(endpoint + path);
CloseableHttpResponse response = client.execute(request);

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
if (response.getCode() != HttpStatus.SC_OK)
throw asError(request, response, null);

return this.gson.fromJson(EntityUtils.toString(response.getEntity()), type);
return this.gson.fromJson(toString(response.getEntity()), type);
}

private IOException asError(HttpRequestBase request, CloseableHttpResponse response, String requestBody)
private IOException asError(HttpUriRequestBase request, CloseableHttpResponse response, String requestBody)
throws IOException
{
return new IOException(request.toString() + " --> " + response.getStatusLine().getStatusCode() + "\n\n"
+ (requestBody != null ? requestBody + "\n\n" : "")
+ EntityUtils.toString(response.getEntity()));
return new IOException(request.toString() + " --> " + response.getCode() + "\n\n"
+ (requestBody != null ? requestBody + "\n\n" : "") + toString(response.getEntity()));
}

private String toString(HttpEntity httpEntity) throws IOException
{
try
{
return EntityUtils.toString(httpEntity);
}
catch (ParseException e)
{
throw new IOException(e);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@
import java.util.Locale;
import java.util.Objects;

import org.apache.http.Header;
import org.apache.http.HttpStatus;
import org.apache.http.client.config.CookieSpecs;
import org.apache.http.client.config.RequestConfig;
import org.apache.http.client.methods.CloseableHttpResponse;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpRequestBase;
import org.apache.http.client.utils.URIBuilder;
import org.apache.http.entity.StringEntity;
import org.apache.http.impl.EnglishReasonPhraseCatalog;
import org.apache.http.impl.client.CloseableHttpClient;
import org.apache.http.impl.client.HttpClientBuilder;
import org.apache.http.message.BasicHeader;
import org.apache.http.util.EntityUtils;
import org.apache.hc.client5.http.classic.methods.HttpGet;
import org.apache.hc.client5.http.classic.methods.HttpPost;
import org.apache.hc.client5.http.classic.methods.HttpUriRequestBase;
import org.apache.hc.client5.http.config.RequestConfig;
import org.apache.hc.client5.http.cookie.StandardCookieSpec;
import org.apache.hc.client5.http.impl.classic.CloseableHttpClient;
import org.apache.hc.client5.http.impl.classic.CloseableHttpResponse;
import org.apache.hc.client5.http.impl.classic.HttpClientBuilder;
import org.apache.hc.core5.http.Header;
import org.apache.hc.core5.http.HttpStatus;
import org.apache.hc.core5.http.ParseException;
import org.apache.hc.core5.http.impl.EnglishReasonPhraseCatalog;
import org.apache.hc.core5.http.io.entity.EntityUtils;
import org.apache.hc.core5.http.io.entity.StringEntity;
import org.apache.hc.core5.http.message.BasicHeader;
import org.apache.hc.core5.net.URIBuilder;
import org.apache.hc.core5.util.Timeout;

//@formatter:off
/**
Expand Down Expand Up @@ -94,7 +96,7 @@ public class WebAccess
@FunctionalInterface
private interface Request
{
HttpRequestBase create(URI uri) throws IOException;
HttpUriRequestBase create(URI uri) throws IOException;
}

public static class WebAccessException extends IOException
Expand All @@ -114,8 +116,10 @@ public int getHttpErrorCode()
}
}

public static final RequestConfig defaultRequestConfig = RequestConfig.custom().setSocketTimeout(20000)
.setConnectTimeout(2000).setConnectionRequestTimeout(20000).setCookieSpec(CookieSpecs.STANDARD)
public static final RequestConfig defaultRequestConfig = RequestConfig.custom()
.setConnectTimeout(Timeout.ofSeconds(2)) //
.setResponseTimeout(Timeout.ofSeconds(2)) //
.setCookieSpec(StandardCookieSpec.STRICT) //
.build();

private final URIBuilder builder;
Expand Down Expand Up @@ -173,8 +177,15 @@ public WebAccess addUserAgent(String userAgent)

public String get() throws IOException
{
CloseableHttpResponse response = executeWith(HttpGet::new);
return EntityUtils.toString(response.getEntity());
try
{
CloseableHttpResponse response = executeWith(HttpGet::new);
return EntityUtils.toString(response.getEntity());
}
catch (ParseException e)
{
throw new IOException(e);
}
}

public void post(String body) throws IOException
Expand All @@ -201,12 +212,11 @@ private CloseableHttpResponse executeWith(Request function) throws IOException
.build();

URI uri = builder.build();
HttpRequestBase request = function.create(uri);
HttpUriRequestBase request = function.create(uri);
response = client.execute(request);

if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK)
throw new WebAccessException(buildMessage(uri, response.getStatusLine().getStatusCode()),
response.getStatusLine().getStatusCode());
if (response.getCode() != HttpStatus.SC_OK)
throw new WebAccessException(buildMessage(uri, response.getCode()), response.getCode());

return response;
}
Expand Down
4 changes: 2 additions & 2 deletions portfolio-app/eclipse/launches.lc
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ eclipse configuration PortfolioPerformance {
feature org.eclipse.emf.ecore;
feature org.eclipse.emf.common;
feature org.eclipse.equinox.p2.core.feature;
feature org.eclipse.ecf.filetransfer.httpclient45.feature;
feature org.eclipse.ecf.filetransfer.httpclient5.feature;
feature org.eclipse.ecf.core.ssl.feature;
feature org.eclipse.ecf.filetransfer.ssl.feature;
feature org.eclipse.ecf.core.feature;
Expand Down Expand Up @@ -50,7 +50,7 @@ abstract junit-plugin configuration TestBase {
feature org.eclipse.emf.ecore;
feature org.eclipse.emf.common;
feature org.eclipse.equinox.p2.core.feature;
feature org.eclipse.ecf.filetransfer.httpclient45.feature;
feature org.eclipse.ecf.filetransfer.httpclient5.feature;
feature org.eclipse.ecf.core.ssl.feature;
feature org.eclipse.ecf.filetransfer.ssl.feature;
feature org.eclipse.ecf.core.feature;
Expand Down
Loading

0 comments on commit 9f695b3

Please sign in to comment.