Skip to content

Commit

Permalink
Merge pull request #274 from eclipse-passage/564420-2
Browse files Browse the repository at this point in the history
Bug 564420 conditions | move HC condition miner to new interfaces
  • Loading branch information
eparovyshnaya authored Jul 1, 2020
2 parents fee538a + 4e682c0 commit 4ebd01a
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,8 @@ private Collection<Condition> netConditions(HttpURLConnection connection, Respon
private Collection<Condition> 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$
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ final class HttpUrlConnectionConfiguration implements Configuration<HttpURLConne
private final Map<String, String> properties;

public HttpUrlConnectionConfiguration(int timeout, Map<String, String> properties) {
Objects.requireNonNull(properties, "HttpUrlConnectionConfiguration::proeprties"); //$NON-NLS-1$
Objects.requireNonNull(properties, "HttpUrlConnectionConfiguration::properties"); //$NON-NLS-1$
this.timeout = timeout;
this.properties = properties;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,15 @@
import org.eclipse.passage.lic.internal.net.LicensingServerCoordinates.HostPort;

/**
* <p>
* Supplies all the data we are to tell a licensing server on mining request.
* </p>
* <ul>
* use
* <li>{@code url()}</li> to compose server coordinates and all the request
* parameters
* <li>{@code config()} to gain a proper request headers configuring unit</li>
* </ul>
*/
@SuppressWarnings("restriction")
public final class RemoteConditionsRequest implements Request<HttpURLConnection> {
Expand All @@ -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 //
Expand All @@ -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[] { //
Expand All @@ -86,7 +95,7 @@ private String parameters() throws UnsupportedEncodingException {
new TemporaryUser("12345678") }) //$NON-NLS-1$ FIXME: for development: #564815
.map(NamedData.Writable<String>::new)//
.forEach(writable -> writable.write(params, "=", "&")); //$NON-NLS-1$ //$NON-NLS-2$
return params.toString();
return '?' + params.toString();

}

Expand Down

0 comments on commit 4ebd01a

Please sign in to comment.