use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class PluginLoadingForStartup method loadPlugin.
private static NamedPlugin loadPlugin(Environment environment, ConfiguredPluginFactory factory) {
PluginFactory.Environment pluginEnvironment = new PluginFactory.Environment() {
@Override
public <T> T pluginConfig(Class<T> clazz) {
return factory.pluginConfig(clazz);
}
@Override
public Configuration configuration() {
return environment.configuration();
}
@Override
public MeterRegistry pluginMeterRegistry() {
return environment.meterRegistry().scope("plugin.internal." + factory.name().toLowerCase());
}
@Override
@Deprecated
public MetricRegistry metricRegistry() {
return environment.metricRegistry().scope("plugin.internal." + factory.name());
}
};
Plugin plugin = factory.pluginFactory().create(pluginEnvironment);
return namedPlugin(factory.name(), plugin);
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method invokesPluginLifecycleMethods.
@Test
public void invokesPluginLifecycleMethods() {
Plugin pluginMock1 = mock(Plugin.class);
Plugin pluginMock2 = mock(Plugin.class);
StyxServer styxServer = styxServerWithPlugins(Map.of("mockplugin1", pluginMock1, "mockplugin2", pluginMock2));
try {
styxServer.startAsync().awaitRunning();
verify(pluginMock1).styxStarting();
verify(pluginMock2).styxStarting();
styxServer.stopAsync().awaitTerminated();
verify(pluginMock1).styxStopping();
verify(pluginMock2).styxStopping();
} finally {
stopIfRunning(styxServer);
}
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class TestPlugin method intercept.
@Override
public Eventual<LiveHttpResponse> intercept(LiveHttpRequest request, Chain chain) {
String header = xHcomPluginsHeader(request);
LiveHttpRequest newRequest = request.newBuilder().header(X_HCOM_PLUGINS_HEADER, header).header("X-Hcom-Styx-Started", styxStarted).header("X-Hcom-Styx-Stopped", styxStopped).build();
Function<ByteBuf, String> byteBufStringFunction = byteBuf -> byteBuf.toString(UTF_8);
return chain.proceed(newRequest).flatMap(response -> response.aggregate(1 * 1024 * 1024)).map(response -> response.newBuilder().header(X_HCOM_PLUGINS_HEADER, header).header("X-Hcom-Styx-Started", styxStarted).header("X-Hcom-Styx-Stopped", styxStopped).addHeader("X-Plugin-Identifier", config.getId()).build()).map(HttpResponse::stream);
}
use of com.hotels.styx.api.plugins.spi.Plugin 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")));
}
use of com.hotels.styx.api.plugins.spi.Plugin in project styx by ExpediaGroup.
the class StyxServerTest method informsPluginOfStopping.
@Test
public void informsPluginOfStopping() {
Plugin plugin = mock(Plugin.class);
styxServer = new StyxServer.Builder().addRoute("/", originServer1.port()).addPlugin("plugin-with-shutdownBehaviour", plugin).start();
styxServer.stop();
verify(plugin).styxStopping();
}
Aggregations