Search in sources :

Example 1 with PluginFactory

use of com.hotels.styx.api.plugins.spi.PluginFactory in project styx by ExpediaGroup.

the class PluginLoadingForStartup method loadPluginFactory.

private static ConfiguredPluginFactory loadPluginFactory(Pair<String, SpiExtension> pair) {
    String pluginName = pair.key();
    SpiExtension spiExtension = pair.value();
    PluginFactory factory = new FileSystemPluginFactoryLoader().load(spiExtension);
    return new ConfiguredPluginFactory(pluginName, factory, spiExtension::config);
}
Also used : FileSystemPluginFactoryLoader(com.hotels.styx.proxy.plugin.FileSystemPluginFactoryLoader) SpiExtension(com.hotels.styx.spi.config.SpiExtension) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory)

Example 2 with PluginFactory

use of com.hotels.styx.api.plugins.spi.PluginFactory in project styx by ExpediaGroup.

the class StyxServerTest method executesPluginsWhenProxying.

@Test
public void executesPluginsWhenProxying() {
    Plugin responseDecorator = (request, chain) -> chain.proceed(request).map(response -> response.newBuilder().header("plugin-executed", "yes").build());
    PluginFactory pluginFactory = environment -> responseDecorator;
    styxServer = new StyxServer.Builder().addRoute("/", originServer1.port()).addPluginFactory("response-decorator", pluginFactory, null).start();
    HttpResponse response = await(client.sendRequest(get(format("http://localhost:%d/foo", styxServer.proxyHttpPort())).build()));
    assertThat(response.status(), is(OK));
    assertThat(response.header("origin"), isValue("first"));
    assertThat(response.header("plugin-executed"), isValue("yes"));
    configureFor(originServer1.port());
    WireMock.verify(getRequestedFor(urlPathEqualTo("/foo")));
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) HttpResponse(com.hotels.styx.api.HttpResponse) StyxFutures.await(com.hotels.styx.common.StyxFutures.await) Matchers.not(org.hamcrest.Matchers.not) StyxHttpClient(com.hotels.styx.client.StyxHttpClient) HttpClient(com.hotels.styx.client.HttpClient) WireMock(com.github.tomakehurst.wiremock.client.WireMock) WireMockServer(com.github.tomakehurst.wiremock.WireMockServer) WireMockConfiguration.wireMockConfig(com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig) HttpRequest.get(com.hotels.styx.api.HttpRequest.get) Map(java.util.Map) Origins.origin(com.hotels.styx.testapi.Origins.origin) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) WireMock.configureFor(com.github.tomakehurst.wiremock.client.WireMock.configureFor) WireMock.urlPathEqualTo(com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo) Collections.emptyMap(java.util.Collections.emptyMap) Eventual(com.hotels.styx.api.Eventual) HttpHandler(com.hotels.styx.api.HttpHandler) Plugin(com.hotels.styx.api.plugins.spi.Plugin) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) WireMock.aResponse(com.github.tomakehurst.wiremock.client.WireMock.aResponse) UTF_8(java.nio.charset.StandardCharsets.UTF_8) Matchers.allOf(org.hamcrest.Matchers.allOf) Mockito.when(org.mockito.Mockito.when) String.format(java.lang.String.format) Mockito.verify(org.mockito.Mockito.verify) TlsSettings(com.hotels.styx.api.extension.service.TlsSettings) Test(org.junit.jupiter.api.Test) AfterEach(org.junit.jupiter.api.AfterEach) IsOptional.isValue(com.hotels.styx.support.matchers.IsOptional.isValue) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) OK(com.hotels.styx.api.HttpResponseStatus.OK) Optional(java.util.Optional) WireMock.stubFor(com.github.tomakehurst.wiremock.client.WireMock.stubFor) WireMock.getRequestedFor(com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor) Matchers.is(org.hamcrest.Matchers.is) Matchers.containsString(org.hamcrest.Matchers.containsString) Mockito.mock(org.mockito.Mockito.mock) HttpResponse(com.hotels.styx.api.HttpResponse) LiveHttpResponse(com.hotels.styx.api.LiveHttpResponse) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) Plugin(com.hotels.styx.api.plugins.spi.Plugin) Test(org.junit.jupiter.api.Test)

Example 3 with PluginFactory

use of com.hotels.styx.api.plugins.spi.PluginFactory in project styx by ExpediaGroup.

the class FileSystemPluginFactoryLoaderTest method pluginLoaderLoadsPluginFromJarFile.

@Test
public void pluginLoaderLoadsPluginFromJarFile() {
    SpiExtensionFactory factory = new SpiExtensionFactory("testgrp.TestPluginModule", pluginsPath.toString());
    PluginFactory plugin = pluginFactoryLoader.load(new SpiExtension(factory, config, null));
    assertThat(plugin, is(not(nullValue())));
    assertThat(plugin.getClass().getName(), is("testgrp.TestPluginModule"));
}
Also used : SpiExtension(com.hotels.styx.spi.config.SpiExtension) PluginFactory(com.hotels.styx.api.plugins.spi.PluginFactory) SpiExtensionFactory(com.hotels.styx.spi.config.SpiExtensionFactory) Test(org.junit.jupiter.api.Test)

Aggregations

PluginFactory (com.hotels.styx.api.plugins.spi.PluginFactory)3 SpiExtension (com.hotels.styx.spi.config.SpiExtension)2 Test (org.junit.jupiter.api.Test)2 WireMockServer (com.github.tomakehurst.wiremock.WireMockServer)1 WireMock (com.github.tomakehurst.wiremock.client.WireMock)1 WireMock.aResponse (com.github.tomakehurst.wiremock.client.WireMock.aResponse)1 WireMock.configureFor (com.github.tomakehurst.wiremock.client.WireMock.configureFor)1 WireMock.getRequestedFor (com.github.tomakehurst.wiremock.client.WireMock.getRequestedFor)1 WireMock.stubFor (com.github.tomakehurst.wiremock.client.WireMock.stubFor)1 WireMock.urlPathEqualTo (com.github.tomakehurst.wiremock.client.WireMock.urlPathEqualTo)1 WireMockConfiguration.wireMockConfig (com.github.tomakehurst.wiremock.core.WireMockConfiguration.wireMockConfig)1 Eventual (com.hotels.styx.api.Eventual)1 HttpHandler (com.hotels.styx.api.HttpHandler)1 HttpRequest.get (com.hotels.styx.api.HttpRequest.get)1 HttpResponse (com.hotels.styx.api.HttpResponse)1 OK (com.hotels.styx.api.HttpResponseStatus.OK)1 LiveHttpResponse (com.hotels.styx.api.LiveHttpResponse)1 TlsSettings (com.hotels.styx.api.extension.service.TlsSettings)1 Plugin (com.hotels.styx.api.plugins.spi.Plugin)1 HttpClient (com.hotels.styx.client.HttpClient)1