From 1529b2319f4da8571a55384ebba6c5aa62d9f87a Mon Sep 17 00:00:00 2001 From: eparovyshnaya Date: Mon, 9 Nov 2020 14:49:22 +0300 Subject: [PATCH] Bug 568632 Implement feature grant acquire/release Abstract HttpClient from condition mining specific. To be used for other kinds of requests (grant acquisition and release) Signed-off-by: eparovyshnaya --- .../lic/internal/hc/remote/Client.java | 7 ++----- .../internal/hc/remote/ResponseHandler.java | 7 ++----- .../hc/remote/impl/DecryptedConditions.java | 2 +- .../internal/hc/remote/impl/HttpClient.java | 19 +++++++------------ .../hc/remote/impl/RemoteConditions.java | 2 +- 5 files changed, 13 insertions(+), 24 deletions(-) diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/Client.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/Client.java index 9a67f567c..94c449a53 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/Client.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/Client.java @@ -12,13 +12,10 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.hc.remote; -import java.util.Collection; - import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; -import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; -public interface Client { +public interface Client { - ServiceInvocationResult> remoteConditions(Request request, ResponseHandler miner); + ServiceInvocationResult request(Request request, ResponseHandler handler); } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/ResponseHandler.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/ResponseHandler.java index bf8e455d7..4154664b2 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/ResponseHandler.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/ResponseHandler.java @@ -12,13 +12,10 @@ *******************************************************************************/ package org.eclipse.passage.lic.internal.hc.remote; -import java.util.Collection; - import org.eclipse.passage.lic.internal.api.LicensingException; -import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; -public interface ResponseHandler { +public interface ResponseHandler { - Collection read(byte[] raw, String contentType) throws LicensingException; + T read(byte[] raw, String contentType) throws LicensingException; } diff --git a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java index ff6e2215d..c1177f428 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/DecryptedConditions.java @@ -27,7 +27,7 @@ import org.eclipse.passage.lic.internal.hc.i18n.HcMessages; import org.eclipse.passage.lic.internal.hc.remote.ResponseHandler; -final class DecryptedConditions implements ResponseHandler { +final class DecryptedConditions implements ResponseHandler> { private final ConditionTransportRegistry transports; private final FloatingServerConnection coordinates; 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 0c593fd06..478b159b7 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 @@ -14,11 +14,9 @@ import java.io.InputStream; import java.net.HttpURLConnection; -import java.util.Collection; import java.util.Collections; import org.eclipse.passage.lic.internal.api.ServiceInvocationResult; -import org.eclipse.passage.lic.internal.api.conditions.ConditionPack; import org.eclipse.passage.lic.internal.api.diagnostic.Trouble; import org.eclipse.passage.lic.internal.base.BaseServiceInvocationResult; import org.eclipse.passage.lic.internal.base.diagnostic.BaseDiagnostic; @@ -28,14 +26,12 @@ import org.eclipse.passage.lic.internal.hc.remote.Request; import org.eclipse.passage.lic.internal.hc.remote.ResponseHandler; -public final class HttpClient implements Client { +public final class HttpClient implements Client { @Override - public ServiceInvocationResult> remoteConditions(Request request, - ResponseHandler miner) { + public ServiceInvocationResult request(Request request, ResponseHandler handler) { try { - return new BaseServiceInvocationResult>( - netConditions(connection(request), miner)); + return new BaseServiceInvocationResult(netResults(connection(request), handler)); } catch (Exception e) { return new BaseServiceInvocationResult<>(// new BaseDiagnostic(// @@ -50,8 +46,7 @@ private HttpURLConnection connection(Request request) throws return request.config().apply((HttpURLConnection) request.url().openConnection()); } - private Collection netConditions(HttpURLConnection connection, ResponseHandler miner) - throws Exception { + private T netResults(HttpURLConnection connection, ResponseHandler handler) throws Exception { // actual connection is happening on the first 'get' (get response code) if (connection.getResponseCode() != HttpURLConnection.HTTP_OK) { connection.getInputStream().close(); // close the connection @@ -59,15 +54,15 @@ private Collection netConditions(HttpURLConnection connection, Re connection.getResponseCode(), // connection.getResponseMessage())); } - return read(connection, miner); + return read(connection, handler); } - private Collection read(HttpURLConnection connection, ResponseHandler miner) throws Exception { + private T read(HttpURLConnection connection, ResponseHandler handler) throws Exception { byte[] content = new byte[connection.getContentLength()]; try (InputStream source = connection.getInputStream()) { source.read(content); // read all and close the connection briefly } - return miner.read(content, connection.getHeaderField("Content-Type")); //$NON-NLS-1$ + return handler.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/RemoteConditions.java b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java index f8f961013..96857602e 100644 --- a/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java +++ b/bundles/org.eclipse.passage.lic.hc/src/org/eclipse/passage/lic/internal/hc/remote/impl/RemoteConditions.java @@ -78,7 +78,7 @@ public ServiceInvocationResult> all(LicensedProduct pr private ServiceInvocationResult> conditions(LicensedProduct product, FloatingLicenseAccess access) { - return new HttpClient().remoteConditions(// + return new HttpClient>().request(// new RemoteConditionsRequest(product, access), // new DecryptedConditions(transports, access.getServer())); }