From 4e682c0208f6a5d5475d406c474f426f62474030 Mon Sep 17 00:00:00 2001 From: "elena.parovyshnaya" Date: Wed, 1 Jul 2020 10:55:20 +0300 Subject: [PATCH] Bug 564420 conditions | move HC condition miner to new interfaces - two cents to documenting new solution - deprecate `HcConditionMinder` Signed-off-by: elena.parovyshnaya --- .../passage/lic/internal/hc/HcConditionMiner.java | 5 +++++ .../lic/internal/hc/remote/impl/HttpClient.java | 4 ++-- .../impl/HttpUrlConnectionConfiguration.java | 2 +- .../hc/remote/impl/RemoteConditionsRequest.java | 15 ++++++++++++--- 4 files changed, 20 insertions(+), 6 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/HcConditionMiner.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/HcConditionMiner.java index 02deab34d..3a6a7dedd 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/HcConditionMiner.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/HcConditionMiner.java @@ -43,9 +43,14 @@ import org.eclipse.passage.lic.base.conditions.BaseConditionMiner; import org.eclipse.passage.lic.equinox.io.EquinoxPaths; import org.eclipse.passage.lic.hc.HttpRequests; +import org.eclipse.passage.lic.internal.hc.remote.impl.RemoteConditions; import org.eclipse.passage.lic.net.LicensingNet; import org.osgi.service.component.annotations.Component; +/** + * @deprecated use {@link RemoteConditions} service instead + */ +@Deprecated @Component(service = ConditionMiner.class) public class HcConditionMiner extends BaseConditionMiner { diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java index 0bf132a1d..1ffe4e839 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpClient.java @@ -54,8 +54,8 @@ private Collection netConditions(HttpURLConnection connection, Respon private Collection read(HttpURLConnection connection, ResponseHandler miner) throws Exception { byte[] content = new byte[connection.getContentLength()]; try (InputStream source = connection.getInputStream()) { - source.read(content); - } // connection is closed here + source.read(content); // read all and close the connection briefly + } return miner.read(content, connection.getHeaderField("Content-Type")); //$NON-NLS-1$ } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpUrlConnectionConfiguration.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpUrlConnectionConfiguration.java index 444ecb2ff..dd3df6925 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpUrlConnectionConfiguration.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/HttpUrlConnectionConfiguration.java @@ -25,7 +25,7 @@ final class HttpUrlConnectionConfiguration implements Configuration properties; public HttpUrlConnectionConfiguration(int timeout, Map properties) { - Objects.requireNonNull(properties, "HttpUrlConnectionConfiguration::proeprties"); //$NON-NLS-1$ + Objects.requireNonNull(properties, "HttpUrlConnectionConfiguration::properties"); //$NON-NLS-1$ this.timeout = timeout; this.properties = properties; } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java index 0d0bf8e8e..76cdc31f4 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditionsRequest.java @@ -42,6 +42,15 @@ import org.eclipse.passage.lic.internal.net.LicensingServerCoordinates.HostPort; /** + *

+ * Supplies all the data we are to tell a licensing server on mining request. + *

+ *
    + * use + *
  • {@code url()}
  • to compose server coordinates and all the request + * parameters + *
  • {@code config()} to gain a proper request headers configuring unit
  • + *
*/ @SuppressWarnings("restriction") public final class RemoteConditionsRequest implements Request { @@ -65,7 +74,7 @@ public URL url() throws ConditionMiningException { return new URL("http", //$NON-NLS-1$ corrdinates.host(), // Integer.parseInt(corrdinates.port()), // - '?' + parameters()); + query()); } catch (LicensingException // | NumberFormatException // | MalformedURLException // @@ -74,7 +83,7 @@ public URL url() throws ConditionMiningException { } } - private String parameters() throws UnsupportedEncodingException { + private String query() throws UnsupportedEncodingException { StringBuilder params = new StringBuilder(); Arrays.stream(// new NamedData[] { // @@ -86,7 +95,7 @@ private String parameters() throws UnsupportedEncodingException { new TemporaryUser("12345678") }) //$NON-NLS-1$ FIXME: for development: #564815 .map(NamedData.Writable::new)// .forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$ - return params.toString(); + return '?' + params.toString(); }