use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class CacheResourceTest method testCorsSameOrigin.
@Test
public void testCorsSameOrigin() {
Map<String, String> headers = new HashMap<>();
String scheme = ssl ? "https://" : "http://";
headers.put(ORIGIN.toString(), scheme + "origin-host.org");
headers.put(HOST.toString(), "origin-host.org");
CompletionStage<RestResponse> response = client.raw().get("/rest/v2/caches", headers);
assertThat(response).isOk();
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class CacheResourceTest method testCORSAllOrigins.
@Test
public void testCORSAllOrigins() throws IOException {
RestServerHelper restServerHelper = null;
RestClient client = null;
try {
RestServerConfigurationBuilder restBuilder = new RestServerConfigurationBuilder();
restBuilder.cors().addNewRule().allowOrigins(new String[] { "*" });
restBuilder.host("localhost").port(0);
restServerHelper = RestServerHelper.defaultRestServer();
RestServerConfiguration build = restBuilder.build();
restServerHelper.withConfiguration(build).start("test");
client = restServerHelper.createClient();
RestResponse response = join(client.cache("default").get("test", singletonMap(ORIGIN.toString(), "http://host.example.com:5576")));
assertThat(response).containsAllHeaders("access-control-allow-origin");
} finally {
client.close();
if (restServerHelper != null)
restServerHelper.stop();
}
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class CacheResourceTest method testIfModifiedHeaderForCache.
@Test
public void testIfModifiedHeaderForCache() {
putStringValueInCache("expiration", "test", "test");
RestCacheClient cacheClient = client.cache("expiration");
RestResponse resp = join(cacheClient.get("test"));
String dateLast = resp.headers().get("Last-Modified").get(0);
CompletionStage<RestResponse> sameLastModAndIfModified = cacheClient.get("test", createHeaders(IF_MODIFIED_SINCE, dateLast));
assertThat(sameLastModAndIfModified).isNotModified();
putStringValueInCache("expiration", "test", "test-new");
RestResponse lastmodAfterIfModified = join(cacheClient.get("test"));
dateLast = lastmodAfterIfModified.headers().get("Last-Modified").get(0);
assertThat(lastmodAfterIfModified).isOk();
Map<String, String> header = createHeaders(IF_MODIFIED_SINCE, plus1Day(dateLast));
CompletionStage<RestResponse> lastmodBeforeIfModified = cacheClient.get("test", header);
assertThat(lastmodBeforeIfModified).isNotModified();
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class CacheResourceTest method shouldReadTextWithPojoCache.
@Test
public void shouldReadTextWithPojoCache() {
// given
RestCacheClient pojoCache = client.cache("pojoCache");
String key = "k1";
String value = "v1";
join(pojoCache.put(key, value));
// when
RestResponse response = join(pojoCache.get(key));
// then
assertThat(response).isOk();
assertThat(response).hasContentType(TEXT_PLAIN_TYPE);
assertThat(response).hasReturnedText(value);
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class CacheResourceTest method testCORSPreflight.
@Test
public void testCORSPreflight() {
String url = String.format("/rest/v2/caches/%s/%s", "default", "key");
RestRawClient rawClient = client.raw();
join(client.cache("default").put("key", "value"));
Map<String, String> headers = new HashMap<>();
headers.put(HOST.toString(), "localhost");
headers.put(ORIGIN.toString(), "http://localhost:" + restServer().getPort());
headers.put(ACCESS_CONTROL_REQUEST_METHOD.toString(), "GET");
CompletionStage<RestResponse> preFlight = rawClient.options(url, headers);
assertThat(preFlight).isOk();
assertThat(preFlight).hasNoContent();
assertThat(preFlight).containsAllHeaders(ACCESS_CONTROL_ALLOW_ORIGIN.toString(), ACCESS_CONTROL_ALLOW_METHODS.toString(), ACCESS_CONTROL_ALLOW_HEADERS.toString());
assertThat(preFlight).hasHeaderWithValues(ACCESS_CONTROL_ALLOW_HEADERS.toString(), (String[]) RequestHeader.toArray());
}
Aggregations