Search in sources :

Example 1 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class Put method exec.

@Override
protected CompletionStage<RestResponse> exec(ContextAwareCommandInvocation invocation, RestClient client, org.infinispan.cli.resources.Resource resource) {
    if ((file != null) && (args.size() != 1)) {
        throw Messages.MSG.illegalCommandArguments();
    } else if ((file == null) && (args.size() != 2)) {
        throw Messages.MSG.illegalCommandArguments();
    }
    RestCacheClient cacheClient = client.cache(cache != null ? cache : CacheResource.cacheName(resource));
    MediaType putEncoding = encoding != null ? MediaType.fromString(encoding) : invocation.getContext().getEncoding();
    RestEntity value = file != null ? RestEntity.create(putEncoding, new File(file.getAbsolutePath())) : RestEntity.create(putEncoding, args.get(1));
    if (ifAbsent) {
        return cacheClient.post(args.get(0), value, ttl, maxIdle);
    } else {
        return cacheClient.put(args.get(0), value, ttl, maxIdle);
    }
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestCacheClient(org.infinispan.client.rest.RestCacheClient) MediaType(org.infinispan.commons.dataconversion.MediaType) File(java.io.File)

Example 2 with RestEntity

use of org.infinispan.client.rest.RestEntity 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 3 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class EmbeddedRestHotRodTest method testCustomObjectRestPutHotRodEmbeddedGet.

public void testCustomObjectRestPutHotRodEmbeddedGet() throws Exception {
    final String key = "77";
    Person p = new Person("Iker");
    // 1. Put with Rest
    RestCacheClient restClient = cacheFactory.getRestCacheClient();
    ByteArrayOutputStream bout = new ByteArrayOutputStream();
    try (ObjectOutputStream oos = new ObjectOutputStream(bout)) {
        oos.writeObject(p);
    }
    RestEntity value = RestEntity.create(APPLICATION_SERIALIZED_OBJECT, new ByteArrayInputStream(bout.toByteArray()));
    join(restClient.put(key, value));
    // 2. Get with Hot Rod
    RemoteCache<String, Object> remote = cacheFactory.getHotRodCache();
    assertEquals(p, remote.get(key));
    // 3. Get with Embedded
    assertEquals(p, cacheFactory.getEmbeddedCache().getAdvancedCache().get(key));
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) ByteArrayInputStream(java.io.ByteArrayInputStream) RestCacheClient(org.infinispan.client.rest.RestCacheClient) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ObjectOutputStream(java.io.ObjectOutputStream)

Example 4 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class EmbeddedRestMemcachedHotRodTest method testRestPutEmbeddedMemcachedHotRodGetTest.

public void testRestPutEmbeddedMemcachedHotRodGetTest() throws Exception {
    final String key = "3";
    // 1. Put with REST
    RestEntity value = RestEntity.create(MediaType.TEXT_PLAIN, "<hey>ho</hey>");
    RestResponse response = join(cacheFactory.getRestCacheClient().put(key, value));
    assertEquals(204, response.getStatus());
    // 2. Get with Embedded (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getEmbeddedCache().get(key));
    // 3. Get with Memcached (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getMemcachedClient().get(key));
    // 4. Get with Hot Rod (given a marshaller, it can unmarshall the result)
    assertEquals("<hey>ho</hey>", cacheFactory.getHotRodCache().get(key));
}
Also used : RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 5 with RestEntity

use of org.infinispan.client.rest.RestEntity in project infinispan by infinispan.

the class IndexedCacheNonIndexedEntityTest method shouldPreventNonIndexedEntities.

@Test
public void shouldPreventNonIndexedEntities() {
    CompletionStage<RestResponse> response = client.schemas().post("customer", SCHEMA);
    ResponseAssertion.assertThat(response).isOk();
    ConfigurationBuilder configurationBuilder = getDefaultStandaloneCacheConfig(false);
    configurationBuilder.statistics().enable();
    configurationBuilder.encoding().mediaType(APPLICATION_PROTOSTREAM_TYPE).indexing().enable().storage(LOCAL_HEAP).addIndexedEntity("NonIndexed");
    String config = cacheConfigToJson(CACHE_NAME, configurationBuilder.build());
    RestEntity configEntity = RestEntity.create(MediaType.APPLICATION_JSON, config);
    RestCacheClient cacheClient = client.cache(CACHE_NAME);
    response = cacheClient.createWithConfiguration(configEntity, VOLATILE);
    // The SearchMapping is started lazily, creating and starting the cache will not throw errors
    ResponseAssertion.assertThat(response).isOk();
    // Force initialization of the SearchMapping
    response = cacheClient.query("FROM NonIndexed");
    ResponseAssertion.assertThat(response).isBadRequest();
    String errorText = "The configured indexed-entity type 'NonIndexed' must be indexed. Please annotate it with @Indexed";
    ResponseAssertion.assertThat(response).containsReturnedText(errorText);
    // Call Indexer operations
    response = cacheClient.clearIndex();
    ResponseAssertion.assertThat(response).containsReturnedText(errorText);
    // The Indexer should not have "running" status
    Indexer indexer = Search.getIndexer(cacheManager.getCache(CACHE_NAME));
    assertFalse(indexer.isRunning());
}
Also used : ConfigurationBuilder(org.infinispan.configuration.cache.ConfigurationBuilder) GlobalConfigurationBuilder(org.infinispan.configuration.global.GlobalConfigurationBuilder) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) Indexer(org.infinispan.query.Indexer) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse) RestCacheClient(org.infinispan.client.rest.RestCacheClient) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) Test(org.testng.annotations.Test)

Aggregations

RestEntity (org.infinispan.client.rest.RestEntity)38 RestResponse (org.infinispan.client.rest.RestResponse)35 RestCacheClient (org.infinispan.client.rest.RestCacheClient)14 Test (org.testng.annotations.Test)14 Util.getResourceAsString (org.infinispan.commons.util.Util.getResourceAsString)11 Json (org.infinispan.commons.dataconversion.internal.Json)5 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)5 RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)4 GlobalConfigurationBuilder (org.infinispan.configuration.global.GlobalConfigurationBuilder)4 DummyInMemoryStoreConfigurationBuilder (org.infinispan.persistence.dummy.DummyInMemoryStoreConfigurationBuilder)3 MediaType (org.infinispan.commons.dataconversion.MediaType)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 ObjectOutputStream (java.io.ObjectOutputStream)1 HashMap (java.util.HashMap)1 Cache (org.infinispan.Cache)1 RemoteCache (org.infinispan.client.hotrod.RemoteCache)1 RemoteCacheManager (org.infinispan.client.hotrod.RemoteCacheManager)1 RestClient (org.infinispan.client.rest.RestClient)1