use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class RollingUpgradeDynamicStoreIT method connectTargetCluster.
protected void connectTargetCluster() throws IOException {
RestCacheClient client = target.getClient().cache(CACHE_NAME);
ConfigurationBuilder builder = new ConfigurationBuilder();
addRemoteStore(builder);
RemoteStoreConfiguration remoteStore = (RemoteStoreConfiguration) builder.build().persistence().stores().iterator().next();
RestEntity restEntity = RestEntity.create(MediaType.APPLICATION_JSON, SerializationUtils.toJson(remoteStore));
RestResponse response = join(client.connectSource(restEntity));
assertEquals(response.getBody(), 204, response.getStatus());
response = join(client.sourceConnection());
RemoteStoreConfiguration remoteStoreConfiguration = SerializationUtils.fromJson(response.getBody());
List<RemoteServerConfiguration> servers = remoteStoreConfiguration.servers();
assertEquals(1, servers.size());
RemoteServerConfiguration initialConfig = remoteStore.servers().iterator().next();
assertEquals(initialConfig.host(), servers.get(0).host());
assertEquals(initialConfig.port(), servers.get(0).port());
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class BaseRestSearchTest method write.
protected void write(int id, String contents, Method method, MediaType contentType) {
RestEntity entity = new StringRestEntityOkHttp(contentType, contents);
CompletionStage<RestResponse> response;
if (method.equals(POST)) {
response = client.cache(CACHE_NAME).post(String.valueOf(id), entity);
} else {
response = client.cache(CACHE_NAME).put(String.valueOf(id), entity);
}
ResponseAssertion.assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.
the class RestTestClientDriver method create.
/**
* Create a new REST client and create a cache whose name will be the test name where this method
* is called from.
*
* @return new {@link RestClient} instance
*/
public RestClient create() {
RestClient restClient = get();
String name = testClient.getMethodName(qualifier);
CompletionStage<RestResponse> future;
if (serverConfiguration != null) {
RestEntity configEntity = RestEntity.create(MediaType.APPLICATION_XML, serverConfiguration.toStringConfiguration(name));
future = restClient.cache(name).createWithConfiguration(configEntity, flags.toArray(new CacheContainerAdmin.AdminFlag[0]));
} else if (mode != null) {
future = restClient.cache(name).createWithTemplate("org.infinispan." + mode.name(), flags.toArray(new CacheContainerAdmin.AdminFlag[0]));
} else {
future = restClient.cache(name).createWithTemplate("org.infinispan." + CacheMode.DIST_SYNC.name(), flags.toArray(new CacheContainerAdmin.AdminFlag[0]));
}
RestResponse response = Exceptions.unchecked(() -> future.toCompletableFuture().get(TIMEOUT, TimeUnit.SECONDS));
response.close();
if (response.getStatus() != 200) {
switch(response.getStatus()) {
case 400:
throw new IllegalArgumentException("Bad request while attempting to obtain rest client: " + response.getStatus());
case 401:
case 403:
throw new SecurityException("Authentication error while attempting to obtain rest client = " + response.getStatus());
default:
throw new RuntimeException("Could not obtain rest client = " + response.getStatus());
}
} else {
// If the request succeeded without authn but we were expecting to authenticate, it's an error
if (restClient.getConfiguration().security().authentication().enabled() && !response.usedAuthentication()) {
throw new SecurityException("Authentication expected but anonymous access succeeded");
}
return restClient;
}
}
Aggregations