diff --git a/clientlibs/java/pom.xml b/clientlibs/java/pom.xml index 4b5fe8f39b..74af6021b2 100644 --- a/clientlibs/java/pom.xml +++ b/clientlibs/java/pom.xml @@ -9,9 +9,9 @@ at the same time that happen to rev to the same new version will be caught by a merge conflict. --> - + - 4.1.0 + 4.1.1 @@ -50,7 +50,11 @@ jersey-media-json-jackson 2.30.1 - + + org.glassfish.jersey.connectors + jersey-apache-connector + 2.30.1 + org.glassfish.jersey.inject jersey-hk2 diff --git a/clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java b/clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java index 1bda54fda0..1203dc2706 100644 --- a/clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java +++ b/clientlibs/java/src/main/java/org/upgradeplatform/client/Main.java @@ -11,110 +11,101 @@ import org.eclipse.jdt.annotation.NonNull; import org.upgradeplatform.interfaces.ResponseCallback; -import org.upgradeplatform.requestbeans.MarkExperimentRequestData; -import org.upgradeplatform.responsebeans.UserAliasResponse; import org.upgradeplatform.responsebeans.Condition; import org.upgradeplatform.responsebeans.ErrorResponse; import org.upgradeplatform.responsebeans.ExperimentUser; import org.upgradeplatform.responsebeans.ExperimentsResponse; import org.upgradeplatform.responsebeans.InitializeUser; import org.upgradeplatform.responsebeans.MarkExperimentPoint; +import org.upgradeplatform.responsebeans.UserAliasResponse; import org.upgradeplatform.utils.Utils.MarkedDecisionPointStatus; public class Main { - public static void main(String[] args) throws InterruptedException, ExecutionException - { - final String baseUrl = "http://localhost:3030"; - final String userId = UUID.randomUUID().toString(); - final String site = "SelectSection"; + public static void main(String[] args) throws InterruptedException, ExecutionException + { + final String baseUrl = "https://upgradeapi.qa-cli.net"; + final String userId = UUID.randomUUID().toString(); + final String site = "SelectSection"; - String target = args.length > 0 ? args[0] : "absolute_value_plot_equality"; + String target = args.length > 0 ? args[0] : "volume_surface_area_cone_vol"; - try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){ - CompletableFuture result = new CompletableFuture<>(); + try(ExperimentClient experimentClient = new ExperimentClient(userId, "BearerToken", baseUrl, Collections.emptyMap())){ + CompletableFuture result = new CompletableFuture<>(); System.out.println(prefix() + "initiating requests"); experimentClient.init(new ResponseCallback() { @Override public void onSuccess(@NonNull InitializeUser t){ - System.out.println("init " + t); - List schools = new ArrayList(); + + List schools = new ArrayList<>(); schools.add("school1"); - Map> group = new HashMap>(); + Map> group = new HashMap<>(); group.put("schoolid", schools); System.out.println(prefix() + "setting group membership"); experimentClient.setGroupMembership(group, new ResponseCallback(){ @Override public void onSuccess(@NonNull ExperimentUser expResult){ - System.out.println("group membership " + expResult); - System.out.println("success updating groups"); - } - @Override - public void onError(@NonNull ErrorResponse error){ - System.out.println("error updating groups " + error); - } - }); - - - System.out.println(prefix() + "setting working group"); - Map workingGroup = new HashMap(); - workingGroup.put("schoolId", "school1"); - experimentClient.setWorkingGroup(workingGroup, new ResponseCallback(){ - @Override - public void onSuccess(@NonNull ExperimentUser expResult){ - System.out.println("working group " + expResult); - System.out.println("success updating working groups"); - } - @Override - public void onError(@NonNull ErrorResponse error){ - System.out.println("error updating working groups " + error); - } - }); + System.out.println(prefix() + "success updating groups; setting working group"); - - System.out.println(prefix() + "setting user aliases"); - List altIds = new ArrayList(); - altIds.add(UUID.randomUUID().toString()); - experimentClient.setAltUserIds(altIds, new ResponseCallback(){ - @Override - public void onSuccess(@NonNull UserAliasResponse t) { - System.out.println("aliases " + t); - System.out.println("success updating user aliases"); - } - @Override - public void onError(@NonNull ErrorResponse error){ - System.out.println("error updating user aliases " + error); - } - - }); - - System.out.println(prefix() + "getting conditions"); - experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback(){ - @Override - public void onSuccess(@NonNull ExperimentsResponse expResult){ - System.out.println("condition " + expResult); - Condition condition = expResult.getAssignedCondition(); - String code = condition == null ? null : condition.getConditionCode(); - MarkExperimentRequestData data = new MarkExperimentRequestData(site, target, condition); - experimentClient.markExperimentPoint(MarkedDecisionPointStatus.CONDITION_APPLIED, data, new ResponseCallback(){ + Map workingGroup = new HashMap<>(); + workingGroup.put("schoolId", "school1"); + experimentClient.setWorkingGroup(workingGroup, new ResponseCallback(){ @Override - public void onSuccess(@NonNull MarkExperimentPoint markResult){ - result.complete("marked " + code + ": " + markResult.toString()); + public void onSuccess(@NonNull ExperimentUser expResult){ + System.out.println(prefix() + "success updating working groups; setting user aliases"); + + List altIds = new ArrayList<>(); + altIds.add(UUID.randomUUID().toString()); + experimentClient.setAltUserIds(altIds, new ResponseCallback(){ + @Override + public void onSuccess(@NonNull UserAliasResponse uar) { + System.out.println(prefix() + "success updating user aliases; getting conditions"); + + experimentClient.getExperimentCondition("assign-prog", site, target, new ResponseCallback(){ + @Override + public void onSuccess(@NonNull ExperimentsResponse expResult){ + System.out.println(prefix() + "success getting condition; marking"); + + Condition condition = expResult.getAssignedCondition(); + String code = condition == null ? null : condition.getConditionCode(); + experimentClient.markExperimentPoint(site, target, code, MarkedDecisionPointStatus.CONDITION_APPLIED, new ResponseCallback(){ + @Override + public void onSuccess(@NonNull MarkExperimentPoint markResult){ + result.complete("marked " + code + ": " + markResult.toString()); + } + + @Override + public void onError(@NonNull ErrorResponse error){ + result.complete("error marking " + code + ": " + error.toString()); + } + }); + } + + @Override + public void onError(@NonNull ErrorResponse error){ + result.complete(error.toString()); + } + + }); + } + @Override + public void onError(@NonNull ErrorResponse error){ + result.complete(error.toString()); + } + + }); } - @Override public void onError(@NonNull ErrorResponse error){ - result.complete("error marking " + code + ": " + error.toString()); + result.complete(error.toString()); } }); } - @Override public void onError(@NonNull ErrorResponse error){ result.complete(error.toString()); } - }); } @@ -127,10 +118,10 @@ public void onError(@NonNull ErrorResponse error){ System.out.println(prefix() + result.getNow("not complete yet")); String rs = result.get(); System.out.println(prefix() + rs); - } - } + } + } - private static final String prefix() { - return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": "; - } + private static final String prefix() { + return "on thread " + Thread.currentThread().getName() + " at " + System.currentTimeMillis() + ": "; + } } \ No newline at end of file diff --git a/clientlibs/java/src/main/java/org/upgradeplatform/utils/APIService.java b/clientlibs/java/src/main/java/org/upgradeplatform/utils/APIService.java index 99832ad089..15c0359b55 100644 --- a/clientlibs/java/src/main/java/org/upgradeplatform/utils/APIService.java +++ b/clientlibs/java/src/main/java/org/upgradeplatform/utils/APIService.java @@ -10,8 +10,9 @@ import javax.ws.rs.client.ClientBuilder; import javax.ws.rs.core.MediaType; +import org.glassfish.jersey.apache.connector.ApacheConnectorProvider; +import org.glassfish.jersey.client.ClientConfig; import org.glassfish.jersey.client.ClientProperties; -import org.glassfish.jersey.client.HttpUrlConnectorProvider; public class APIService implements AutoCloseable{ @@ -35,7 +36,7 @@ public APIService(String baseUrl, String authToken, String sessionId, Map properties) { - Client client = ClientBuilder.newClient(); + Client client = ClientBuilder.newClient(new ClientConfig().connectorProvider(new ApacheConnectorProvider())); client.property(ClientProperties.CONNECT_TIMEOUT, 3000); client.property(ClientProperties.READ_TIMEOUT, 3000); properties.entrySet().stream() @@ -57,7 +58,6 @@ public AsyncInvoker prepareRequest(String apiPath) { .request(MediaType.APPLICATION_JSON) .header("Authorization", "Bearer "+this.authToken) .header("Session-Id", this.sessionId) - .property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true) .async(); } @@ -65,4 +65,4 @@ public AsyncInvoker prepareRequest(String apiPath) { public void close() { client.close(); } -} +} \ No newline at end of file