Search in sources :

Example 26 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class RestAccessLoggingTest method setup.

@Override
protected void setup() throws Exception {
    super.setup();
    testShortName = TestResourceTracker.getCurrentTestShortName();
    logAppender = new StringLogAppender("org.infinispan.REST_ACCESS_LOG", Level.TRACE, t -> t.getName().startsWith("non-blocking-thread-" + testShortName), PatternLayout.newBuilder().withPattern(LOG_FORMAT).build());
    logAppender.install();
    restServer = new RestServerHelper(cacheManager);
    restServer.start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort());
    restClient = RestClient.forConfiguration(builder.create());
    cacheClient = restClient.cache("default");
}
Also used : CompletionStages.join(org.infinispan.util.concurrent.CompletionStages.join) SingleCacheManagerTest(org.infinispan.test.SingleCacheManagerTest) TestResourceTracker(org.infinispan.commons.test.TestResourceTracker) Level(org.apache.logging.log4j.Level) RestClient(org.infinispan.client.rest.RestClient) Test(org.testng.annotations.Test) AssertJUnit.assertTrue(org.testng.AssertJUnit.assertTrue) RestCacheClient(org.infinispan.client.rest.RestCacheClient) RestServerHelper(org.infinispan.rest.helper.RestServerHelper) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) EmbeddedCacheManager(org.infinispan.manager.EmbeddedCacheManager) TestCacheManagerFactory(org.infinispan.test.fwk.TestCacheManagerFactory) PatternLayout(org.apache.logging.log4j.core.layout.PatternLayout) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) StringLogAppender(org.infinispan.commons.test.skip.StringLogAppender) RestServerHelper(org.infinispan.rest.helper.RestServerHelper)

Example 27 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class AbstractRestResourceTest method getClientConfig.

protected RestClientConfigurationBuilder getClientConfig(String username, String password) {
    RestClientConfigurationBuilder clientConfigurationBuilder = new RestClientConfigurationBuilder();
    if (protocol != null) {
        clientConfigurationBuilder.protocol(protocol);
    }
    if (ssl) {
        clientConfigurationBuilder.security().ssl().enable().hostnameVerifier((hostname, session) -> true).trustStoreFileName(CLIENT_KEY_STORE).trustStorePassword(STORE_PASSWORD).trustStoreType(STORE_TYPE).keyStoreFileName(CLIENT_KEY_STORE).keyStorePassword(STORE_PASSWORD).keyStoreType(STORE_TYPE);
    }
    if (isSecurityEnabled()) {
        clientConfigurationBuilder.security().authentication().enable().username(username).password(password);
    }
    restServers.forEach(s -> clientConfigurationBuilder.addServer().host(s.getHost()).port(s.getPort()));
    return clientConfigurationBuilder;
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)

Example 28 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class Http2Test method shouldReportErrorCorrectly.

@Test
public void shouldReportErrorCorrectly() {
    restServer = RestServerHelper.defaultRestServer().withKeyStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).withTrustStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder config = new RestClientConfigurationBuilder();
    config.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(HTTP_20).priorKnowledge(true).security().ssl().enable().trustStoreFileName(KEY_STORE_PATH).trustStorePassword(STORE_PASSWORD).trustStoreType(STORE_TYPE).keyStoreFileName(KEY_STORE_PATH).keyStorePassword(STORE_PASSWORD).keyStoreType(STORE_TYPE).hostnameVerifier((hostname, session) -> true);
    client = RestClient.forConfiguration(config.build());
    CompletionStage<RestResponse> response = client.raw().get("/invalid");
    ResponseAssertion.assertThat(response).isNotFound();
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestResponse(org.infinispan.client.rest.RestResponse) Test(org.testng.annotations.Test) AbstractInfinispanTest(org.infinispan.test.AbstractInfinispanTest)

Example 29 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class Http2Test method clearTextUpgrade.

private void clearTextUpgrade(boolean previousKnowledge) {
    restServer = RestServerHelper.defaultRestServer().start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).priorKnowledge(previousKnowledge).protocol(Protocol.HTTP_20);
    client = RestClient.forConfiguration(builder.build());
    CompletionStage<RestResponse> response = client.cacheManager("default").info();
    ResponseAssertion.assertThat(response).isOk();
    RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "test".getBytes(CharsetUtil.UTF_8));
    response = client.cache("defaultcache").post("test", value);
    Assertions.assertThat(join(response).getStatus()).isEqualTo(204);
    Assertions.assertThat(restServer.getCacheManager().getCache().size()).isEqualTo(1);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Example 30 with RestClientConfigurationBuilder

use of org.infinispan.client.rest.configuration.RestClientConfigurationBuilder in project infinispan by infinispan.

the class Http2Test method secureUpgradeTest.

private void secureUpgradeTest(Protocol choice) {
    // given
    restServer = RestServerHelper.defaultRestServer().withKeyStore(KEY_STORE_PATH, STORE_PASSWORD, STORE_TYPE).start(TestResourceTracker.getCurrentTestShortName());
    RestClientConfigurationBuilder builder = new RestClientConfigurationBuilder();
    builder.addServer().host(restServer.getHost()).port(restServer.getPort()).protocol(choice).security().ssl().trustStoreFileName(KEY_STORE_PATH).trustStorePassword(STORE_PASSWORD).hostnameVerifier((hostname, session) -> true);
    client = RestClient.forConfiguration(builder.build());
    RestEntity value = RestEntity.create(MediaType.APPLICATION_OCTET_STREAM, "test".getBytes(CharsetUtil.UTF_8));
    CompletionStage<RestResponse> response = client.cache("defaultcache").post("test", value);
    // then
    ResponseAssertion.assertThat(response).isOk();
    Assertions.assertThat(restServer.getCacheManager().getCache().size()).isEqualTo(1);
}
Also used : RestClientConfigurationBuilder(org.infinispan.client.rest.configuration.RestClientConfigurationBuilder) RestEntity(org.infinispan.client.rest.RestEntity) RestResponse(org.infinispan.client.rest.RestResponse)

Aggregations

RestClientConfigurationBuilder (org.infinispan.client.rest.configuration.RestClientConfigurationBuilder)56 Test (org.junit.Test)26 RestClient (org.infinispan.client.rest.RestClient)25 RestResponse (org.infinispan.client.rest.RestResponse)22 RestClientConfiguration (org.infinispan.client.rest.configuration.RestClientConfiguration)8 RestServerHelper (org.infinispan.rest.helper.RestServerHelper)6 ConfigurationBuilder (org.infinispan.client.hotrod.configuration.ConfigurationBuilder)5 InetSocketAddress (java.net.InetSocketAddress)4 RestCacheClient (org.infinispan.client.rest.RestCacheClient)4 EmbeddedCacheManager (org.infinispan.manager.EmbeddedCacheManager)4 RestServer (org.infinispan.rest.RestServer)4 RestServerConfigurationBuilder (org.infinispan.rest.configuration.RestServerConfigurationBuilder)4 AbstractRestResourceTest (org.infinispan.rest.resources.AbstractRestResourceTest)4 DummyServerManagement (org.infinispan.server.core.DummyServerManagement)4 IOException (java.io.IOException)3 ArrayList (java.util.ArrayList)3 RestEntity (org.infinispan.client.rest.RestEntity)3 Json (org.infinispan.commons.dataconversion.internal.Json)3 ConfigurationBuilder (org.infinispan.configuration.cache.ConfigurationBuilder)3 Router (org.infinispan.server.router.Router)3