Search in sources :

Example 1 with RestResponse

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;
}
Also used : RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) SerializationContextInitializer(org.infinispan.protostream.SerializationContextInitializer)

Example 2 with RestResponse

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());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache)

Example 3 with RestResponse

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());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) Cache(org.infinispan.Cache) RemoteCache(org.infinispan.client.hotrod.RemoteCache)

Example 4 with RestResponse

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>"));
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse)

Example 5 with RestResponse

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());
}
Also used : RestResponse(org.infinispan.client.rest.RestResponse) ObjectInputStream(java.io.ObjectInputStream)

Aggregations

RestResponse (org.infinispan.client.rest.RestResponse)233 Test (org.testng.annotations.Test)108 Json (org.infinispan.commons.dataconversion.internal.Json)52 RestCacheClient (org.infinispan.client.rest.RestCacheClient)42 Test (org.junit.Test)41 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)39 RestClient (org.infinispan.client.rest.RestClient)37 RestEntity (org.infinispan.client.rest.RestEntity)36 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)23 HashMap (java.util.HashMap)8 RestCounterClient (org.infinispan.client.rest.RestCounterClient)8 TestClass (org.infinispan.rest.TestClass)8 RestSchemaClient (org.infinispan.client.rest.RestSchemaClient)7 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)7 RestCacheManagerClient (org.infinispan.client.rest.RestCacheManagerClient)6 RestMetricsClient (org.infinispan.client.rest.RestMetricsClient)6 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)6 Cache (org.infinispan.Cache)5 RestRawClient (org.infinispan.client.rest.RestRawClient)5 MultipleCacheManagersTest (org.infinispan.test.MultipleCacheManagersTest)5