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);
}
}
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;
}
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));
}
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));
}
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());
}
Aggregations