use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class ProtoRegistrationJsonTest method createRemoteCacheManager.
@Override
protected RemoteCacheManager createRemoteCacheManager() {
SerializationContextInitializer sci = EndpointITSCI.INSTANCE;
RemoteCacheManager remoteCacheManager = new RemoteCacheManager(new org.infinispan.client.hotrod.configuration.ConfigurationBuilder().addServer().host("localhost").port(hotRodServer.getPort()).addContextInitializer(sci).build());
// initialize server-side serialization context via rest endpoint
RestEntity protoFile = RestEntity.create(MediaType.TEXT_PLAIN, sci.getProtoFile());
RestResponse response = join(restClient.cache(PROTOBUF_METADATA_CACHE_NAME).put(sci.getProtoFileName(), protoFile));
assertEquals(response.getStatus(), 204);
return remoteCacheManager;
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class ReplEmbeddedRestHotRodTest method testEmbeddedPutRestHotRodGet.
public void testEmbeddedPutRestHotRodGet() {
final String key = "2";
// 1. Put with Embedded
Cache cache = cacheFactory2.getEmbeddedCache().getAdvancedCache();
assertNull(cache.put(key, "v1"));
// 2. Get with Hot Rod via remote client, will use the configured encoding
assertEquals("v1", cacheFactory1.getHotRodCache().get(key));
// 3. Get with REST, specifying the results as 'text'
RestResponse response = join(cacheFactory2.getRestCacheClient().get(key, TEXT_PLAIN_TYPE));
assertEquals(200, response.getStatus());
assertEquals("v1", response.getBody());
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class ReplEmbeddedRestHotRodTest method testHotRodPutEmbeddedRestGet.
public void testHotRodPutEmbeddedRestGet() {
final String key = "3";
// 1. Put with Hot Rod
RemoteCache<Object, Object> remote = cacheFactory1.getHotRodCache();
assertEquals(null, remote.withFlags(Flag.FORCE_RETURN_VALUE).put(key, "v1"));
// 2. Get with Embedded
Cache embeddedCache = cacheFactory2.getEmbeddedCache().getAdvancedCache();
assertEquals("v1", embeddedCache.get(key));
// 3. Get with REST
RestResponse response = join(cacheFactory2.getRestCacheClient().get(key, TEXT_PLAIN_TYPE));
assertEquals(200, response.getStatus());
assertEquals("v1", response.getBody());
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class EmbeddedRestHotRodTest method testCustomObjectEmbeddedPutRestGetAcceptJSONAndXML.
public void testCustomObjectEmbeddedPutRestGetAcceptJSONAndXML() {
final String key = "6";
final Person p = new Person("Anna");
// 1. Put with Embedded
assertNull(cacheFactory.getEmbeddedCache().put(key, p));
// 2. Get with REST (accept application/json)
RestResponse response = join(cacheFactory.getRestCacheClient().get(key, APPLICATION_JSON_TYPE));
String body = response.getBody();
assertEquals(200, response.getStatus());
assertEquals(asJson(p), body);
// 3. Get with REST (accept application/xml)
response = join(cacheFactory.getRestCacheClient().get(key, APPLICATION_XML_TYPE));
assertEquals(200, response.getStatus());
assertTrue(response.getBody().contains("<name>Anna</name>"));
}
use of org.infinispan.client.rest.RestResponse in project infinispan by infinispan.
the class EmbeddedRestHotRodTest method testCustomObjectEmbeddedPutHotRodRestGet.
public void testCustomObjectEmbeddedPutHotRodRestGet() throws Exception {
final String key = "5";
Person p = new Person("Galder");
// 1. Put with Embedded
assertNull(cacheFactory.getEmbeddedCache().put(key, p));
// 2. Get with Hot Rod
assertEquals(p, cacheFactory.getHotRodCache().get(key));
// 3. Get with REST
RestResponse response = join(cacheFactory.getRestCacheClient().get(key, "application/x-java-serialized-object, application/json;q=0.3"));
assertEquals(200, response.getStatus());
// REST finds the Java POJO in-memory and returns the Java serialized version
assertEquals(p, new ObjectInputStream(response.getBodyAsStream()).readObject());
}
Aggregations