From 2756d0f7fc993435ab9ca98c476becd754ae66ee Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20G=C3=B6rdes?= <118011644+christiangoerdes@users.noreply.github.com> Date: Tue, 23 Dec 2025 17:11:33 +0100 Subject: [PATCH 01/40] refactor: move globalInterceptor to beanFactory --- .gitignore | 1 + annot/pom.xml | 21 ++- .../annot/beanregistry/BeanCollector.java | 22 ++- .../annot/beanregistry/BeanRegistry.java | 4 + .../annot/beanregistry/BeanRegistryAware.java | 20 +++ .../BeanRegistryImplementation.java | 21 ++- .../BeanRegistryImplementationTest.java | 62 +++++++ .../membrane/annot/util/YamlParser.java | 10 +- .../predic8/membrane/core/Configuration.java | 143 +++++++++++++++ .../com/predic8/membrane/core/Router.java | 166 +++++------------- .../predic8/membrane/core/cli/RouterCLI.java | 81 +++++---- .../core/interceptor/jwt/TidValidator.java | 14 ++ .../predic8/membrane/core/jmx/JmxRouter.java | 4 +- .../core/kubernetes/KubernetesWatcher.java | 2 +- .../membrane/core/proxies/AbstractProxy.java | 2 +- .../membrane/core/transport/Transport.java | 4 +- .../com/predic8/membrane/core/RouterTest.java | 4 +- .../core/azure/AzureDnsApiSimulator.java | 2 +- .../ElasticSearchExchangeStoreTest.java | 6 +- .../membrane/core/http/ChunkedBodyTest.java | 2 +- .../adminapi/AdminApiInterceptorTest.java | 2 +- ...InternalServiceRoutingInterceptorTest.java | 2 +- .../json/JsonProtectionInterceptorTest.java | 2 +- .../oauth2/client/AuthServerMock.java | 2 +- .../OAuth2ResourceErrorForwardingTest.java | 4 +- .../client/OAuth2ResourceRpIniLogoutTest.java | 4 +- .../oauth2/client/OAuth2ResourceTest.java | 4 +- .../oauth2/client/b2c/B2CMembrane.java | 2 +- .../client/b2c/MockAuthorizationServer.java | 2 +- .../shadowing/ShadowingInterceptorTest.java | 4 +- .../soap/SoapAndInternalProxyTest.java | 2 +- .../kubernetes/GenericYamlParserTest.java | 17 +- .../client/KubernetesClientTest.java | 2 +- .../groovy/GroovyBuiltInFunctionsTest.java | 14 ++ .../functions/SpELBuiltInFunctionsTest.java | 14 ++ .../serviceproxy/ApiDocsInterceptorTest.java | 2 +- .../serviceproxy/OpenAPI31ReferencesTest.java | 2 +- .../openapi/serviceproxy/OpenAPI31Test.java | 2 +- .../serviceproxy/OpenAPIInterceptorTest.java | 2 +- .../OpenAPIPublisherInterceptorTest.java | 2 +- .../serviceproxy/OpenAPIRecordTest.java | 2 +- .../openapi/serviceproxy/RewriteTest.java | 2 +- .../openapi/serviceproxy/Swagger20Test.java | 2 +- .../AbstractSecurityValidatorTest.java | 2 +- .../BasicAuthSecurityValidationTest.java | 2 +- .../membrane/core/proxies/ProxySSLTest.java | 4 +- .../membrane/core/proxies/ProxyTest.java | 2 +- ...SOAPProxyWSDLPublisherInterceptorTest.java | 2 +- .../ServiceProxyWSDLInterceptorsTest.java | 2 +- .../proxies/UnavailableSoapProxyTest.java | 6 +- .../core/transport/http/HttpTimeoutTest.java | 4 +- .../transport/http/HttpTransportTest.java | 6 +- .../http/IllegalCharactersInURLTest.java | 6 +- .../http2/Http2ClientServerTest.java | 2 +- .../transport/ssl/HttpsKeepAliveTest.java | 2 +- .../transport/ssl/SessionResumptionTest.java | 2 +- .../ssl/acme/AcmeServerSimulator.java | 2 +- .../core/transport/ssl/acme/AcmeStepTest.java | 2 +- .../core/ws/SoapProxyInvocationTest.java | 2 +- .../predic8/membrane/integration/Util.java | 2 +- .../MassivelyParallelTest.java | 2 +- .../interceptor/AcmeRenewTest.java | 2 +- .../interceptor/oauth2/OAuth2Test.java | 4 +- .../6-health-monitor/proxies-tls.xml | 3 +- .../6-health-monitor/proxies.xml | 2 +- 65 files changed, 508 insertions(+), 239 deletions(-) create mode 100644 annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryAware.java create mode 100644 annot/src/test/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementationTest.java create mode 100644 core/src/main/java/com/predic8/membrane/core/Configuration.java diff --git a/.gitignore b/.gitignore index 656c52dca3..272d92a4c7 100644 --- a/.gitignore +++ b/.gitignore @@ -127,3 +127,4 @@ maven-plugin/target/surefire/ .vscode/ /core/derby.log /distribution/conf/apis.yaml +/distribution/conf/membrane.log diff --git a/annot/pom.xml b/annot/pom.xml index 76f74f68e2..8f83de2e0f 100644 --- a/annot/pom.xml +++ b/annot/pom.xml @@ -12,19 +12,21 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. - --> + --> + 4.0.0 service-proxy-annot ${project.artifactId} jar - - org.membrane-soa - service-proxy-parent - ../pom.xml - 7.0.5 - + + org.membrane-soa + service-proxy-parent + ../pom.xml + 7.0.5 + @@ -87,6 +89,11 @@ 3.0 test + + org.mockito + mockito-core + test + diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCollector.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCollector.java index 5206440861..f04135aab6 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCollector.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCollector.java @@ -27,6 +27,20 @@ * and send it a series of change events. */ public interface BeanCollector { + + default List parseYamlBeanDefinitions(InputStream yamls, Grammar grammar) throws IOException { + List bds = GenericYamlParser.parseMembraneResources(yamls, grammar); + for (BeanDefinition bd : bds) { + handle(new BeanDefinitionChanged(WatchAction.ADDED, bd), false); + } + return bds; + } + + default void finishStaticConfiguration() { + handle(new StaticConfigurationLoaded(), true); + start(); + } + /** * Utility method to ingest a stream of YAML objects as a static configuration and then * start the bean registry. @@ -34,12 +48,8 @@ public interface BeanCollector { * @param grammar the grammar to use for parsing */ default void parseYamls(InputStream yamls, Grammar grammar) throws IOException { - List bds = GenericYamlParser.parseMembraneResources(yamls, grammar); - for (int i = 0; i < bds.size(); i++) { - handle(new BeanDefinitionChanged(WatchAction.ADDED, bds.get(i)), i == bds.size() - 1); - } - handle(new StaticConfigurationLoaded(), true); - start(); + parseYamlBeanDefinitions(yamls, grammar); + finishStaticConfiguration(); } /** diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java index ae8aceabd2..97b7b031fe 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java @@ -26,4 +26,8 @@ public interface BeanRegistry { Grammar getGrammar(); List getBeans(Class clazz); + + Optional getBean(Class clazz); + + void register(String beanName, Object object); } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryAware.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryAware.java new file mode 100644 index 0000000000..ece37dec87 --- /dev/null +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryAware.java @@ -0,0 +1,20 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.annot.beanregistry; + +public interface BeanRegistryAware { + void setRegistry(BeanRegistry registry); +} + diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 90f60e1b26..7e8b7d1de1 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -41,9 +41,10 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { record UidAction(String uid, WatchAction action) {} - public BeanRegistryImplementation(BeanCacheObserver observer, Grammar grammar) { + public BeanRegistryImplementation(BeanCacheObserver observer, BeanRegistryAware registryAware, Grammar grammar) { this.observer = observer; this.grammar = grammar; + registryAware.setRegistry(this); } private Object define(BeanDefinition bd) { @@ -172,4 +173,22 @@ public List getBeans(Class clazz) { .map(clazz::cast) .toList(); } + + public Optional getBean(Class clazz) { + var beans = getBeans(clazz); + if (beans.size() > 1) { + var msg = "One bean was asked. But found %d beans of %s".formatted(beans.size(),clazz); + log.debug(msg); + throw new RuntimeException(msg); + } + return beans.size() == 1 ? Optional.of(beans.getFirst()) : Optional.empty(); + } + + public void register(String beanName, Object object) { + var uuid = UUID.randomUUID().toString(); + BeanContainer bc = new BeanContainer(new BeanDefinition("component", beanName,null, uuid, null)); + bc.setSingleton(object); + singletonBeans.put(uuid,bc); + bcs.put(uuid, bc); + } } diff --git a/annot/src/test/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementationTest.java b/annot/src/test/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementationTest.java new file mode 100644 index 0000000000..3a6b387bb7 --- /dev/null +++ b/annot/src/test/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementationTest.java @@ -0,0 +1,62 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.annot.beanregistry; + +import org.junit.jupiter.api.*; +import org.mockito.*; + +import java.util.*; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +class BeanRegistryImplementationTest { + + private BeanRegistryImplementation registry; + private BeanRegistryAware aware; + + @BeforeEach + void setup() { + aware = Mockito.mock(BeanRegistryAware.class); + registry = new BeanRegistryImplementation(null, aware, null); + } + + @Test + void register() { + A a1 = new A("a1"); + A a2 = new A("a2"); + A a3 = new A("a3"); + registry.register("bean1", a1); + registry.register("bean2", a2); + registry.register("bean3", a3); + List as = registry.getBeans(A.class); + assertEquals(3, as.size()); + assertEquals(Set.of(a1,a2,a3),new HashSet<>(as)); + } + + @Test + void getBean() { + A a1 = new A("a1"); + registry.register("bean1", a1); + assertEquals(a1, registry.getBean(A.class).orElseThrow()); + } + + class A { + String value; + + public A(String value) { + this.value = value; + } + } +} \ No newline at end of file diff --git a/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java b/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java index 72eda7c984..703b37b8cc 100644 --- a/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java +++ b/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java @@ -38,6 +38,14 @@ public class YamlParser { */ private final BeanRegistry beanRegistry; + private static class TestRouter implements BeanRegistryAware { + + @Override + public void setRegistry(BeanRegistry registry) { + + } + } + public YamlParser(String resourceName) throws ClassNotFoundException, NoSuchMethodException, InvocationTargetException, InstantiationException, IllegalAccessException, IOException, InterruptedException { Grammar generator = getGrammar(); @@ -48,7 +56,7 @@ public YamlParser(String resourceName) throws ClassNotFoundException, NoSuchMeth String normalized = resourceName.startsWith("/") ? resourceName.substring(1) : resourceName; - BeanRegistryImplementation impl = new BeanRegistryImplementation(getLatchObserver(cdl), generator); + BeanRegistryImplementation impl = new BeanRegistryImplementation(getLatchObserver(cdl), new TestRouter(), generator); impl.parseYamls(requireNonNull(cl.getResourceAsStream(normalized)), generator); beanRegistry = impl; diff --git a/core/src/main/java/com/predic8/membrane/core/Configuration.java b/core/src/main/java/com/predic8/membrane/core/Configuration.java new file mode 100644 index 0000000000..d1dab26928 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/Configuration.java @@ -0,0 +1,143 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.annot.MCAttribute; +import com.predic8.membrane.annot.MCChildElement; +import com.predic8.membrane.annot.MCElement; +import com.predic8.membrane.core.interceptor.administration.AdminConsoleInterceptor; +import com.predic8.membrane.core.proxies.Proxy; +import com.predic8.membrane.core.util.URIFactory; + +@MCElement(name = "configuration", topLevel = true, component = false) +public class Configuration { + + /** + * Set production to true to run Membrane in production mode. + * In production mode the security level is increased e.g. there is less information + * in error messages sent to clients. + */ + private boolean production; + + private boolean hotDeploy = true; + + private int retryInitInterval = 5 * 60 * 1000; // 5 minutes + + private boolean retryInit = false; + + private String jmxRouterName; + + private URIFactory uriFactory = new URIFactory(false); + + /** + * @param hotDeploy If true the hot deploy feature will be activated during init of the Router. + * @description

Whether changes to the router's configuration file should automatically trigger a restart. + *

+ *

+ * Monitoring the router's configuration file proxies.xml is only possible, if the router + * is created by a Spring Application Context which supports monitoring. + *

+ *

Calling this method does not start or stop the hot deploy feature. It is just for configuration before init is called.

+ * @default true + */ + @MCAttribute + public void setHotDeploy(boolean hotDeploy) { + this.hotDeploy = hotDeploy; + } + + public boolean isHotDeploy() { + return hotDeploy; + } + + /** + * @description number of milliseconds after which reinitialization of <soapProxy>s should be attempted periodically + * @default 5 minutes + */ + @MCAttribute + public void setRetryInitInterval(int retryInitInterval) { + this.retryInitInterval = retryInitInterval; + } + + public int getRetryInitInterval() { + return retryInitInterval; + } + + /** + * @description

Whether the router should continue startup, if initialization of a rule (proxy, serviceProxy or soapProxy) failed + * (for example, when a WSDL a component depends on could not be downloaded).

+ *

If false, the router will exit with code -1 just after startup, when the initialization of a rule failed.

+ *

If true, the router will continue startup, and all rules which could not be initialized will be inactive (=not + * {@link Proxy#isActive()}).

+ *

Inactive rules

+ *

Inactive rules will simply be ignored for routing decisions for incoming requests. + * This means that requests for inactive rules might be routed using different routes or result in a "400 Bad Request" + * when no active route could be matched to the request.

+ *

Once rules become active due to reinitialization, they are considered in future routing decision.

+ *

Reinitialization

+ *

Inactive rules may be reinitialized and, if reinitialization succeeds, become active.

+ *

By default, reinitialization is attempted at regular intervals using a timer (see {@link #setRetryInitInterval(int)}).

+ *

Additionally, using the {@link AdminConsoleInterceptor}, an admin may trigger reinitialization of inactive rules at any time.

+ * @default false + */ + @MCAttribute + public void setRetryInit(boolean retryInit) { + this.retryInit = retryInit; + } + + public boolean isRetryInit() { + return retryInit; + } + + /** + * @description Sets the JMX name for this router. Also declare a global <jmxExporter> instance. + */ + @MCAttribute + public void setJmxRouterName(String jmxRouterName) { + this.jmxRouterName = jmxRouterName; + } + + public String getJmx() { + return jmxRouterName; + } + + /** + * @description

By default the error messages Membrane sends back to an HTTP client provide information to help the caller + * find the problem. The caller might even get sensitive information. In production the error messages should not reveal + * to much details. With this option you can put Membrane in production mode and reduce the amount of information in + * error messages.

+ * @default false + */ + @MCAttribute + public void setProduction(boolean production) { + this.production = production; + } + + public boolean isProduction() { + return production; + } + + /** + * @description Sets the URI factory used by the router. Use this only, if you need to allow + * special (off-spec) characters in URLs which are not supported by java.net.URI . + */ + @MCChildElement(order = -1, allowForeign = true) + public void setUriFactory(URIFactory uriFactory) { + this.uriFactory = uriFactory; + } + + public URIFactory getUriFactory() { + return uriFactory; + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 69ea9d0c19..e0f5ff2e1d 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -17,6 +17,8 @@ import com.predic8.membrane.annot.*; import com.predic8.membrane.annot.beanregistry.BeanDefinition; import com.predic8.membrane.annot.beanregistry.BeanDefinitionChanged; +import com.predic8.membrane.annot.beanregistry.BeanRegistry; +import com.predic8.membrane.annot.beanregistry.BeanRegistryAware; import com.predic8.membrane.annot.yaml.*; import com.predic8.membrane.core.RuleManager.*; import com.predic8.membrane.core.config.spring.*; @@ -79,27 +81,21 @@ outputName = "router-conf.xsd", targetNamespace = "http://membrane-soa.org/proxies/1/") @MCElement(name = "router") -public class Router implements Lifecycle, ApplicationContextAware, BeanNameAware, BeanCacheObserver { +public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver { private static final Logger log = LoggerFactory.getLogger(Router.class.getName()); private ApplicationContext beanFactory; + private BeanRegistry registry; + // // Configuration // - private String id; private String baseLocation; - protected URIFactory uriFactory = new URIFactory(false); - protected String jmxRouterName; - /** - * Set production to true to run Membrane in production mode. - * In production mode the security level is increased e.g. there is less information - * in error messages sent to clients. - */ - private boolean production; + private Configuration config = new Configuration(); // // Components @@ -109,7 +105,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanNameAware protected final FlowController flowController; protected ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); protected Transport transport; - protected GlobalInterceptor globalInterceptor = new GlobalInterceptor(); protected final ResolverMap resolverMap; protected final DNSCache dnsCache = new DNSCache(); private final KubernetesWatcher kubernetesWatcher = new KubernetesWatcher(this); @@ -132,8 +127,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanNameAware // Reinitialization // - private int retryInitInterval = 5 * 60 * 1000; // 5 minutes - private boolean retryInit; private Timer reinitializer; private boolean asynchronousInitialization = false; @@ -210,7 +203,7 @@ public void start() { throw e; } - if (retryInitInterval > 0) + if (config.getRetryInitInterval() > 0) startAutoReinitializer(); } catch (DuplicatePathException e) { System.err.printf(""" @@ -382,7 +375,7 @@ private void initJmx() { try { JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); //exporter.removeBean(prefix + jmxRouterName); - exporter.addBean("org.membrane-soa:00=routers, name=" + jmxRouterName, new JmxRouter(this, exporter)); + exporter.addBean("org.membrane-soa:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); } catch (NoSuchBeanDefinitionException ignored) { // If bean is not available do not init jmx } @@ -403,7 +396,7 @@ private void startAutoReinitializer() { public void run() { tryReinitialization(); } - }, retryInitInterval, retryInitInterval); + }, config.getRetryInitInterval(), config.getRetryInitInterval()); } public void tryReinitialization() { @@ -464,39 +457,6 @@ public boolean isRunning() { } } - /** - * @param hotDeploy If true the hot deploy feature will be activated during init of the Router. - * @description

Whether changes to the router's configuration file should automatically trigger a restart. - *

- *

- * Monitoring the router's configuration file proxies.xml is only possible, if the router - * is created by a Spring Application Context which supports monitoring. - *

- *

Calling this method does not start or stop the hot deploy feature. It is just for configuration before init is called.

- * @default true - */ - @MCAttribute - public void setHotDeploy(boolean hotDeploy) { - hotDeployer = hotDeploy ? new DefaultHotDeployer() : new NullHotDeployer(); - } - - public boolean isHotDeploy() { - return hotDeployer.isEnabled(); - } - - public int getRetryInitInterval() { - return retryInitInterval; - } - - /** - * @description number of milliseconds after which reinitialization of <soapProxy>s should be attempted periodically - * @default 5 minutes - */ - @MCAttribute - public void setRetryInitInterval(int retryInitInterval) { - this.retryInitInterval = retryInitInterval; - } - private ArrayList getInactiveRules() { ArrayList inactive = new ArrayList<>(); for (Proxy proxy : getRuleManager().getRules()) @@ -517,78 +477,14 @@ public ApplicationContext getBeanFactory() { return beanFactory; } - public boolean isRetryInit() { - return retryInit; - } - - /** - * @explanation

Whether the router should continue startup, if initialization of a rule (proxy, serviceProxy or soapProxy) failed - * (for example, when a WSDL a component depends on could not be downloaded).

- *

If false, the router will exit with code -1 just after startup, when the initialization of a rule failed.

- *

If true, the router will continue startup, and all rules which could not be initialized will be inactive (=not - * {@link Proxy#isActive()}).

- *

Inactive rules

- *

Inactive rules will simply be ignored for routing decisions for incoming requests. - * This means that requests for inactive rules might be routed using different routes or result in a "400 Bad Request" - * when no active route could be matched to the request.

- *

Once rules become active due to reinitialization, they are considered in future routing decision.

- *

Reinitialization

- *

Inactive rules may be reinitialized and, if reinitialization succeeds, become active.

- *

By default, reinitialization is attempted at regular intervals using a timer (see {@link #setRetryInitInterval(int)}).

- *

Additionally, using the {@link AdminConsoleInterceptor}, an admin may trigger reinitialization of inactive rules at any time.

- * @default false - */ - @MCAttribute - public void setRetryInit(boolean retryInit) { - this.retryInit = retryInit; - } - - public URIFactory getUriFactory() { - return uriFactory; - } - - /** - * @description Sets the URI factory used by the router. Use this only, if you need to allow - * special (off-spec) characters in URLs which are not supported by java.net.URI . - */ - @MCChildElement(order = -1, allowForeign = true) - public void setUriFactory(URIFactory uriFactory) { - this.uriFactory = uriFactory; - } - public boolean isProduction() { - return production; + return config.isProduction(); } - /** - * @explanation

By default the error messages Membrane sends back to an HTTP client provide information to help the caller - * find the problem. The caller might even get sensitive information. In production the error messages should not reveal - * to much details. With this option you can put Membrane in production mode and reduce the amount of information in - * error messages.

- * @default false - */ - @MCAttribute - public void setProduction(boolean production) { - this.production = production; - } - - public Statistics getStatistics() { return statistics; } - /** - * @description Sets the JMX name for this router. Also declare a global <jmxExporter> instance. - */ - @MCAttribute - public void setJmx(String name) { - jmxRouterName = name; - } - - public String getJmx() { - return jmxRouterName; - } - @SuppressWarnings("NullableProblems") @Override public void setBeanName(String s) { @@ -600,7 +496,7 @@ public void setBeanName(String s) { */ @MCChildElement(order = 2) public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { - this.globalInterceptor = globalInterceptor; + registry.register("globalInterceptor", globalInterceptor); } public String getId() { @@ -633,17 +529,13 @@ public FlowController getFlowController() { return flowController; } - public GlobalInterceptor getGlobalInterceptor() { - return globalInterceptor; - } - public synchronized void setAsynchronousInitialization(boolean asynchronousInitialization) { this.asynchronousInitialization = asynchronousInitialization; notifyAll(); } public void handleAsynchronousInitializationResult(boolean success) { - if (!success && !retryInit) + if (!success && !config.isRetryInit()) System.exit(1); ApiInfo.logInfosAboutStartedProxies(ruleManager); logStartupMessage(); @@ -686,4 +578,38 @@ public AbstractRefreshableApplicationContext getRef() { return bf; throw new RuntimeException("ApplicationContext is not a AbstractRefreshableApplicationContext. Please set ."); } + + @Override + public void setRegistry(BeanRegistry registry) { + this.registry = registry; + } + + public BeanRegistry getRegistry() { + return registry; + } + + public void applyConfiguration(Configuration configuration) { + hotDeployer = configuration.isHotDeploy() ? new DefaultHotDeployer() : new NullHotDeployer(); + this.config = configuration; + } + + public URIFactory getUriFactory() { + return config.getUriFactory(); + } + + /** + * Sets the configuration object for this router. + * Only used for xml + * + * @param config the configuration object + */ + @MCChildElement(order = -1) + public void setConfig(Configuration config) { + this.config = config; + } + + public Configuration getConfig() { + return config; + } + } \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 7f41263e94..171ac6b386 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -14,33 +14,44 @@ package com.predic8.membrane.core.cli; -import com.predic8.membrane.annot.beanregistry.BeanCollector; -import com.predic8.membrane.annot.beanregistry.BeanRegistry; +import com.predic8.membrane.annot.beanregistry.BeanDefinition; import com.predic8.membrane.annot.beanregistry.BeanRegistryImplementation; -import com.predic8.membrane.core.*; -import com.predic8.membrane.core.config.spring.*; -import com.predic8.membrane.core.exceptions.*; -import com.predic8.membrane.core.openapi.serviceproxy.*; -import com.predic8.membrane.core.resolver.*; -import org.apache.commons.cli.*; -import org.jetbrains.annotations.*; -import org.slf4j.*; -import org.springframework.beans.factory.xml.*; - -import java.io.*; -import java.util.*; - -import static com.predic8.membrane.annot.yaml.GenericYamlParser.*; -import static com.predic8.membrane.core.Constants.*; -import static com.predic8.membrane.core.cli.util.JwkGenerator.*; -import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.*; -import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.*; -import static com.predic8.membrane.core.openapi.util.OpenAPIUtil.*; -import static com.predic8.membrane.core.util.ExceptionUtil.*; -import static com.predic8.membrane.core.util.OSUtil.*; -import static com.predic8.membrane.core.util.URIUtil.*; -import static java.lang.Integer.*; -import static org.apache.commons.lang3.exception.ExceptionUtils.*; +import com.predic8.membrane.core.Configuration; +import com.predic8.membrane.core.ExitException; +import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.config.spring.GrammarAutoGenerated; +import com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext; +import com.predic8.membrane.core.exceptions.SpringConfigurationErrorHandler; +import com.predic8.membrane.core.openapi.serviceproxy.APIProxy; +import com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec; +import com.predic8.membrane.core.resolver.ResolverMap; +import com.predic8.membrane.core.resolver.ResourceRetrievalException; +import org.apache.commons.cli.ParseException; +import org.jetbrains.annotations.NotNull; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; + +import java.io.File; +import java.io.IOException; +import java.io.InputStream; +import java.util.List; +import java.util.Optional; + +import static com.predic8.membrane.core.Constants.MEMBRANE_HOME; +import static com.predic8.membrane.core.cli.util.JwkGenerator.generateJWK; +import static com.predic8.membrane.core.cli.util.JwkGenerator.privateJWKtoPublic; +import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.InvalidConfigurationException; +import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.handleXmlBeanDefinitionStoreException; +import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.YES; +import static com.predic8.membrane.core.openapi.util.OpenAPIUtil.isOpenAPIMisplacedError; +import static com.predic8.membrane.core.util.ExceptionUtil.concatMessageAndCauseMessages; +import static com.predic8.membrane.core.util.OSUtil.fixBackslashes; +import static com.predic8.membrane.core.util.URIUtil.pathFromFileURI; +import static java.lang.Integer.parseInt; +import static org.apache.commons.lang3.exception.ExceptionUtils.getMessage; +import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage; public class RouterCLI { @@ -164,17 +175,27 @@ private static Router initRouterByYAML(MembraneCommandLine commandLine, String o private static Router initRouterByYAML(String location) throws Exception { var router = new HttpRouter(); router.setBaseLocation(location); - router.setHotDeploy(false); router.setAsynchronousInitialization(true); - router.start(); GrammarAutoGenerated grammar = new GrammarAutoGenerated(); - BeanCollector collector = new BeanRegistryImplementation(router, grammar); - collector.parseYamls(router.getResolverMap().resolve(location), grammar); + BeanRegistryImplementation reg = new BeanRegistryImplementation(router, router, grammar); + + getConfigDefinition(reg.parseYamlBeanDefinitions(router.getResolverMap().resolve(location), grammar)) + .ifPresent(beanDefinition -> router.applyConfiguration((Configuration) reg.resolve(beanDefinition.getName()))); + + router.start(); + + reg.finishStaticConfiguration(); return router; } + private static @NotNull Optional getConfigDefinition(List bds) { + return bds.stream() + .filter(bd -> "configuration".equals(bd.getKind())) + .findFirst(); + } + private static @NotNull APIProxy getApiProxy(MembraneCommandLine commandLine) throws IOException { APIProxy api = new APIProxy(); api.setPort(commandLine.getCommand().isOptionSet("p") ? diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/TidValidator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/TidValidator.java index 278470771f..c3cfc972e8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/TidValidator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/TidValidator.java @@ -1,3 +1,17 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core.interceptor.jwt; import org.jose4j.jwt.JwtClaims; diff --git a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java index d5545fb6e6..f2aa721b50 100644 --- a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java @@ -34,7 +34,7 @@ public JmxRouter(Router router, JmxExporter exporter) { @ManagedAttribute public String getName(){ - return router.getJmx(); + return router.getConfig().getJmx(); } private void exportServiceProxyList(){ @@ -46,7 +46,7 @@ private void exportServiceProxyList(){ } private void exportServiceProxy(ServiceProxy rule) { - String prefix = "org.membrane-soa:00=serviceProxies, 01=" + router.getJmx()+ ", name="; + String prefix = "org.membrane-soa:00=serviceProxies, 01=" + router.getConfig().getJmx()+ ", name="; exporter.addBean(prefix + rule.getName().replace(":",""), new JmxServiceProxy(rule, router)); } } diff --git a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java index ce453e845f..9d39d62b98 100644 --- a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java +++ b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java @@ -47,7 +47,7 @@ public class KubernetesWatcher { public KubernetesWatcher(Router router) { this.router = router; this.grammar = new GrammarAutoGenerated(); - var br = new BeanRegistryImplementation(router, grammar); + var br = new BeanRegistryImplementation(router, router, grammar); this.beanRegistry = new AsyncBeanCollector(br); } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java index d34112818a..b35df337de 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java @@ -101,7 +101,7 @@ public final void init(Router router) { } active = true; } catch (Exception e) { - if (!router.isRetryInit()) + if (!router.getConfig().isRetryInit()) throw e; log.error("", e); active = false; diff --git a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java index 2359d18564..8d1a15cca7 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java @@ -33,8 +33,8 @@ public abstract class Transport { * SSL and Non-SSL are mixed here, maybe split that in future */ protected final Set menuListeners = new HashSet<>(); - private List interceptors = new Vector<>(); + private Router router; private boolean reverseDNS = true; @@ -62,7 +62,7 @@ public void init(Router router) throws Exception { interceptors.add(getExchangeStoreInterceptor()); interceptors.add(getInterceptor(DispatchingInterceptor.class)); interceptors.add(getInterceptor(ReverseProxyingInterceptor.class)); - interceptors.add(router.getGlobalInterceptor()); + router.getRegistry().getBean(GlobalInterceptor.class).ifPresent(i -> interceptors.add(i )); interceptors.add(getInterceptor(UserFeatureInterceptor.class)); interceptors.add(getInterceptor(InternalRoutingInterceptor.class)); interceptors.add(getInterceptor(HTTPClientInterceptor.class)); diff --git a/core/src/test/java/com/predic8/membrane/core/RouterTest.java b/core/src/test/java/com/predic8/membrane/core/RouterTest.java index 5a534cc82d..91dce137f7 100644 --- a/core/src/test/java/com/predic8/membrane/core/RouterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/RouterTest.java @@ -114,7 +114,7 @@ void devXML() { private static Router createRouter(int port, boolean production) throws IOException { HttpRouter r = new HttpRouter(); - r.setProduction(production); + r.getConfig().setProduction(production); APIProxy api = new APIProxy(); api.setKey(new APIProxyKey(port)); api.getFlow().add(new AbstractInterceptor() { @@ -128,7 +128,7 @@ public String getDisplayName() { return "interceptor"; } }); - r.setHotDeploy(false); + r.getConfig().setHotDeploy(false); r.add(api); r.start(); return r; diff --git a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java index dcd122ea6b..cc9795e7ae 100644 --- a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java @@ -44,7 +44,7 @@ public AzureDnsApiSimulator(int port) { public void start() throws IOException { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); var sp = new ServiceProxy(new ServiceProxyKey(port), "localhost", port); diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java index ef3afe794b..07493028cc 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java @@ -70,7 +70,7 @@ public static void start() throws IOException { private static void initializeElasticSearchMock() throws IOException { elasticMock = new HttpRouter(); - elasticMock.setHotDeploy(false); + elasticMock.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3066), null, 0); sp.getFlow().add(createBodyLoggingInterceptor()); sp.getFlow().add(createElasticSearchMockInterceptor()); @@ -86,7 +86,7 @@ private static void initializeElasticSearchMock() throws IOException { private static void initializeGateway(boolean addLoggingInterceptors) throws IOException { gateway = new HttpRouter(); - gateway.setHotDeploy(false); + gateway.getConfig().setHotDeploy(false); es = new ElasticSearchExchangeStore(); es.setLocation("http://localhost:3066"); es.setUpdateIntervalMs(100); @@ -103,7 +103,7 @@ private static void initializeGateway(boolean addLoggingInterceptors) throws IOE private static void initializeBackend() throws IOException { back = new HttpRouter(); - back.setHotDeploy(false); + back.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); StaticInterceptor si = new StaticInterceptor(); si.setSrc(RESPONSE_BODY); diff --git a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java index 3d7ed4766e..0f833435ea 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java @@ -185,7 +185,7 @@ public X509Certificate[] getAcceptedIssuers() { private HttpRouter setupRouter(boolean http2, boolean http2Client) { HttpRouter router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(http2 ? 3060 : 3059), "localhost", 3060); if (http2) { SSLParser sslParser = getSslParserForHttp2(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index 35153518d2..faf46879c2 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -46,7 +46,7 @@ class AdminApiInterceptorTest { @BeforeAll static void setUp() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); sp.getFlow().add(new FastWebSocketClosingInterceptor()); // speeds up test execution AdminApiInterceptor e = new AdminApiInterceptor(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index 75d2d7b0e8..535746c493 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -40,7 +40,7 @@ abstract class AbstractInternalServiceRoutingInterceptorTest { @BeforeEach void setup() throws Exception { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); configure(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java index 25e93ab28c..3d7bcf5b01 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java @@ -33,7 +33,7 @@ public class JsonProtectionInterceptorTest { private static JsonProtectionInterceptor buildJPI(boolean prod) { Router router = new Router(); - router.setProduction(prod); + router.getConfig().setProduction(prod); JsonProtectionInterceptor jpi = new JsonProtectionInterceptor(); jpi.setMaxTokens(4096); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java index d7d286f1b2..493c24fcb5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java @@ -22,7 +22,7 @@ public abstract class AuthServerMock extends HttpRouter { public AuthServerMock() throws IOException { getTransport().setBacklog(10_000); getTransport().setSocketTimeout(10_000); - setHotDeploy(false); + getConfig().setHotDeploy(false); getTransport().setConcurrentConnectionLimitPerIp(500); getRuleManager().addProxyAndOpenPortIfNew(mockServiceProxy()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java index c9954b421c..56f80ff4fd 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java @@ -67,7 +67,7 @@ public void init() throws IOException { mockAuthServer = new HttpRouter(); mockAuthServer.getTransport().setBacklog(10000); mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.setHotDeploy(false); + mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit); mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); mockAuthServer.start(); @@ -75,7 +75,7 @@ public void init() throws IOException { oauth2Resource = new HttpRouter(); oauth2Resource.getTransport().setBacklog(10000); oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.setHotDeploy(false); + oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit); oauth2Resource.getRuleManager().addProxy(getErrorCaptor(), MANUAL); oauth2Resource.getRuleManager().addProxy(getConfiguredOAuth2Resource(), MANUAL); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java index 75a93fdafc..e907475ef3 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java @@ -82,12 +82,12 @@ public void init() throws IOException, JoseException { createKey(); mockAuthServer = new HttpRouter(); - mockAuthServer.setHotDeploy(false); + mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); mockAuthServer.start(); oauth2Resource = new HttpRouter(); - oauth2Resource.setHotDeploy(false); + oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getRuleManager().addProxyAndOpenPortIfNew(getConfiguredOAuth2Resource()); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java index 9f276d4f9b..4f5ab3953f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java @@ -70,7 +70,7 @@ public void init() throws IOException { mockAuthServer = new HttpRouter(); mockAuthServer.getTransport().setBacklog(10000); mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.setHotDeploy(false); + mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit+1); mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); mockAuthServer.start(); @@ -78,7 +78,7 @@ public void init() throws IOException { oauth2Resource = new HttpRouter(); oauth2Resource.getTransport().setBacklog(10000); oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.setHotDeploy(false); + oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit+1); oauth2Resource.getRuleManager().addProxyAndOpenPortIfNew(getConfiguredOAuth2Resource()); oauth2Resource.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index 557690b698..149a5b9842 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -67,7 +67,7 @@ public void init() { oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(10000); oauth2Resource.getTransport().setBacklog(10000); oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.setHotDeploy(false); + oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); ServiceProxy sp1_oauth2resource2 = createOAuth2Resource2ServiceProxy(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java index 3745ad92e6..15b56638a1 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java @@ -81,7 +81,7 @@ public void init() throws IOException, JoseException { mockAuthServer = new HttpRouter(); mockAuthServer.getTransport().setBacklog(10000); mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.setHotDeploy(false); + mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); mockAuthServer.getRuleManager().addProxy(getMockAuthServiceProxy(SERVER_PORT, tc.susiFlowId), MANUAL); mockAuthServer.getRuleManager().addProxy(getMockAuthServiceProxy(SERVER_PORT, tc.peFlowId), MANUAL); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java index a27a4bbeed..093af82b2e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java @@ -68,7 +68,7 @@ void setUp() throws Exception { @BeforeAll static void startup() throws Exception { interceptorRouter = new Router(); - interceptorRouter.setHotDeploy(false); + interceptorRouter.getConfig().setHotDeploy(false); interceptorRouter.setExchangeStore(new ForgetfulExchangeStore()); interceptorRouter.setTransport(new HttpTransport()); @@ -92,7 +92,7 @@ static void startup() throws Exception { interceptorRouter.start(); shadowingRouter = new Router(); - shadowingRouter.setHotDeploy(false); + shadowingRouter.getConfig().setHotDeploy(false); shadowingRouter.setExchangeStore(new ForgetfulExchangeStore()); shadowingRouter.setTransport(new HttpTransport()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java index d249bb6038..f42317aa16 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java @@ -40,7 +40,7 @@ public class SoapAndInternalProxyTest { @BeforeEach void setup() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java index 9e28337587..e0216123fd 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java @@ -346,21 +346,16 @@ public List getBeans() { return List.of(); } - @Override public void parseYamls(InputStream yamls, Grammar grammar) throws IOException { BeanCollector.super.parseYamls(yamls, grammar); } @Override - public void handle(ChangeEvent changeEvent, boolean isLast) { - - } + public void handle(ChangeEvent changeEvent, boolean isLast) {} @Override - public void start() { - - } + public void start() {} @Override public Grammar getGrammar() { @@ -371,6 +366,14 @@ public Grammar getGrammar() { public List getBeans(Class clazz) { return List.of(); } + + @Override + public Optional getBean(Class clazz) { + return Optional.empty(); + } + + @Override + public void register(String beanName, Object object) {} } private static APIProxy parse(String yaml, BeanRegistry reg) { diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java index ad52b6231d..b51289b797 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java @@ -42,7 +42,7 @@ public class KubernetesClientTest { @BeforeAll public static void prepare() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3053), null, 0); sp.getFlow().add(new AbstractInterceptor() { @Override diff --git a/core/src/test/java/com/predic8/membrane/core/lang/groovy/GroovyBuiltInFunctionsTest.java b/core/src/test/java/com/predic8/membrane/core/lang/groovy/GroovyBuiltInFunctionsTest.java index b333e6165d..8cab5a1ee7 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/groovy/GroovyBuiltInFunctionsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/groovy/GroovyBuiltInFunctionsTest.java @@ -1,3 +1,17 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core.lang.groovy; import com.predic8.membrane.core.http.*; diff --git a/core/src/test/java/com/predic8/membrane/core/lang/spel/functions/SpELBuiltInFunctionsTest.java b/core/src/test/java/com/predic8/membrane/core/lang/spel/functions/SpELBuiltInFunctionsTest.java index 72cc30f4c4..5d88cfcc9a 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/spel/functions/SpELBuiltInFunctionsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/spel/functions/SpELBuiltInFunctionsTest.java @@ -1,3 +1,17 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core.lang.spel.functions; import com.predic8.membrane.core.lang.spel.*; diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index 8afb05fc91..a4284d77bc 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -46,7 +46,7 @@ class ApiDocsInterceptorTest { @BeforeEach public void setUp() throws Exception { router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); exc.setRequest(new Request.Builder().get("/foo").build()); exc.setOriginalRequestUri("/foo"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index 44f043f4a1..a6ee16e7d0 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -41,7 +41,7 @@ public class OpenAPI31ReferencesTest { @BeforeAll public static void setUp() throws Exception { router = new HttpRouter(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); OpenAPISpec spec = new OpenAPISpec(); spec.location = getPathFromResource( "openapi/specs/oas31/request-reference.yaml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java index 76dd954d87..22584d01b3 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java @@ -38,7 +38,7 @@ public class OpenAPI31Test { @BeforeEach public void setUp() { Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); petstore_v3_1 = new OpenAPISpec(); petstore_v3_1.location = getPathFromResource("openapi/specs/petstore-v3.1.json"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index 915aae8e06..2bd3a7da01 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -49,7 +49,7 @@ class OpenAPIInterceptorTest { @BeforeEach public void setUp() { router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); specInfoServers = new OpenAPISpec(); specInfoServers.location = getPathFromResource("openapi/specs/info-servers.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java index 8a733389e9..f055f13b62 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java @@ -52,7 +52,7 @@ public class OpenAPIPublisherInterceptorTest { @BeforeEach void setUp() { Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); openAPIRecordFactory = new OpenAPIRecordFactory(router); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java index 695e37ba39..ab081d8576 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java @@ -30,7 +30,7 @@ class OpenAPIRecordTest { @BeforeEach void setUp() { Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); get.setRequest(new Request.Builder().method("GET").build()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java index 5a01cd176c..d47e8faedf 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java @@ -50,7 +50,7 @@ void setUp() { rewriteAll.basePath = "/foo"; Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); OpenAPIRecordFactory openAPIRecordFactory = new OpenAPIRecordFactory(router); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java index ca0f174adb..bb8bef51db 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java @@ -41,7 +41,7 @@ public void setUp() throws Exception { router = new Router(); router.setTransport(new HttpTransport()); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); router.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy()); router.getRuleManager().addProxyAndOpenPortIfNew(getTargetProxy()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java index 2202d9b084..90cd11bb06 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java @@ -43,7 +43,7 @@ protected Exchange getExchange(String method, String path, SecurityScheme scheme protected static Router getRouter() { Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); return router; } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java index 461cbe8e69..a07a7e3999 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java @@ -43,7 +43,7 @@ public class BasicAuthSecurityValidationTest { @BeforeEach void setUpSpec() { Router router = new Router(); - router.setUriFactory(new URIFactory()); + router.getConfig().setUriFactory(new URIFactory()); OpenAPISpec spec = new OpenAPISpec(); spec.location = getPathFromResource("openapi/specs/security/http-basic.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index 094dba67ff..b5ee17935c 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -63,7 +63,7 @@ void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int pro private static @NotNull Router createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) { Router proxy = new Router(); - proxy.setHotDeploy(false); + proxy.getConfig().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(proxyPort)); rule.getFlow().add(new AbstractInterceptor() { @Override @@ -118,7 +118,7 @@ private static void testClient(boolean backendUsesSSL, int backendPort, HttpClie private static @NotNull Router createBackend(boolean backendUsesSSL, int backendPort) { // Step 1: create the backend Router backend = new Router(); - backend.setHotDeploy(false); + backend.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(backendPort), null, 0); if (backendUsesSSL) { sp.setSslInboundParser(getSslParser("classpath:/ssl-rsa.keystore")); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index 529c3ac334..8283516eee 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -54,7 +54,7 @@ public class ProxyTest { public static void init() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(3055)); rule.getFlow().add(new AbstractInterceptor() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java index cd93114775..dae0c8f08a 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java @@ -29,7 +29,7 @@ public class SOAPProxyWSDLPublisherInterceptorTest { @BeforeAll static void setUp() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java index c09633961c..a3e16c0513 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java @@ -33,7 +33,7 @@ public class ServiceProxyWSDLInterceptorsTest { @BeforeAll static void setUp() { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 6385619bd7..60331a7272 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -51,8 +51,8 @@ void startRouter() { HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); r.setHttpClientConfig(httpClientConfig); - r.setHotDeploy(false); - r.setRetryInit(true); + r.getConfig().setHotDeploy(false); + r.getConfig().setRetryInit(true); sp = new SOAPProxy(); sp.setPort(2000); @@ -69,7 +69,7 @@ void startRouter() { sp2.setPort(2001); sp2.setWsdl("http://localhost:4000?wsdl"); r2 = new Router(); - r2.setHotDeploy(false); + r2.getConfig().setHotDeploy(false); r2.getRules().add(sp2); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java index 57c8535e26..e35bf95c61 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java @@ -48,7 +48,7 @@ private void setupMembrane() { hcc.getRetryHandler().setRetries(1); proxyRouter = new HttpRouter(); - proxyRouter.setHotDeploy(false); + proxyRouter.getConfig().setHotDeploy(false); proxyRouter.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(hcc); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3023), "localhost", 3022); @@ -58,7 +58,7 @@ private void setupMembrane() { private void setupSlowBackend() throws Exception { slowBackend = new HttpRouter(); - slowBackend.setHotDeploy(false); + slowBackend.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3022), "", -1); sp.getFlow().add(new AbstractInterceptor(){ diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java index ad91d08b7f..5ac41b380c 100755 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java @@ -14,6 +14,7 @@ package com.predic8.membrane.core.transport.http; +import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.GlobalInterceptor; @@ -39,14 +40,15 @@ public class HttpTransportTest { private final GlobalInterceptor globalInterceptor = new GlobalInterceptor(); @BeforeEach - public void before() throws Exception { + void before() throws Exception { when(resolverMap.getHTTPSchemaResolver()).thenReturn(httpSchemaResolver); when(router.getResolverMap()).thenReturn(resolverMap); when(router.getRuleManager()).thenReturn(ruleManager); when(router.getExchangeStore()).thenReturn(exchangeStore); - when(router.getGlobalInterceptor()).thenReturn(globalInterceptor); when(router.getHttpClientFactory()).thenReturn(new HttpClientFactory(null)); when(router.getStatistics()).thenReturn(statistics); + BeanRegistryImplementation value = new BeanRegistryImplementation(null, router, null); // Do not inline! Otherwise mocking is not possible! + when(router.getRegistry()).thenReturn(value); transport = new HttpTransport(); transport.init(router); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java index 8f7c0729aa..12cb574297 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java @@ -36,7 +36,7 @@ class IllegalCharactersInURLTest { @BeforeEach void init() throws Exception { r = new HttpRouter(); - r.setHotDeploy(false); + r.getConfig().setHotDeploy(false); r.add(new ServiceProxy(new ServiceProxyKey(3027), "localhost", 3028)); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey(3028), null, 80); sp2.getFlow().add(new AbstractInterceptor() { @@ -68,13 +68,13 @@ void apacheHttpClient() { @Test void illegal_with_router_tolerant_urifactory() throws Exception { - r.setUriFactory(new URIFactory(true)); + r.getConfig().setUriFactory(new URIFactory(true)); makeCallWithIllegalCharacters(200); } @Test void illegal_with_router_intolerant_urifactory() throws Exception { - r.setUriFactory(new URIFactory(false)); + r.getConfig().setUriFactory(new URIFactory(false)); makeCallWithIllegalCharacters(400); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java index 0a75bccca9..75178273df 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java @@ -52,7 +52,7 @@ public void setup() { sslParser.getKeyStore().setKeyPassword("secret"); router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3049), "localhost", 80); sp.setSslInboundParser(sslParser); sp.getFlow().add(new AbstractInterceptor() { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java index 30c0424210..23de4682c9 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java @@ -40,7 +40,7 @@ public class HttpsKeepAliveTest { @BeforeAll public static void startServer() { server = new HttpRouter(); - server.setHotDeploy(false); + server.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(); sp.setPort(3063); SSLParser sslIB = new SSLParser(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index b7ab5e7bc2..9405efecb3 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -86,7 +86,7 @@ public void doit() throws Exception { private static Router createTLSServer(int port) { Router router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(port), null, 0); SSLParser sslInboundParser = new SSLParser(); KeyStore keyStore = new KeyStore(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java index 46b53d1c53..6738c8771c 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java @@ -71,7 +71,7 @@ public AcmeServerSimulator(int port, int challengePort, boolean actuallyPerformC public void start() throws IOException { router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(port), "localhost", 80); sp.getFlow().add(new AbstractInterceptor() { final ObjectMapper om = new ObjectMapper(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java index 65cd376de2..63f8119848 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java @@ -67,7 +67,7 @@ public void all() throws Exception { acme.setAcmeSynchronizedStorage(new MemoryStorage()); HttpRouter router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); SSLParser sslParser = new SSLParser(); sslParser.setAcme(acme); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey(3051), "localhost", 80); diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index fcd8f653bc..48d4e09fdf 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -66,7 +66,7 @@ public static void setup() throws Exception { private static void setupGateway() throws Exception { gw = new HttpRouter(); - gw.setHotDeploy(false); + gw.getConfig().setHotDeploy(false); gw.getRuleManager().addProxyAndOpenPortIfNew(createCitiesSoapProxyGateway()); gw.getRuleManager().addProxyAndOpenPortIfNew(createTwoServicesSOAPProxyGateway("ServiceA")); gw.init(); diff --git a/core/src/test/java/com/predic8/membrane/integration/Util.java b/core/src/test/java/com/predic8/membrane/integration/Util.java index 70bb23dc4b..5e236c78e8 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Util.java +++ b/core/src/test/java/com/predic8/membrane/integration/Util.java @@ -25,7 +25,7 @@ public class Util { public static HttpRouter basicRouter(Proxy... proxies){ HttpRouter router = new HttpRouter(); router.getTransport().setForceSocketCloseOnHotDeployAfter(1000); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); Arrays.stream(proxies).forEach(rule -> router.getRuleManager().addProxy(rule, RuleManager.RuleDefinitionSource.MANUAL)); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java index d78955cc51..65d6be89f1 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java @@ -57,7 +57,7 @@ public static void init() { server.getTransport().setConcurrentConnectionLimitPerIp(CONCURRENT_THREADS); server.getTransport().setBacklog(CONCURRENT_THREADS); server.getTransport().setSocketTimeout(10000); - server.setHotDeploy(false); + server.getConfig().setHotDeploy(false); server.getRuleManager().addProxy(createServiceProxy(), MANUAL); server.start(); } diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java index 8a9796bc69..2750f74d80 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java @@ -68,7 +68,7 @@ public void all() throws Exception { acme.setAcmeSynchronizedStorage(new MemoryStorage()); HttpRouter router = new HttpRouter(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); SSLParser sslParser = new SSLParser(); sslParser.setAcme(acme); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey(3051), "localhost", 80); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java index 89144f5a14..2f25f9d350 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java @@ -54,7 +54,7 @@ class OAuth2Test { @BeforeAll static void startup() throws Exception { router = new Router(); - router.setHotDeploy(false); + router.getConfig().setHotDeploy(false); router.setExchangeStore(new ForgetfulExchangeStore()); router.setTransport(new HttpTransport()); @@ -68,7 +68,7 @@ static void startup() throws Exception { router.start(); router2 = new Router(); - router2.setHotDeploy(false); + router2.getConfig().setHotDeploy(false); router2.setExchangeStore(new ForgetfulExchangeStore()); router2.setTransport(new HttpTransport()); diff --git a/distribution/examples/loadbalancing/6-health-monitor/proxies-tls.xml b/distribution/examples/loadbalancing/6-health-monitor/proxies-tls.xml index 6ca221808d..131aee79e5 100644 --- a/distribution/examples/loadbalancing/6-health-monitor/proxies-tls.xml +++ b/distribution/examples/loadbalancing/6-health-monitor/proxies-tls.xml @@ -16,7 +16,8 @@ - + + diff --git a/distribution/examples/loadbalancing/6-health-monitor/proxies.xml b/distribution/examples/loadbalancing/6-health-monitor/proxies.xml index a49c4c6857..a4e2417162 100644 --- a/distribution/examples/loadbalancing/6-health-monitor/proxies.xml +++ b/distribution/examples/loadbalancing/6-health-monitor/proxies.xml @@ -12,7 +12,7 @@ - + From e76ce7fc29fd330ecd4d4ec74ad1f80af87fc963 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 24 Dec 2025 13:22:16 +0100 Subject: [PATCH 02/40] refactor: streamline exception messages, improve logging, and enhance Javadoc comments across classes --- .../annot/beanregistry/BeanRegistry.java | 16 +++++++++++++++- .../beanregistry/BeanRegistryImplementation.java | 8 ++++---- .../membrane/annot/yaml/GenericYamlParser.java | 7 +------ .../com/predic8/membrane/core/cli/RouterCLI.java | 2 +- .../core/interceptor/GlobalInterceptor.java | 2 +- 5 files changed, 22 insertions(+), 13 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java index 97b7b031fe..3c5390144e 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java @@ -27,7 +27,21 @@ public interface BeanRegistry { List getBeans(Class clazz); + /** + * Retrieves a single bean of the specified type. + * + * @param clazz the class of the bean to retrieve + * @param the bean type + * @return Optional containing the bean if exactly one exists, empty otherwise + * @throws RuntimeException if multiple beans of the specified type exist + */ Optional getBean(Class clazz); - void register(String beanName, Object object); + /** + * Registers a bean with the specified name. + * + * @param beanName the name to register the bean under + * @param bean instance to register (must not be null) + */ + void register(String beanName, Object bean); } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 7e8b7d1de1..bdd6e52fc7 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -178,17 +178,17 @@ public Optional getBean(Class clazz) { var beans = getBeans(clazz); if (beans.size() > 1) { var msg = "One bean was asked. But found %d beans of %s".formatted(beans.size(),clazz); - log.debug(msg); + log.error(msg); throw new RuntimeException(msg); } return beans.size() == 1 ? Optional.of(beans.getFirst()) : Optional.empty(); } - public void register(String beanName, Object object) { + public void register(String beanName, Object bean) { var uuid = UUID.randomUUID().toString(); BeanContainer bc = new BeanContainer(new BeanDefinition("component", beanName,null, uuid, null)); - bc.setSingleton(object); - singletonBeans.put(uuid,bc); + bc.setSingleton(bean); + singletonBeans.put(uuid,bean); bcs.put(uuid, bc); } } diff --git a/annot/src/main/java/com/predic8/membrane/annot/yaml/GenericYamlParser.java b/annot/src/main/java/com/predic8/membrane/annot/yaml/GenericYamlParser.java index 9a19b7f2ea..d586e4d2b4 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/yaml/GenericYamlParser.java +++ b/annot/src/main/java/com/predic8/membrane/annot/yaml/GenericYamlParser.java @@ -105,12 +105,7 @@ public static List parseMembraneResources(@NotNull InputStream r try (resource) { return parseToBeanDefinitions(resource, grammar); } catch (JsonParseException e) { - throw new IOException( - "Invalid YAML: multiple configurations must be separated by '---' " - + "(at line " + e.getLocation().getLineNr() - + ", column " + e.getLocation().getColumnNr() + ").", - e - ); + throw new IOException("Invalid YAML: multiple configurations must be separated by '---' (at line %d, column %d).".formatted(e.getLocation().getLineNr(), e.getLocation().getColumnNr()), e); } } diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 171ac6b386..d5155ad378 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -173,7 +173,7 @@ private static Router initRouterByYAML(MembraneCommandLine commandLine, String o } private static Router initRouterByYAML(String location) throws Exception { - var router = new HttpRouter(); + var router = new Router(); router.setBaseLocation(location); router.setAsynchronousInitialization(true); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/GlobalInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/GlobalInterceptor.java index 476def64d3..d09fd3c491 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/GlobalInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/GlobalInterceptor.java @@ -22,7 +22,7 @@ * @description The global chain applies plugins to all endpoints, enabling centralized features * such as global user authentication, logging, and other cross-cutting concerns. */ -@MCElement(name = "global", excludeFromFlow = true) +@MCElement(name = "global", excludeFromFlow = true, component = false, topLevel = true) public class GlobalInterceptor extends AbstractFlowWithChildrenInterceptor { @Override From e21be9afcf7e042dd33a3c614ba2aab1e8e0ea0f Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 24 Dec 2025 19:53:03 +0100 Subject: [PATCH 03/40] feat: global interceptor support for YAML --- .../annot/beanregistry/BeanContainer.java | 7 ++- .../annot/beanregistry/BeanDefinition.java | 10 ++++ .../BeanRegistryImplementation.java | 4 +- .../com/predic8/membrane/core/Router.java | 55 +++++++++++-------- .../predic8/membrane/core/cli/RouterCLI.java | 19 +++++-- .../membrane/core/transport/Transport.java | 4 ++ 6 files changed, 69 insertions(+), 30 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index 87d143e2b8..e5ef1a3318 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -14,8 +14,6 @@ package com.predic8.membrane.annot.beanregistry; -import com.fasterxml.jackson.databind.JsonNode; - public class BeanContainer { private final BeanDefinition definition; /** @@ -39,4 +37,9 @@ public void setSingleton(Object singleton) { public BeanDefinition getDefinition() { return definition; } + + @Override + public String toString() { + return "BeanContainer: %s of %s".formatted( definition.getName(),definition.getKind()); + } } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java index 4530a030c5..9b81626a2a 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java @@ -100,4 +100,14 @@ public boolean isPrototype() { return PROTOTYPE.equals(getScope()); } + @Override + public String toString() { + return "BeanDefinition{" + + "name='" + name + '\'' + + ", namespace='" + namespace + '\'' + + ", uid='" + uid + '\'' + + ", node=" + node + + ", kind='" + kind + '\'' + + '}'; + } } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index bdd6e52fc7..923e43048b 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -80,7 +80,9 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { if (!bd.isComponent() && observer.isActivatable(bd)) { uidsToActivate.add(new UidAction(bd.getUid(), action)); } - + if ("global".equals(bd.getKind())) { + uidsToActivate.add(new UidAction(bd.getUid(), action)); + } if (isLast) activationRun(); } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index e0f5ff2e1d..6990c37429 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -15,14 +15,10 @@ package com.predic8.membrane.core; import com.predic8.membrane.annot.*; -import com.predic8.membrane.annot.beanregistry.BeanDefinition; -import com.predic8.membrane.annot.beanregistry.BeanDefinitionChanged; -import com.predic8.membrane.annot.beanregistry.BeanRegistry; -import com.predic8.membrane.annot.beanregistry.BeanRegistryAware; +import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.annot.yaml.*; import com.predic8.membrane.core.RuleManager.*; import com.predic8.membrane.core.config.spring.*; -import com.predic8.membrane.core.exceptions.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.administration.*; @@ -89,6 +85,8 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA private BeanRegistry registry; + private boolean openPorts = true; + // // Configuration // @@ -242,14 +240,6 @@ public void start() { synchronized (lock) { running = true; } - - ApiInfo.logInfosAboutStartedProxies(ruleManager); - if (!asynchronousInitialization) - logStartupMessage(); - } - - private static void logStartupMessage() { - log.info("{}{} {} up and running!{}", BRIGHT_CYAN(), PRODUCT_NAME, VERSION, RESET()); } public Collection getRules() { @@ -307,6 +297,7 @@ public Transport getTransport() { */ @MCChildElement(order = 1, allowForeign = true) public void setTransport(Transport transport) { + transport.setRouter(this); this.transport = transport; } @@ -350,7 +341,10 @@ public ExecutorService getBackgroundInitializer() { public void add(Proxy proxy) throws IOException { if (proxy instanceof SSLableProxy sp) { - ruleManager.addProxyAndOpenPortIfNew(sp); + if (openPorts) + ruleManager.addProxyAndOpenPortIfNew(sp); + else + ruleManager.addProxy(sp, RuleDefinitionSource.MANUAL); } else { ruleManager.addProxy(proxy, RuleDefinitionSource.MANUAL); } @@ -538,12 +532,15 @@ public void handleAsynchronousInitializationResult(boolean success) { if (!success && !config.isRetryInit()) System.exit(1); ApiInfo.logInfosAboutStartedProxies(ruleManager); - logStartupMessage(); setAsynchronousInitialization(false); } @Override public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { + if (bean instanceof GlobalInterceptor) { + return; + } + if (!(bean instanceof Proxy newProxy)) { throw new IllegalArgumentException("Bean must be a Proxy instance, but got: " + bean.getClass().getName()); } @@ -551,14 +548,19 @@ public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBe if (newProxy.getName() == null) newProxy.setName(bdc.bd().getName()); - try { - newProxy.init(this); - } catch (ConfigurationException e) { - SpringConfigurationErrorHandler.handleRootCause(e, log); - throw e; - } catch (Exception e) { - throw new RuntimeException("Could not init rule.", e); - } + // TODO: Code Should be deleted before merge + // Only kept for discussion + // init in Proxies was called twice, here and in Router.initRemainingRules + // We should only keep one place. + +// try { +// newProxy.init(this); +// } catch (ConfigurationException e) { +// SpringConfigurationErrorHandler.handleRootCause(e, log); +// throw e; +// } catch (Exception e) { +// throw new RuntimeException("Could not init rule.", e); +// } if (bdc.action().isAdded()) add(newProxy); @@ -612,4 +614,11 @@ public Configuration getConfig() { return config; } + public boolean isOpenPorts() { + return openPorts; + } + + public void setOpenPorts(boolean openPorts) { + this.openPorts = openPorts; + } } \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index d5155ad378..33d8a1e878 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -27,6 +27,7 @@ import com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec; import com.predic8.membrane.core.resolver.ResolverMap; import com.predic8.membrane.core.resolver.ResourceRetrievalException; +import com.predic8.schema.*; import org.apache.commons.cli.ParseException; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -39,7 +40,7 @@ import java.util.List; import java.util.Optional; -import static com.predic8.membrane.core.Constants.MEMBRANE_HOME; +import static com.predic8.membrane.core.Constants.*; import static com.predic8.membrane.core.cli.util.JwkGenerator.generateJWK; import static com.predic8.membrane.core.cli.util.JwkGenerator.privateJWKtoPublic; import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.InvalidConfigurationException; @@ -49,6 +50,8 @@ import static com.predic8.membrane.core.util.ExceptionUtil.concatMessageAndCauseMessages; import static com.predic8.membrane.core.util.OSUtil.fixBackslashes; import static com.predic8.membrane.core.util.URIUtil.pathFromFileURI; +import static com.predic8.membrane.core.util.text.TerminalColors.BRIGHT_CYAN; +import static com.predic8.membrane.core.util.text.TerminalColors.RESET; import static java.lang.Integer.parseInt; import static org.apache.commons.lang3.exception.ExceptionUtils.getMessage; import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage; @@ -153,7 +156,9 @@ public static String getExceptionMessageWithCauses(Throwable throwable) { private static Router initRouterByConfig(MembraneCommandLine commandLine) throws Exception { String config = getRulesFile(commandLine); if (config.endsWith(".xml")) { - return initRouterByXml(config); + Router router = initRouterByXml(config); + logStartupMessage(); + return router; } if (config.endsWith(".yaml") || config.endsWith(".yml")) { return initRouterByYAML(config); @@ -174,6 +179,7 @@ private static Router initRouterByYAML(MembraneCommandLine commandLine, String o private static Router initRouterByYAML(String location) throws Exception { var router = new Router(); + router.setOpenPorts(false); router.setBaseLocation(location); router.setAsynchronousInitialization(true); @@ -183,10 +189,11 @@ private static Router initRouterByYAML(String location) throws Exception { getConfigDefinition(reg.parseYamlBeanDefinitions(router.getResolverMap().resolve(location), grammar)) .ifPresent(beanDefinition -> router.applyConfiguration((Configuration) reg.resolve(beanDefinition.getName()))); - router.start(); - reg.finishStaticConfiguration(); + router.start(); + router.getRuleManager().openPorts(); + logStartupMessage(); return router; } @@ -371,4 +378,8 @@ private static String prefix(String dir) { } return dir; } + + private static void logStartupMessage() { + log.info("{}{} {} up and running!{}", BRIGHT_CYAN(), PRODUCT_NAME, VERSION, RESET()); + } } \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java index 8d1a15cca7..d469c28745 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java @@ -147,4 +147,8 @@ public int getConcurrentConnectionLimitPerIp() { public void setConcurrentConnectionLimitPerIp(int concurrentConnectionLimitPerIp) { this.concurrentConnectionLimitPerIp = concurrentConnectionLimitPerIp; } + + public void setRouter(Router router) { + this.router = router; + } } From dfdca8608ece5d58f5635540707e6c54dcf09ec6 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 24 Dec 2025 20:19:27 +0100 Subject: [PATCH 04/40] refactor: streamline imports, remove unused methods, and improve exception formatting in `Router` --- .../annot/beanregistry/BeanDefinition.java | 6 ++---- .../java/com/predic8/membrane/core/Router.java | 16 ++-------------- 2 files changed, 4 insertions(+), 18 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java index 9b81626a2a..eaaea4951b 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java @@ -13,10 +13,8 @@ limitations under the License. */ package com.predic8.membrane.annot.beanregistry; -import com.fasterxml.jackson.databind.JsonNode; -import com.predic8.membrane.annot.yaml.WatchAction; - -import static com.predic8.membrane.annot.yaml.WatchAction.*; +import com.fasterxml.jackson.databind.*; +import com.predic8.membrane.annot.yaml.*; public class BeanDefinition { diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 6990c37429..18d1bccd12 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -19,6 +19,7 @@ import com.predic8.membrane.annot.yaml.*; import com.predic8.membrane.core.RuleManager.*; import com.predic8.membrane.core.config.spring.*; +import com.predic8.membrane.core.exceptions.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.administration.*; @@ -48,10 +49,8 @@ import java.util.Timer; import java.util.concurrent.*; -import static com.predic8.membrane.core.Constants.*; import static com.predic8.membrane.core.jmx.JmxExporter.*; import static com.predic8.membrane.core.util.DLPUtil.*; -import static com.predic8.membrane.core.util.text.TerminalColors.*; import static java.util.concurrent.Executors.*; /** @@ -166,7 +165,7 @@ public static Router init(String resource) { bf.start(); if (bf.getBeansOfType(Router.class).size() > 1) { - throw new RuntimeException("More than one router found in spring config (beans {}). This is not supported anymore.".formatted(bf.getBeanDefinitionNames())); + throw new RuntimeException("More than one router found in spring config (beans %s). This is not supported anymore.".formatted(bf.getBeanDefinitionNames())); } return bf.getBean("router", Router.class); @@ -438,12 +437,6 @@ public void stop() { } } - public void stopAll() { - for (String s : this.getBeanFactory().getBeanNamesForType(Router.class)) { - ((Router) this.getBeanFactory().getBean(s)).stop(); - } - } - @Override public boolean isRunning() { synchronized (lock) { @@ -552,7 +545,6 @@ public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBe // Only kept for discussion // init in Proxies was called twice, here and in Router.initRemainingRules // We should only keep one place. - // try { // newProxy.init(this); // } catch (ConfigurationException e) { @@ -614,10 +606,6 @@ public Configuration getConfig() { return config; } - public boolean isOpenPorts() { - return openPorts; - } - public void setOpenPorts(boolean openPorts) { this.openPorts = openPorts; } From de82e1fa24283afa9407261695bbc473454ab204 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 24 Dec 2025 21:15:54 +0100 Subject: [PATCH 05/40] refactor: remove unused `setRouter` method from `Transport` and enhance Javadoc for `Router` settings --- .../BeanRegistryImplementation.java | 3 +- .../com/predic8/membrane/core/Router.java | 39 ++++++++++++------- .../membrane/core/transport/Transport.java | 4 -- 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 923e43048b..2d4f7bd206 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -79,8 +79,7 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { if (!bd.isComponent() && observer.isActivatable(bd)) { uidsToActivate.add(new UidAction(bd.getUid(), action)); - } - if ("global".equals(bd.getKind())) { + } else if ("global".equals(bd.getKind())) { uidsToActivate.add(new UidAction(bd.getUid(), action)); } if (isLast) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 18d1bccd12..7fbd6cd8df 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -84,6 +84,13 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA private BeanRegistry registry; + /** + * Indicates whether the router should automatically open TCP ports when adding proxies. + * This flag determines if the ports associated with the proxies are opened immediately + * when they are added to the router. Setting this to {@code false} allows for proxies + * to be defined without opening the associated ports, providing more control over when + * the ports are made accessible. + */ private boolean openPorts = true; // @@ -296,7 +303,6 @@ public Transport getTransport() { */ @MCChildElement(order = 1, allowForeign = true) public void setTransport(Transport transport) { - transport.setRouter(this); this.transport = transport; } @@ -541,18 +547,20 @@ public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBe if (newProxy.getName() == null) newProxy.setName(bdc.bd().getName()); - // TODO: Code Should be deleted before merge - // Only kept for discussion - // init in Proxies was called twice, here and in Router.initRemainingRules - // We should only keep one place. -// try { -// newProxy.init(this); -// } catch (ConfigurationException e) { -// SpringConfigurationErrorHandler.handleRootCause(e, log); -// throw e; -// } catch (Exception e) { -// throw new RuntimeException("Could not init rule.", e); -// } + // TODO: Comment or code Should be deleted before merge + // Comment is kept for discussion only. + // + // init() in Proxies was called twice, here and in Router.initRemainingRules + // We should only keep one place. Which one is up to discussion + // + // try { + // newProxy.init(this); + // } catch (ConfigurationException e) { + // SpringConfigurationErrorHandler.handleRootCause(e, log); + // throw e; + // } catch (Exception e) { + // throw new RuntimeException("Could not init rule.", e); + // } if (bdc.action().isAdded()) add(newProxy); @@ -606,6 +614,11 @@ public Configuration getConfig() { return config; } + /** + * Configures whether the router should open tcp ports when adding proxies. Use this field to create a router + * and open the ports later + * @param openPorts a boolean indicating whether ports should be opened (true) or closed (false) + */ public void setOpenPorts(boolean openPorts) { this.openPorts = openPorts; } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java index d469c28745..8d1a15cca7 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java @@ -147,8 +147,4 @@ public int getConcurrentConnectionLimitPerIp() { public void setConcurrentConnectionLimitPerIp(int concurrentConnectionLimitPerIp) { this.concurrentConnectionLimitPerIp = concurrentConnectionLimitPerIp; } - - public void setRouter(Router router) { - this.router = router; - } } From adbe257839fc909ec17e1aac7fa1f7ee04617535 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 10:20:44 +0100 Subject: [PATCH 06/40] refactor: remove unused imports, simplify package structure, and clean up redundant code in YAML integration --- .../annot/{yaml => beanregistry}/BeanCacheObserver.java | 6 +----- .../annot/beanregistry/BeanRegistryImplementation.java | 3 --- .../java/com/predic8/membrane/annot/util/YamlParser.java | 1 - core/src/main/java/com/predic8/membrane/core/Router.java | 4 ---- 4 files changed, 1 insertion(+), 13 deletions(-) rename annot/src/main/java/com/predic8/membrane/annot/{yaml => beanregistry}/BeanCacheObserver.java (88%) diff --git a/annot/src/main/java/com/predic8/membrane/annot/yaml/BeanCacheObserver.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCacheObserver.java similarity index 88% rename from annot/src/main/java/com/predic8/membrane/annot/yaml/BeanCacheObserver.java rename to annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCacheObserver.java index 1fdb696581..3abbac7524 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/yaml/BeanCacheObserver.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanCacheObserver.java @@ -12,11 +12,7 @@ See the License for the specific language governing permissions and limitations under the License. */ -package com.predic8.membrane.annot.yaml; - -import com.predic8.membrane.annot.beanregistry.BeanDefinition; -import com.predic8.membrane.annot.beanregistry.BeanDefinitionChanged; -import com.predic8.membrane.annot.beanregistry.BeanRegistryImplementation; +package com.predic8.membrane.annot.beanregistry; import java.io.IOException; diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 2d4f7bd206..4398ecb180 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -15,7 +15,6 @@ import com.predic8.membrane.annot.Grammar; import com.predic8.membrane.annot.bean.BeanFactory; -import com.predic8.membrane.annot.yaml.BeanCacheObserver; import com.predic8.membrane.annot.yaml.GenericYamlParser; import com.predic8.membrane.annot.yaml.WatchAction; import org.jetbrains.annotations.*; @@ -79,8 +78,6 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { if (!bd.isComponent() && observer.isActivatable(bd)) { uidsToActivate.add(new UidAction(bd.getUid(), action)); - } else if ("global".equals(bd.getKind())) { - uidsToActivate.add(new UidAction(bd.getUid(), action)); } if (isLast) activationRun(); diff --git a/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java b/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java index 703b37b8cc..8c87d4a490 100644 --- a/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java +++ b/annot/src/test/java/com/predic8/membrane/annot/util/YamlParser.java @@ -16,7 +16,6 @@ import com.predic8.membrane.annot.Grammar; import com.predic8.membrane.annot.beanregistry.*; -import com.predic8.membrane.annot.yaml.*; import org.jetbrains.annotations.*; import java.io.IOException; diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 7fbd6cd8df..d8b14184ad 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -16,10 +16,8 @@ import com.predic8.membrane.annot.*; import com.predic8.membrane.annot.beanregistry.*; -import com.predic8.membrane.annot.yaml.*; import com.predic8.membrane.core.RuleManager.*; import com.predic8.membrane.core.config.spring.*; -import com.predic8.membrane.core.exceptions.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.administration.*; @@ -104,7 +102,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA // // Components // - protected RuleManager ruleManager = new RuleManager(); protected final FlowController flowController; protected ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); @@ -130,7 +127,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA // // Reinitialization // - private Timer reinitializer; private boolean asynchronousInitialization = false; From 21ae9a15f4e8dcaccda1e4d23a72d11b3f7317ad Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 10:32:27 +0100 Subject: [PATCH 07/40] refactor: remove unused imports, simplify package structure, and clean up redundant code in YAML integration --- core/src/main/java/com/predic8/membrane/core/Router.java | 7 ------- .../main/java/com/predic8/membrane/core/cli/RouterCLI.java | 1 - 2 files changed, 8 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index d8b14184ad..454c3670a9 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -128,7 +128,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA // Reinitialization // private Timer reinitializer; - private boolean asynchronousInitialization = false; /** * HotDeployer for changes on the XML configuration file. Does not cover YAML. @@ -518,16 +517,10 @@ public FlowController getFlowController() { return flowController; } - public synchronized void setAsynchronousInitialization(boolean asynchronousInitialization) { - this.asynchronousInitialization = asynchronousInitialization; - notifyAll(); - } - public void handleAsynchronousInitializationResult(boolean success) { if (!success && !config.isRetryInit()) System.exit(1); ApiInfo.logInfosAboutStartedProxies(ruleManager); - setAsynchronousInitialization(false); } @Override diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 33d8a1e878..f31f0540b7 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -181,7 +181,6 @@ private static Router initRouterByYAML(String location) throws Exception { var router = new Router(); router.setOpenPorts(false); router.setBaseLocation(location); - router.setAsynchronousInitialization(true); GrammarAutoGenerated grammar = new GrammarAutoGenerated(); BeanRegistryImplementation reg = new BeanRegistryImplementation(router, router, grammar); From 6346a37023718dc356d09ba694d7612f86d847e0 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 16:39:12 +0100 Subject: [PATCH 08/40] refactor: extend and streamline BeanRegistry integration in Router, improve exception formatting, enhance concurrency handling --- .../annot/beanregistry/BeanRegistry.java | 14 ++++++++ .../BeanRegistryImplementation.java | 36 ++++++++++++------- .../com/predic8/membrane/core/Router.java | 33 +++++++++-------- .../predic8/membrane/core/cli/RouterCLI.java | 3 +- .../kubernetes/GenericYamlParserTest.java | 6 ++++ 5 files changed, 64 insertions(+), 28 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java index 3c5390144e..92e9b6b17b 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java @@ -16,6 +16,7 @@ import com.predic8.membrane.annot.*; import java.util.*; +import java.util.function.*; public interface BeanRegistry { @@ -44,4 +45,17 @@ public interface BeanRegistry { * @param bean instance to register (must not be null) */ void register(String beanName, Object bean); + + /** + * Registers a bean of the specified type with the given name if it is not already registered. + * If a bean with the given name is already present, the existing instance is returned. + * Otherwise, the supplier is used to create and register a new instance. + * + * @param name the name to register the bean under + * @param type the class type of the bean + * @param supplier a supplier that provides a new instance of the bean if not already registered + * @param the generic type of the bean + * @return the existing or newly created and registered bean instance + */ + T registerIfAbsent(String name, Class type, Supplier supplier); } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 4398ecb180..f647c8ba4d 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -13,16 +13,15 @@ limitations under the License. */ package com.predic8.membrane.annot.beanregistry; -import com.predic8.membrane.annot.Grammar; -import com.predic8.membrane.annot.bean.BeanFactory; -import com.predic8.membrane.annot.yaml.GenericYamlParser; -import com.predic8.membrane.annot.yaml.WatchAction; +import com.predic8.membrane.annot.*; +import com.predic8.membrane.annot.bean.*; +import com.predic8.membrane.annot.yaml.*; import org.jetbrains.annotations.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.slf4j.*; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.*; +import java.util.function.*; public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { @@ -38,7 +37,8 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { private final Map bcs = new ConcurrentHashMap<>(); // Order is not critical. Order is determined by uidsToActivate private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order - record UidAction(String uid, WatchAction action) {} + record UidAction(String uid, WatchAction action) { + } public BeanRegistryImplementation(BeanCacheObserver observer, BeanRegistryAware registryAware, Grammar grammar) { this.observer = observer; @@ -46,7 +46,7 @@ public BeanRegistryImplementation(BeanCacheObserver observer, BeanRegistryAware registryAware.setRegistry(this); } - private Object define(BeanDefinition bd) { + private Object define(BeanDefinition bd) { log.debug("defining bean: {}", bd.getNode()); try { if ("bean".equals(bd.getKind())) { @@ -175,7 +175,7 @@ public List getBeans(Class clazz) { public Optional getBean(Class clazz) { var beans = getBeans(clazz); if (beans.size() > 1) { - var msg = "One bean was asked. But found %d beans of %s".formatted(beans.size(),clazz); + var msg = "One bean was asked. But found %d beans of %s".formatted(beans.size(), clazz); log.error(msg); throw new RuntimeException(msg); } @@ -184,9 +184,21 @@ public Optional getBean(Class clazz) { public void register(String beanName, Object bean) { var uuid = UUID.randomUUID().toString(); - BeanContainer bc = new BeanContainer(new BeanDefinition("component", beanName,null, uuid, null)); + BeanContainer bc = new BeanContainer(new BeanDefinition("component", beanName, null, uuid, null)); bc.setSingleton(bean); - singletonBeans.put(uuid,bean); + singletonBeans.put(uuid, bean); bcs.put(uuid, bc); } + + public T registerIfAbsent(String name, Class type, Supplier supplier) { + return getBean(type).orElseGet(() -> { + synchronized (this) { + return getBean(type).orElseGet(() -> { + T created = supplier.get(); + register(name, created); + return created; + }); + } + }); + } } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 454c3670a9..a60b8fb034 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -80,7 +80,7 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA private ApplicationContext beanFactory; - private BeanRegistry registry; + protected BeanRegistry registry; /** * Indicates whether the router should automatically open TCP ports when adding proxies. @@ -103,15 +103,13 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA // Components // protected RuleManager ruleManager = new RuleManager(); - protected final FlowController flowController; protected ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); protected Transport transport; - protected final ResolverMap resolverMap; - protected final DNSCache dnsCache = new DNSCache(); - private final KubernetesWatcher kubernetesWatcher = new KubernetesWatcher(this); + private final TimerManager timerManager = new TimerManager(); private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); + protected final ResolverMap resolverMap; protected final ExecutorService backgroundInitializer = newSingleThreadExecutor(new HttpServerThreadFactory("Router Background Initializer")); @@ -140,7 +138,6 @@ public Router() { ruleManager.setRouter(this); resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); resolverMap.addRuleResolver(this); - flowController = new FlowController(this); } // @@ -167,9 +164,11 @@ public static Router init(String resource) { bf.start(); if (bf.getBeansOfType(Router.class).size() > 1) { - throw new RuntimeException("More than one router found in spring config (beans %s). This is not supported anymore.".formatted(bf.getBeanDefinitionNames())); + throw new RuntimeException( + "More than one router bean found in the Spring configuration (%s). This is no longer supported." + .formatted(Arrays.toString(bf.getBeanDefinitionNames())) + ); } - return bf.getBean("router", Router.class); } @@ -188,7 +187,8 @@ public void start() { exchangeStore = new LimitedMemoryExchangeStore(); if (transport == null) transport = new HttpTransport(); - kubernetesWatcher.start(); + + getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); init(); initJmx(); @@ -316,7 +316,7 @@ public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { } public DNSCache getDnsCache() { - return dnsCache; + return getRegistry().getBean(DNSCache.class).orElse(new DNSCache()); } public ResolverMap getResolverMap() { @@ -428,7 +428,7 @@ public void stopAutoReinitializer() { @Override public void stop() { - kubernetesWatcher.stop(); + getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::stop); hotDeployer.stop(); shutdown(); @@ -484,7 +484,7 @@ public void setBeanName(String s) { */ @MCChildElement(order = 2) public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { - registry.register("globalInterceptor", globalInterceptor); + getRegistry().register("globalInterceptor", globalInterceptor); } public String getId() { @@ -514,7 +514,7 @@ public HttpClientFactory getHttpClientFactory() { } public FlowController getFlowController() { - return flowController; + return getRegistry().getBean(FlowController.class).orElse(new FlowController(this)); } public void handleAsynchronousInitializationResult(boolean success) { @@ -576,6 +576,8 @@ public void setRegistry(BeanRegistry registry) { } public BeanRegistry getRegistry() { + if (registry == null) + registry = new BeanRegistryImplementation(null, this, null); return registry; } @@ -605,7 +607,10 @@ public Configuration getConfig() { /** * Configures whether the router should open tcp ports when adding proxies. Use this field to create a router - * and open the ports later + * and open the ports later. + * This method should typically be called during router initialization, before {@link #start()}, to avoid + * race conditions with concurrent proxy additions. + * * @param openPorts a boolean indicating whether ports should be opened (true) or closed (false) */ public void setOpenPorts(boolean openPorts) { diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index f31f0540b7..cb8cbd869f 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -27,7 +27,6 @@ import com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec; import com.predic8.membrane.core.resolver.ResolverMap; import com.predic8.membrane.core.resolver.ResourceRetrievalException; -import com.predic8.schema.*; import org.apache.commons.cli.ParseException; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -43,7 +42,7 @@ import static com.predic8.membrane.core.Constants.*; import static com.predic8.membrane.core.cli.util.JwkGenerator.generateJWK; import static com.predic8.membrane.core.cli.util.JwkGenerator.privateJWKtoPublic; -import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.InvalidConfigurationException; +import static com.predic8.membrane.core.config.spring.CheckableBeanFactory.InvalidConfigurationException; import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.handleXmlBeanDefinitionStoreException; import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.YES; import static com.predic8.membrane.core.openapi.util.OpenAPIUtil.isOpenAPIMisplacedError; diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java index e0216123fd..6f047bd81a 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java @@ -45,6 +45,7 @@ import java.io.IOException; import java.io.InputStream; import java.util.*; +import java.util.function.*; import java.util.stream.Stream; import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.NO; @@ -374,6 +375,11 @@ public Optional getBean(Class clazz) { @Override public void register(String beanName, Object object) {} + + @Override + public T registerIfAbsent(String name, Class type, Supplier supplier) { + return null; + } } private static APIProxy parse(String yaml, BeanRegistry reg) { From 88af125131a320eaf3c54fdb75b4d886d4cac913 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 16:41:00 +0100 Subject: [PATCH 09/40] refactor: streamline imports in `GenericYamlParserTest`, improve readability and maintainability --- .../kubernetes/GenericYamlParserTest.java | 63 +++++++++---------- 1 file changed, 28 insertions(+), 35 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java index 6f047bd81a..bbbbbbe6e4 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java @@ -10,46 +10,39 @@ package com.predic8.membrane.core.kubernetes; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; -import com.predic8.membrane.annot.Grammar; -import com.predic8.membrane.annot.beanregistry.BeanCollector; -import com.predic8.membrane.annot.beanregistry.BeanDefinition; -import com.predic8.membrane.annot.beanregistry.BeanRegistry; -import com.predic8.membrane.annot.beanregistry.ChangeEvent; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.*; +import com.fasterxml.jackson.dataformat.yaml.*; +import com.predic8.membrane.annot.*; +import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.annot.yaml.*; -import com.predic8.membrane.core.config.spring.GrammarAutoGenerated; -import com.predic8.membrane.core.interceptor.authentication.BasicAuthenticationInterceptor; -import com.predic8.membrane.core.interceptor.authentication.session.StaticUserDataProvider; -import com.predic8.membrane.core.interceptor.balancer.LoadBalancingInterceptor; -import com.predic8.membrane.core.interceptor.beautifier.BeautifierInterceptor; -import com.predic8.membrane.core.interceptor.flow.ResponseInterceptor; -import com.predic8.membrane.core.interceptor.lang.SetCookiesInterceptor; -import com.predic8.membrane.core.interceptor.log.LogInterceptor; -import com.predic8.membrane.core.interceptor.oauth2client.MemcachedOriginalExchangeStore; -import com.predic8.membrane.core.interceptor.oauth2client.OAuth2Resource2Interceptor; -import com.predic8.membrane.core.interceptor.ratelimit.RateLimitInterceptor; -import com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor; -import com.predic8.membrane.core.interceptor.xml.Xml2JsonInterceptor; -import com.predic8.membrane.core.openapi.serviceproxy.APIProxy; +import com.predic8.membrane.core.config.spring.*; +import com.predic8.membrane.core.interceptor.authentication.*; +import com.predic8.membrane.core.interceptor.authentication.session.*; +import com.predic8.membrane.core.interceptor.balancer.*; +import com.predic8.membrane.core.interceptor.beautifier.*; +import com.predic8.membrane.core.interceptor.flow.*; +import com.predic8.membrane.core.interceptor.lang.*; +import com.predic8.membrane.core.interceptor.log.*; +import com.predic8.membrane.core.interceptor.oauth2client.*; +import com.predic8.membrane.core.interceptor.ratelimit.*; +import com.predic8.membrane.core.interceptor.rewrite.*; +import com.predic8.membrane.core.interceptor.xml.*; +import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.proxies.AbstractServiceProxy.*; -import com.predic8.membrane.core.util.MemcachedConnector; -import org.jetbrains.annotations.NotNull; -import org.junit.jupiter.api.TestInstance; -import org.junit.jupiter.api.TestInstance.Lifecycle; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.io.IOException; -import java.io.InputStream; +import com.predic8.membrane.core.util.*; +import org.jetbrains.annotations.*; +import org.junit.jupiter.api.*; +import org.junit.jupiter.api.TestInstance.*; +import org.junit.jupiter.params.*; +import org.junit.jupiter.params.provider.*; + +import java.io.*; import java.util.*; import java.util.function.*; -import java.util.stream.Stream; +import java.util.stream.*; -import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.NO; -import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.YES; +import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.*; import static org.junit.jupiter.api.Assertions.*; @TestInstance(Lifecycle.PER_CLASS) From 4d3917e875bbff481ca48f7f0718320b729760b5 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 17:43:37 +0100 Subject: [PATCH 10/40] refactor: simplify `registerIfAbsent` usage in `Router` and `BeanRegistry`, streamline bean registration logic --- .../com/predic8/membrane/annot/beanregistry/BeanRegistry.java | 4 +--- core/src/main/java/com/predic8/membrane/core/Router.java | 4 ++-- .../membrane/core/kubernetes/GenericYamlParserTest.java | 4 ++-- 3 files changed, 5 insertions(+), 7 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java index 92e9b6b17b..d562b2ea33 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistry.java @@ -50,12 +50,10 @@ public interface BeanRegistry { * Registers a bean of the specified type with the given name if it is not already registered. * If a bean with the given name is already present, the existing instance is returned. * Otherwise, the supplier is used to create and register a new instance. - * - * @param name the name to register the bean under * @param type the class type of the bean * @param supplier a supplier that provides a new instance of the bean if not already registered * @param the generic type of the bean * @return the existing or newly created and registered bean instance */ - T registerIfAbsent(String name, Class type, Supplier supplier); + T registerIfAbsent(Class type, Supplier supplier); } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index a60b8fb034..7f02a52445 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -316,7 +316,7 @@ public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { } public DNSCache getDnsCache() { - return getRegistry().getBean(DNSCache.class).orElse(new DNSCache()); + return getRegistry().registerIfAbsent( DNSCache.class, DNSCache::new); } public ResolverMap getResolverMap() { @@ -514,7 +514,7 @@ public HttpClientFactory getHttpClientFactory() { } public FlowController getFlowController() { - return getRegistry().getBean(FlowController.class).orElse(new FlowController(this)); + return getRegistry().registerIfAbsent(FlowController.class, () -> new FlowController(this)); } public void handleAsynchronousInitializationResult(boolean success) { diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java index bbbbbbe6e4..26e03653fc 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/GenericYamlParserTest.java @@ -370,8 +370,8 @@ public Optional getBean(Class clazz) { public void register(String beanName, Object object) {} @Override - public T registerIfAbsent(String name, Class type, Supplier supplier) { - return null; + public T registerIfAbsent(Class type, Supplier supplier) { + return type.cast(null); } } From d773f929bef08424c2f773dd69284cf49ad208c8 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 17:43:59 +0100 Subject: [PATCH 11/40] refactor: simplify `registerIfAbsent` by removing `name` parameter, streamline bean registration --- .../annot/beanregistry/BeanRegistryImplementation.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index f647c8ba4d..467c5925e4 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -190,12 +190,12 @@ public void register(String beanName, Object bean) { bcs.put(uuid, bc); } - public T registerIfAbsent(String name, Class type, Supplier supplier) { + public T registerIfAbsent(Class type, Supplier supplier) { return getBean(type).orElseGet(() -> { synchronized (this) { return getBean(type).orElseGet(() -> { T created = supplier.get(); - register(name, created); + register(null, created); return created; }); } From 5369b43afe5a477112e80c55513bbdbac7963d44 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 17:47:45 +0100 Subject: [PATCH 12/40] refactor: remove duplicate `openPorts` field from `Router` --- core/src/main/java/com/predic8/membrane/core/Router.java | 9 --------- 1 file changed, 9 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index d41e845fad..7f02a52445 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -91,15 +91,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA */ private boolean openPorts = true; - /** - * Indicates whether the router should automatically open TCP ports when adding proxies. - * This flag determines if the ports associated with the proxies are opened immediately - * when they are added to the router. Setting this to {@code false} allows for proxies - * to be defined without opening the associated ports, providing more control over when - * the ports are made accessible. - */ - private boolean openPorts = true; - // // Configuration // From a197d781cd0704afcaa9999613dfe775e1f896a1 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Thu, 25 Dec 2025 20:31:29 +0100 Subject: [PATCH 13/40] refactor: enhance concurrency handling in `BeanRegistryImplementation`, improve logging and null checks, and streamline `activationRun` logic --- .../BeanRegistryImplementation.java | 62 ++++++++++++------- 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 467c5925e4..1dd3cf8a65 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -23,6 +23,13 @@ import java.util.concurrent.*; import java.util.function.*; +/** + * TODO: + * - More Tests + * - Document + * - singletonBeans + * - bcs + */ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { private static final Logger log = LoggerFactory.getLogger(BeanRegistryImplementation.class); @@ -85,38 +92,51 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { } private void activationRun() { - Set uidsToRemove = new HashSet<>(); - for (UidAction uidAction : uidsToActivate) { + for (UidAction uidAction : cloneUidActions()) { BeanContainer bc = bcs.get(uidAction.uid); - try { - Object bean = define(bc.getDefinition()); - bc.setSingleton(bean); + if (bc == null) { + log.warn("Skipping activation for missing uid {}", uidAction.uid); + continue; + } - // e.g. inform router about new proxy - observer.handleBeanEvent(new BeanDefinitionChanged(uidAction.action, bc.getDefinition()), bean, getOldBean(uidAction.action, bc.getDefinition())); + BeanDefinition def = bc.getDefinition(); + Object oldBean = getOldBean(uidAction.action, uidAction.uid); // capture first + Object newBean = null; // Do not inline! - if (uidAction.action.isAdded() || uidAction.action.isModified()) - singletonBeans.put(bc.getDefinition().getUid(), bean); + try { if (uidAction.action.isDeleted()) { - singletonBeans.remove(bc.getDefinition().getUid()); - bcs.remove(bc.getDefinition().getUid()); + singletonBeans.remove(uidAction.uid); + bcs.remove(uidAction.uid); + } else { + newBean = define(def); + bc.setSingleton(newBean); + singletonBeans.put(uidAction.uid, newBean); } - uidsToRemove.add(uidAction); + + observer.handleBeanEvent( + new BeanDefinitionChanged(uidAction.action, def), + newBean, + oldBean + ); } catch (Exception e) { - log.error("Could not handle {} {}/{}", uidAction.action, - bc.getDefinition().getNamespace(), bc.getDefinition().getName(), e); + log.error("Could not handle {} {}/{}", uidAction.action, def.getNamespace(), def.getName(), e); throw new RuntimeException(e); } } - for (UidAction uidAction : uidsToRemove) - uidsToActivate.remove(uidAction); } - private @Nullable Object getOldBean(WatchAction action, BeanDefinition bd) { - Object oldBean = null; - if (action.isModified() || action.isDeleted()) - oldBean = singletonBeans.get(bd.getUid()); - return oldBean; + private @NotNull List cloneUidActions() { + // Iterate safely over synchronizedSet + final List actions; + synchronized (uidsToActivate) { + actions = new ArrayList<>(uidsToActivate); + uidsToActivate.clear(); + } + return actions; + } + + private @Nullable Object getOldBean(WatchAction action, String uid) { + return (action.isModified() || action.isDeleted()) ? singletonBeans.get(uid) : null; } @Override From 612cef6a99a6fe41d5efd8ae64ad54e5b4326204 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 14:04:56 +0100 Subject: [PATCH 14/40] refactor: replace `Router.init` with `Router.initByXML`, improve thread-safety in `BeanContainer`, and streamline `BeanRegistry` handling --- .../annot/beanregistry/BeanContainer.java | 18 +++- .../BeanRegistryImplementation.java | 90 ++++++++++--------- .../com/predic8/membrane/core/Router.java | 9 +- .../predic8/membrane/core/cli/RouterCLI.java | 3 +- .../com/predic8/membrane/core/SimpleTest.java | 2 +- .../config/ReadRulesConfigurationTest.java | 2 +- ...ulesWithInterceptorsConfigurationTest.java | 2 +- .../core/config/SpringReferencesTest.java | 2 +- .../interceptor/InternalInvocationTest.java | 2 +- .../core/interceptor/UserFeatureTest.java | 2 +- .../membrane/core/proxies/ProxyRuleTest.java | 2 +- .../interceptor/SOAPProxyIntegrationTest.java | 2 +- .../predic8/membrane/plugin/RouterFacade.java | 2 +- 13 files changed, 81 insertions(+), 57 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index e5ef1a3318..0e0898cad7 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -14,24 +14,34 @@ package com.predic8.membrane.annot.beanregistry; +import java.util.concurrent.atomic.*; + public class BeanContainer { private final BeanDefinition definition; /** * Constructed bean after initialization. */ - private volatile Object singleton; + private final AtomicReference singleton = new AtomicReference<>(); public BeanContainer(BeanDefinition definition) { this.definition = definition; } - public Object getSingleton() { - return singleton; + return singleton.get(); } public void setSingleton(Object singleton) { - this.singleton = singleton; + this.singleton.set(singleton); + } + + /** + * Sets the singleton if not already set. + * + * @return true if this call published the singleton + */ + public boolean setIfAbsent(Object instance) { + return singleton.compareAndSet(null, instance); } public BeanDefinition getDefinition() { diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 1dd3cf8a65..e337ecafc8 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -27,8 +27,8 @@ * TODO: * - More Tests * - Document - * - singletonBeans - * - bcs + * - Do we need uuid when then name is unique? + * - For TB Unclear: Lifecycle activation/resolve */ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { @@ -37,9 +37,6 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { private final BeanCacheObserver observer; private final Grammar grammar; - // uid -> bean - private final ConcurrentHashMap singletonBeans = new ConcurrentHashMap<>(); // Order is here not critical - // uid -> bean container private final Map bcs = new ConcurrentHashMap<>(); // Order is not critical. Order is determined by uidsToActivate private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order @@ -92,6 +89,7 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { } private void activationRun() { + // Iterate safely over clone for (UidAction uidAction : cloneUidActions()) { BeanContainer bc = bcs.get(uidAction.uid); if (bc == null) { @@ -100,24 +98,24 @@ private void activationRun() { } BeanDefinition def = bc.getDefinition(); - Object oldBean = getOldBean(uidAction.action, uidAction.uid); // capture first - Object newBean = null; // Do not inline! + Object oldBean; + Object newBean = null; try { + synchronized (bc) { + oldBean = (uidAction.action.isModified() || uidAction.action.isDeleted()) ? bc.getSingleton() : null; + if (!uidAction.action.isDeleted()) { + newBean = define(def); + bc.setSingleton(newBean); + } + } + + // Remove container after releasing the lock (avoid holding bc while mutating registry map) if (uidAction.action.isDeleted()) { - singletonBeans.remove(uidAction.uid); bcs.remove(uidAction.uid); - } else { - newBean = define(def); - bc.setSingleton(newBean); - singletonBeans.put(uidAction.uid, newBean); } - observer.handleBeanEvent( - new BeanDefinitionChanged(uidAction.action, def), - newBean, - oldBean - ); + observer.handleBeanEvent(new BeanDefinitionChanged(uidAction.action, def), newBean, oldBean); } catch (Exception e) { log.error("Could not handle {} {}/{}", uidAction.action, def.getNamespace(), def.getName(), e); throw new RuntimeException(e); @@ -126,7 +124,6 @@ private void activationRun() { } private @NotNull List cloneUidActions() { - // Iterate safely over synchronizedSet final List actions; synchronized (uidsToActivate) { actions = new ArrayList<>(uidsToActivate); @@ -135,25 +132,28 @@ private void activationRun() { return actions; } - private @Nullable Object getOldBean(WatchAction action, String uid) { - return (action.isModified() || action.isDeleted()) ? singletonBeans.get(uid) : null; - } - @Override public Object resolve(String url) { BeanContainer bc = getFirstByName(url).orElseThrow(() -> new RuntimeException("Reference %s not found".formatted(url))); boolean prototype = isPrototypeScope(bc.getDefinition()); - if (!prototype && bc.getSingleton() != null) - return bc.getSingleton(); - - Object instance = define(bc.getDefinition()); + // Prototypes are created anew every time. + if (prototype) { + return define(bc.getDefinition()); + } - if (!prototype) - bc.setSingleton(instance); + // Singleton: ensure define() runs at most once per BeanContainer. + synchronized (bc) { + Object existing = bc.getSingleton(); + if (existing != null) { + return existing; + } - return instance; + Object created = define(bc.getDefinition()); + bc.setSingleton(created); + return created; + } } private @NotNull Optional getFirstByName(String url) { @@ -203,22 +203,32 @@ public Optional getBean(Class clazz) { } public void register(String beanName, Object bean) { + if (bean == null) + throw new IllegalArgumentException("bean must not be null"); + var uuid = UUID.randomUUID().toString(); - BeanContainer bc = new BeanContainer(new BeanDefinition("component", beanName, null, uuid, null)); + BeanContainer bc = new BeanContainer(new BeanDefinition("component", computeBeanName(beanName, uuid), null, uuid, null)); bc.setSingleton(bean); - singletonBeans.put(uuid, bean); bcs.put(uuid, bc); } public T registerIfAbsent(Class type, Supplier supplier) { - return getBean(type).orElseGet(() -> { - synchronized (this) { - return getBean(type).orElseGet(() -> { - T created = supplier.get(); - register(null, created); - return created; - }); - } - }); + var existing = getBean(type); + if (existing.isPresent()) + return existing.get(); + + T created = supplier.get(); // outside lock + + synchronized (this) { + return getBean(type).orElseGet(() -> { + register(null, created); + return created; + }); + } + } + + private static @NotNull String computeBeanName(String beanName, String uuid) { + return beanName != null ? beanName : "#" + uuid; } + } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 7f02a52445..d711b07ac3 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -143,7 +143,6 @@ public Router() { // // Initialization // - public void init() throws Exception { initRemainingRules(); transport.init(this); @@ -155,7 +154,13 @@ private void initRemainingRules() throws Exception { proxy.init(this); } - public static Router init(String resource) { + /** + * Initializes a {@link Router} instance from the specified Spring XML configuration resource. + * @param resource the path to the Spring XML configuration file that defines the {@link Router} bean + * @return the initialized {@link Router} instance + * @throws RuntimeException if no {@link Router} bean is found or more than one {@link Router} bean is found + */ + public static Router initByXML(String resource) { log.debug("loading spring config: {}", resource); TrackingFileSystemXmlApplicationContext bf = diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index f277404548..b9d8fc3e45 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -27,7 +27,6 @@ import com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec; import com.predic8.membrane.core.resolver.ResolverMap; import com.predic8.membrane.core.resolver.ResourceRetrievalException; -import com.predic8.schema.*; import org.apache.commons.cli.ParseException; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; @@ -235,7 +234,7 @@ private static String getLocation(MembraneCommandLine commandLine) throws IOExce private static Router initRouterByXml(String config) throws Exception { try { - return Router.init(config); + return Router.initByXML(config); } catch (XmlBeanDefinitionStoreException e) { handleXmlBeanDefinitionStoreException(e); } diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index 8457b4ae62..58c1b97a87 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -23,7 +23,7 @@ public class SimpleTest { @BeforeAll static void setUp() throws Exception { - router = Router.init("classpath:/test-proxies.xml"); + router = Router.initByXML("classpath:/test-proxies.xml"); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 3a89abd588..504ef3a209 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -31,7 +31,7 @@ public class ReadRulesConfigurationTest { @BeforeAll public static void setUp() { - router = Router.init("classpath:/proxies.xml"); + router = Router.initByXML("classpath:/proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java index 664f3da706..4b775a54f0 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java @@ -30,7 +30,7 @@ public class ReadRulesWithInterceptorsConfigurationTest { @BeforeAll static void setUp() { - router = Router.init("src/test/resources/ref.proxies.xml"); + router = Router.initByXML("src/test/resources/ref.proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index 1996ac8ed6..1e07ccb718 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -29,7 +29,7 @@ public class SpringReferencesTest { @BeforeAll public static void before() { - r = Router.init("classpath:/proxies-using-spring-refs.xml"); + r = Router.initByXML("classpath:/proxies-using-spring-refs.xml"); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java index a2b4e7ecc7..62ab4c1fe7 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java @@ -26,7 +26,7 @@ public class InternalInvocationTest { @BeforeEach public void setUp() throws Exception { - router = Router.init("classpath:/internal-invocation/proxies.xml"); + router = Router.initByXML("classpath:/internal-invocation/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index f89ac993cf..fc6c8d87a5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -36,7 +36,7 @@ class UserFeatureTest { @BeforeAll static void setUp() { - router = Router.init("classpath:/userFeature/proxies.xml"); + router = Router.initByXML("classpath:/userFeature/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java index 3bad491115..027a93f34d 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java @@ -30,7 +30,7 @@ public class ProxyRuleTest { @BeforeAll public static void setUp() { - router = Router.init("src/test/resources/proxy-rules-test-monitor-beans.xml"); + router = Router.initByXML("src/test/resources/proxy-rules-test-monitor-beans.xml"); proxy = new ProxyRule(new ProxyRuleKey(8888)); proxy.setName("Rule 1"); // TODO: this is not possible anymore rule.setInboundTLS(true); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index a62dfb7823..fa4346990c 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -45,7 +45,7 @@ public static void teardown() { @BeforeEach public void startRouter() { - router = Router.init("classpath:/soap-proxy.xml"); + router = Router.initByXML("classpath:/soap-proxy.xml"); } @AfterEach diff --git a/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java b/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java index cee3e1f71f..3f84afe9d9 100644 --- a/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java +++ b/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java @@ -28,7 +28,7 @@ private RouterFacade(Router router) { } static RouterFacade createStarted(String proxiesPath) { - return new RouterFacade(Router.init(proxiesPath)); + return new RouterFacade(Router.initByXML(proxiesPath)); } void stop() { From 7be9eab02faedae2d867af4b0d07d23e71c97db3 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 14:06:52 +0100 Subject: [PATCH 15/40] refactor: remove redundant `Exception` declarations, simplify `tearDown` and `setUp` methods, and clean up `BeanContainer` by removing unused `setIfAbsent` method --- .../membrane/annot/beanregistry/BeanContainer.java | 9 --------- .../java/com/predic8/membrane/core/SimpleTest.java | 4 ++-- .../membrane/core/interceptor/UserFeatureTest.java | 14 +++++++------- 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index 0e0898cad7..a67abf8b1b 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -35,15 +35,6 @@ public void setSingleton(Object singleton) { this.singleton.set(singleton); } - /** - * Sets the singleton if not already set. - * - * @return true if this call published the singleton - */ - public boolean setIfAbsent(Object instance) { - return singleton.compareAndSet(null, instance); - } - public BeanDefinition getDefinition() { return definition; } diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index 58c1b97a87..31ef0a2c9c 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -22,7 +22,7 @@ public class SimpleTest { private static Router router; @BeforeAll - static void setUp() throws Exception { + static void setUp() { router = Router.initByXML("classpath:/test-proxies.xml"); } @@ -32,7 +32,7 @@ public void test() { } @AfterAll - static void tearDown() throws Exception { + static void tearDown() { router.shutdown(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index fc6c8d87a5..2fc558f885 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -49,7 +49,7 @@ void beforeEach() { } @AfterAll - static void tearDown() throws Exception { + static void tearDown() { router.shutdown(); } @@ -60,19 +60,19 @@ private void callService(String s) { } @Test - void testInvocation() throws Exception { + void testInvocation() { callService("ok"); MockInterceptor.assertContent(labels, inverseLabels, new ArrayList<>()); } @Test - void testAbort() throws Exception { + void testAbort() { callService("abort"); MockInterceptor.assertContent(labels, new ArrayList<>(), inversAbortLabels); } @Test - void testFailInRequest() throws Exception { + void testFailInRequest() { labels.add("mock8"); callService("failinrequest"); @@ -80,7 +80,7 @@ void testFailInRequest() throws Exception { } @Test - void testFailInResponse() throws Exception { + void testFailInResponse() { labels.add("mock9"); callService("failinresponse"); @@ -88,9 +88,9 @@ void testFailInResponse() throws Exception { } @Test - void testFailInAbort() throws Exception { + void testFailInAbort() { labels.add("mock10"); - inversAbortLabels.add(0, "mock10"); + inversAbortLabels.addFirst("mock10"); callService("failinabort"); MockInterceptor.assertContent(labels, new ArrayList<>(), inversAbortLabels); From 3d4c8080acef9fa6f82bb9a45ff845ecc86980b6 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 19:09:08 +0100 Subject: [PATCH 16/40] refactor: simplify Router lifecycle methods, streamline test setup/teardown logic, and remove unused classes --- .../com/predic8/membrane/core/HttpRouter.java | 69 ++++--- .../com/predic8/membrane/core/Router.java | 21 ++- .../predic8/membrane/core/cli/RouterCLI.java | 1 - .../ElasticSearchExchangeStore.java | 6 +- .../core/interceptor/acl/Hostname.java | 2 +- .../predic8/membrane/core/proxies/Proxy.java | 2 +- .../membrane/core/proxies/SSLProxy.java | 2 +- .../GateKeeperClientInterceptor.java | 114 ------------ .../RouterIpResolverInterceptor.java | 2 +- .../core/sslinterceptor/SSLInterceptor.java | 2 +- .../membrane/core/transport/Transport.java | 11 +- .../core/transport/http/HttpTransport.java | 2 +- .../membrane/core/util/TimerManager.java | 9 + .../membrane/AbstractTestWithRouter.java | 10 +- .../java/com/predic8/membrane/AllTests.java | 27 --- .../core/RuleManagerUriTemplateTest.java | 6 +- .../com/predic8/membrane/core/UnitTests.java | 2 +- .../config/ReadRulesConfigurationTest.java | 169 +++++++++--------- .../ElasticSearchExchangeStoreTest.java | 110 ++++++------ ...ingWithClusterManagerAndNoSessionTest.java | 3 +- .../LoadBalancingWithClusterManagerTest.java | 12 +- .../OpenTelemetryInterceptorTest.java | 3 +- .../session/SessionInterceptorTest.java | 17 +- .../lang/TemplateExchangeExpressionTest.java | 12 +- .../JsonpathExchangeExpressionTest.java | 2 +- .../openapi/serviceproxy/OpenAPI31Test.java | 7 +- .../serviceproxy/OpenAPIInterceptorTest.java | 7 +- ...WTInterceptorAndSecurityValidatorTest.java | 17 +- .../core/proxies/InternalProxyTest.java | 10 +- .../membrane/core/proxies/SOAPProxyTest.java | 12 +- .../ServiceProxyWSDLInterceptorsTest.java | 10 +- ...Test.java => TargetURLExpressionTest.java} | 20 +-- .../proxies/UnavailableSoapProxyTest.java | 16 +- .../core/security/KeyStoreUtilTest.java | 2 +- .../http/ConcurrentConnectionLimitTest.java | 5 +- .../core/transport/http/ConnectionTest.java | 6 +- .../transport/ssl/SessionResumptionTest.java | 28 ++- .../LoadBalancingInterceptorTest.java | 20 +-- core/src/test/resources/log4j2.xml | 2 +- core/src/test/resources/ref.proxies.xml | 3 +- docs/ROADMAP.md | 4 + 41 files changed, 329 insertions(+), 456 deletions(-) delete mode 100644 core/src/main/java/com/predic8/membrane/core/sslinterceptor/GateKeeperClientInterceptor.java delete mode 100644 core/src/test/java/com/predic8/membrane/AllTests.java rename core/src/test/java/com/predic8/membrane/core/proxies/{AbstractServiceProxyExpressionTest.java => TargetURLExpressionTest.java} (68%) diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index 1bde0fe7cb..fb62f607b4 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -23,43 +23,42 @@ public class HttpRouter extends Router { - public HttpRouter() { - this(null); - } + public HttpRouter() { + this(null); + } - public HttpRouter(ProxyConfiguration proxyConfiguration) { - transport = createTransport(); - resolverMap.getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); - } + public HttpRouter(ProxyConfiguration proxyConfiguration) { + transport = createTransport(); + resolverMap.getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + } - /** - * Same as the default config from monitor-beans.xml - */ - private Transport createTransport() { - Transport transport = new HttpTransport(); - List interceptors = new ArrayList<>(); - interceptors.add(new RuleMatchingInterceptor()); - interceptors.add(new DispatchingInterceptor()); - interceptors.add(new UserFeatureInterceptor()); - interceptors.add(new InternalRoutingInterceptor()); - HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor(); - interceptors.add(httpClientInterceptor); - transport.setFlow(interceptors); - return transport; - } + @Override + public HttpTransport getTransport() { + return (HttpTransport) transport; + } - @Override - public HttpTransport getTransport() { - return (HttpTransport)transport; - } - - /** - * TODO Only used for tests. It s brittle cause it is dependent on - * the list. In tests interceptors in the proxy can be used instead. - */ - public void addUserFeatureInterceptor(Interceptor i) { - List is = getTransport().getFlow(); - is.add(is.size()-3, i); - } + /** + * TODO Only used for tests. It s brittle cause it is dependent on + * the list. In tests interceptors in the proxy can be used instead. + */ + public void addUserFeatureInterceptor(Interceptor i) { + List is = getTransport().getFlow(); + is.add(is.size() - 3, i); + } + /** + * Same as the default config from monitor-beans.xml + */ + private static Transport createTransport() { + Transport transport = new HttpTransport(); + List interceptors = new ArrayList<>(); + interceptors.add(new RuleMatchingInterceptor()); + interceptors.add(new DispatchingInterceptor()); + interceptors.add(new UserFeatureInterceptor()); + interceptors.add(new InternalRoutingInterceptor()); + HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor(); + interceptors.add(httpClientInterceptor); + transport.setFlow(interceptors); + return transport; + } } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index d711b07ac3..2a4a7d53a9 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -122,6 +122,8 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA @GuardedBy("lock") private boolean running; + private boolean initialized; + // // Reinitialization // @@ -143,13 +145,16 @@ public Router() { // // Initialization // - public void init() throws Exception { + public void init() { initRemainingRules(); - transport.init(this); + if (transport != null) + transport.init(this); displayTraceWarning(); + + initialized = true; } - private void initRemainingRules() throws Exception { + private void initRemainingRules() { for (Proxy proxy : getRuleManager().getRules()) proxy.init(this); } @@ -187,15 +192,20 @@ public static Router initFromXMLString(String xmlString) { @Override public void start() { + if (!initialized) + init(); + try { if (exchangeStore == null) exchangeStore = new LimitedMemoryExchangeStore(); - if (transport == null) + if (transport == null) { transport = new HttpTransport(); + transport.init(this); + } getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); - init(); + //init(); initJmx(); getRuleManager().openPorts(); @@ -236,6 +246,7 @@ public void start() { """, e.getMessage(), e.getLocation()); throw new ExitException(); } catch (Exception e) { + log.error("Could not start router.", e); if (e instanceof RuntimeException) throw (RuntimeException) e; throw new RuntimeException(e); diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index b9d8fc3e45..387a604c46 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -190,7 +190,6 @@ private static Router initRouterByYAML(String location) throws Exception { reg.finishStaticConfiguration(); router.start(); - router.getRuleManager().openPorts(); logStartupMessage(); return router; } diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java index 670ae7ca8f..ba5d1b6304 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java @@ -507,11 +507,9 @@ private void setUpIndex() { log.info("Index {} created",index); } } catch (JSONException e) { - if(indexRes.getJSONObject("error").getJSONArray("root_cause") - .getJSONObject(0).getString("type").equals("resource_already_exists_exception")){ + if(indexRes.has("error") && indexRes.getJSONObject("error").getJSONArray("root_cause").getJSONObject(0).getString("type").equals("resource_already_exists_exception")){ log.info("Index already exists skipping index creation"); - } - else{ + } else { log.error("Error happened. Reply from elastic search is below"); log.error(indexRes.toString()); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java index bb71c83037..82eac20914 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java @@ -104,6 +104,6 @@ public boolean matches(String hostname, String ip) { @Override public void init(Router router) { super.init(router); - reverseDNS = router.getTransport().isReverseDNS(); + reverseDNS = router.getTransport() != null && router.getTransport().isReverseDNS(); } } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java index 99307694b8..911280dba7 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java @@ -38,7 +38,7 @@ public interface Proxy extends Cloneable { RuleStatisticCollector getStatisticCollector(); - void init(Router router) throws Exception; + void init(Router router); boolean isTargetAdjustHostHeader(); diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java index 69f0c21905..187d6a8fc7 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java @@ -195,7 +195,7 @@ public SSLProvider getSslOutboundContext() { Router router; @Override - public void init(Router router) throws Exception { + public void init(Router router) { this.router = router; cm = new ConnectionManager(connectionConfiguration.getKeepAliveTimeout(), router.getTimerManager()); for (SSLInterceptor i : sslInterceptors) diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/GateKeeperClientInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/GateKeeperClientInterceptor.java deleted file mode 100644 index 1fb3aeadd7..0000000000 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/GateKeeperClientInterceptor.java +++ /dev/null @@ -1,114 +0,0 @@ -/* Copyright 2019 predic8 GmbH, www.predic8.com - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ -package com.predic8.membrane.core.sslinterceptor; - -import com.fasterxml.jackson.databind.*; -import com.google.common.cache.*; -import com.google.common.collect.*; -import com.predic8.membrane.annot.*; -import com.predic8.membrane.core.*; -import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.transport.http.client.*; -import com.predic8.membrane.core.transport.ssl.*; - -import java.util.*; - -import static com.predic8.membrane.core.http.MimeType.*; -import static com.predic8.membrane.core.http.Request.post; -import static java.util.concurrent.TimeUnit.*; - -/** - * Connects to the predic8 Gatekeeper to check, whether access is allowed or not. - */ -@MCElement(id = "sslProxy-gatekeeper", name = "gatekeeper", component = false) -public class GateKeeperClientInterceptor implements SSLInterceptor { - - protected final String name; - private String url; - private HttpClientConfiguration httpClientConfiguration; - - private HttpClient httpClient; - private final ObjectMapper om = new ObjectMapper(); - - public GateKeeperClientInterceptor() { - name = "gatekeeper"; - } - - @Override - public void init(Router router) throws Exception { - httpClient = router.getHttpClientFactory().createClient(httpClientConfiguration); - } - - final Cache cache = CacheBuilder.newBuilder().expireAfterWrite(1, MINUTES).build(); - - public Outcome handleRequest(SSLExchange exc) throws Exception { - - String ruleName = exc.getRule().getName(); - String clientIP = exc.getRemoteAddrIp(); - - - String body = om.writeValueAsString(ImmutableMap.builder() - .put("rule", ruleName) - .put("clientIP", clientIP) - .build()); - - Map result = cache.getIfPresent(body); - if (result == null) - result = getResult(body); - if (result.get("error") != null) - return createResponse(exc); - boolean gate = (boolean) result.get("gate"); - - if (gate) { - cache.put(body, result); - return Outcome.CONTINUE; - } - return createResponse(exc); - } - - private Map getResult(String body) throws Exception { - var exc = post(this.url).contentType(APPLICATION_JSON).body(body).buildExchange(); - httpClient.call(exc); - - - if(exc.getResponse().getStatusCode() != 200) - return ImmutableMap.of("error", "status " + exc.getResponse().getStatusCode()); - - return ImmutableMap.copyOf(om.readValue(exc.getResponse().getBodyAsStreamDecoded(), Map.class)); - } - - private Outcome createResponse(SSLExchange exc) { - exc.setError(TLSError.access_denied); - return Outcome.RETURN; - } - - public String getUrl() { - return url; - } - - @MCAttribute - public void setUrl(String url) { - this.url = url; - } - - public HttpClientConfiguration getHttpClientConfiguration() { - return httpClientConfiguration; - } - - @MCChildElement(order = 10) - public void setHttpClientConfiguration(HttpClientConfiguration httpClientConfiguration) { - this.httpClientConfiguration = httpClientConfiguration; - } -} diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java index 473a9e1cd8..2a5495b7e6 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java @@ -112,7 +112,7 @@ public void setSslParser(SSLParser sslParser) { } @Override - public void init(Router router) throws Exception { + public void init(Router router) { httpClient = router.getHttpClientFactory().createClient(httpClientConfiguration); if (sslParser != null) sslContext = new StaticSSLContext(sslParser, router.getResolverMap(), router.getBaseLocation()); diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java index b451ba39f6..2e25464d2f 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java @@ -18,7 +18,7 @@ import com.predic8.membrane.core.transport.ssl.SSLExchange; public interface SSLInterceptor { - void init(Router router) throws Exception; + void init(Router router); Outcome handleRequest(SSLExchange exc) throws Exception; } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java index 8d1a15cca7..baed3b59c4 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java @@ -25,6 +25,7 @@ import org.springframework.beans.factory.*; import java.io.*; +import java.lang.reflect.*; import java.util.*; public abstract class Transport { @@ -53,7 +54,7 @@ public void setFlow(List flow) { this.interceptors = flow; } - public void init(Router router) throws Exception { + public void init(Router router) { this.router = router; if (interceptors.isEmpty()) { @@ -76,14 +77,18 @@ public void init(Router router) throws Exception { /** * Look up an interceptor in the Spring context; fall back to default construction. */ - private @NotNull T getInterceptor(Class clazz) throws ReflectiveOperationException { + private @NotNull T getInterceptor(Class clazz) { BeanFactory bf = router.getBeanFactory(); if (bf instanceof ListableBeanFactory lbf) { T bean = lbf.getBeanProvider(clazz).getIfAvailable(); if (bean != null) return bean; } - return clazz.getConstructor().newInstance(); + try { + return clazz.getConstructor().newInstance(); + } catch (Exception e) { + throw new RuntimeException("Cannot instantiate object of class %s".formatted(clazz),e); + } } /** diff --git a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java index c3cfa9fe86..98c4472fcb 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java @@ -60,7 +60,7 @@ public class HttpTransport extends Transport { new SynchronousQueue<>(), new HttpServerThreadFactory()); @Override - public void init(Router router) throws Exception { + public void init(Router router) { super.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java b/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java index 696e11e1bd..df5405c05e 100644 --- a/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java +++ b/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java @@ -13,6 +13,9 @@ limitations under the License. */ package com.predic8.membrane.core.util; +import com.predic8.membrane.core.*; +import org.slf4j.*; + import java.util.Timer; import java.util.TimerTask; @@ -20,17 +23,23 @@ * Manages periodic tasks with a single timer. */ public class TimerManager { + + private static final Logger log = LoggerFactory.getLogger(TimerManager.class.getName()); + protected final java.util.Timer timer = new Timer(true); public void schedulePeriodicTask(TimerTask task, long period, String title) { + log.debug("Scheduling periodic task {} every {} ms.", title, period); timer.schedule(task, period, period); } public void schedule(TimerTask task, long delay, String title) { + log.debug("Scheduling task {} in {} ms.", title, delay); timer.schedule(task, delay); } public void shutdown() { + log.debug("Shutting down timer."); timer.cancel(); } } diff --git a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java index 3285f204cb..c7d991c020 100644 --- a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java +++ b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java @@ -18,15 +18,15 @@ public abstract class AbstractTestWithRouter { - protected static Router router; + protected Router router; - @BeforeAll - static void setUp() { + @BeforeEach + void setUp() { router = new HttpRouter(); } - @AfterAll - static void shutDown() { + @AfterEach + void shutDown() { router.shutdown(); } } diff --git a/core/src/test/java/com/predic8/membrane/AllTests.java b/core/src/test/java/com/predic8/membrane/AllTests.java deleted file mode 100644 index 2c87adeadc..0000000000 --- a/core/src/test/java/com/predic8/membrane/AllTests.java +++ /dev/null @@ -1,27 +0,0 @@ -/* Copyright 2009, 2011 predic8 GmbH, www.predic8.com - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ -package com.predic8.membrane; - -import com.predic8.membrane.core.*; -import com.predic8.membrane.integration.*; -import org.junit.platform.suite.api.SelectClasses; -import org.junit.platform.suite.api.Suite; - -@Suite -@SelectClasses({ - UnitTests.class, - IntegrationTestsWithoutInternet.class, - IntegrationTestsWithInternet.class -}) -public class AllTests {} \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java b/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java index 6a8d4d2eef..5c2c8cb183 100644 --- a/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java +++ b/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java @@ -26,7 +26,7 @@ import static com.predic8.membrane.core.http.Request.*; import static org.junit.jupiter.api.Assertions.*; -public class RuleManagerUriTemplateTest extends AbstractTestWithRouter { +public class RuleManagerUriTemplateTest { static Stream matches() { return Stream.of(Arguments.of("/foo","/foo"), @@ -57,9 +57,9 @@ void pathDoesntMatchesUriTemplate(String uriTemplate,String path) throws Excepti assertNotEquals(p, getMatchingProxy(uriTemplate, path, p)); } - private static Proxy getMatchingProxy(String uriTemplate, String path, APIProxy p) throws URISyntaxException { + private Proxy getMatchingProxy(String uriTemplate, String path, APIProxy p) throws URISyntaxException { p.setPath(new Path(false, uriTemplate)); - p.init(router); + p.init(new Router()); return new RuleManager() {{ proxies.add(p); }}.getMatchingRule(get(path).buildExchange()); diff --git a/core/src/test/java/com/predic8/membrane/core/UnitTests.java b/core/src/test/java/com/predic8/membrane/core/UnitTests.java index e63eec2563..c83bfab31d 100644 --- a/core/src/test/java/com/predic8/membrane/core/UnitTests.java +++ b/core/src/test/java/com/predic8/membrane/core/UnitTests.java @@ -13,13 +13,13 @@ limitations under the License. */ package com.predic8.membrane.core; +import org.junit.jupiter.api.*; import org.junit.platform.suite.api.*; @Suite @SelectPackages({"com.predic8"}) @ExcludePackages("com.predic8.membrane.integration") @ExcludeClassNamePatterns({ - "com.predic8.membrane.AllTests", // Replaced with package scan "com.predic8.membrane.core.transport.http.ConnectionTest", // #2180 should fix it "com.predic8.membrane.integration.withinternet.interceptor.RewriteInterceptorIntegrationTest", // Rewrite as UnitTest with sampleSOAPService "com.predic8.membrane.core.interceptor.tunnel.WebsocketStompTest", // Fails: not standalone; depends on external WS+STOMP setup diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 504ef3a209..40ab65c3f7 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -13,102 +13,99 @@ limitations under the License. */ package com.predic8.membrane.core.config; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.proxies.*; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; -import java.util.List; +import java.util.*; import static org.junit.jupiter.api.Assertions.*; public class ReadRulesConfigurationTest { - private static Router router; + private static Router router; - private static List proxies; + private static List proxies; - @BeforeAll - public static void setUp() { + @BeforeAll + static void setUp() { router = Router.initByXML("classpath:/proxies.xml"); - proxies = router.getRuleManager().getRules(); - } - - @Test - void testRulesSize() { - assertEquals(3, proxies.size()); - } - - @Test - void testProxyRuleListenPort() { - assertEquals(3090, proxies.getFirst().getKey().getPort()); - } - - @Test - void testServiceProxyListenPort() { - assertEquals(3000, proxies.get(1).getKey().getPort()); - } - - @Test - void testServiceProxyTargetPort() { - assertEquals(80, ((ServiceProxy) proxies.get(1)).getTargetPort()); - } - - @Test - void testServiceProxyTargetHost() { - assertEquals("thomas-bayer.com", ((ServiceProxy) proxies.get(1)).getTargetHost()); - } - - @Test - void testServiceProxyDefaultMethod() { - assertEquals("*", proxies.get(1).getKey().getMethod()); - } - - @Test - void testTestServiceProxyDefaultHost() { - assertEquals("*", proxies.get(1).getKey().getHost()); - } - - @Test - void testLocalServiceProxyListenPort() { - assertEquals(2000, proxies.get(2).getKey().getPort()); - } - - @Test - void testLocalServiceProxyTargetPort() { - assertEquals(3011, ((ServiceProxy) proxies.get(2)).getTargetPort()); - } - - @Test - void testServiceProxyMethodSet() { - assertEquals("GET", proxies.get(2).getKey().getMethod()); - } - - @Test - void testServiceProxyHostSet() { - assertEquals("localhost", proxies.get(2).getKey().getHost()); - } - - @Test - void testLocalServiceProxyInboundSSL() { + proxies = router.getRuleManager().getRules(); + } + + @AfterAll + public static void tearDown() { + router.shutdown(); + } + + @Test + void testRulesSize() { + assertEquals(3, proxies.size()); + } + + @Test + void testProxyRuleListenPort() { + assertEquals(3090, proxies.getFirst().getKey().getPort()); + } + + @Test + void testServiceProxyListenPort() { + assertEquals(3000, proxies.get(1).getKey().getPort()); + } + + @Test + void testServiceProxyTargetPort() { + assertEquals(80, ((ServiceProxy) proxies.get(1)).getTargetPort()); + } + + @Test + void testServiceProxyTargetHost() { + assertEquals("thomas-bayer.com", ((ServiceProxy) proxies.get(1)).getTargetHost()); + } + + @Test + void testServiceProxyDefaultMethod() { + assertEquals("*", proxies.get(1).getKey().getMethod()); + } + + @Test + void testTestServiceProxyDefaultHost() { + assertEquals("*", proxies.get(1).getKey().getHost()); + } + + @Test + void testLocalServiceProxyListenPort() { + assertEquals(2000, proxies.get(2).getKey().getPort()); + } + + @Test + void testLocalServiceProxyTargetPort() { + assertEquals(3011, ((ServiceProxy) proxies.get(2)).getTargetPort()); + } + + @Test + void testServiceProxyMethodSet() { + assertEquals("GET", proxies.get(2).getKey().getMethod()); + } + + @Test + void testServiceProxyHostSet() { + assertEquals("localhost", proxies.get(2).getKey().getHost()); + } + + @Test + void testLocalServiceProxyInboundSSL() { if (proxies.get(2) instanceof SSLableProxy sp) { - assertFalse(sp.isInboundSSL()); - } - assertTrue(true); - } - - @Test - void testLocalServiceProxyOutboundSSL() { - if (proxies.get(2) instanceof SSLableProxy sp) { - assertNull(sp.getSslOutboundContext()); - } - assertTrue(true); - } - - @AfterAll - public static void tearDown() { - router.shutdown(); - } + assertFalse(sp.isInboundSSL()); + } + assertTrue(true); + } + @Test + void testLocalServiceProxyOutboundSSL() { + if (proxies.get(2) instanceof SSLableProxy sp) { + assertNull(sp.getSslOutboundContext()); + } + assertTrue(true); + } } diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java index 07493028cc..14360cbde2 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java @@ -14,61 +14,59 @@ package com.predic8.membrane.core.exchangestore; -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Request; -import com.predic8.membrane.core.interceptor.AbstractInterceptor; -import com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor; -import com.predic8.membrane.core.interceptor.Interceptor; -import com.predic8.membrane.core.interceptor.Outcome; -import com.predic8.membrane.core.interceptor.flow.ReturnInterceptor; -import com.predic8.membrane.core.interceptor.log.LogInterceptor; -import com.predic8.membrane.core.interceptor.templating.StaticInterceptor; -import com.predic8.membrane.core.proxies.ServiceProxy; -import com.predic8.membrane.core.proxies.ServiceProxyKey; -import com.predic8.membrane.core.transport.http.HttpClient; -import org.jetbrains.annotations.NotNull; +import com.fasterxml.jackson.core.*; +import com.fasterxml.jackson.databind.*; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.interceptor.flow.*; +import com.predic8.membrane.core.interceptor.log.*; +import com.predic8.membrane.core.interceptor.templating.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.transport.http.*; +import org.jetbrains.annotations.*; import org.jose4j.base64url.Base64; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.List; - -import static com.predic8.membrane.core.http.Header.AUTHORIZATION; -import static com.predic8.membrane.core.http.Header.CONTENT_TYPE; -import static com.predic8.membrane.core.http.MimeType.TEXT_PLAIN; -import static com.predic8.membrane.core.http.Response.ok; -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; -import static java.nio.charset.StandardCharsets.UTF_8; +import org.junit.jupiter.api.*; + +import java.io.*; +import java.util.*; + +import static com.predic8.membrane.core.http.Header.*; +import static com.predic8.membrane.core.http.MimeType.*; +import static com.predic8.membrane.core.http.Response.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; +import static java.nio.charset.StandardCharsets.*; import static org.junit.jupiter.api.Assertions.*; class ElasticSearchExchangeStoreTest { - private static HttpRouter gateway; - private static HttpRouter back; - private static HttpRouter elasticMock; - private static ElasticSearchExchangeStore es; - - private static final List insertedObjects = new ArrayList<>(); - private static String RESPONSE_BODY = """ + private static final String RESPONSE_BODY = """ {"demo": true}"""; - private String REQUEST_BODY = """ + private static final String REQUEST_BODY = """ {"where":"there"}"""; - @BeforeAll - public static void start() throws IOException { + private HttpRouter gateway; + private HttpRouter back; + private HttpRouter elasticMock; + private ElasticSearchExchangeStore es; + + private final List insertedObjects = new ArrayList<>(); + + + @BeforeEach + public void start() throws IOException { initializeElasticSearchMock(); initializeBackend(); } - private static void initializeElasticSearchMock() throws IOException { + @AfterEach + public void done() { + back.stop(); + elasticMock.stop(); + } + + private void initializeElasticSearchMock() throws IOException { elasticMock = new HttpRouter(); elasticMock.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3066), null, 0); @@ -84,7 +82,7 @@ private static void initializeElasticSearchMock() throws IOException { return log; } - private static void initializeGateway(boolean addLoggingInterceptors) throws IOException { + private void initializeGateway(boolean addLoggingInterceptors) throws IOException { gateway = new HttpRouter(); gateway.getConfig().setHotDeploy(false); es = new ElasticSearchExchangeStore(); @@ -101,7 +99,7 @@ private static void initializeGateway(boolean addLoggingInterceptors) throws IOE gateway.start(); } - private static void initializeBackend() throws IOException { + private void initializeBackend() throws IOException { back = new HttpRouter(); back.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); @@ -109,31 +107,25 @@ private static void initializeBackend() throws IOException { si.setSrc(RESPONSE_BODY); sp.getFlow().add(si); ReturnInterceptor ri = new ReturnInterceptor(); - ri.setStatusCode(200); + ri.setStatus(200); sp.getFlow().add(ri); back.add(sp); back.start(); } - @AfterAll - public static void done() { - back.stop(); - elasticMock.stop(); - } - - private static Interceptor createElasticSearchMockInterceptor() { + private Interceptor createElasticSearchMockInterceptor() { ObjectMapper om = new ObjectMapper(); return new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { if (exc.getRequest().isGETRequest()) { exc.setResponse(ok(""" - {"acknowledged": true}""").build()); + {"acknowledged": true}""").build()); return RETURN; } - if (exc.getRequest().getMethod().equals("GET") && exc.getRequest().getUri().equals("/membrane/_mapping")) { + if (exc.getRequest().isGETRequest() && exc.getRequest().getUri().equals("/membrane/_mapping")) { exc.setResponse(ok(""" - {"membrane": {"mappings": {"something":true}}}""").build()); + {"membrane": {"mappings": {"something":true}}}""").build()); return RETURN; } return getOutcome(exc, om); @@ -141,8 +133,8 @@ public Outcome handleRequest(Exchange exc) { }; } - private static @NotNull Outcome getOutcome(Exchange exc, ObjectMapper om) { - if (exc.getRequest().getMethod().equals("POST") && exc.getRequest().getUri().equals("/_bulk")) { + private @NotNull Outcome getOutcome(Exchange exc, ObjectMapper om) { + if (exc.getRequest().isPOSTRequest() && exc.getRequest().getUri().equals("/_bulk")) { for (String line : exc.getRequest().getBodyAsStringDecoded().split("\n")) { try { JsonNode obj = om.readTree(line); @@ -161,7 +153,7 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } - public static List getInsertedObjectsAndClearList() { + public List getInsertedObjectsAndClearList() { synchronized (insertedObjects) { List insertedObjects1 = new ArrayList(insertedObjects); insertedObjects.clear(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerAndNoSessionTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerAndNoSessionTest.java index 0fe2649d4d..5836a04b50 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerAndNoSessionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerAndNoSessionTest.java @@ -16,8 +16,7 @@ import com.predic8.membrane.interceptor.LoadBalancingInterceptorTest; import org.junit.jupiter.api.BeforeEach; -public class LoadBalancingWithClusterManagerAndNoSessionTest extends -LoadBalancingInterceptorTest { +public class LoadBalancingWithClusterManagerAndNoSessionTest extends LoadBalancingInterceptorTest { @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java index 12612e0667..f885d1136e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java @@ -30,10 +30,10 @@ public class LoadBalancingWithClusterManagerTest { - private static HttpRouter lb; - private static HttpRouter node1; - private static HttpRouter node2; - private static HttpRouter node3; + private HttpRouter lb; + private HttpRouter node1; + private HttpRouter node2; + private HttpRouter node3; @Test void nodesTest() throws Exception { @@ -84,8 +84,8 @@ void nodesTest() throws Exception { assertEquals(2, service3.getCount()); } - @AfterAll - public static void tearDown() { + @AfterEach + public void tearDown() { lb.shutdown(); node1.shutdown(); node2.shutdown(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index 10b41ee202..e4a314c816 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -24,7 +24,7 @@ class OpenTelemetryInterceptorTest { @Test - void initTest() throws Exception { + void initTest() { Proxy r = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3141), null, 0); r.getFlow().add(new OpenTelemetryInterceptor()); @@ -32,5 +32,6 @@ void initTest() throws Exception { rtr.getRuleManager().addProxy(r, SPRING); rtr.init(); + rtr.shutdown(); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index a79a289156..e4f1afe76a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -36,6 +36,7 @@ import java.util.concurrent.atomic.*; import java.util.stream.*; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.interceptor.Outcome.CONTINUE; import static com.predic8.membrane.core.interceptor.Outcome.RETURN; import static java.nio.charset.StandardCharsets.*; @@ -61,7 +62,7 @@ void shutDown() throws IOException { @Test public void generalSessionUsageTest() throws Exception { ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxyAndOpenPortIfNew(sp); + router.getRuleManager().addProxy(sp, MANUAL); AtomicLong counter = new AtomicLong(0); List vals = new ArrayList<>(); @@ -71,7 +72,7 @@ public void generalSessionUsageTest() throws Exception { sp.getFlow().add(interceptor); sp.getFlow().add(testResponseInterceptor()); - router.init(); + router.start(); IntStream.range(0, 50).forEach(i -> sendRequest()); @@ -90,7 +91,7 @@ private ServiceProxy createTestServiceProxy() { @Test public void expirationTest() throws Exception{ ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxyAndOpenPortIfNew(sp); + router.getRuleManager().addProxy(sp,MANUAL); AtomicLong counter = new AtomicLong(0); List vals = new ArrayList<>(); @@ -100,7 +101,7 @@ public void expirationTest() throws Exception{ sp.getFlow().add(interceptor); sp.getFlow().add(testResponseInterceptor()); - router.init(); + router.start(); interceptor.getSessionManager().setExpiresAfterSeconds(0); @@ -113,12 +114,12 @@ public void expirationTest() throws Exception{ @Test public void noUnneededRenewalOnReadOnlySession() throws Exception{ ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxyAndOpenPortIfNew(sp); + router.getRuleManager().addProxy(sp,MANUAL); sp.getFlow().add(createAndReadOnlySessionInterceptor()); sp.getFlow().add(testResponseInterceptor()); - router.init(); + router.start(); List> bodies = new ArrayList<>(); @@ -139,8 +140,8 @@ public void renewalOnReadOnlySession() throws Exception{ sp.getFlow().add(createAndReadOnlySessionInterceptor); sp.getFlow().add(testResponseInterceptor()); - router.getRuleManager().addProxyAndOpenPortIfNew(sp); - router.init(); + router.getRuleManager().addProxy(sp,MANUAL); + router.start(); List> bodies = new ArrayList<>(); diff --git a/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java index 886472d2d1..7fc01e8eef 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java @@ -26,12 +26,12 @@ class TemplateExchangeExpressionTest { - static Exchange exc; - static Language language; - static Router router; + Exchange exc; + Language language; + Router router; - @BeforeAll - static void setUp() throws Exception { + @BeforeEach + void setUp() throws Exception { exc = Request.get("/foo") .header("bar", "42") .buildExchange(); @@ -65,7 +65,7 @@ void multiple() { assertEquals("Mars - 42 - 6 7", eval("${property.prop1} - ${header.bar} - ${2*3} ${7}")); } - private static String eval(String expr) { + private String eval(String expr) { return new TemplateExchangeExpression(new InterceptorAdapter(router), language, expr).evaluate(exc, REQUEST,String.class); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpressionTest.java index 10dcccad82..70e8cdb5e4 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/jsonpath/JsonpathExchangeExpressionTest.java @@ -160,7 +160,7 @@ void number() throws URISyntaxException { assertEquals(314, expr.evaluate(post("/foo").json("314").buildExchange(), REQUEST, Integer.class)); } - private static T evaluateWithEmptyBodyFor(Class type) throws URISyntaxException { + private T evaluateWithEmptyBodyFor(Class type) throws URISyntaxException { return expression(new InterceptorAdapter(router), JSONPATH, "$").evaluate(get("/foo").buildExchange(), REQUEST, type); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java index 22584d01b3..da6d393f64 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java @@ -23,6 +23,9 @@ import com.predic8.membrane.core.util.*; import org.junit.jupiter.api.*; +import java.net.*; + +import static com.predic8.membrane.core.http.Request.get; import static com.predic8.membrane.core.openapi.util.OpenAPITestUtils.createProxy; import static com.predic8.membrane.test.TestUtil.getPathFromResource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -36,14 +39,14 @@ public class OpenAPI31Test { final Exchange exc = new Exchange(null); @BeforeEach - public void setUp() { + void setUp() throws URISyntaxException { Router router = new Router(); router.getConfig().setUriFactory(new URIFactory()); petstore_v3_1 = new OpenAPISpec(); petstore_v3_1.location = getPathFromResource("openapi/specs/petstore-v3.1.json"); - exc.setRequest(new Request.Builder().method("GET").build()); + exc.setRequest(get("/foo").build()); interceptor = new OpenAPIInterceptor(createProxy(router, petstore_v3_1)); interceptor.init(router); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index 2bd3a7da01..435b4d6997 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -47,7 +47,7 @@ class OpenAPIInterceptorTest { OpenAPIInterceptor interceptor3Server; @BeforeEach - public void setUp() { + void setUp() { router = new Router(); router.getConfig().setUriFactory(new URIFactory()); @@ -68,6 +68,11 @@ public void setUp() { interceptor3Server.init(router); } + @AfterEach + void tearDown() { + router.shutdown(); + } + @Test void getMatchingBasePathOneServer() { exc.getRequest().setUri("/base/v2/foo"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index daed523211..d956074da6 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -34,21 +34,20 @@ import java.util.*; import static com.predic8.membrane.core.exchange.Exchange.SECURITY_SCHEMES; +import static com.predic8.membrane.core.http.Request.get; import static com.predic8.membrane.core.openapi.util.OpenAPITestUtils.*; import static com.predic8.membrane.test.TestUtil.getPathFromResource; import static org.junit.jupiter.api.Assertions.*; public class JWTInterceptorAndSecurityValidatorTest { - public static final String SPEC_LOCATION = getPathFromResource( "openapi/openapi-proxy/no-extensions.yml"); - APIProxy proxy; + private static final String SPEC_LOCATION = getPathFromResource( "openapi/openapi-proxy/no-extensions.yml"); + private APIProxy proxy; RsaJsonWebKey privateKey; - @BeforeEach public void setUp() throws Exception { - Router router = new Router(); proxy = createProxy(router, getSpec()); @@ -56,15 +55,11 @@ public void setUp() throws Exception { privateKey.setKeyId("membrane"); proxy.getFlow().add(getJwtAuthInterceptor(router)); - - router.setTransport(new HttpTransport()); - router.setExchangeStore(new ForgetfulExchangeStore()); - router.init(); } @Test - public void checkIfScopesAreStoredInProperty() throws Exception { - Exchange exc = new Request.Builder().get("/foo").header("Authorization", "bearer " + getSignedJwt(privateKey, getJwtClaimsStringScopesList())).buildExchange(); + void checkIfScopesAreStoredInProperty() throws Exception { + Exchange exc = get("/foo").header("Authorization", "bearer " + getSignedJwt(privateKey, getJwtClaimsStringScopesList())).buildExchange(); callInterceptorChain(exc); //noinspection unchecked @@ -72,7 +67,7 @@ public void checkIfScopesAreStoredInProperty() throws Exception { } @Test - public void checkIfScopesCanBeReadFromListType() throws Exception { + void checkIfScopesCanBeReadFromListType() throws Exception { Exchange exc = new Request.Builder().get("/foo").header("Authorization", "bearer " + getSignedJwt(privateKey, getJwtClaimsArrayScopesList())).buildExchange(); callInterceptorChain(exc); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index 92b3b6b7cd..5ad9a84dc1 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -28,10 +28,10 @@ class InternalProxyTest { - private static Router router; + private Router router; - @BeforeAll - public static void setup() throws Exception { + @BeforeEach + void setup() throws Exception { router = new HttpRouter(); router.add(new APIProxy() {{ @@ -112,8 +112,8 @@ public static void setup() throws Exception { } - @AfterAll - public static void teardown() { + @AfterEach + void teardown() { router.shutdown(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index 5f421c6b40..db7543ae8e 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -62,14 +62,14 @@ void shutDown() { void parseWSDL() throws Exception { proxy.setWsdl("classpath:/ws/cities.wsdl"); router.add(proxy); - router.init(); + router.start(); } @Test void parseWSDLWithMultiplePortsPerService() throws Exception { proxy.setWsdl("classpath:/blz-service.wsdl"); router.add(proxy); - router.init(); + router.start(); } @Test @@ -77,7 +77,7 @@ void parseWSDLWithMultipleServices() throws Exception { proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); proxy.setServiceName("CityServiceA"); router.add(proxy); - router.init(); + router.start(); } @Test @@ -85,7 +85,7 @@ void parseWSDLWithMultipleServicesForAGivenServiceA() throws Exception { proxy.setServiceName("CityServiceA"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); router.add(proxy); - router.init(); + router.start(); } @Test @@ -93,7 +93,7 @@ void parseWSDLWithMultipleServicesForAGivenServiceB() throws Exception { proxy.setServiceName("CityServiceB"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); router.add(proxy); - router.init(); + router.start(); // @formatter: off given().when() @@ -111,6 +111,6 @@ void parseWSDLWithMultipleServicesForAWrongService() throws Exception { proxy.setServiceName("WrongService"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); router.add(proxy); - assertThrows(IllegalArgumentException.class, () -> router.init()); + assertThrows(IllegalArgumentException.class, () -> router.start()); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java index a3e16c0513..4f38e7d758 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java @@ -28,16 +28,16 @@ @SuppressWarnings("HttpUrlsUsage") public class ServiceProxyWSDLInterceptorsTest { - static Router router; + Router router; - @BeforeAll - static void setUp() { + @BeforeEach + void setUp() { router = new HttpRouter(); router.getConfig().setHotDeploy(false); } - @AfterAll - static void teardown() { + @AfterEach + void teardown() { router.stop(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/AbstractServiceProxyExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java similarity index 68% rename from core/src/test/java/com/predic8/membrane/core/proxies/AbstractServiceProxyExpressionTest.java rename to core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index 0ea1f3c3ff..b21a6d90a1 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/AbstractServiceProxyExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -14,32 +14,28 @@ package com.predic8.membrane.core.proxies; import com.predic8.membrane.AbstractTestWithRouter; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.config.Path; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.interceptor.DispatchingInterceptor; -import com.predic8.membrane.core.interceptor.flow.ReturnInterceptor; -import com.predic8.membrane.core.interceptor.log.LogInterceptor; import com.predic8.membrane.core.openapi.serviceproxy.APIProxy; -import com.predic8.membrane.core.openapi.serviceproxy.APIProxyKey; -import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import java.io.IOException; import java.net.URISyntaxException; -import static com.predic8.membrane.core.interceptor.flow.invocation.FlowTestInterceptors.A; +import static com.predic8.membrane.core.http.Request.get; import static io.restassured.RestAssured.given; -import static org.hamcrest.Matchers.equalToIgnoringCase; import static org.junit.jupiter.api.Assertions.assertEquals; -class AbstractServiceProxyExpressionTest extends AbstractTestWithRouter { +/** + * Verifies that expressions in the target URL are evaluated correctly. + */ +class TargetURLExpressionTest { @Test void targetWithExpression() throws IOException, URISyntaxException { - HttpRouter r = new HttpRouter(); - Exchange rq = new Request.Builder().get("http://localhost:2000/").buildExchange(); + Router r = new Router(); + Exchange rq = get("http://localhost:2000/").buildExchange(); APIProxy api = new APIProxy() {{ setTarget(new Target() {{ setUrl("http://localhost:${2000 + 1000}"); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 60331a7272..5c34ee049b 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -27,12 +27,12 @@ public class UnavailableSoapProxyTest { private Router r, r2; - private static Router backendRouter; + private Router backendRouter; private SOAPProxy sp; private ServiceProxy sp3; - @BeforeAll - static void setup() throws Exception { + @BeforeEach + void setup() throws Exception { ServiceProxy cityAPI = new ServiceProxy(new ServiceProxyKey(4000), null, 0); cityAPI.getFlow().add(new SampleSoapServiceInterceptor()); backendRouter = new HttpRouter(); @@ -40,14 +40,16 @@ static void setup() throws Exception { backendRouter.init(); } - @AfterAll - static void teardown() { + @AfterEach + void teardown() { backendRouter.shutdown(); + r.shutdown(); + r2.shutdown(); } @BeforeEach void startRouter() { - r = new Router(); + r = new HttpRouter(); HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); r.setHttpClientConfig(httpClientConfig); @@ -68,7 +70,7 @@ void startRouter() { SOAPProxy sp2 = new SOAPProxy(); sp2.setPort(2001); sp2.setWsdl("http://localhost:4000?wsdl"); - r2 = new Router(); + r2 = new HttpRouter(); r2.getConfig().setHotDeploy(false); r2.getRules().add(sp2); } diff --git a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java index 43b148a255..b7cc62186d 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java @@ -54,7 +54,7 @@ static void setUp() throws Exception { @AfterAll static void tearDown() { - router.stop(); + router.shutdown(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index de9dd17d54..e8098f6456 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -23,6 +23,7 @@ import java.util.concurrent.*; import java.util.stream.*; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.interceptor.flow.invocation.FlowTestInterceptors.*; import static org.junit.jupiter.api.Assertions.*; @@ -48,8 +49,8 @@ public void setup() throws Exception{ sp.getFlow().add(GROOVY("Thread.sleep(1000)")); sp.getFlow().add(RETURN); - router.getRuleManager().addProxyAndOpenPortIfNew(sp); - router.init(); + router.getRuleManager().addProxy(sp, MANUAL); + router.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java index b749addd9e..166e3e74f0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java @@ -29,7 +29,7 @@ public class ConnectionTest { HttpRouter router; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { ServiceProxy proxy2000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 2000), "predic8.com", 80); router = new HttpRouter(); @@ -40,7 +40,7 @@ public void setUp() throws Exception { } @AfterEach - public void tearDown() throws Exception { + void tearDown() throws Exception { conLocalhost.close(); con127_0_0_1.close(); assertTrue(conLocalhost.isClosed()); @@ -51,7 +51,7 @@ public void tearDown() throws Exception { @Test - public void testIsSame() { + void isSame() { assertTrue(conLocalhost.isSame("127.0.0.1", 2000)); assertTrue(con127_0_0_1.isSame("localhost", 2000)); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index 9405efecb3..b37d267473 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -18,8 +18,8 @@ import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.http.*; import org.junit.jupiter.api.*; @@ -27,9 +27,8 @@ import java.net.*; import java.util.concurrent.atomic.*; -import static com.predic8.membrane.core.exchange.Exchange.SSL_CONTEXT; -import static com.predic8.membrane.core.http.Header.CONTENT_ENCODING; -import static com.predic8.membrane.core.http.Header.CONTENT_TYPE; +import static com.predic8.membrane.core.exchange.Exchange.*; +import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.interceptor.Outcome.*; /** @@ -46,14 +45,20 @@ public class SessionResumptionTest { private static SSLContext clientTLSContext; @BeforeAll - public static void init() throws IOException { + static void init() throws IOException { tcpForwarder = startTCPForwarder(3044); router1 = createTLSServer(3042); router2 = createTLSServer(3043); - clientTLSContext = createClientTLSContext(); } + @AfterAll + static void done() throws IOException { + tcpForwarder.close(); + router1.shutdown(); + router2.shutdown(); + } + private static SSLContext createClientTLSContext() { SSLParser sslParser = new SSLParser(); TrustStore trustStore = new TrustStore(); @@ -64,17 +69,10 @@ private static SSLContext createClientTLSContext() { return new StaticSSLContext(sslParser, new ResolverMap(), "."); } - @AfterAll - public static void done() throws IOException { - tcpForwarder.close(); - router1.shutdown(); - router2.shutdown(); - } - @Disabled @Test public void doit() throws Exception { - try(HttpClient hc = new HttpClient()) { + try (HttpClient hc = new HttpClient()) { for (int i = 0; i < 2; i++) { // the tcp forwarder will forward the first connection to 3042, the second to 3043 Exchange exc = new Request.Builder().get("https://localhost:3044").buildExchange(); @@ -140,7 +138,7 @@ private static Closeable startTCPForwarder(int port) throws IOException { throw e; } int port1 = 3042 + counter.incrementAndGet() % 2; - try(Socket outbout = new Socket("localhost", port1)) { + try (Socket outbout = new Socket("localhost", port1)) { Thread s = new Thread(new StreamPump(inbound.getInputStream(), outbout.getOutputStream(), sps, "a", mock)); s.start(); Thread s2 = new Thread(new StreamPump(outbout.getInputStream(), inbound.getOutputStream(), sps, "b", mock)); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 2fbd0056b0..0be4419cb0 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -27,6 +27,7 @@ import java.net.*; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.http.Response.internalServerError; @@ -40,7 +41,7 @@ import static org.apache.http.params.HttpProtocolParams.*; import static org.junit.jupiter.api.Assertions.*; -public class LoadBalancingInterceptorTest { +public abstract class LoadBalancingInterceptorTest { private DummyWebServiceInterceptor mockInterceptor1; private DummyWebServiceInterceptor mockInterceptor2; @@ -54,8 +55,8 @@ public class LoadBalancingInterceptorTest { @BeforeEach public void setUp() throws Exception { - int port2k = getFreePortEqualAbove(2000); - int port3k = getFreePortEqualAbove(3000); + int port2k = 2000; + int port3k = 3000; service1 = new HttpRouter(); mockInterceptor1 = new DummyWebServiceInterceptor(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", @@ -63,13 +64,13 @@ public void setUp() throws Exception { sp1.getFlow().add(new AbstractInterceptor(){ @Override public Outcome handleResponse(Exchange exc) { - exc.getResponse().getHeader().add("Connection", "close"); + exc.getResponse().getHeader().setConnection("close"); return CONTINUE; } }); sp1.getFlow().add(mockInterceptor1); - service1.getRuleManager().addProxyAndOpenPortIfNew(sp1); - service1.init(); + service1.getRuleManager().addProxy(sp1, MANUAL); + service1.start(); service2 = new HttpRouter(); mockInterceptor2 = new DummyWebServiceInterceptor(); @@ -78,13 +79,13 @@ public Outcome handleResponse(Exchange exc) { sp2.getFlow().add(new AbstractInterceptor(){ @Override public Outcome handleResponse(Exchange exc) { - exc.getResponse().getHeader().add("Connection", "close"); + exc.getResponse().getHeader().setConnection("close"); return CONTINUE; } }); sp2.getFlow().add(mockInterceptor2); - service2.getRuleManager().addProxyAndOpenPortIfNew(sp2); - service2.init(); + service2.getRuleManager().addProxy(sp2, MANUAL); + service2.start(); balancer = new HttpRouter(); ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", @@ -146,7 +147,6 @@ void roundRobinDispatchingStrategy() throws Exception { PostMethod vari = getPostMethod(); int status = client.executeMethod(vari); - //System.out.println(new String(vari.getResponseBody())); assertEquals(200, status); assertEquals(1, mockInterceptor1.getCount()); diff --git a/core/src/test/resources/log4j2.xml b/core/src/test/resources/log4j2.xml index 169c6a9115..2fca88179f 100644 --- a/core/src/test/resources/log4j2.xml +++ b/core/src/test/resources/log4j2.xml @@ -14,7 +14,7 @@ - + diff --git a/core/src/test/resources/ref.proxies.xml b/core/src/test/resources/ref.proxies.xml index 4d32511761..75f003c13b 100644 --- a/core/src/test/resources/ref.proxies.xml +++ b/core/src/test/resources/ref.proxies.xml @@ -39,8 +39,7 @@ - + diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 9ab79ee21b..e6bf6cd1eb 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -15,6 +15,9 @@ # 7.1.0 +- reverseDNS + - Now it is in transport + - Maybe move it to configuration - Register JSON Schema for YAML at: https://www.schemastore.org - Grafana Dashboard: Complete Dashboard for Membrane with documentation in examples/monitoring/grafana - Remove GroovyTemplateInterceptor (Not Template Interceptor) @@ -42,6 +45,7 @@ ## (Breaking) Interface Changes +- Removed GateKeeperClientInterceptor - Removed support for `internal:` syntax in target URLs, leaving `internal://` as the only valid way to call internal APIs. - Remove WADLInterceptor - HttpClient TB (done) From c9dd5c44104a3fdcf901b25ae293804b39a37bc6 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 19:12:17 +0100 Subject: [PATCH 17/40] refactor: streamline imports in test files and remove redundant `Exception` declarations --- .../com/predic8/membrane/core/UnitTests.java | 1 - .../session/SessionInterceptorTest.java | 8 ++++---- .../core/proxies/InternalProxyTest.java | 9 +++------ .../core/proxies/TargetURLExpressionTest.java | 20 +++++++++---------- .../LoadBalancingInterceptorTest.java | 7 +++---- 5 files changed, 19 insertions(+), 26 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/UnitTests.java b/core/src/test/java/com/predic8/membrane/core/UnitTests.java index c83bfab31d..2167afb4bf 100644 --- a/core/src/test/java/com/predic8/membrane/core/UnitTests.java +++ b/core/src/test/java/com/predic8/membrane/core/UnitTests.java @@ -13,7 +13,6 @@ limitations under the License. */ package com.predic8.membrane.core; -import org.junit.jupiter.api.*; import org.junit.platform.suite.api.*; @Suite diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index e4f1afe76a..f86dd02bb5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -60,7 +60,7 @@ void shutDown() throws IOException { } @Test - public void generalSessionUsageTest() throws Exception { + public void generalSessionUsageTest() { ServiceProxy sp = createTestServiceProxy(); router.getRuleManager().addProxy(sp, MANUAL); @@ -89,7 +89,7 @@ private ServiceProxy createTestServiceProxy() { } @Test - public void expirationTest() throws Exception{ + public void expirationTest() { ServiceProxy sp = createTestServiceProxy(); router.getRuleManager().addProxy(sp,MANUAL); @@ -112,7 +112,7 @@ public void expirationTest() throws Exception{ } @Test - public void noUnneededRenewalOnReadOnlySession() throws Exception{ + public void noUnneededRenewalOnReadOnlySession() { ServiceProxy sp = createTestServiceProxy(); router.getRuleManager().addProxy(sp,MANUAL); @@ -133,7 +133,7 @@ public void noUnneededRenewalOnReadOnlySession() throws Exception{ @Disabled @Test - public void renewalOnReadOnlySession() throws Exception{ + public void renewalOnReadOnlySession() { ServiceProxy sp = createTestServiceProxy(); AbstractInterceptorWithSession createAndReadOnlySessionInterceptor = createAndReadOnlySessionInterceptor(); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index 5ad9a84dc1..44ebd69811 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -14,17 +14,14 @@ package com.predic8.membrane.core.proxies; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.interceptor.flow.ResponseInterceptor; -import com.predic8.membrane.core.interceptor.flow.ReturnInterceptor; -import com.predic8.membrane.core.interceptor.groovy.GroovyInterceptor; -import com.predic8.membrane.core.interceptor.log.LogInterceptor; +import com.predic8.membrane.core.interceptor.flow.*; +import com.predic8.membrane.core.interceptor.groovy.*; import com.predic8.membrane.core.openapi.serviceproxy.*; -import org.hamcrest.*; import org.junit.jupiter.api.*; import static com.predic8.membrane.core.interceptor.flow.invocation.FlowTestInterceptors.*; import static io.restassured.RestAssured.*; -import static org.hamcrest.Matchers.equalTo; +import static org.hamcrest.Matchers.*; class InternalProxyTest { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index b21a6d90a1..e0ae9d84bc 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -13,19 +13,17 @@ limitations under the License. */ package com.predic8.membrane.core.proxies; -import com.predic8.membrane.AbstractTestWithRouter; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.interceptor.DispatchingInterceptor; -import com.predic8.membrane.core.openapi.serviceproxy.APIProxy; -import org.junit.jupiter.api.Test; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.openapi.serviceproxy.*; +import org.junit.jupiter.api.*; -import java.io.IOException; -import java.net.URISyntaxException; +import java.io.*; +import java.net.*; -import static com.predic8.membrane.core.http.Request.get; -import static io.restassured.RestAssured.given; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static com.predic8.membrane.core.http.Request.*; +import static org.junit.jupiter.api.Assertions.*; /** * Verifies that expressions in the target URL are evaluated correctly. @@ -33,7 +31,7 @@ class TargetURLExpressionTest { @Test - void targetWithExpression() throws IOException, URISyntaxException { + void targetWithExpression() throws URISyntaxException { Router r = new Router(); Exchange rq = get("http://localhost:2000/").buildExchange(); APIProxy api = new APIProxy() {{ diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 0be4419cb0..1a19de7855 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -27,14 +27,13 @@ import java.net.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.http.MimeType.*; -import static com.predic8.membrane.core.http.Response.internalServerError; -import static com.predic8.membrane.core.interceptor.InterceptorUtil.getInterceptors; +import static com.predic8.membrane.core.http.Response.*; +import static com.predic8.membrane.core.interceptor.InterceptorUtil.*; import static com.predic8.membrane.core.interceptor.Outcome.*; import static com.predic8.membrane.core.interceptor.balancer.BalancerUtil.*; -import static com.predic8.membrane.core.util.NetworkUtil.*; import static java.lang.Thread.*; import static java.util.Objects.*; import static org.apache.commons.httpclient.HttpVersion.*; From bf9f618dc8ec322fce904d2884f4e536fdc872ec Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 19:28:17 +0100 Subject: [PATCH 18/40] refactor: improve thread-safety in `registerIfAbsent` by introducing dedicated lock --- .../BeanRegistryImplementation.java | 23 +++++++++---------- 1 file changed, 11 insertions(+), 12 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index e337ecafc8..0c04d43612 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -41,6 +41,8 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { private final Map bcs = new ConcurrentHashMap<>(); // Order is not critical. Order is determined by uidsToActivate private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order + private final Object registrationLock = new Object(); + record UidAction(String uid, WatchAction action) { } @@ -213,18 +215,15 @@ public void register(String beanName, Object bean) { } public T registerIfAbsent(Class type, Supplier supplier) { - var existing = getBean(type); - if (existing.isPresent()) - return existing.get(); - - T created = supplier.get(); // outside lock - - synchronized (this) { - return getBean(type).orElseGet(() -> { - register(null, created); - return created; - }); - } + return getBean(type).orElseGet(() -> { + synchronized (registrationLock) { + return getBean(type).orElseGet(() -> { + T created = supplier.get(); + register(null, created); + return created; + }); + } + }); } private static @NotNull String computeBeanName(String beanName, String uuid) { From 4be156a0266de566008f0983ad20d776737d006b Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Fri, 26 Dec 2025 20:16:06 +0100 Subject: [PATCH 19/40] refactor: update test lifecycle methods to use `@BeforeAll`/`@AfterAll`, remove redundant assertions, and improve object reuse --- .../core/config/ReadRulesConfigurationTest.java | 2 -- .../ElasticSearchExchangeStoreTest.java | 12 ++++++------ .../core/proxies/UnavailableSoapProxyTest.java | 14 +++++++------- 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 40ab65c3f7..99a835d060 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -98,7 +98,6 @@ void testLocalServiceProxyInboundSSL() { if (proxies.get(2) instanceof SSLableProxy sp) { assertFalse(sp.isInboundSSL()); } - assertTrue(true); } @Test @@ -106,6 +105,5 @@ void testLocalServiceProxyOutboundSSL() { if (proxies.get(2) instanceof SSLableProxy sp) { assertNull(sp.getSslOutboundContext()); } - assertTrue(true); } } diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java index 14360cbde2..189a6a746e 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java @@ -41,6 +41,8 @@ class ElasticSearchExchangeStoreTest { + private static final ObjectMapper om = new ObjectMapper(); + private static final String RESPONSE_BODY = """ {"demo": true}"""; private static final String REQUEST_BODY = """ @@ -53,7 +55,6 @@ class ElasticSearchExchangeStoreTest { private final List insertedObjects = new ArrayList<>(); - @BeforeEach public void start() throws IOException { initializeElasticSearchMock(); @@ -114,18 +115,17 @@ private void initializeBackend() throws IOException { } private Interceptor createElasticSearchMockInterceptor() { - ObjectMapper om = new ObjectMapper(); return new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { - if (exc.getRequest().isGETRequest()) { + if (exc.getRequest().isGETRequest() && exc.getRequest().getUri().equals("/membrane/_mapping")) { exc.setResponse(ok(""" - {"acknowledged": true}""").build()); + {"membrane": {"mappings": {"something":true}}}""").build()); return RETURN; } - if (exc.getRequest().isGETRequest() && exc.getRequest().getUri().equals("/membrane/_mapping")) { + if (exc.getRequest().isGETRequest()) { exc.setResponse(ok(""" - {"membrane": {"mappings": {"something":true}}}""").build()); + {"acknowledged": true}""").build()); return RETURN; } return getOutcome(exc, om); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 5c34ee049b..7f14b7cd76 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -26,13 +26,13 @@ public class UnavailableSoapProxyTest { - private Router r, r2; - private Router backendRouter; + private static Router r, r2; + private static Router backendRouter; private SOAPProxy sp; private ServiceProxy sp3; - @BeforeEach - void setup() throws Exception { + @BeforeAll + static void setup() throws Exception { ServiceProxy cityAPI = new ServiceProxy(new ServiceProxyKey(4000), null, 0); cityAPI.getFlow().add(new SampleSoapServiceInterceptor()); backendRouter = new HttpRouter(); @@ -40,8 +40,8 @@ void setup() throws Exception { backendRouter.init(); } - @AfterEach - void teardown() { + @AfterAll + static void teardown() { backendRouter.shutdown(); r.shutdown(); r2.shutdown(); @@ -76,7 +76,7 @@ void startRouter() { } @AfterEach - void shutdownRouter() { + void teardownEach() { r.shutdown(); r2.shutdown(); } From 7564a5ea68a83c844fe6517113180ca69bc39328 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Sun, 28 Dec 2025 21:34:06 +0100 Subject: [PATCH 20/40] refactor: refactor `Router` lifecycle methods, remove `openPorts` handling, improve proxy addition & initialization logic --- .../com/predic8/membrane/core/Router.java | 177 ++++++++---- .../predic8/membrane/core/RuleManager.java | 4 +- .../predic8/membrane/core/cli/RouterCLI.java | 3 +- .../core/exchangestore/AbortExchangeTest.java | 37 +-- .../membrane/core/http/ChunkedBodyTest.java | 4 +- .../membrane/core/http/Http10Test.java | 10 +- .../membrane/core/http/Http11Test.java | 8 +- .../membrane/core/http/MethodTest.java | 4 +- .../interceptor/AdjustContentLengthTest.java | 6 +- .../adminapi/AdminApiInterceptorTest.java | 6 +- .../balancer/ClusterBalancerTest.java | 4 +- .../ClusterNotificationInterceptorTest.java | 6 +- .../LoadBalancingWithClusterManagerTest.java | 234 ++++++++-------- .../AbstractInterceptorFlowTest.java | 11 +- ...InternalServiceRoutingInterceptorTest.java | 7 +- .../oauth2/OAuth2RedirectTest.java | 4 +- .../OAuth2ResourceErrorForwardingTest.java | 6 +- .../client/OAuth2ResourceRpIniLogoutTest.java | 4 +- .../oauth2/client/OAuth2ResourceTest.java | 4 +- .../oauth2/client/b2c/B2CMembrane.java | 18 +- .../client/b2c/MockAuthorizationServer.java | 6 +- .../b2c/OAuth2ResourceB2CTestSetup.java | 2 +- .../client/b2c/OAuth2ResourceB2CUnitTest.java | 2 +- .../server/WSDLPublisherInterceptorTest.java | 4 +- .../session/SessionInterceptorTest.java | 112 ++++---- .../shadowing/ShadowingInterceptorTest.java | 6 +- .../soap/SoapAndInternalProxyTest.java | 11 +- .../client/KubernetesClientTest.java | 4 +- .../serviceproxy/OpenAPI31ReferencesTest.java | 6 +- .../openapi/serviceproxy/Swagger20Test.java | 9 +- .../core/proxies/APIProxyKeyTest.java | 10 +- .../core/proxies/InternalProxyTest.java | 2 +- .../membrane/core/proxies/ProxySSLTest.java | 9 +- .../membrane/core/proxies/ProxyTest.java | 13 +- .../membrane/core/proxies/SOAPProxyTest.java | 4 +- .../core/proxies/ServiceProxyTest.java | 2 +- .../proxies/UnavailableSoapProxyTest.java | 21 +- .../membrane/core/resolver/ResolverTest.java | 60 ++--- .../transport/http/BoundConnectionTest.java | 6 +- .../http/ConcurrentConnectionLimitTest.java | 2 +- .../core/transport/http/ConnectionTest.java | 3 +- .../transport/http/Http2DowngradeTest.java | 6 +- .../transport/http/HttpKeepAliveTest.java | 4 +- .../core/transport/http/HttpTimeoutTest.java | 10 +- .../transport/http/ServiceInvocationTest.java | 13 +- .../http2/Http2ClientServerTest.java | 29 +- .../transport/ssl/HttpsKeepAliveTest.java | 35 ++- .../ssl/acme/AcmeServerSimulator.java | 26 +- .../core/transport/ssl/acme/AcmeStepTest.java | 3 +- .../core/ws/SoapProxyInvocationTest.java | 12 +- ...nterceptorFaultMonitoringStrategyTest.java | 8 +- .../LoadBalancingInterceptorTest.java | 8 +- .../MultipleLoadBalancersTest.java | 255 +++++++++--------- .../test/FileExchangeStoreExampleTest.java | 5 + ...oadbalancing6HealthMonitorExampleTest.java | 2 +- 55 files changed, 662 insertions(+), 605 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 2a4a7d53a9..48c11304dd 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -14,6 +14,7 @@ package com.predic8.membrane.core; +import com.jayway.jsonpath.internal.function.sequence.*; import com.predic8.membrane.annot.*; import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.core.RuleManager.*; @@ -47,18 +48,41 @@ import java.util.Timer; import java.util.concurrent.*; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.jmx.JmxExporter.*; import static com.predic8.membrane.core.util.DLPUtil.*; import static java.util.concurrent.Executors.*; +/* + TODO: + - ADR: First start router than init and add proxies or first init proxies and add them later? + + ADR: + - The Router is responsible for the lifecycle of the proxies + - Ports are opened in start() + - init() + - does not open ports + - inits the proxies + - In sequence as added or reverse or not defined? + - new Router(), add(proxy) init() start() + - add(proxy) could be called any time + - If router is started port will be opened if needed by the proxy + - What if a proxy needs to make a call to another proxy during init(Tests: e.g. B2C) + - Delete addProxyAndOpenPortIfNew() from RuleManager + + HTTPRouter: + - Purpose? Test? + + */ + /** * @description

* Membrane API Gateway's main object. *

*

* The router is a Spring Lifecycle object: It is automatically started and stopped according to the - * Lifecycle of the Spring Context containing it. In Membrane's standard setup (standalone or in a J2EE web - * app), Membrane itself controls the creation of the Spring Context and its Lifecycle. + * Lifecycle of the Spring Context containing it. In Membrane's standard setup + * Membrane itself controls the creation of the Spring Context and its Lifecycle. *

*

* In this case, the router is hot deployable: It can monitor proxies.xml, the Spring @@ -82,15 +106,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA protected BeanRegistry registry; - /** - * Indicates whether the router should automatically open TCP ports when adding proxies. - * This flag determines if the ports associated with the proxies are opened immediately - * when they are added to the router. Setting this to {@code false} allows for proxies - * to be defined without opening the associated ports, providing more control over when - * the ports are made accessible. - */ - private boolean openPorts = true; - // // Configuration // @@ -102,8 +117,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA // // Components // - protected RuleManager ruleManager = new RuleManager(); - protected ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); protected Transport transport; private final TimerManager timerManager = new TimerManager(); @@ -137,7 +150,7 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA private HotDeployer hotDeployer = new DefaultHotDeployer(); public Router() { - ruleManager.setRouter(this); + log.debug("Creating new router."); resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); resolverMap.addRuleResolver(this); } @@ -145,22 +158,53 @@ public Router() { // // Initialization // + + /** + * Initializes the {@code Router} + * - by setting up its associated components. + * - calling init() on each of its {@link Proxy} instances. + *

+ * This method ensures that the {@code Router} and its dependencies are prepared for operation. + * But it does not start the router itself. Use {@link #start()} to start the router. + * If start() is called a separate call to init() is not needed. + * The init() is useful for testing without the expensive start() call. + */ public void init() { - initRemainingRules(); - if (transport != null) - transport.init(this); - displayTraceWarning(); + log.debug("Initializing."); + + // TODO: Temporary guard, to check correct behaviour, remove later + if (initialized) + throw new IllegalStateException("Router already initialized."); + + getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); + getRegistry().registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(this); + return rm; + }); + + // Transport last + if (transport == null) { + transport = new HttpTransport(); + } + transport.init(this); + + initProxies(); initialized = true; } - private void initRemainingRules() { - for (Proxy proxy : getRuleManager().getRules()) + private void initProxies() { + log.debug("Initializing proxies."); + for (Proxy proxy : getRuleManager().getRules()) { + log.debug("Initializing proxy {}.", proxy.getName()); proxy.init(this); + } } /** * Initializes a {@link Router} instance from the specified Spring XML configuration resource. + * * @param resource the path to the Spring XML configuration file that defines the {@link Router} bean * @return the initialized {@link Router} instance * @throws RuntimeException if no {@link Router} bean is found or more than one {@link Router} bean is found @@ -171,7 +215,6 @@ public static Router initByXML(String resource) { TrackingFileSystemXmlApplicationContext bf = new TrackingFileSystemXmlApplicationContext(new String[]{resource}, false); bf.refresh(); - bf.start(); if (bf.getBeansOfType(Router.class).size() > 1) { throw new RuntimeException( @@ -179,10 +222,14 @@ public static Router initByXML(String resource) { .formatted(Arrays.toString(bf.getBeanDefinitionNames())) ); } - return bf.getBean("router", Router.class); + Router router = bf.getBean("router", Router.class); + router.init(); + bf.start(); // Starting ApplicationContext will also call router.start(). Init should happen before. + return router; } public static Router initFromXMLString(String xmlString) { + log.debug("Loading spring config from string"); GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(new ByteArrayResource(xmlString.getBytes(StandardCharsets.UTF_8))); ctx.refresh(); @@ -190,23 +237,28 @@ public static Router initFromXMLString(String xmlString) { return ctx.getBean(Router.class); } + /** + * Starts the main processing logic of the application. + * This method initializes essential components, validates the configuration, + * and starts background services required for the application's functionality. + * Key responsibilities: + * - Initializes the application if it hasn't been initialized yet. + * - Opens TCP ports + */ @Override public void start() { + log.debug("Starting."); + displayTraceWarning(); + if (!initialized) - init(); + init(); try { - if (exchangeStore == null) - exchangeStore = new LimitedMemoryExchangeStore(); - if (transport == null) { - transport = new HttpTransport(); - transport.init(this); - } getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); - //init(); initJmx(); + startJmx(); getRuleManager().openPorts(); try { @@ -252,15 +304,14 @@ public void start() { throw new RuntimeException(e); } - startJmx(); - synchronized (lock) { running = true; } } public Collection getRules() { - return getRuleManager().getRulesBySource(RuleDefinitionSource.SPRING); + log.debug("Getting rules."); + return getRuleManager().getRulesBySource(RuleDefinitionSource.SPRING); // TODO: Source? } @MCChildElement(order = 3) @@ -279,16 +330,22 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } public RuleManager getRuleManager() { - return ruleManager; + var rm = getRegistry().getBean(RuleManager.class); + if (rm.isPresent()) return rm.get(); + RuleManager rmi = new RuleManager(); + rmi.setRouter(this); + getRegistry().register("ruleManager", rmi); + return rmi; } public void setRuleManager(RuleManager ruleManager) { - this.ruleManager = ruleManager; + log.debug("Setting ruleManager."); ruleManager.setRouter(this); + getRegistry().register("ruleManager", ruleManager); } public ExchangeStore getExchangeStore() { - return exchangeStore; + return registry.getBean(ExchangeStore.class).orElseThrow(); } /** @@ -299,7 +356,7 @@ public ExchangeStore getExchangeStore() { */ @MCAttribute public void setExchangeStore(ExchangeStore exchangeStore) { - this.exchangeStore = exchangeStore; + getRegistry().register("exchangeStore", exchangeStore); } public Transport getTransport() { @@ -332,7 +389,7 @@ public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { } public DNSCache getDnsCache() { - return getRegistry().registerIfAbsent( DNSCache.class, DNSCache::new); + return getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); } public ResolverMap getResolverMap() { @@ -355,14 +412,25 @@ public ExecutorService getBackgroundInitializer() { return backgroundInitializer; } + /** + * Adds a proxy to the router and initializes it. + * @param proxy + * @throws IOException + */ public void add(Proxy proxy) throws IOException { + log.debug("Adding proxy {}.", proxy.getName()); + RuleManager ruleManager = getRuleManager(); if (proxy instanceof SSLableProxy sp) { - if (openPorts) - ruleManager.addProxyAndOpenPortIfNew(sp); - else - ruleManager.addProxy(sp, RuleDefinitionSource.MANUAL); + if (running) { // TODO + ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); + } else + ruleManager.addProxy(sp, MANUAL); } else { - ruleManager.addProxy(proxy, RuleDefinitionSource.MANUAL); + ruleManager.addProxy(proxy, MANUAL); + } + if (running) { + // init() has already been called + proxy.init(this); } } @@ -534,13 +602,15 @@ public FlowController getFlowController() { } public void handleAsynchronousInitializationResult(boolean success) { + log.debug("Asynchronous initialization finished."); if (!success && !config.isRetryInit()) System.exit(1); - ApiInfo.logInfosAboutStartedProxies(ruleManager); + ApiInfo.logInfosAboutStartedProxies(getRuleManager()); } @Override public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { + log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(),bean); if (bean instanceof GlobalInterceptor) { return; } @@ -567,12 +637,13 @@ public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBe // throw new RuntimeException("Could not init rule.", e); // } - if (bdc.action().isAdded()) + if (bdc.action().isAdded()) { add(newProxy); - else if (bdc.action().isDeleted()) + } else if (bdc.action().isDeleted()) getRuleManager().removeRule((Proxy) oldBean); - else if (bdc.action().isModified()) + else if (bdc.action().isModified()) { getRuleManager().replaceRule((Proxy) oldBean, newProxy); + } } @Override @@ -620,16 +691,4 @@ public void setConfig(Configuration config) { public Configuration getConfig() { return config; } - - /** - * Configures whether the router should open tcp ports when adding proxies. Use this field to create a router - * and open the ports later. - * This method should typically be called during router initialization, before {@link #start()}, to avoid - * race conditions with concurrent proxy additions. - * - * @param openPorts a boolean indicating whether ports should be opened (true) or closed (false) - */ - public void setOpenPorts(boolean openPorts) { - this.openPorts = openPorts; - } } \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/RuleManager.java b/core/src/main/java/com/predic8/membrane/core/RuleManager.java index 24cf5e74c5..82069fec42 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleManager.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleManager.java @@ -281,6 +281,7 @@ public synchronized void replaceRule(Proxy proxy, Proxy newProxy) { getExchangeStore().removeAllExchanges(proxy); int i = proxies.indexOf(proxy); + newProxy.init(router); proxies.set(i, newProxy); for (IRuleChangeListener listener : listeners) { @@ -340,5 +341,4 @@ public void add(int index, Proxy e) { } }; } - -} +} \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 387a604c46..bfb908b363 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -155,7 +155,7 @@ public static String getExceptionMessageWithCauses(Throwable throwable) { private static Router initRouterByConfig(MembraneCommandLine commandLine) throws Exception { String config = getRulesFile(commandLine); if (config.endsWith(".xml")) { - Router router = initRouterByXml(config); + var router = initRouterByXml(config); logStartupMessage(); return router; } @@ -178,7 +178,6 @@ private static Router initRouterByYAML(MembraneCommandLine commandLine, String o private static Router initRouterByYAML(String location) throws Exception { var router = new Router(); - router.setOpenPorts(false); router.setBaseLocation(location); GrammarAutoGenerated grammar = new GrammarAutoGenerated(); diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java index 0b710aec76..d532d6313f 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java @@ -13,30 +13,21 @@ limitations under the License. */ package com.predic8.membrane.core.exchangestore; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; -import com.predic8.membrane.core.exchange.AbstractExchange; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.BodyUtil; -import com.predic8.membrane.core.http.Request; -import com.predic8.membrane.core.http.Response; -import com.predic8.membrane.core.interceptor.AbstractInterceptor; -import com.predic8.membrane.core.interceptor.ExchangeStoreInterceptor; -import com.predic8.membrane.core.interceptor.Outcome; -import com.predic8.membrane.core.proxies.ServiceProxy; -import com.predic8.membrane.core.proxies.ServiceProxyKey; -import com.predic8.membrane.core.transport.http.HttpClient; -import org.apache.commons.io.IOUtils; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.transport.http.*; +import org.apache.commons.io.*; import org.junit.jupiter.api.*; -import java.io.ByteArrayOutputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; +import java.io.*; +import java.util.*; -import static com.predic8.membrane.core.http.Request.get; -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; -import static java.lang.Thread.sleep; +import static com.predic8.membrane.core.http.Request.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; +import static java.lang.Thread.*; import static org.junit.jupiter.api.Assertions.*; public class AbortExchangeTest { @@ -73,8 +64,8 @@ public int read() { return RETURN; } }); - router.getRuleManager().addProxyAndOpenPortIfNew(sp2); - router.init(); + router.add(sp2); + router.start(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java index 0f833435ea..2ff7d1ca16 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java @@ -183,7 +183,7 @@ public X509Certificate[] getAcceptedIssuers() { } } - private HttpRouter setupRouter(boolean http2, boolean http2Client) { + private HttpRouter setupRouter(boolean http2, boolean http2Client) throws IOException { HttpRouter router = new HttpRouter(); router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(http2 ? 3060 : 3059), "localhost", 3060); @@ -241,7 +241,7 @@ private static byte[] getContent() { } }); } - router.getRules().add(sp); + router.add(sp); router.start(); return router; } diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java index 1c526036eb..b7c4c72bd8 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java @@ -38,12 +38,14 @@ public static void setUp() throws Exception { ServiceProxy proxy2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), null, 0); proxy2.getFlow().add(new SampleSoapServiceInterceptor()); router2 = new HttpRouter(); - router2.getRuleManager().addProxyAndOpenPortIfNew(proxy2); - router2.init(); + router2.add(proxy2); + ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "localhost", 2000); router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); - router.init(); + router.add(proxy); + + router2.start(); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java index 74eea0a0d7..81607aaa94 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java @@ -41,12 +41,12 @@ public static void setUp() throws Exception { ServiceProxy proxy2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port5k), null, 0); proxy2.getFlow().add(new SampleSoapServiceInterceptor()); router2 = new HttpRouter(); - router2.getRuleManager().addProxyAndOpenPortIfNew(proxy2); - router2.init(); + router2.add(proxy2); + router2.start(); ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port4k), "localhost", port5k); router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); - router.init(); + router.add(proxy); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java index baabe75daf..0c5912a900 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java @@ -44,8 +44,8 @@ public Outcome handleRequest(Exchange exc) { }); proxy.getFlow().add(new ExceptionTestInterceptor()); // Cause exception router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); - router.init(); + router.add(proxy); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java index f07822ae75..ebc368bc44 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java @@ -31,9 +31,9 @@ public class AdjustContentLengthTest { @BeforeAll public static void setUp() throws Exception { router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(createMonitorRule()); - router.getRuleManager().addProxyAndOpenPortIfNew(createEndpointRule()); - router.init(); + router.add(createMonitorRule()); + router.add(createEndpointRule()); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index faf46879c2..131996f78a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -15,6 +15,7 @@ import com.predic8.membrane.core.HttpRouter; import com.predic8.membrane.core.exchange.Exchange; +import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.interceptor.AbstractInterceptor; import com.predic8.membrane.core.interceptor.Outcome; @@ -44,15 +45,16 @@ class AdminApiInterceptorTest { private static HttpRouter router; @BeforeAll - static void setUp() { + static void setUp() throws IOException { router = new HttpRouter(); router.getConfig().setHotDeploy(false); + router.setExchangeStore(new LimitedMemoryExchangeStore()); // Needed by the AdminApiInterceptor ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); sp.getFlow().add(new FastWebSocketClosingInterceptor()); // speeds up test execution AdminApiInterceptor e = new AdminApiInterceptor(); e.getMemoryWatcher().setIntervalMilliseconds(50); // speeds up test execution sp.getFlow().add(e); - router.getRules().add(sp); + router.add(sp); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java index 7b303929ed..d91c6bfc6d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java @@ -47,8 +47,8 @@ public static void setUp() throws Exception { ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3011), "predic8.com", 80); sp.getFlow().add(lb); - r.getRuleManager().addProxyAndOpenPortIfNew(sp); - r.init(); + r.add(sp); + r.start(); BalancerUtil.up(r, "Default", "Default", "localhost", 2000); BalancerUtil.up(r, "Default", "Default", "localhost", 3000); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java index 0c0e47fdfe..81f32b3867 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java @@ -42,7 +42,7 @@ public class ClusterNotificationInterceptorTest { public void setUp() throws Exception { ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3002), "thomas-bayer.com", 80); router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); + router.add(proxy); interceptor = new ClusterNotificationInterceptor(); router.addUserFeatureInterceptor(interceptor); @@ -50,9 +50,9 @@ public void setUp() throws Exception { LoadBalancingInterceptor lbi = new LoadBalancingInterceptor(); lbi.setName("Default"); ServiceProxy proxy2 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3003), "thomas-bayer.com", 80); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy2); + router.add(proxy2); proxy2.getFlow().add(lbi); - router.init(); + router.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java index f885d1136e..87f57e9d17 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java @@ -30,122 +30,122 @@ public class LoadBalancingWithClusterManagerTest { - private HttpRouter lb; - private HttpRouter node1; - private HttpRouter node2; - private HttpRouter node3; - - @Test - void nodesTest() throws Exception { - node1 = new HttpRouter(); - node2 = new HttpRouter(); - node3 = new HttpRouter(); - - DummyWebServiceInterceptor service1 = startNode(node1, 2000); - DummyWebServiceInterceptor service2 = startNode(node2, 3000); - DummyWebServiceInterceptor service3 = startNode(node3, 4000); - - startLB(); - - sendNotification("up", 2000); - sendNotification("up", 3000); - - assertEquals(200, post("/getBankwithSession555555.xml"));// goes to service one - assertEquals(1, service1.getCount()); - assertEquals(0, service2.getCount()); - - assertEquals(200, post("/getBankwithSession555555.xml"));// goes to service 1 again - assertEquals(2, service1.getCount()); - assertEquals(0, service2.getCount()); - - assertEquals(200, post("/getBankwithSession444444.xml")); // goes to service 2 - assertEquals(2, service1.getCount()); - assertEquals(1, service2.getCount()); - - sendNotification("down", 2000); - - assertEquals(200, post("/getBankwithSession555555.xml")); // goes to service 2 because service 1 is down - assertEquals(2, service1.getCount()); - assertEquals(2, service2.getCount()); - - sendNotification("up", 4000); - - assertEquals(0, service3.getCount()); - assertEquals(200, post("/getBankwithSession666666.xml")); // goes to service 3 - assertEquals(2, service1.getCount()); - assertEquals(2, service2.getCount()); - assertEquals(1, service3.getCount()); - - assertEquals(200, post("/getBankwithSession555555.xml")); // goes to service 2 - assertEquals(200, post("/getBankwithSession444444.xml")); // goes to service 2 - assertEquals(200, post("/getBankwithSession666666.xml")); // goes to service 3 - assertEquals(2, service1.getCount()); - assertEquals(4, service2.getCount()); - assertEquals(2, service3.getCount()); - } - - @AfterEach - public void tearDown() { - lb.shutdown(); - node1.shutdown(); - node2.shutdown(); - node3.shutdown(); - } - - private void startLB() throws Exception { - - LoadBalancingInterceptor lbi = new LoadBalancingInterceptor(); - lbi.setName("Default"); - XMLElementSessionIdExtractor extractor = new XMLElementSessionIdExtractor(); - extractor.setLocalName("session"); - extractor.setNamespace("http://predic8.com/session/"); - lbi.setSessionIdExtractor(extractor); - - ServiceProxy lbiRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3017), "thomas-bayer.com", 80); - lbiRule.getFlow().add(lbi); - - ClusterNotificationInterceptor cni = new ClusterNotificationInterceptor(); - - ServiceProxy cniRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3012), "thomas-bayer.com", 80); - cniRule.getFlow().add(cni); - - lb = new HttpRouter(); - lb.getRuleManager().addProxyAndOpenPortIfNew(lbiRule); - lb.getRuleManager().addProxyAndOpenPortIfNew(cniRule); - lb.init(); - } - - private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception { - DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor(); - node.addUserFeatureInterceptor(service1); - node.getRuleManager().addProxyAndOpenPortIfNew(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80)); - node.init(); - return service1; - } - - private HttpClient getClient() { - HttpClient client = new HttpClient(); - client.getParams().setParameter(PROTOCOL_VERSION, HttpVersion.HTTP_1_1); - return client; - } - - private PostMethod getPostMethod(String request) { - PostMethod post = new PostMethod("http://localhost:3017/axis2/services/BLZService"); - post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream(request))); - post.setRequestHeader(CONTENT_TYPE, TEXT_XML_UTF8); - post.setRequestHeader(SOAP_ACTION, ""); - return post; - } - - private void sendNotification(String cmd, int port) throws IOException { - PostMethod post = new PostMethod("http://localhost:3012/clustermanager/"+cmd+"?"+ - createQueryString("host", "localhost", - "port", String.valueOf(port))); - new HttpClient().executeMethod(post); - } - - private int post(String req) throws IOException { - return getClient().executeMethod(getPostMethod(req)); - } + private HttpRouter lb; + private HttpRouter node1; + private HttpRouter node2; + private HttpRouter node3; + + @AfterEach + public void tearDown() { + lb.shutdown(); + node1.shutdown(); + node2.shutdown(); + node3.shutdown(); + } + + @Test + void nodesTest() throws Exception { + node1 = new HttpRouter(); + node2 = new HttpRouter(); + node3 = new HttpRouter(); + + DummyWebServiceInterceptor service1 = startNode(node1, 2000); + DummyWebServiceInterceptor service2 = startNode(node2, 3000); + DummyWebServiceInterceptor service3 = startNode(node3, 4000); + + startLB(); + + sendNotification("up", 2000); + sendNotification("up", 3000); + + assertEquals(200, post("/getBankwithSession555555.xml"));// goes to service one + assertEquals(1, service1.getCount()); + assertEquals(0, service2.getCount()); + + assertEquals(200, post("/getBankwithSession555555.xml"));// goes to service 1 again + assertEquals(2, service1.getCount()); + assertEquals(0, service2.getCount()); + + assertEquals(200, post("/getBankwithSession444444.xml")); // goes to service 2 + assertEquals(2, service1.getCount()); + assertEquals(1, service2.getCount()); + + sendNotification("down", 2000); + + assertEquals(200, post("/getBankwithSession555555.xml")); // goes to service 2 because service 1 is down + assertEquals(2, service1.getCount()); + assertEquals(2, service2.getCount()); + + sendNotification("up", 4000); + + assertEquals(0, service3.getCount()); + assertEquals(200, post("/getBankwithSession666666.xml")); // goes to service 3 + assertEquals(2, service1.getCount()); + assertEquals(2, service2.getCount()); + assertEquals(1, service3.getCount()); + + assertEquals(200, post("/getBankwithSession555555.xml")); // goes to service 2 + assertEquals(200, post("/getBankwithSession444444.xml")); // goes to service 2 + assertEquals(200, post("/getBankwithSession666666.xml")); // goes to service 3 + assertEquals(2, service1.getCount()); + assertEquals(4, service2.getCount()); + assertEquals(2, service3.getCount()); + } + + private void startLB() throws Exception { + + LoadBalancingInterceptor lbi = new LoadBalancingInterceptor(); + lbi.setName("Default"); + XMLElementSessionIdExtractor extractor = new XMLElementSessionIdExtractor(); + extractor.setLocalName("session"); + extractor.setNamespace("http://predic8.com/session/"); + lbi.setSessionIdExtractor(extractor); + + ServiceProxy lbiRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3017), "thomas-bayer.com", 80); + lbiRule.getFlow().add(lbi); + + ClusterNotificationInterceptor cni = new ClusterNotificationInterceptor(); + + ServiceProxy cniRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3012), "thomas-bayer.com", 80); + cniRule.getFlow().add(cni); + + lb = new HttpRouter(); + lb.add(lbiRule); + lb.add(cniRule); + lb.start(); + } + + private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception { + DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor(); + node.addUserFeatureInterceptor(service1); + node.add(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80)); + node.start(); + return service1; + } + + private HttpClient getClient() { + HttpClient client = new HttpClient(); + client.getParams().setParameter(PROTOCOL_VERSION, HttpVersion.HTTP_1_1); + return client; + } + + private PostMethod getPostMethod(String request) { + PostMethod post = new PostMethod("http://localhost:3017/axis2/services/BLZService"); + post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream(request))); + post.setRequestHeader(CONTENT_TYPE, TEXT_XML_UTF8); + post.setRequestHeader(SOAP_ACTION, ""); + return post; + } + + private void sendNotification(String cmd, int port) throws IOException { + PostMethod post = new PostMethod("http://localhost:3012/clustermanager/" + cmd + "?" + + createQueryString("host", "localhost", + "port", String.valueOf(port))); + new HttpClient().executeMethod(post); + } + + private int post(String req) throws IOException { + return getClient().executeMethod(getPostMethod(req)); + } } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java index 7551515225..1d06e0f030 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java @@ -36,7 +36,7 @@ public abstract class AbstractInterceptorFlowTest { @BeforeAll static void setUp() { - router = getRouter(); + router = new HttpRouter(); } @AfterAll @@ -57,7 +57,7 @@ protected String getResponse(Interceptor... interceptors) throws Exception { private void setUpRouter(Interceptor[] interceptors) throws Exception { router.setRules(EMPTY_LIST); router.add(getApiProxy(interceptors)); - router.init(); + router.start(); } private static @NotNull APIProxy getApiProxy(Interceptor[] interceptors) { @@ -73,11 +73,4 @@ private static APIProxy getServiceProxy() { api.setKey(new ServiceProxyKey("*","*",null,2000)); return api; } - - @NotNull - private static Router getRouter() { - Router r = new Router(); - r.setTransport(new HttpTransport()); - return r; - } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index 535746c493..fb87aca28b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -41,10 +41,7 @@ abstract class AbstractInternalServiceRoutingInterceptorTest { void setup() throws Exception { router = new HttpRouter(); router.getConfig().setHotDeploy(false); - configure(); - - router.init(); router.start(); } @@ -56,7 +53,7 @@ void tearDown() { public void api(Consumer c) throws Exception { TestAPIProxy api = new TestAPIProxy(); c.accept(api); - router.getRuleManager().addProxyAndOpenPortIfNew(api); + router.add(api); } protected static class TestAPIProxy extends APIProxy { @@ -69,7 +66,7 @@ public void internal(Consumer c) throws Exception { TestInternalProxy api = new TestInternalProxy(); c.accept(api); api.setKey(new InternalProxyKey()); - router.getRuleManager().addProxyAndOpenPortIfNew(api); + router.add(api); } protected static class TestInternalProxy extends InternalProxy { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java index 108b10e3c6..e880433228 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java @@ -166,8 +166,8 @@ private static Router startProxyRule(SSLableProxy azureRule) throws Exception { Router router = new Router(); router.setExchangeStore(new ForgetfulExchangeStore()); router.setTransport(new HttpTransport()); - router.getRuleManager().addProxyAndOpenPortIfNew(azureRule); - router.init(); + router.add(azureRule); + router.start(); return router; } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java index 56f80ff4fd..57b5bb75b8 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java @@ -69,7 +69,7 @@ public void init() throws IOException { mockAuthServer.getTransport().setSocketTimeout(10000); mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit); - mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); + mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); oauth2Resource = new HttpRouter(); @@ -77,8 +77,8 @@ public void init() throws IOException { oauth2Resource.getTransport().setSocketTimeout(10000); oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit); - oauth2Resource.getRuleManager().addProxy(getErrorCaptor(), MANUAL); - oauth2Resource.getRuleManager().addProxy(getConfiguredOAuth2Resource(), MANUAL); + oauth2Resource.add(getErrorCaptor()); + oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java index e907475ef3..082b5ced9f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java @@ -83,12 +83,12 @@ public void init() throws IOException, JoseException { mockAuthServer = new HttpRouter(); mockAuthServer.getConfig().setHotDeploy(false); - mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); + mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); oauth2Resource = new HttpRouter(); oauth2Resource.getConfig().setHotDeploy(false); - oauth2Resource.getRuleManager().addProxyAndOpenPortIfNew(getConfiguredOAuth2Resource()); + oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java index 4f5ab3953f..c4d416f305 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java @@ -72,7 +72,7 @@ public void init() throws IOException { mockAuthServer.getTransport().setSocketTimeout(10000); mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit+1); - mockAuthServer.getRuleManager().addProxyAndOpenPortIfNew(getMockAuthServiceProxy()); + mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); oauth2Resource = new HttpRouter(); @@ -80,7 +80,7 @@ public void init() throws IOException { oauth2Resource.getTransport().setSocketTimeout(10000); oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit+1); - oauth2Resource.getRuleManager().addProxyAndOpenPortIfNew(getConfiguredOAuth2Resource()); + oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index 149a5b9842..b9be5a8557 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -62,7 +62,7 @@ public B2CMembrane(B2CTestConfig tc, SessionManager sessionManager) { this.sessionManager = sessionManager; } - public void init() { + public void init() throws IOException { oauth2Resource = new HttpRouter(); oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(10000); oauth2Resource.getTransport().setBacklog(10000); @@ -89,14 +89,14 @@ public void init() { ServiceProxy sp7_requireAuth = createRequireAuthServiceProxy(tc.api2Id, "/api2/", ra -> ra.setScope("https://localhost/" + tc.api2Id + "/Read")); ServiceProxy sp8_afterLogout = createAfterLogoutServiceProxy(); - oauth2Resource.getRuleManager().addProxy(sp8_afterLogout, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp7_requireAuth, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp6_requireAuth_ErrorStatus403, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp5_requireAuth_AuthNotRequired, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp4_requireAuth, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp3_flowInitiator_noLogout, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp2_flowInitiator_logoutBeforeFlow, MANUAL); - oauth2Resource.getRuleManager().addProxy(sp1_oauth2resource2, MANUAL); + oauth2Resource.add(sp8_afterLogout); + oauth2Resource.add(sp7_requireAuth); + oauth2Resource.add(sp6_requireAuth_ErrorStatus403); + oauth2Resource.add(sp5_requireAuth_AuthNotRequired); + oauth2Resource.add(sp4_requireAuth); + oauth2Resource.add(sp3_flowInitiator_noLogout); + oauth2Resource.add(sp2_flowInitiator_logoutBeforeFlow); + oauth2Resource.add(sp1_oauth2resource2); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java index 15b56638a1..d1ff483bf6 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java @@ -83,9 +83,9 @@ public void init() throws IOException, JoseException { mockAuthServer.getTransport().setSocketTimeout(10000); mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); - mockAuthServer.getRuleManager().addProxy(getMockAuthServiceProxy(SERVER_PORT, tc.susiFlowId), MANUAL); - mockAuthServer.getRuleManager().addProxy(getMockAuthServiceProxy(SERVER_PORT, tc.peFlowId), MANUAL); - mockAuthServer.getRuleManager().addProxy(getMockAuthServiceProxy(SERVER_PORT, tc.pe2FlowId), MANUAL); + mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.susiFlowId)); + mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.peFlowId)); + mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.pe2FlowId)); mockAuthServer.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CTestSetup.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CTestSetup.java index c99f16e43d..6dc6c46f56 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CTestSetup.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CTestSetup.java @@ -24,7 +24,7 @@ import java.util.concurrent.atomic.AtomicBoolean; public abstract class OAuth2ResourceB2CTestSetup { - protected final Logger LOG = LoggerFactory.getLogger(OAuth2ResourceB2CTestSetup.class); + protected final Logger log = LoggerFactory.getLogger(OAuth2ResourceB2CTestSetup.class); protected final B2CTestConfig tc = new B2CTestConfig(); protected final ObjectMapper om = new ObjectMapper(); protected final AtomicBoolean didLogIn = new AtomicBoolean(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java index 3a169271ec..e08ddaea3a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java @@ -90,7 +90,7 @@ public Outcome handleRequest(Exchange exc) { Exchange excCallResource = get(tc.getClientAddress() + "/malicious").buildExchange(); - LOG.debug("getting {}", excCallResource.getDestinations().getFirst()); + log.debug("getting {}", excCallResource.getDestinations().getFirst()); browser.apply(excCallResource); // will be aborted browser.clearCookies(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java index 1013c203a8..a6025e823b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java @@ -42,8 +42,8 @@ void before(String wsdlLocation, int port) throws Exception { wi.setWsdl(wsdlLocation); wi.init(router); sp2.getFlow().add(wi); - router.getRuleManager().addProxyAndOpenPortIfNew(sp2); - router.init(); + router.add(sp2); + router.start(); } void after() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index f86dd02bb5..42fcdb8c89 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -36,9 +36,8 @@ import java.util.concurrent.atomic.*; import java.util.stream.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; -import static com.predic8.membrane.core.interceptor.Outcome.CONTINUE; -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; import static java.nio.charset.StandardCharsets.*; import static org.junit.jupiter.api.Assertions.*; @@ -60,28 +59,29 @@ void shutDown() throws IOException { } @Test - public void generalSessionUsageTest() { + public void generalSessionUsageTest() throws IOException { ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxy(sp, MANUAL); + AtomicLong counter = new AtomicLong(0); List vals = new ArrayList<>(); - AbstractInterceptorWithSession interceptor = defineInterceptor(counter,vals); + AbstractInterceptorWithSession interceptor = defineInterceptor(counter, vals); sp.getFlow().add(interceptor); sp.getFlow().add(testResponseInterceptor()); + router.add(sp); router.start(); IntStream.range(0, 50).forEach(i -> sendRequest()); assertNull(vals.getFirst()); - for(int i = 1; i < 98; i+=2){ - int index = Math.round((i-1)/2f); - assertEquals(index,vals.get(i).intValue()); + for (int i = 1; i < 98; i += 2) { + int index = Math.round((i - 1) / 2f); + assertEquals(index, vals.get(i).intValue()); } - assertEquals(49,vals.get(99).intValue()); + assertEquals(49, vals.get(99).intValue()); } private ServiceProxy createTestServiceProxy() { @@ -89,46 +89,43 @@ private ServiceProxy createTestServiceProxy() { } @Test - public void expirationTest() { - ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxy(sp,MANUAL); - - AtomicLong counter = new AtomicLong(0); + public void expirationTest() throws IOException { List vals = new ArrayList<>(); - AbstractInterceptorWithSession interceptor = defineInterceptor(counter, vals); + AbstractInterceptorWithSession interceptor = defineInterceptor(new AtomicLong(0), vals); + ServiceProxy sp = createTestServiceProxy(); sp.getFlow().add(interceptor); sp.getFlow().add(testResponseInterceptor()); + router.add(sp); router.start(); - interceptor.getSessionManager().setExpiresAfterSeconds(0); IntStream.range(0, 50).forEach(i -> sendRequest()); - for(int i = 0; i < 100; i+=2) + for (int i = 0; i < 100; i += 2) assertNull(vals.get(i)); } @Test public void noUnneededRenewalOnReadOnlySession() { ServiceProxy sp = createTestServiceProxy(); - router.getRuleManager().addProxy(sp,MANUAL); + router.getRuleManager().addProxy(sp, MANUAL); sp.getFlow().add(createAndReadOnlySessionInterceptor()); sp.getFlow().add(testResponseInterceptor()); router.start(); - List> bodies = new ArrayList<>(); + List> bodies = new ArrayList<>(); int lowerBound = 0; int upperBound = 1000; IntStream.range(lowerBound, upperBound).forEach(i -> bodies.add(sendRequest())); - IntStream.range(lowerBound+1,upperBound-1).forEach(i -> assertEquals(bodies.get(i),bodies.get(i+1))); + IntStream.range(lowerBound + 1, upperBound - 1).forEach(i -> assertEquals(bodies.get(i), bodies.get(i + 1))); } @Disabled @@ -140,10 +137,10 @@ public void renewalOnReadOnlySession() { sp.getFlow().add(createAndReadOnlySessionInterceptor); sp.getFlow().add(testResponseInterceptor()); - router.getRuleManager().addProxy(sp,MANUAL); + router.getRuleManager().addProxy(sp, MANUAL); router.start(); - List> bodies = new ArrayList<>(); + List> bodies = new ArrayList<>(); int lowerBound = 0; int upperBound = 10; @@ -152,15 +149,15 @@ public void renewalOnReadOnlySession() { bodies.forEach(this::printCookie); - IntStream.range(lowerBound+1,upperBound-1).forEach(i -> assertEquals(getCookieKey(bodies.get(i)),getCookieKey(bodies.get(i+1)))); + IntStream.range(lowerBound + 1, upperBound - 1).forEach(i -> assertEquals(getCookieKey(bodies.get(i)), getCookieKey(bodies.get(i + 1)))); - String cookieOne = getCookieKey(bodies.get(upperBound-1)); + String cookieOne = getCookieKey(bodies.get(upperBound - 1)); - Duration origRenewalTime = ((JwtSessionManager)createAndReadOnlySessionInterceptor.getSessionManager()).getRenewalTime(); + Duration origRenewalTime = ((JwtSessionManager) createAndReadOnlySessionInterceptor.getSessionManager()).getRenewalTime(); - ((JwtSessionManager)createAndReadOnlySessionInterceptor.getSessionManager()).setRenewalTime(Duration.ofMillis(0)); + ((JwtSessionManager) createAndReadOnlySessionInterceptor.getSessionManager()).setRenewalTime(Duration.ofMillis(0)); sendRequest(); - ((JwtSessionManager)createAndReadOnlySessionInterceptor.getSessionManager()).setRenewalTime(origRenewalTime); + ((JwtSessionManager) createAndReadOnlySessionInterceptor.getSessionManager()).setRenewalTime(origRenewalTime); bodies.clear(); @@ -168,19 +165,19 @@ public void renewalOnReadOnlySession() { bodies.forEach(this::printCookie); - IntStream.range(lowerBound+1,upperBound-1).forEach(i -> assertEquals(getCookieKey(bodies.get(i)),getCookieKey(bodies.get(i+1)))); + IntStream.range(lowerBound + 1, upperBound - 1).forEach(i -> assertEquals(getCookieKey(bodies.get(i)), getCookieKey(bodies.get(i + 1)))); - String cookieTwo = getCookieKey(bodies.get(upperBound-1)); - assertNotEquals(cookieOne,cookieTwo); + String cookieTwo = getCookieKey(bodies.get(upperBound - 1)); + assertNotEquals(cookieOne, cookieTwo); } - public void printCookie(Map body){ + public void printCookie(Map body) { System.out.println(getCookieKey(body)); } - public String getCookieKey(Map cookie){ - String raw = ((Map)cookie.get("request")).get("Cookie").toString(); + public String getCookieKey(Map cookie) { + String raw = ((Map) cookie.get("request")).get("Cookie").toString(); return raw.split("=")[0]; } @@ -188,7 +185,7 @@ private AbstractInterceptor testResponseInterceptor() { return new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { - if(exc.getResponse() == null) + if (exc.getResponse() == null) exc.setResponse(Response.ok().build()); try { exc.getResponse().setBodyContent(createTestResponseBody(exc).getBytes()); @@ -225,24 +222,24 @@ private String createTestResponseBody(Exchange exc) throws JsonProcessingExcepti Map response = new HashMap(); Stream.of("Cookie") - .forEach(cookieName -> addJoinedHeaderTo(request,cookieName,exc.getRequest())); + .forEach(cookieName -> addJoinedHeaderTo(request, cookieName, exc.getRequest())); Stream.of("Set-Cookie") - .forEach(cookieName -> addJoinedHeaderTo(response,cookieName,exc.getResponse())); + .forEach(cookieName -> addJoinedHeaderTo(response, cookieName, exc.getResponse())); ImmutableMap value = ImmutableMap.of("request", request, "response", response); return new ObjectMapper().writeValueAsString(value); } - private Stream getHeader(String name, Message msg){ - if(msg == null) + private Stream getHeader(String name, Message msg) { + if (msg == null) return Stream.empty(); return Stream.of(msg.getHeader().getAllHeaderFields()) .filter(hf -> hf.getHeaderName().getName().equalsIgnoreCase(name)); } - private void addJoinedHeaderTo(Map cache, String name, Message msg){ - cache.put(name, getHeader(name,msg) + private void addJoinedHeaderTo(Map cache, String name, Message msg) { + cache.put(name, getHeader(name, msg) .map(HeaderField::getValue) .collect(Collectors.joining(";"))); } @@ -251,13 +248,14 @@ private static CloseableHttpClient createHttpClient() { return HttpClients.custom().setConnectionManager(new BasicHttpClientConnectionManager()).setDefaultRequestConfig(RequestConfig.custom().setCookieSpec(CookieSpecs.STANDARD).build()).build(); } - private Map sendRequest() { + private Map sendRequest() { Map result; HttpGet httpGet = new HttpGet("http://localhost:3001"); try { try (CloseableHttpResponse response = httpClient.execute(httpGet)) { String string = IOUtils.toString(response.getEntity().getContent(), UTF_8); - result = new ObjectMapper().readValue(string, new TypeReference<>() {}); + result = new ObjectMapper().readValue(string, new TypeReference<>() { + }); EntityUtils.consume(response.getEntity()); } } catch (Exception e) { @@ -268,20 +266,20 @@ private Map sendRequest() { private AbstractInterceptorWithSession defineInterceptor(AtomicLong counter, List vals) { return new AbstractInterceptorWithSession() { - @Override - public Outcome handleRequestInternal(Exchange exc) { - Session s = getSessionManager().getSession(exc); - vals.add(s.get("value")); - long nextVal = counter.getAndIncrement(); - s.put("value", nextVal); - vals.add(s.get("value")); - return CONTINUE; - } + @Override + public Outcome handleRequestInternal(Exchange exc) { + Session s = getSessionManager().getSession(exc); + vals.add(s.get("value")); + long nextVal = counter.getAndIncrement(); + s.put("value", nextVal); + vals.add(s.get("value")); + return CONTINUE; + } - @Override - protected Outcome handleResponseInternal(Exchange exc) { - return CONTINUE; - } - }; + @Override + protected Outcome handleResponseInternal(Exchange exc) { + return CONTINUE; + } + }; } } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java index 093af82b2e..144eb8fb7e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java @@ -87,8 +87,7 @@ static void startup() throws Exception { new ReturnInterceptor() )); - interceptorRouter.getRuleManager().addProxyAndOpenPortIfNew(interceptorProxy); - interceptorRouter.init(); + interceptorRouter.add(interceptorProxy); interceptorRouter.start(); shadowingRouter = new Router(); @@ -101,8 +100,7 @@ static void startup() throws Exception { returnInterceptorMock.setStatusCode(200); shadowingProxy.setFlow(List.of(returnInterceptorMock)); - shadowingRouter.getRuleManager().addProxyAndOpenPortIfNew(shadowingProxy); - shadowingRouter.init(); + shadowingRouter.add(shadowingProxy); shadowingRouter.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java index f42317aa16..833d1a4827 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java @@ -16,14 +16,13 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.server.*; -import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.proxies.AbstractServiceProxy.*; +import com.predic8.membrane.core.proxies.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.io.*; -import static com.google.common.collect.Lists.*; import static io.restassured.RestAssured.*; import static java.nio.charset.StandardCharsets.*; import static java.util.Objects.*; @@ -50,11 +49,9 @@ void teardown() { @Test void test() throws Exception { - router.setRules(newArrayList(createInternalProxy())); + router.add(createInternalProxy()); + router.add(createServiceProxyWithWSDLInterceptors()); router.start(); - Proxy soapProxy = createServiceProxyWithWSDLInterceptors(); - soapProxy.init(router); - router.add(soapProxy); runCheck(); } @@ -82,7 +79,7 @@ private Proxy createInternalProxy() { InternalProxy ip = new InternalProxy(); ip.setName("int"); ip.getFlow().add(new SampleSoapServiceInterceptor()); - ip.setTarget(new Target("localhost",9501)); + ip.setTarget(new Target("localhost", 9501)); return ip; } diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java index b51289b797..4c17d84d2c 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java @@ -40,7 +40,7 @@ public class KubernetesClientTest { private static HttpRouter router; @BeforeAll - public static void prepare() { + public static void prepare() throws IOException { router = new HttpRouter(); router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3053), null, 0); @@ -99,7 +99,7 @@ public Outcome handleRequestInternal(Exchange exc) throws IOException { return RETURN; } }); - router.getRules().add(sp); + router.add(sp); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index a6ee16e7d0..7c55bf99a1 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -50,14 +50,14 @@ public static void setUp() throws Exception { api = new APIProxy(); api.setPort(2000); api.setSpecs(List.of(spec)); - router.getRuleManager().addProxyAndOpenPortIfNew(api); + router.add(api); APIProxy backend = new APIProxy(); backend.setPort(3000); backend.getFlow().add(new ReturnInterceptor()); - router.getRuleManager().addProxyAndOpenPortIfNew(backend); + router.add(backend); - router.init(); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java index bb8bef51db..83857c85cb 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java @@ -39,13 +39,12 @@ public class Swagger20Test { @BeforeEach public void setUp() throws Exception { - router = new Router(); - router.setTransport(new HttpTransport()); + router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); - router.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy()); - router.getRuleManager().addProxyAndOpenPortIfNew(getTargetProxy()); - router.init(); + router.add(getApiProxy()); + router.add(getTargetProxy()); + router.start(); } private @NotNull APIProxy getApiProxy() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java index fdb26947a5..836795eb8f 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java @@ -43,7 +43,7 @@ public static void shutdown() { @Test void serviceProxyPathSubpath() throws Exception { registerApiProxy("/foo", "Baz"); - router.init(); + router.start(); // @formatter:off when() @@ -57,7 +57,7 @@ void serviceProxyPathSubpath() throws Exception { @Test void apiProxyPathSubpath() throws Exception { registerApiProxy("/foo", "Baz"); - router.init(); + router.start(); when() .get("http://localhost:3000/foo/bar") .then() @@ -67,7 +67,7 @@ void apiProxyPathSubpath() throws Exception { @Test void apiProxyPathMatch() throws Exception { registerApiProxy("/foo", "Baz"); - router.init(); + router.start(); when() .get("http://localhost:3000/foo") .then() @@ -78,7 +78,7 @@ void apiProxyPathMatch() throws Exception { void apiProxyPathFallthrough() throws Exception { registerApiProxy("/foo", "Baz"); registerApiProxy(null, "Foobar"); - router.init(); + router.start(); when() .get("http://localhost:3000") .then() @@ -86,7 +86,7 @@ void apiProxyPathFallthrough() throws Exception { } private static void registerApiProxy(String path, String body) throws IOException { - router.getRuleManager().addProxyAndOpenPortIfNew(new APIProxy() {{ + router.add(new APIProxy() {{ setKey(new APIProxyKey("127.0.0.1", "localhost", 3000, path, "*", null,false)); getFlow().add(new TemplateInterceptor() {{ setSrc(body); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index 44ebd69811..d1636cace4 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -105,7 +105,7 @@ void setup() throws Exception { interceptors.add(RETURN); }}); - router.init(); + router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index b5ee17935c..f7ab0776ff 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -32,6 +32,7 @@ import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.MethodSource; +import java.io.*; import java.util.Arrays; import java.util.Collection; import java.util.concurrent.atomic.AtomicInteger; @@ -61,7 +62,7 @@ void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int pro backend.shutdown(); } - private static @NotNull Router createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) { + private static @NotNull Router createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) throws IOException { Router proxy = new Router(); proxy.getConfig().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(proxyPort)); @@ -75,7 +76,7 @@ public Outcome handleRequest(Exchange exc) { if (proxyUsesSSL) { rule.setSslInboundParser(getSslParser("classpath:/ssl-rsa2.keystore")); } - proxy.getRuleManager().addProxy(rule, RuleManager.RuleDefinitionSource.MANUAL); + proxy.add(rule); proxy.start(); return proxy; } @@ -115,7 +116,7 @@ private static void testClient(boolean backendUsesSSL, int backendPort, HttpClie return new HttpClient(httpClientConfiguration); } - private static @NotNull Router createBackend(boolean backendUsesSSL, int backendPort) { + private static @NotNull Router createBackend(boolean backendUsesSSL, int backendPort) throws IOException { // Step 1: create the backend Router backend = new Router(); backend.getConfig().setHotDeploy(false); @@ -124,7 +125,7 @@ private static void testClient(boolean backendUsesSSL, int backendPort, HttpClie sp.setSslInboundParser(getSslParser("classpath:/ssl-rsa.keystore")); } sp.getFlow().add(new CountInterceptor()); - backend.getRuleManager().addProxy(sp, RuleManager.RuleDefinitionSource.MANUAL); + backend.add(sp); backend.start(); return backend; } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index 8283516eee..46f614a456 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -43,6 +43,7 @@ import java.security.UnrecoverableKeyException; import java.util.concurrent.atomic.AtomicReference; +import static com.predic8.membrane.core.interceptor.Outcome.RETURN; import static org.junit.jupiter.api.Assertions.*; public class ProxyTest { @@ -51,7 +52,7 @@ public class ProxyTest { static final AtomicReference lastMethod = new AtomicReference<>(); @BeforeAll - public static void init() { + public static void init() throws IOException { router = new HttpRouter(); router.getConfig().setHotDeploy(false); @@ -64,17 +65,17 @@ public Outcome handleRequest(Exchange exc) { return super.handleRequest(exc); } }); - router.getRules().add(rule); + router.add(rule); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3056), null, 0); sp.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { exc.setResponse(Response.ok("secret1").build()); - return Outcome.RETURN; + return RETURN; } }); - router.getRules().add(sp); + router.add(sp); SSLParser sslParser = new SSLParser(); sslParser.setKeyStore(new KeyStore()); @@ -86,10 +87,10 @@ public Outcome handleRequest(Exchange exc) { @Override public Outcome handleRequest(Exchange exc) { exc.setResponse(Response.ok("secret2").build()); - return Outcome.RETURN; + return RETURN; } }); - router.getRules().add(sp2); + router.add(sp2); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index db7543ae8e..0e4ccc7ac6 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -110,7 +110,7 @@ void parseWSDLWithMultipleServicesForAGivenServiceB() throws Exception { void parseWSDLWithMultipleServicesForAWrongService() throws Exception { proxy.setServiceName("WrongService"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); - router.add(proxy); - assertThrows(IllegalArgumentException.class, () -> router.start()); + + assertThrows(IllegalArgumentException.class, () -> router.add(proxy)); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java index c7b7d57d51..25d54ff2af 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java @@ -35,7 +35,7 @@ public static void setup() throws Exception { key = new APIProxyKey(2000); }}; router.add(proxyWithOutTarget); - router.init(); + router.start(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 7f14b7cd76..eb6d6ca0bc 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -20,6 +20,7 @@ import com.predic8.membrane.core.transport.http.client.*; import org.junit.jupiter.api.*; +import java.io.*; import java.util.*; import static org.junit.jupiter.api.Assertions.*; @@ -36,8 +37,8 @@ static void setup() throws Exception { ServiceProxy cityAPI = new ServiceProxy(new ServiceProxyKey(4000), null, 0); cityAPI.getFlow().add(new SampleSoapServiceInterceptor()); backendRouter = new HttpRouter(); - backendRouter.getRuleManager().addProxyAndOpenPortIfNew(cityAPI); - backendRouter.init(); + backendRouter.add(cityAPI); + backendRouter.start(); } @AfterAll @@ -48,7 +49,7 @@ static void teardown() { } @BeforeEach - void startRouter() { + void startRouter() throws IOException { r = new HttpRouter(); HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); @@ -72,7 +73,7 @@ void startRouter() { sp2.setWsdl("http://localhost:4000?wsdl"); r2 = new HttpRouter(); r2.getConfig().setHotDeploy(false); - r2.getRules().add(sp2); + r2.add(sp2); } @AfterEach @@ -101,21 +102,21 @@ private void test() { } @Test - void checkWSDLDownloadFailureInSoapProxy() { - r.getRules().add(sp); + void checkWSDLDownloadFailureInSoapProxy() throws IOException { + r.add(sp); test(); } @Test - void checkWSDLDownloadFailureInSoapProxyAndValidator() { + void checkWSDLDownloadFailureInSoapProxyAndValidator() throws IOException { sp.getFlow().add(new ValidatorInterceptor()); - r.getRules().add(sp); + r.add(sp); test(); } @Test - void checkWSDLDownloadFailureInValidatorOfServiceProxy() { - r.getRules().add(sp3); + void checkWSDLDownloadFailureInValidatorOfServiceProxy() throws IOException { + r.add(sp3); test(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java index 56cc3a4193..37e599e436 100644 --- a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java +++ b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java @@ -65,6 +65,36 @@ public enum BasisUrlType { WINDOWS_DRIVE_BACKSLASH } + @BeforeAll + public static void setup() throws Exception { + ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3029), "localhost", 8080); + + sp.getFlow().add(new AbstractInterceptor() { + @Override + public Outcome handleRequest(Exchange exc) { + hit = true; + return CONTINUE; + } + }); + + WebServerInterceptor i = new WebServerInterceptor(); + if (deployment.equals(STANDALONE)) + i.setDocBase(getPathFromResource("")); + else { + i.setDocBase("/test"); + router.getResolverMap().addSchemaResolver(resolverMap.getFileSchemaResolver()); + } + sp.getFlow().add(i); + + router.add(sp); + router.start(); + } + + @AfterAll + public static void teardown() { + router.shutdown(); + } + // RelativeUrlType (SCHEMA, NAME, SAME_DIR, PARENT_DIR) is handled by the test methods as well as by the test resources // (WSDL and XSD files referencing other files in these ways) @@ -243,34 +273,4 @@ public static boolean isWindows() { public static final String deployment = STANDALONE; - @BeforeAll - public static void setup() throws Exception { - ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3029), "localhost", 8080); - - sp.getFlow().add(new AbstractInterceptor() { - @Override - public Outcome handleRequest(Exchange exc) { - hit = true; - return CONTINUE; - } - }); - - WebServerInterceptor i = new WebServerInterceptor(); - if (deployment.equals(STANDALONE)) - i.setDocBase(getPathFromResource("")); - else { - i.setDocBase("/test"); - router.getResolverMap().addSchemaResolver(resolverMap.getFileSchemaResolver()); - } - sp.getFlow().add(i); - - router.add(sp); - router.init(); - } - - @AfterAll - public static void teardown() { - router.shutdown(); - } - } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java index e24f20cb37..0b63aa70c0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java @@ -37,7 +37,7 @@ public void setUp() throws Exception { router = new HttpRouter(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3021), "localhost", 3022); - router.getRuleManager().addProxyAndOpenPortIfNew(sp1); + router.add(sp1); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3022), "", -1); sp2.getFlow().add(new AbstractInterceptor(){ @@ -53,8 +53,8 @@ public Outcome handleRequest(Exchange exc) { return Outcome.RETURN; } }); - router.getRuleManager().addProxyAndOpenPortIfNew(sp2); - router.init(); + router.add(sp2); + router.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index e8098f6456..6d3c529afc 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -49,7 +49,7 @@ public void setup() throws Exception{ sp.getFlow().add(GROOVY("Thread.sleep(1000)")); sp.getFlow().add(RETURN); - router.getRuleManager().addProxy(sp, MANUAL); + router.add(sp); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java index 166e3e74f0..258a668195 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java @@ -33,7 +33,8 @@ void setUp() throws Exception { ServiceProxy proxy2000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 2000), "predic8.com", 80); router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy2000); + router.add(proxy2000); + router.start(); conLocalhost = Connection.open("localhost", 2000, null, null, 30000); con127_0_0_1 = Connection.open("127.0.0.1", 2000, null, null, 30000); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java index f9c3ad422d..0abda9fc5a 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java @@ -20,6 +20,8 @@ import com.predic8.membrane.core.proxies.*; import org.junit.jupiter.api.*; +import java.io.*; + import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.http.Request.*; import static com.predic8.membrane.core.interceptor.Outcome.*; @@ -31,7 +33,7 @@ public class Http2DowngradeTest { private static HttpRouter router; @BeforeAll - public static void beforeAll() { + public static void beforeAll() throws IOException { router = new HttpRouter(); ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey(3064), null, 0); proxy.getFlow().add(new AbstractInterceptor() { @@ -41,7 +43,7 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } }); - router.getRules().add(proxy); + router.add(proxy); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java index 826359be8e..c82c1088c0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java @@ -63,8 +63,8 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } }); - service1.getRuleManager().addProxyAndOpenPortIfNew(sp1); - service1.init(); + service1.add(sp1); + service1.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java index e35bf95c61..193939c5b6 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java @@ -42,7 +42,7 @@ public void setUp() throws Exception { setupSlowBackend(); } - private void setupMembrane() { + private void setupMembrane() throws IOException { HttpClientConfiguration hcc = new HttpClientConfiguration(); hcc.getConnection().setSoTimeout(1); hcc.getRetryHandler().setRetries(1); @@ -52,7 +52,7 @@ private void setupMembrane() { proxyRouter.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(hcc); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3023), "localhost", 3022); - proxyRouter.getRules().add(sp2); + proxyRouter.add(sp2); proxyRouter.start(); } @@ -78,8 +78,8 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } }); - slowBackend.getRuleManager().addProxyAndOpenPortIfNew(sp); - slowBackend.init(); + slowBackend.add(sp); + slowBackend.start(); } @AfterEach @@ -100,8 +100,6 @@ void httpTimeout() throws Exception { client.call(exc); assertEquals(500, exc.getResponse().getStatusCode()); - System.out.println(exc.getResponse()); - System.out.println(exc.getResponse().getBodyAsStringDecoded()); } watch.stop(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java index 513af03008..fb0a51c229 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java @@ -33,13 +33,13 @@ public class ServiceInvocationTest { private HttpRouter router; @BeforeEach - public void setUp() throws Exception { + void setUp() throws Exception { router = createRouter(); MockInterceptor.clear(); } @Test - public void testInterceptorSequence() throws Exception { + void testInterceptorSequence() throws Exception { callService(); MockInterceptor.assertContent( @@ -48,7 +48,6 @@ public void testInterceptorSequence() throws Exception { new String[] {}); // aborts } - @AfterEach public void tearDown() { router.shutdown(); @@ -90,11 +89,11 @@ private PostMethod createPostMethod() { private HttpRouter createRouter() throws Exception { HttpRouter router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(createFirstRule()); - router.getRuleManager().addProxyAndOpenPortIfNew(createServiceRule()); - router.getRuleManager().addProxyAndOpenPortIfNew(createEndpointRule()); + router.add(createFirstRule()); + router.add(createServiceRule()); + router.add(createEndpointRule()); router.getTransport().getFlow().add(router.getTransport().getFlow().size()-1, new MockInterceptor("transport-log")); - router.init(); + router.start(); return router; } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java index 75178273df..d6f2257ba5 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java @@ -23,11 +23,14 @@ import com.predic8.membrane.core.transport.http.client.*; import com.predic8.membrane.core.transport.http.client.protocol.*; import com.predic8.membrane.core.util.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; +import java.io.*; import java.util.concurrent.*; import java.util.function.*; +import static com.predic8.membrane.core.interceptor.Outcome.RETURN; import static com.predic8.membrane.core.transport.http2.StreamState.*; import static java.util.concurrent.TimeUnit.*; import static org.junit.jupiter.api.Assertions.*; @@ -41,15 +44,9 @@ public class Http2ClientServerTest { private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); @BeforeEach - public void setup() { + public void setup() throws IOException { connectionHashes.clear(); - SSLParser sslParser = new SSLParser(); - sslParser.setUseExperimentalHttp2(true); - sslParser.setEndpointIdentificationAlgorithm(""); - sslParser.setShowSSLExceptions(true); - sslParser.setKeyStore(new KeyStore()); - sslParser.getKeyStore().setLocation("classpath:/ssl-rsa.keystore"); - sslParser.getKeyStore().setKeyPassword("secret"); + SSLParser sslParser = getSslParser(); router = new HttpRouter(); router.getConfig().setHotDeploy(false); @@ -63,13 +60,12 @@ public Outcome handleRequest(Exchange exc) { if (requestAsserter != null) requestAsserter.accept(exc.getRequest()); exc.setResponse(response); - return Outcome.RETURN; + return RETURN; } }); - router.getRules().add(sp); + router.add(sp); router.start(); - SSLParser sslParser2 = new SSLParser(); sslParser2.setEndpointIdentificationAlgorithm(""); sslParser2.setShowSSLExceptions(true); @@ -87,6 +83,17 @@ public Outcome handleRequest(Exchange exc) { hc = new HttpClient(configuration); } + private static @NotNull SSLParser getSslParser() { + SSLParser sslParser = new SSLParser(); + sslParser.setUseExperimentalHttp2(true); + sslParser.setEndpointIdentificationAlgorithm(""); + sslParser.setShowSSLExceptions(true); + sslParser.setKeyStore(new KeyStore()); + sslParser.getKeyStore().setLocation("classpath:/ssl-rsa.keystore"); + sslParser.getKeyStore().setKeyPassword("secret"); + return sslParser; + } + @AfterEach public void done() { hc.close(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java index 23de4682c9..b6183d05e0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java @@ -22,12 +22,15 @@ import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.http.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; +import java.io.*; import java.util.concurrent.*; import static com.predic8.membrane.core.exchange.Exchange.*; import static com.predic8.membrane.core.http.Request.*; +import static com.predic8.membrane.core.http.Response.ok; import static com.predic8.membrane.core.interceptor.Outcome.*; import static org.junit.jupiter.api.Assertions.*; @@ -38,30 +41,31 @@ public class HttpsKeepAliveTest { private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); @BeforeAll - public static void startServer() { + public static void startServer() throws IOException { server = new HttpRouter(); server.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(); sp.setPort(3063); SSLParser sslIB = new SSLParser(); - KeyStore ksIB = new KeyStore(); - ksIB.setLocation("classpath:/alias-keystore.p12"); - ksIB.setKeyPassword("secret"); - ksIB.setKeyAlias("key1"); - sslIB.setKeyStore(ksIB); + sslIB.setKeyStore(getKeyStore()); sp.setSslInboundParser(sslIB); sp.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { - exc.setResponse(Response.ok("ssltest").build()); - connectionHashes.put("" + ((HttpServerHandler)exc.getHandler()).getSrcOut().hashCode(), true); + exc.setResponse(ok("ssltest").build()); + connectionHashes.put("" + ((HttpServerHandler) exc.getHandler()).getSrcOut().hashCode(), true); return RETURN; } }); - server.getRules().add(sp); + server.add(sp); server.start(); } + @AfterAll + public static void shutdownServer() { + server.stop(); + } + private static StaticSSLContext createSSLOutboundContext() { SSLParser sslOB = new SSLParser(); sslOB.setEndpointIdentificationAlgorithm(""); @@ -72,11 +76,6 @@ private static StaticSSLContext createSSLOutboundContext() { return new StaticSSLContext(sslOB, new ResolverMap(), "/"); } - @AfterAll - public static void shutdownServer() { - server.stop(); - } - @Test void httpsKeepAlive() throws Exception { SSLContext sslCtxOb = createSSLOutboundContext(); @@ -93,4 +92,12 @@ void httpsKeepAlive() throws Exception { assertEquals(1, connectionHashes.size()); } + + private static @NotNull KeyStore getKeyStore() { + var ks = new KeyStore(); + ks.setLocation("classpath:/alias-keystore.p12"); + ks.setKeyPassword("secret"); + ks.setKeyAlias("key1"); + return ks; + } } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java index 6738c8771c..089e9162b1 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java @@ -43,13 +43,14 @@ import static com.predic8.membrane.core.http.Header.USER_AGENT; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.http.Request.get; +import static com.predic8.membrane.core.http.Response.ok; import static com.predic8.membrane.core.interceptor.Outcome.*; import static java.nio.charset.StandardCharsets.UTF_8; import static org.jose4j.lang.HashUtil.SHA_256; import static org.junit.jupiter.api.Assertions.*; public class AcmeServerSimulator { - private static final Logger LOG = LoggerFactory.getLogger(AcmeServerSimulator.class); + private static final Logger log = LoggerFactory.getLogger(AcmeServerSimulator.class); private final int port; private final int challengePort; private final boolean actuallyPerformChallenge; @@ -65,7 +66,6 @@ public AcmeServerSimulator(int port, int challengePort, boolean actuallyPerformC this.port = port; this.challengePort = challengePort; this.actuallyPerformChallenge = actuallyPerformChallenge; - ca.init(); } @@ -86,16 +86,16 @@ public Outcome handleRequest(Exchange exc) { } public Outcome handleRequestInternal(Exchange exc) throws Exception { - LOG.debug("acme server: got " + exc.getRequest().getUri() + " request"); + log.debug("acme server: got " + exc.getRequest().getUri() + " request"); if ("/directory".equals(exc.getRequest().getUri())) { - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .body(Resources.toString(getResource("acme/directory.json"), UTF_8)) .build()); return RETURN; } if ("/acme/new-nonce".equals(exc.getRequest().getUri()) && "HEAD".equals(exc.getRequest().getMethod())) { - exc.setResponse(Response.ok() + exc.setResponse(ok() .header("Replay-Nonce", createNonce()) .body("") .build()); @@ -135,7 +135,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { assertNotNull(jws.getJwkHeader(), "RFC 8555 Section 6.2"); String accountUrl = "http://localhost:3050/acme/acct/123456"; - exc.setResponse(Response.ok().status(201, "Created") + exc.setResponse(ok().status(201, "Created") .contentType(APPLICATION_JSON) .header("Location", accountUrl) .header("Replay-Nonce", createNonce()) @@ -166,7 +166,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { return RETURN; } - exc.setResponse(Response.ok().status(201, "Created") + exc.setResponse(ok().status(201, "Created") .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .header("Location", "http://localhost:3050/acme/order/42212345") @@ -176,7 +176,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { return RETURN; } if ("/acme/order/42212345".equals(exc.getRequest().getUri())) { - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(Resources.toString(getResource("acme/order-" + orderStatus.get() + ".json"), UTF_8)) @@ -186,13 +186,13 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { } if ("/acme/authz-v3/151234567".equals(exc.getRequest().getUri())) { if (challengeSucceeded.get()) { - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(Resources.toString(getResource("acme/authorization-valid.json"), UTF_8)) .build()); } else { - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(Resources.toString(getResource("acme/authorization.json"), UTF_8)) @@ -203,7 +203,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { if ("/acme/chall-v3/1555123456/abCd1E".equals(exc.getRequest().getUri())) { startChallenge(jws.getKeyIdHeaderValue()); - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(Resources.toString(getResource("acme/challenge-pending.json"), UTF_8)) @@ -215,7 +215,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { certificates = ca.sign((String) om.readValue(jws.getPayload(), Map.class).get("csr")); orderStatus.set("valid"); - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(Resources.toString(getResource("acme/order-processing.json"), UTF_8)) @@ -224,7 +224,7 @@ public Outcome handleRequestInternal(Exchange exc) throws Exception { return RETURN; } if ("/acme/cert/fab123456789abcdef0123456789abcdef12".equals(exc.getRequest().getUri())) { - exc.setResponse(Response.ok() + exc.setResponse(ok() .contentType(APPLICATION_JSON) .header("Replay-Nonce", createNonce()) .body(certificates) diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java index 63f8119848..28524bbb7d 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java @@ -84,7 +84,8 @@ public Outcome handleRequest(Exchange exc) { AcmeHttpChallengeInterceptor acmeHttpChallengeInterceptor = new AcmeHttpChallengeInterceptor(); acmeHttpChallengeInterceptor.setIgnorePort(true); sp2.getFlow().add(acmeHttpChallengeInterceptor); - router.setRules(ImmutableList.of(sp1, sp2)); + router.add(sp1); + router.add(sp2); router.start(); try { diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index 48d4e09fdf..38b8884e45 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -67,9 +67,9 @@ public static void setup() throws Exception { private static void setupGateway() throws Exception { gw = new HttpRouter(); gw.getConfig().setHotDeploy(false); - gw.getRuleManager().addProxyAndOpenPortIfNew(createCitiesSoapProxyGateway()); - gw.getRuleManager().addProxyAndOpenPortIfNew(createTwoServicesSOAPProxyGateway("ServiceA")); - gw.init(); + gw.add(createCitiesSoapProxyGateway()); + gw.add(createTwoServicesSOAPProxyGateway("ServiceA")); + gw.start(); } private static @NotNull SOAPProxy createCitiesSoapProxyGateway() { @@ -90,9 +90,9 @@ private static void setupGateway() throws Exception { private static void setupBackend() throws Exception { backend = new HttpRouter(); - backend.getRuleManager().addProxyAndOpenPortIfNew(createAServiceProxy()); - backend.getRuleManager().addProxyAndOpenPortIfNew(createCitiesServiceProxy()); - backend.init(); + backend.add(createAServiceProxy()); + backend.add(createCitiesServiceProxy()); + backend.start(); } private static @NotNull APIProxy createCitiesServiceProxy() { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java index 7dfbb9f89e..e7a530463c 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java @@ -81,9 +81,9 @@ private HttpRouter createLoadBalancer() throws Exception { balancingInterceptor = new LoadBalancingInterceptor(); balancingInterceptor.setName("Default"); sp3.getFlow().add(balancingInterceptor); - r.getRuleManager().addProxyAndOpenPortIfNew(sp3); + r.add(sp3); r.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(getHttpClientConfigurationWithRetries()); - r.init(); + r.start(); return r; } @@ -99,8 +99,8 @@ private HttpRouter createLoadBalancer() throws Exception { private Router createRouterForNode(TestingContext ctx, int i) throws Exception { HttpRouter r = new HttpRouter(); - r.getRuleManager().addProxyAndOpenPortIfNew(createServiceProxy(ctx, i)); - r.init(); + r.add(createServiceProxy(ctx, i)); + r.start(); return r; } diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 1a19de7855..0c9677d341 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -68,7 +68,7 @@ public Outcome handleResponse(Exchange exc) { } }); sp1.getFlow().add(mockInterceptor1); - service1.getRuleManager().addProxy(sp1, MANUAL); + service1.add(sp1); service1.start(); service2 = new HttpRouter(); @@ -83,7 +83,7 @@ public Outcome handleResponse(Exchange exc) { } }); sp2.getFlow().add(mockInterceptor2); - service2.getRuleManager().addProxy(sp2, MANUAL); + service2.add(sp2); service2.start(); balancer = new HttpRouter(); @@ -92,9 +92,9 @@ public Outcome handleResponse(Exchange exc) { balancingInterceptor = new LoadBalancingInterceptor(); balancingInterceptor.setName("Default"); sp3.getFlow().add(balancingInterceptor); - balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3); + balancer.add(sp3); enableFailOverOn5XX(); - balancer.init(); + balancer.start(); lookupBalancer(balancer, "Default").up("Default", "localhost", port2k); lookupBalancer(balancer, "Default").up("Default", "localhost", port3k); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index 0de9b01119..a5035ca8f1 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -15,8 +15,8 @@ package com.predic8.membrane.interceptor; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.interceptor.balancer.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.services.*; @@ -28,132 +28,131 @@ import static org.junit.jupiter.api.Assertions.*; public class MultipleLoadBalancersTest { - private static MockService service1; - private static MockService service2; - private static MockService service11; - private static MockService service12; - - protected static LoadBalancingInterceptor balancingInterceptor1; - protected static LoadBalancingInterceptor balancingInterceptor2; - private static DispatchingStrategy roundRobinStrategy1; - private static DispatchingStrategy roundRobinStrategy2; - protected static HttpRouter balancer; - - private static class MockService { - final int port; - final HttpRouter service1; - final DummyWebServiceInterceptor mockInterceptor1; - - MockService(int port) throws Exception { - this.port = port; - service1 = new HttpRouter(); - mockInterceptor1 = new DummyWebServiceInterceptor(); - ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", - "POST", ".*", port), "thomas-bayer.com", 80); - sp1.getFlow().add(mockInterceptor1); - service1.getRuleManager().addProxyAndOpenPortIfNew(sp1); - service1.init(); - } - - public void close() { - service1.shutdown(); - } - } - - private static LoadBalancingInterceptor createBalancingInterceptor(int port, String name) throws Exception { - ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80); - LoadBalancingInterceptor balancingInterceptor1 = new LoadBalancingInterceptor(); - balancingInterceptor1.setName(name); - sp3.getFlow().add(balancingInterceptor1); - balancer.getRuleManager().addProxyAndOpenPortIfNew(sp3); - balancer.init(); - return balancingInterceptor1; - } - - - @BeforeAll - public static void setUp() throws Exception { - - service1 = new MockService(2001); - service2 = new MockService(2002); - service11 = new MockService(2011); - service12 = new MockService(2012); - - balancer = new HttpRouter(); - - balancingInterceptor1 = createBalancingInterceptor(3054, "Default"); - balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2"); - - BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service1.port); - BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service2.port); - - BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service11.port); - BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service12.port); - - - roundRobinStrategy1 = new RoundRobinStrategy(); - roundRobinStrategy2 = new RoundRobinStrategy(); - } - - @AfterAll - public static void tearDown() throws Exception { - service1.close(); - service2.close(); - service11.close(); - service12.close(); - balancer.shutdown(); - } - - private void assertMockCounters(int n1, int n2, int n11, int n12) { - assertEquals(n1, service1.mockInterceptor1.getCount()); - assertEquals(n2, service2.mockInterceptor1.getCount()); - assertEquals(n11, service11.mockInterceptor1.getCount()); - assertEquals(n12, service12.mockInterceptor1.getCount()); - } - - @Test - public void testRoundRobinDispachingStrategy() throws Exception { - balancingInterceptor1.setDispatchingStrategy(roundRobinStrategy1); - balancingInterceptor2.setDispatchingStrategy(roundRobinStrategy2); - - HttpClient client = new HttpClient(); - client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, - HttpVersion.HTTP_1_1); - - PostMethod vari = getPostMethod(3054); - int status = client.executeMethod(vari); - - assertEquals(200, status); - assertMockCounters(1, 0, 0, 0); - - assertEquals(200, client.executeMethod(getPostMethod(3054))); - assertMockCounters(1, 1, 0, 0); - - assertEquals(200, client.executeMethod(getPostMethod(3054))); - assertMockCounters(2, 1, 0, 0); - - assertEquals(200, client.executeMethod(getPostMethod(3054))); - assertMockCounters(2, 2, 0, 0); - - assertEquals(200, client.executeMethod(getPostMethod(7001))); - assertMockCounters(2, 2, 1, 0); - - assertEquals(200, client.executeMethod(getPostMethod(7001))); - assertMockCounters(2, 2, 1, 1); - - assertEquals(200, client.executeMethod(getPostMethod(7001))); - assertMockCounters(2, 2, 2, 1); - } - - private PostMethod getPostMethod(int port) { - PostMethod post = new PostMethod( - "http://localhost:" + port + "/axis2/services/BLZService"); - post.setRequestEntity(new InputStreamRequestEntity(this.getClass() - .getResourceAsStream("/getBank.xml"))); - post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); - post.setRequestHeader(Header.SOAP_ACTION, ""); - - return post; - } + private static MockService service1; + private static MockService service2; + private static MockService service11; + private static MockService service12; + + protected static LoadBalancingInterceptor balancingInterceptor1; + protected static LoadBalancingInterceptor balancingInterceptor2; + private static DispatchingStrategy roundRobinStrategy1; + private static DispatchingStrategy roundRobinStrategy2; + protected static HttpRouter balancer; + + @AfterAll + public static void tearDown() throws Exception { + service1.close(); + service2.close(); + service11.close(); + service12.close(); + balancer.shutdown(); + } + + private static class MockService { + final int port; + final HttpRouter service1; + final DummyWebServiceInterceptor mockInterceptor1; + + MockService(int port) throws Exception { + this.port = port; + service1 = new HttpRouter(); + mockInterceptor1 = new DummyWebServiceInterceptor(); + ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", + "POST", ".*", port), "thomas-bayer.com", 80); + sp1.getFlow().add(mockInterceptor1); + service1.add(sp1); + service1.start(); + } + + public void close() { + service1.shutdown(); + } + } + + private static LoadBalancingInterceptor createBalancingInterceptor(int port, String name) throws Exception { + ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80); + LoadBalancingInterceptor balancingInterceptor1 = new LoadBalancingInterceptor(); + balancingInterceptor1.setName(name); + sp3.getFlow().add(balancingInterceptor1); + balancer.add(sp3); + balancer.start(); + return balancingInterceptor1; + } + + + @BeforeAll + public static void setUp() throws Exception { + + service1 = new MockService(2001); + service2 = new MockService(2002); + service11 = new MockService(2011); + service12 = new MockService(2012); + + balancer = new HttpRouter(); + + balancingInterceptor1 = createBalancingInterceptor(3054, "Default"); + balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2"); + + BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service1.port); + BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service2.port); + + BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service11.port); + BalancerUtil.lookupBalancer(balancer, "Balancer2").up("Default", "localhost", service12.port); + + roundRobinStrategy1 = new RoundRobinStrategy(); + roundRobinStrategy2 = new RoundRobinStrategy(); + } + + private void assertMockCounters(int n1, int n2, int n11, int n12) { + assertEquals(n1, service1.mockInterceptor1.getCount()); + assertEquals(n2, service2.mockInterceptor1.getCount()); + assertEquals(n11, service11.mockInterceptor1.getCount()); + assertEquals(n12, service12.mockInterceptor1.getCount()); + } + + @Test + public void testRoundRobinDispachingStrategy() throws Exception { + balancingInterceptor1.setDispatchingStrategy(roundRobinStrategy1); + balancingInterceptor2.setDispatchingStrategy(roundRobinStrategy2); + + HttpClient client = new HttpClient(); + client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, + HttpVersion.HTTP_1_1); + + PostMethod vari = getPostMethod(3054); + int status = client.executeMethod(vari); + + assertEquals(200, status); + assertMockCounters(1, 0, 0, 0); + + assertEquals(200, client.executeMethod(getPostMethod(3054))); + assertMockCounters(1, 1, 0, 0); + + assertEquals(200, client.executeMethod(getPostMethod(3054))); + assertMockCounters(2, 1, 0, 0); + + assertEquals(200, client.executeMethod(getPostMethod(3054))); + assertMockCounters(2, 2, 0, 0); + + assertEquals(200, client.executeMethod(getPostMethod(7001))); + assertMockCounters(2, 2, 1, 0); + + assertEquals(200, client.executeMethod(getPostMethod(7001))); + assertMockCounters(2, 2, 1, 1); + + assertEquals(200, client.executeMethod(getPostMethod(7001))); + assertMockCounters(2, 2, 2, 1); + } + + private PostMethod getPostMethod(int port) { + PostMethod post = new PostMethod( + "http://localhost:" + port + "/axis2/services/BLZService"); + post.setRequestEntity(new InputStreamRequestEntity(this.getClass() + .getResourceAsStream("/getBank.xml"))); + post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); + post.setRequestHeader(Header.SOAP_ACTION, ""); + + return post; + } } diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java index 4729a680e1..1a1b3dc89e 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/FileExchangeStoreExampleTest.java @@ -14,11 +14,13 @@ package com.predic8.membrane.examples.withinternet.test; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchangestore.FileExchangeStore; import com.predic8.membrane.examples.util.DistributionExtractingTestcase; import com.predic8.membrane.examples.util.Process2; import com.predic8.membrane.test.HttpAssertions; import org.junit.jupiter.api.Test; +import org.slf4j.*; import java.io.File; import java.io.FilenameFilter; @@ -32,6 +34,8 @@ public class FileExchangeStoreExampleTest extends DistributionExtractingTestcase { + private static final Logger log = LoggerFactory.getLogger(FileExchangeStoreExampleTest.class.getName()); + @Override protected String getExampleDirName() { return "extending-membrane/file-exchangestore"; @@ -124,6 +128,7 @@ private void recursiveDelete(File file) { } private boolean containsRecursively(File base, FilenameFilter filter) { + log.info("Checking {} for {}", base, filter); //noinspection ConstantConditions for (File f : base.listFiles()) { if (f.isDirectory()) diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java index a9ed971fd9..4891438524 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/withoutinternet/test/Loadbalancing6HealthMonitorExampleTest.java @@ -189,7 +189,7 @@ void https_lbAlternates() throws Exception { void https_adminShowsNodesUp() throws Exception { ensureCertificates(); try (Process2 ignored = builder.parameters(PROXIES_TLS_XML_OPTION).start()) { - // @formatter:off + // @formatter:off String html = given() .relaxedHTTPSValidation() .get(ADMIN_URL_HTTPS).then() From 3e5715f2a526bee1e6f274b72fea4ae7f6a46d0f Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Sun, 28 Dec 2025 21:39:52 +0100 Subject: [PATCH 21/40] refactor: streamline imports, remove redundant declarations, and improve readability in test files --- .../adminapi/AdminApiInterceptorTest.java | 6 +-- .../OAuth2ResourceErrorForwardingTest.java | 1 - .../oauth2/client/b2c/B2CMembrane.java | 3 +- .../client/b2c/MockAuthorizationServer.java | 9 ++--- .../shadowing/ShadowingInterceptorTest.java | 6 +-- .../membrane/core/proxies/ProxySSLTest.java | 37 ++++++++----------- .../membrane/core/proxies/ProxyTest.java | 1 - .../membrane/core/proxies/SOAPProxyTest.java | 2 +- .../membrane/core/resolver/ResolverTest.java | 1 - .../http/ConcurrentConnectionLimitTest.java | 1 - .../core/transport/ssl/acme/AcmeStepTest.java | 26 ++++++------- .../LoadBalancingInterceptorTest.java | 1 - 12 files changed, 40 insertions(+), 54 deletions(-) diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index 131996f78a..e14d5e4493 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -122,7 +122,7 @@ private static class TestHandler extends FakeHttpHandler implements TwoWayStream private final NotifyingByteArrayOutputStream outputStream = new NotifyingByteArrayOutputStream(); private InputStream inputStream = new InputStream() { @Override - public int read() throws IOException { + public int read() { while (!closed) { synchronized (TestHandler.this) { try { @@ -156,7 +156,7 @@ public String getRemoteDescription() { } @Override - public void removeSocketSoTimeout() throws SocketException { + public void removeSocketSoTimeout() { // do nothing } @@ -166,7 +166,7 @@ public boolean isClosed() { } @Override - public void close() throws IOException { + public void close() { closed = true; synchronized (this) { notifyAll(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java index 57b5bb75b8..83b65d876b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java @@ -34,7 +34,6 @@ import java.util.*; import java.util.concurrent.atomic.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.http.MimeType.*; import static org.junit.jupiter.api.Assertions.*; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index b9be5a8557..bbe8340eab 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -30,10 +30,9 @@ import java.util.*; import java.util.function.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.http.Response.*; -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; +import static com.predic8.membrane.core.interceptor.Outcome.*; /** * A locally running Membrane with various B2C features to test (1 ServiceProxy per feature). Primarily: diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java index d1ff483bf6..7c093cc1f6 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java @@ -34,15 +34,14 @@ import java.math.*; import java.security.*; import java.util.*; -import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.interceptor.oauth2.ParamNames.*; -import static com.predic8.membrane.core.util.URLParamUtil.DuplicateKeyOrInvalidFormStrategy.ERROR; -import static java.net.URLEncoder.encode; -import static java.nio.charset.StandardCharsets.UTF_8; +import static com.predic8.membrane.core.util.URLParamUtil.DuplicateKeyOrInvalidFormStrategy.*; +import static java.net.URLEncoder.*; +import static java.nio.charset.StandardCharsets.*; import static org.junit.jupiter.api.Assertions.*; public class MockAuthorizationServer { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java index 144eb8fb7e..9a86b88393 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java @@ -97,7 +97,7 @@ static void startup() throws Exception { shadowingProxy = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3000), null, 0); returnInterceptorMock = Mockito.spy(new ReturnInterceptor()); - returnInterceptorMock.setStatusCode(200); + returnInterceptorMock.setStatus(200); shadowingProxy.setFlow(List.of(returnInterceptorMock)); shadowingRouter.add(shadowingProxy); @@ -115,7 +115,7 @@ static void shutdown() { * and ensures that the ReturnInterceptor's handleRequest() is invoked once. */ @Test - void testIfShadowTargetIsCalled() throws Exception { + void testIfShadowTargetIsCalled() { given().when().get("http://localhost:2000").then().statusCode(200); verify(returnInterceptorMock, timeout(10000).times(1)).handleRequest(any(Exchange.class)); } @@ -125,7 +125,7 @@ void testIfShadowTargetIsCalled() throws Exception { * handleRequest() is invoked with an Exchange object not containing the "foo" header. */ @Test - void testIfShadowTargetHasFooHeader() throws Exception { + void testIfShadowTargetHasFooHeader() { given().when().get("http://localhost:2000").then().statusCode(200); ArgumentCaptor exchangeCaptor = ArgumentCaptor.forClass(Exchange.class); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index f7ab0776ff..a6fc4b4e01 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -13,32 +13,25 @@ limitations under the License. */ package com.predic8.membrane.core.proxies; -import com.predic8.membrane.core.Router; -import com.predic8.membrane.core.RuleManager; -import com.predic8.membrane.core.config.security.KeyStore; -import com.predic8.membrane.core.config.security.SSLParser; -import com.predic8.membrane.core.config.security.TrustStore; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Request; -import com.predic8.membrane.core.interceptor.AbstractInterceptor; -import com.predic8.membrane.core.interceptor.CountInterceptor; -import com.predic8.membrane.core.interceptor.Outcome; -import com.predic8.membrane.core.resolver.ResolverMap; -import com.predic8.membrane.core.transport.http.HttpClient; -import com.predic8.membrane.core.transport.http.client.HttpClientConfiguration; -import com.predic8.membrane.core.transport.http.client.ProxyConfiguration; -import com.predic8.membrane.core.transport.ssl.StaticSSLContext; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.config.security.*; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.http.client.*; +import com.predic8.membrane.core.transport.ssl.*; import org.jetbrains.annotations.*; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; +import org.junit.jupiter.params.*; +import org.junit.jupiter.params.provider.*; import java.io.*; -import java.util.Arrays; -import java.util.Collection; -import java.util.concurrent.atomic.AtomicInteger; +import java.util.*; +import java.util.concurrent.atomic.*; -import static com.predic8.membrane.core.exchange.Exchange.SSL_CONTEXT; -import static org.junit.jupiter.api.Assertions.assertEquals; +import static com.predic8.membrane.core.exchange.Exchange.*; +import static org.junit.jupiter.api.Assertions.*; public class ProxySSLTest { public static Collection data() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index 46f614a456..b281df702b 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -120,7 +120,6 @@ public void runHTTP() throws IOException { public void runHTTPS() throws IOException, UnrecoverableKeyException, NoSuchAlgorithmException, KeyStoreException, KeyManagementException, InterruptedException { SSLSocketFactory sslsf = new SSLSocketFactory("TLS", null, null, null, null, new TrustAllStrategy(), new AllowAllHostnameVerifier()); - Scheme https = new Scheme("https", 3057, sslsf); CloseableHttpClient hc = HttpClientBuilder.create() .setSSLSocketFactory(sslsf) diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index 0e4ccc7ac6..a474ef1ea8 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -107,7 +107,7 @@ void parseWSDLWithMultipleServicesForAGivenServiceB() throws Exception { } @Test - void parseWSDLWithMultipleServicesForAWrongService() throws Exception { + void parseWSDLWithMultipleServicesForAWrongService() { proxy.setServiceName("WrongService"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); diff --git a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java index 37e599e436..e08edf3695 100644 --- a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java +++ b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java @@ -269,7 +269,6 @@ public static boolean isWindows() { static volatile boolean hit = false; public static final String STANDALONE = "standalone"; - public static final String J2EE = "J2EE"; public static final String deployment = STANDALONE; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index 6d3c529afc..a826380bfe 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -23,7 +23,6 @@ import java.util.concurrent.*; import java.util.stream.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.interceptor.flow.invocation.FlowTestInterceptors.*; import static org.junit.jupiter.api.Assertions.*; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java index 28524bbb7d..7ae0998900 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java @@ -101,7 +101,7 @@ public Outcome handleRequest(Exchange exc) { OrderAndLocation ol = acmeClient.createOrder(accountUrl, Arrays.asList(hosts)); - assertTrue(ol.getOrder().getAuthorizations().size() > 0); + assertFalse(ol.getOrder().getAuthorizations().isEmpty()); for (String authorization : ol.getOrder().getAuthorizations()) { Authorization auth = acmeClient.getAuth(accountUrl, authorization); @@ -144,18 +144,18 @@ public Outcome handleRequest(Exchange exc) { Thread.sleep(10); } - HttpClient hc = new HttpClient(); - Exchange e = new Request.Builder().get("https://localhost:3051/").buildExchange(); - SSLParser sslParser1 = new SSLParser(); - Trust trust = new Trust(); - Certificate certificate = new Certificate(); - certificate.setContent(sim.getCA().getCertificate()); - trust.setCertificateList(ImmutableList.of(certificate)); - sslParser1.setTrust(trust); - e.setProperty(Exchange.SSL_CONTEXT, new StaticSSLContext(sslParser1, router.getResolverMap(), router.getBaseLocation())); - hc.call(e); - - assertEquals(234, e.getResponse().getStatusCode()); + try(HttpClient hc = new HttpClient()) { + Exchange e = new Request.Builder().get("https://localhost:3051/").buildExchange(); + SSLParser sslParser1 = new SSLParser(); + Trust trust = new Trust(); + Certificate certificate = new Certificate(); + certificate.setContent(sim.getCA().getCertificate()); + trust.setCertificateList(ImmutableList.of(certificate)); + sslParser1.setTrust(trust); + e.setProperty(Exchange.SSL_CONTEXT, new StaticSSLContext(sslParser1, router.getResolverMap(), router.getBaseLocation())); + hc.call(e); + assertEquals(234, e.getResponse().getStatusCode()); + } } finally { router.stop(); // TODO shutdown router in AfterAll } diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 0c9677d341..9af59c8c2e 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -27,7 +27,6 @@ import java.net.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.http.Response.*; From 1c5f812248411f79acb96848faafbad7b4d45902 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 09:12:59 +0100 Subject: [PATCH 22/40] refactor: improve Router lifecycle management, update test setup/teardown methods, and streamline imports across test cases --- .../com/predic8/membrane/core/Router.java | 10 +++-- .../membrane/core/proxies/SSLProxy.java | 8 +--- .../membrane/core/util/TimerManager.java | 2 +- .../predic8/membrane/core/acl/ACLTest.java | 15 +++++++- .../ElasticSearchExchangeStoreTest.java | 29 +++++++------- .../OpenTelemetryInterceptorTest.java | 21 ++++++---- .../core/proxies/APIProxyKeyTest.java | 8 ++-- .../membrane/core/proxies/SOAPProxyTest.java | 3 +- .../core/proxies/TargetURLExpressionTest.java | 21 ++++++++-- .../transport/ssl/SessionResumptionTest.java | 38 +++++++++++-------- .../MultipleLoadBalancersTest.java | 2 +- 11 files changed, 98 insertions(+), 59 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 48c11304dd..90d096c0a6 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -14,7 +14,6 @@ package com.predic8.membrane.core; -import com.jayway.jsonpath.internal.function.sequence.*; import com.predic8.membrane.annot.*; import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.core.RuleManager.*; @@ -48,7 +47,7 @@ import java.util.Timer; import java.util.concurrent.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.jmx.JmxExporter.*; import static com.predic8.membrane.core.util.DLPUtil.*; import static java.util.concurrent.Executors.*; @@ -309,9 +308,14 @@ public void start() { } } + /* + TODO: + - Why is the source hardcoded here. + - Why does it matter? + */ public Collection getRules() { log.debug("Getting rules."); - return getRuleManager().getRulesBySource(RuleDefinitionSource.SPRING); // TODO: Source? + return getRuleManager().getRulesBySource(MANUAL); // TODO: Source? } @MCChildElement(order = 3) diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java index 187d6a8fc7..b55688bb49 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java @@ -45,7 +45,7 @@ import static com.predic8.membrane.core.interceptor.FlowController.ABORTION_REASON; /** - * TODO Do will still use this? + * Proxies SSL connections to a target server without decrypting the traffic. */ @MCElement(name="sslProxy") public class SSLProxy implements Proxy { @@ -220,11 +220,7 @@ public String getErrorState() { @Override public SSLProxy clone() throws CloneNotSupportedException { SSLProxy clone = (SSLProxy) super.clone(); - try { - clone.init(router); - } catch (Exception e) { - throw new RuntimeException(e); - } + clone.init(router); return clone; } diff --git a/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java b/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java index df5405c05e..b64370bd88 100644 --- a/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java +++ b/core/src/main/java/com/predic8/membrane/core/util/TimerManager.java @@ -24,7 +24,7 @@ */ public class TimerManager { - private static final Logger log = LoggerFactory.getLogger(TimerManager.class.getName()); + private static final Logger log = LoggerFactory.getLogger(TimerManager.class); protected final java.util.Timer timer = new Timer(true); diff --git a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java index 519b33780a..cf155b2b55 100644 --- a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java @@ -15,6 +15,7 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.acl.*; +import org.junit.jupiter.api.*; import java.util.function.*; @@ -22,8 +23,20 @@ public abstract class ACLTest extends AccessControlInterceptor { + protected Router router; + + @BeforeEach + void setUpEach() { + router = new HttpRouter(); + router.start(); + } + + @AfterEach + void tearDownEach() { + router.stop(); + } + private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { - Router router = new Router(); AccessControlInterceptor aci = buildAci(f.apply(router), router); aci.setUseXForwardedForAsClientAddr(useForwardedFor); return aci; diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java index 189a6a746e..0a0465bcde 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java @@ -45,7 +45,7 @@ class ElasticSearchExchangeStoreTest { private static final String RESPONSE_BODY = """ {"demo": true}"""; - private static final String REQUEST_BODY = """ + private static final String REQUEST_BODY = """ {"where":"there"}"""; private HttpRouter gateway; @@ -63,8 +63,15 @@ public void start() throws IOException { @AfterEach public void done() { - back.stop(); - elasticMock.stop(); + try { + back.stop(); + } finally { + try { + gateway.stop(); + } finally { + elasticMock.stop(); + } + } } private void initializeElasticSearchMock() throws IOException { @@ -77,7 +84,7 @@ private void initializeElasticSearchMock() throws IOException { elasticMock.start(); } - private static @NotNull LogInterceptor createBodyLoggingInterceptor() { + private @NotNull LogInterceptor createBodyLoggingInterceptor() { LogInterceptor log = new LogInterceptor(); log.setBody(true); return log; @@ -155,7 +162,7 @@ public Outcome handleRequest(Exchange exc) { public List getInsertedObjectsAndClearList() { synchronized (insertedObjects) { - List insertedObjects1 = new ArrayList(insertedObjects); + List insertedObjects1 = new ArrayList<>(insertedObjects); insertedObjects.clear(); return insertedObjects1; } @@ -175,9 +182,7 @@ private void runTest(boolean addLoggingInterceptors) throws Exception { initializeGateway(addLoggingInterceptors); try (var client = new HttpClient()) { - client.call(Request.post("http://localhost:3064") - .header(AUTHORIZATION, "Demo") - .body(REQUEST_BODY).buildExchange()); + client.call(Request.post("http://localhost:3064").header(AUTHORIZATION, "Demo").body(REQUEST_BODY).buildExchange()); } waitForExchangeStoreToFlush(); @@ -200,17 +205,11 @@ private void runTest(boolean addLoggingInterceptors) throws Exception { assertTrue(insertedObjects.get(1).get("timeResSent").longValue() > 1740000000000L); } - @AfterEach - public void done2() { - gateway.stop(); - } - private void waitForExchangeStoreToFlush() { while (true) { synchronized (es.shortTermMemoryForBatching) { int size = es.shortTermMemoryForBatching.size(); - if (size == 0 && !es.updateThreadWorking) - return; + if (size == 0 && !es.updateThreadWorking) return; } try { //noinspection BusyWait diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index e4a314c816..eda9dbbd37 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -13,25 +13,32 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.opentelemetry; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.proxies.Proxy; import com.predic8.membrane.core.proxies.ServiceProxy; import com.predic8.membrane.core.proxies.ServiceProxyKey; -import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.*; + +import java.io.*; import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.SPRING; class OpenTelemetryInterceptorTest { + private Router router; + @Test - void initTest() { + void initTest() throws IOException { Proxy r = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3141), null, 0); r.getFlow().add(new OpenTelemetryInterceptor()); - HttpRouter rtr = new HttpRouter(); - rtr.getRuleManager().addProxy(r, SPRING); + router = new HttpRouter(); + router.add(r); + router.init(); + } - rtr.init(); - rtr.shutdown(); + @AfterEach + void tearDown() { + router.shutdown(); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java index 836795eb8f..e89005f747 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java @@ -30,13 +30,13 @@ public class APIProxyKeyTest { private static Router router; - @BeforeAll - public static void setup() { + @BeforeEach + public void setup() { router = new HttpRouter(); } - @AfterAll - public static void shutdown() { + @AfterEach + public void shutdown() { router.shutdown(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index a474ef1ea8..dd1fcfd48f 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -111,6 +111,7 @@ void parseWSDLWithMultipleServicesForAWrongService() { proxy.setServiceName("WrongService"); proxy.setWsdl("classpath:/ws/cities-2-services.wsdl"); - assertThrows(IllegalArgumentException.class, () -> router.add(proxy)); + assertThrows(IllegalArgumentException.class, () -> {router.add(proxy); router.start(); + }); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index e0ae9d84bc..dec13e1c28 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -19,7 +19,6 @@ import com.predic8.membrane.core.openapi.serviceproxy.*; import org.junit.jupiter.api.*; -import java.io.*; import java.net.*; import static com.predic8.membrane.core.http.Request.*; @@ -30,9 +29,21 @@ */ class TargetURLExpressionTest { + private static Router router; + + @BeforeEach + void setUp() { + router = new Router(); + } + + @AfterEach + void tearDown() { + router.stop(); + } + @Test void targetWithExpression() throws URISyntaxException { - Router r = new Router(); + router = new Router(); Exchange rq = get("http://localhost:2000/").buildExchange(); APIProxy api = new APIProxy() {{ setTarget(new Target() {{ @@ -40,13 +51,15 @@ void targetWithExpression() throws URISyntaxException { }}); }}; rq.setProxy(api); - api.init(r); + api.init(router); DispatchingInterceptor di = new DispatchingInterceptor() {{ - router = r; + router = TargetURLExpressionTest.router; }}; di.handleRequest(rq); assertEquals("http://localhost:3000/", rq.getDestinations().getFirst()); } + + } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index b37d267473..48fc876cdb 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -54,9 +54,15 @@ static void init() throws IOException { @AfterAll static void done() throws IOException { - tcpForwarder.close(); - router1.shutdown(); - router2.shutdown(); + try { + tcpForwarder.close(); + } finally { + try { + router1.shutdown(); + } finally { + router2.shutdown(); + } + } } private static SSLContext createClientTLSContext() { @@ -69,19 +75,6 @@ private static SSLContext createClientTLSContext() { return new StaticSSLContext(sslParser, new ResolverMap(), "."); } - @Disabled - @Test - public void doit() throws Exception { - try (HttpClient hc = new HttpClient()) { - for (int i = 0; i < 2; i++) { - // the tcp forwarder will forward the first connection to 3042, the second to 3043 - Exchange exc = new Request.Builder().get("https://localhost:3044").buildExchange(); - exc.setProperty(SSL_CONTEXT, clientTLSContext); - hc.call(exc); - } - } - } - private static Router createTLSServer(int port) { Router router = new HttpRouter(); router.getConfig().setHotDeploy(false); @@ -156,4 +149,17 @@ private static Closeable startTCPForwarder(int port) throws IOException { }; } } + + @Disabled + @Test + public void doit() throws Exception { + try (HttpClient hc = new HttpClient()) { + for (int i = 0; i < 2; i++) { + // the tcp forwarder will forward the first connection to 3042, the second to 3043 + Exchange exc = new Request.Builder().get("https://localhost:3044").buildExchange(); + exc.setProperty(SSL_CONTEXT, clientTLSContext); + hc.call(exc); + } + } + } } diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index a5035ca8f1..59740b0194 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -75,7 +75,6 @@ private static LoadBalancingInterceptor createBalancingInterceptor(int port, Str balancingInterceptor1.setName(name); sp3.getFlow().add(balancingInterceptor1); balancer.add(sp3); - balancer.start(); return balancingInterceptor1; } @@ -92,6 +91,7 @@ public static void setUp() throws Exception { balancingInterceptor1 = createBalancingInterceptor(3054, "Default"); balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2"); + balancer.start(); BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service1.port); BalancerUtil.lookupBalancer(balancer, "Default").up("Default", "localhost", service2.port); From f873164bf9286a57166094e5c5b89ca65867c6fd Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 12:34:32 +0100 Subject: [PATCH 23/40] refactor: replace `Router.initByXML` with `RouterBootstrap.initByXML`, improve HotDeployer lifecycle, and streamline `Router` initialization logic --- .../predic8/membrane/core/Configuration.java | 2 +- .../com/predic8/membrane/core/IRouter.java | 30 +++ .../com/predic8/membrane/core/Router.java | 236 ++++++------------ .../membrane/core/RouterBootstrap.java | 65 +++++ .../membrane/core/RuleReinitializer.java | 87 +++++++ .../predic8/membrane/core/cli/RouterCLI.java | 7 +- .../predic8/membrane/core/jmx/JmxRouter.java | 2 +- .../router/hotdeploy/DefaultHotDeployer.java | 10 +- .../core/router/hotdeploy/HotDeployer.java | 3 +- .../router/hotdeploy/NullHotDeployer.java | 5 +- .../com/predic8/membrane/core/SimpleTest.java | 2 +- .../predic8/membrane/core/acl/ACLTest.java | 6 +- .../config/ReadRulesConfigurationTest.java | 2 +- ...ulesWithInterceptorsConfigurationTest.java | 2 +- .../core/config/SpringReferencesTest.java | 2 +- .../membrane/core/http/Http10Test.java | 1 - .../interceptor/InternalInvocationTest.java | 2 +- .../core/interceptor/UserFeatureTest.java | 2 +- .../adminapi/AdminApiInterceptorTest.java | 32 +-- .../OpenTelemetryInterceptorTest.java | 6 +- .../membrane/core/proxies/ProxyRuleTest.java | 2 +- .../membrane/core/proxies/ProxyTest.java | 47 ++-- .../core/proxies/TargetURLExpressionTest.java | 12 +- .../proxies/UnavailableSoapProxyTest.java | 4 +- .../client/HttpClientConfigurationTest.java | 2 +- .../transport/ssl/SessionResumptionTest.java | 55 ++-- .../interceptor/SOAPProxyIntegrationTest.java | 2 +- .../MultipleLoadBalancersTest.java | 16 +- docs/ROADMAP.md | 8 +- .../predic8/membrane/plugin/RouterFacade.java | 2 +- 30 files changed, 359 insertions(+), 295 deletions(-) create mode 100644 core/src/main/java/com/predic8/membrane/core/IRouter.java create mode 100644 core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java create mode 100644 core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java diff --git a/core/src/main/java/com/predic8/membrane/core/Configuration.java b/core/src/main/java/com/predic8/membrane/core/Configuration.java index d1dab26928..aeca9ab180 100644 --- a/core/src/main/java/com/predic8/membrane/core/Configuration.java +++ b/core/src/main/java/com/predic8/membrane/core/Configuration.java @@ -37,7 +37,7 @@ public class Configuration { private boolean retryInit = false; - private String jmxRouterName; + private String jmxRouterName = "default"; private URIFactory uriFactory = new URIFactory(false); diff --git a/core/src/main/java/com/predic8/membrane/core/IRouter.java b/core/src/main/java/com/predic8/membrane/core/IRouter.java new file mode 100644 index 0000000000..8ec0666771 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/IRouter.java @@ -0,0 +1,30 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.core.proxies.*; +import org.springframework.context.*; + +import java.io.*; + +public interface IRouter extends Lifecycle { + + void init(); + + void shutdown(); + + void add(Proxy proxy) throws IOException; + +} diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 90d096c0a6..01fc2dd8a9 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -38,13 +38,10 @@ import org.springframework.beans.factory.*; import org.springframework.context.*; import org.springframework.context.support.*; -import org.springframework.core.io.*; import javax.annotation.concurrent.*; import java.io.*; -import java.nio.charset.*; import java.util.*; -import java.util.Timer; import java.util.concurrent.*; import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; @@ -53,6 +50,11 @@ import static java.util.concurrent.Executors.*; /* + Responsibilities: + - Start and stop Membrane + - Start, stop internal services + - Control lifecycle of proxies + TODO: - ADR: First start router than init and add proxies or first init proxies and add them later? @@ -72,6 +74,9 @@ HTTPRouter: - Purpose? Test? + - JMX + - Beans added after Router.start() should also be exported as JMS beans + */ /** @@ -97,9 +102,9 @@ outputName = "router-conf.xsd", targetNamespace = "http://membrane-soa.org/proxies/1/") @MCElement(name = "router") -public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver { +public class Router implements ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver, IRouter { - private static final Logger log = LoggerFactory.getLogger(Router.class.getName()); + private static final Logger log = LoggerFactory.getLogger(Router.class); private ApplicationContext beanFactory; @@ -136,11 +141,6 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA private boolean initialized; - // - // Reinitialization - // - private Timer reinitializer; - /** * HotDeployer for changes on the XML configuration file. Does not cover YAML. * Not synchronized, since only modified during initialization @@ -148,6 +148,8 @@ public class Router implements Lifecycle, ApplicationContextAware, BeanRegistryA */ private HotDeployer hotDeployer = new DefaultHotDeployer(); + private RuleReinitializer reinitializer; + public Router() { log.debug("Creating new router."); resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); @@ -181,6 +183,7 @@ public void init() { rm.setRouter(this); return rm; }); + getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); // Transport last if (transport == null) { @@ -191,6 +194,7 @@ public void init() { initProxies(); initialized = true; + reinitializer = new RuleReinitializer(this); // Bean } private void initProxies() { @@ -201,41 +205,6 @@ private void initProxies() { } } - /** - * Initializes a {@link Router} instance from the specified Spring XML configuration resource. - * - * @param resource the path to the Spring XML configuration file that defines the {@link Router} bean - * @return the initialized {@link Router} instance - * @throws RuntimeException if no {@link Router} bean is found or more than one {@link Router} bean is found - */ - public static Router initByXML(String resource) { - log.debug("loading spring config: {}", resource); - - TrackingFileSystemXmlApplicationContext bf = - new TrackingFileSystemXmlApplicationContext(new String[]{resource}, false); - bf.refresh(); - - if (bf.getBeansOfType(Router.class).size() > 1) { - throw new RuntimeException( - "More than one router bean found in the Spring configuration (%s). This is no longer supported." - .formatted(Arrays.toString(bf.getBeanDefinitionNames())) - ); - } - Router router = bf.getBean("router", Router.class); - router.init(); - bf.start(); // Starting ApplicationContext will also call router.start(). Init should happen before. - return router; - } - - public static Router initFromXMLString(String xmlString) { - log.debug("Loading spring config from string"); - GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); - ctx.load(new ByteArrayResource(xmlString.getBytes(StandardCharsets.UTF_8))); - ctx.refresh(); - ctx.start(); - return ctx.getBean(Router.class); - } - /** * Starts the main processing logic of the application. * This method initializes essential components, validates the configuration, @@ -256,46 +225,17 @@ public void start() { getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); - initJmx(); startJmx(); getRuleManager().openPorts(); - try { - hotDeployer.init(this); - hotDeployer.start(); - } catch (Exception e) { - shutdown(); - throw e; - } + hotDeployer.start(this); if (config.getRetryInitInterval() > 0) - startAutoReinitializer(); + reinitializer.startAutoReinitializer(); } catch (DuplicatePathException e) { - System.err.printf(""" - ================================================================================================ - - Configuration Error: Several OpenAPI Documents share the same path! - - An API routes and validates requests according to the path of the OpenAPI's servers.url fields. - Within one API the same path should be used only by one OpenAPI. Change the paths or place - openapi-elements into separate api-elements. - - Shared path: %s - %n""", e.getPath()); - throw new ExitException(); + handleDuplicateOpenAPIPaths(e); } catch (OpenAPIParsingException e) { - System.err.printf(""" - ================================================================================================ - - Configuration Error: Could not read or parse OpenAPI Document - - Reason: %s - - Location: %s - - Have a look at the proxies.xml file. - """, e.getMessage(), e.getLocation()); - throw new ExitException(); + handleOpenAPIParsingException(e); } catch (Exception e) { log.error("Could not start router.", e); if (e instanceof RuntimeException) @@ -349,7 +289,7 @@ public void setRuleManager(RuleManager ruleManager) { } public ExchangeStore getExchangeStore() { - return registry.getBean(ExchangeStore.class).orElseThrow(); + return getRegistry().getBean(ExchangeStore.class).orElseThrow(); } /** @@ -393,7 +333,7 @@ public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { } public DNSCache getDnsCache() { - return getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); + return getRegistry().getBean(DNSCache.class).orElseThrow(); // TODO } public ResolverMap getResolverMap() { @@ -418,100 +358,42 @@ public ExecutorService getBackgroundInitializer() { /** * Adds a proxy to the router and initializes it. + * * @param proxy * @throws IOException */ public void add(Proxy proxy) throws IOException { log.debug("Adding proxy {}.", proxy.getName()); RuleManager ruleManager = getRuleManager(); - if (proxy instanceof SSLableProxy sp) { - if (running) { // TODO - ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); - } else - ruleManager.addProxy(sp, MANUAL); - } else { - ruleManager.addProxy(proxy, MANUAL); - } - if (running) { - // init() has already been called - proxy.init(this); - } - } - - private void startJmx() { - if (getBeanFactory() == null) - return; - try { - getBeanFactory().getBean(JMX_EXPORTER_NAME, JmxExporter.class).initAfterBeansAdded(); - } catch (NoSuchBeanDefinitionException ignored) { - // If bean is not available, then don't start jmx + synchronized (lock) { + if (proxy instanceof SSLableProxy sp) { + if (running) { // TODO + ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); + } else + ruleManager.addProxy(sp, MANUAL); + } else { + ruleManager.addProxy(proxy, MANUAL); + } + if (running) { + // init() has already been called + proxy.init(this); + } } - } - private void initJmx() { + private void startJmx() { if (beanFactory == null) return; try { JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); //exporter.removeBean(prefix + jmxRouterName); - exporter.addBean("org.membrane-soa:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); + exporter.addBean("io.membrane-api:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); + exporter.initAfterBeansAdded(); } catch (NoSuchBeanDefinitionException ignored) { // If bean is not available do not init jmx } - - } - - // - // Reinitialization - // - - private void startAutoReinitializer() { - if (getInactiveRules().isEmpty()) - return; - - reinitializer = new Timer("auto reinitializer", true); - reinitializer.schedule(new TimerTask() { - @Override - public void run() { - tryReinitialization(); - } - }, config.getRetryInitInterval(), config.getRetryInitInterval()); - } - - public void tryReinitialization() { - boolean stillFailing = false; - ArrayList inactive = getInactiveRules(); - if (!inactive.isEmpty()) { - log.info("Trying to activate all inactive rules."); - for (Proxy proxy : inactive) { - try { - log.info("Trying to start API {}.", proxy.getName()); - Proxy newProxy = proxy.clone(); - if (!newProxy.isActive()) { - log.warn("New rule for API {} is still not active.", proxy.getName()); - stillFailing = true; - } - getRuleManager().replaceRule(proxy, newProxy); - } catch (CloneNotSupportedException e) { - log.error("", e); - } - } - } - if (stillFailing) - log.info("There are still inactive rules."); - else { - stopAutoReinitializer(); - log.info("All rules have been initialized."); - } - } - - public void stopAutoReinitializer() { - if (reinitializer != null) { - reinitializer.cancel(); - } } @Override @@ -533,14 +415,6 @@ public boolean isRunning() { } } - private ArrayList getInactiveRules() { - ArrayList inactive = new ArrayList<>(); - for (Proxy proxy : getRuleManager().getRules()) - if (!proxy.isActive()) - inactive.add(proxy); - return inactive; - } - public String getBaseLocation() { return baseLocation; } @@ -614,7 +488,7 @@ public void handleAsynchronousInitializationResult(boolean success) { @Override public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { - log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(),bean); + log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(), bean); if (bean instanceof GlobalInterceptor) { return; } @@ -695,4 +569,38 @@ public void setConfig(Configuration config) { public Configuration getConfig() { return config; } + + public RuleReinitializer getReinitializer() { + return reinitializer; + } + + private static void handleOpenAPIParsingException(OpenAPIParsingException e) { + System.err.printf(""" + ================================================================================================ + + Configuration Error: Could not read or parse OpenAPI Document + + Reason: %s + + Location: %s + + Have a look at the proxies.xml file. + """, e.getMessage(), e.getLocation()); + throw new ExitException(); + } + + private static void handleDuplicateOpenAPIPaths(DuplicatePathException e) { + System.err.printf(""" + ================================================================================================ + + Configuration Error: Several OpenAPI Documents share the same path! + + An API routes and validates requests according to the path of the OpenAPI's servers.url fields. + Within one API the same path should be used only by one OpenAPI. Change the paths or place + openapi-elements into separate api-elements. + + Shared path: %s + %n""", e.getPath()); + throw new ExitException(); + } } \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java b/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java new file mode 100644 index 0000000000..07bae9f180 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java @@ -0,0 +1,65 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.core.config.spring.*; +import org.slf4j.*; +import org.springframework.context.support.*; +import org.springframework.core.io.*; + +import java.nio.charset.*; +import java.util.*; + +/** + * Bootstrapping a {@link Router} instance using Spring XML-based configuration. + */ +public class RouterBootstrap { + + private static final Logger log = LoggerFactory.getLogger(RouterBootstrap.class); + + /** + * Initializes a {@link Router} instance from the specified Spring XML configuration resource. + * + * @param resource the path to the Spring XML configuration file that defines the {@link Router} bean + * @return the initialized {@link Router} instance + * @throws RuntimeException if no {@link Router} bean is found or more than one {@link Router} bean is found + */ + public static Router initByXML(String resource) { + log.debug("loading spring config: {}", resource); + + TrackingFileSystemXmlApplicationContext bf = + new TrackingFileSystemXmlApplicationContext(new String[]{resource}, false); + bf.refresh(); + + if (bf.getBeansOfType(Router.class).size() > 1) { + throw new RuntimeException( + "More than one router bean found in the Spring configuration (%s). This is no longer supported." + .formatted(Arrays.toString(bf.getBeanDefinitionNames())) + ); + } + Router router = bf.getBean("router", Router.class); + bf.start(); // Starting ApplicationContext will also call router.start(). Init should happen before. + return router; + } + + public static Router initFromXMLString(String xmlString) { + log.debug("Loading spring config from string"); + GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); + ctx.load(new ByteArrayResource(xmlString.getBytes(StandardCharsets.UTF_8))); + ctx.refresh(); + ctx.start(); + return ctx.getBean(Router.class); + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java new file mode 100644 index 0000000000..8a09952448 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -0,0 +1,87 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.core.proxies.*; +import org.slf4j.*; + +import java.util.*; + +public class RuleReinitializer { + + private static final Logger log = LoggerFactory.getLogger(RuleReinitializer.class); + + private Router router; + + private Timer timer; + + public RuleReinitializer(Router router) { + this.router = router; + } + + void startAutoReinitializer() { + if (getInactiveRules().isEmpty()) + return; + + timer = new Timer("auto reinitializer", true); + timer.schedule(new TimerTask() { + @Override + public void run() { + tryReinitialization(); + } + }, router.getConfig().getRetryInitInterval(), router.getConfig().getRetryInitInterval()); + } + + public void tryReinitialization() { + boolean stillFailing = false; + ArrayList inactive = getInactiveRules(); + if (!inactive.isEmpty()) { + log.info("Trying to activate all inactive rules."); + for (Proxy proxy : inactive) { + try { + log.info("Trying to start API {}.", proxy.getName()); + Proxy newProxy = proxy.clone(); + if (!newProxy.isActive()) { + log.warn("New rule for API {} is still not active.", proxy.getName()); + stillFailing = true; + } + router.getRuleManager().replaceRule(proxy, newProxy); + } catch (CloneNotSupportedException e) { + log.error("", e); + } + } + } + if (stillFailing) + log.info("There are still inactive rules."); + else { + stopAutoReinitializer(); + log.info("All rules have been initialized."); + } + } + + public void stopAutoReinitializer() { + if (timer != null) { + timer.cancel(); + } + } + + ArrayList getInactiveRules() { + ArrayList inactive = new ArrayList<>(); + for (Proxy proxy : router.getRuleManager().getRules()) + if (!proxy.isActive()) + inactive.add(proxy); + return inactive; + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index bfb908b363..6558df045d 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -16,10 +16,7 @@ import com.predic8.membrane.annot.beanregistry.BeanDefinition; import com.predic8.membrane.annot.beanregistry.BeanRegistryImplementation; -import com.predic8.membrane.core.Configuration; -import com.predic8.membrane.core.ExitException; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.spring.GrammarAutoGenerated; import com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext; import com.predic8.membrane.core.exceptions.SpringConfigurationErrorHandler; @@ -232,7 +229,7 @@ private static String getLocation(MembraneCommandLine commandLine) throws IOExce private static Router initRouterByXml(String config) throws Exception { try { - return Router.initByXML(config); + return RouterBootstrap.initByXML(config); } catch (XmlBeanDefinitionStoreException e) { handleXmlBeanDefinitionStoreException(e); } diff --git a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java index f2aa721b50..10a3eb2bf9 100644 --- a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java @@ -46,7 +46,7 @@ private void exportServiceProxyList(){ } private void exportServiceProxy(ServiceProxy rule) { - String prefix = "org.membrane-soa:00=serviceProxies, 01=" + router.getConfig().getJmx()+ ", name="; + String prefix = "org.membrane-soa:00=serviceProxies, 01=%s, name=".formatted(router.getConfig().getJmx()); exporter.addBean(prefix + rule.getName().replace(":",""), new JmxServiceProxy(rule, router)); } } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java index 8c542ab87a..a0ea8b94c7 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java @@ -30,12 +30,12 @@ public class DefaultHotDeployer implements HotDeployer { private Router router; @Override - public void init(Router router) { + public void start(Router router) { this.router = router; + startInternal(); } - @Override - public void start() { + private void startInternal() { // Prevent multiple threads from starting hot deployment at the same time. synchronized (this) { if (hdt != null) @@ -60,7 +60,7 @@ public void stop() { if (hdt == null) return; - router.stopAutoReinitializer(); + router.getReinitializer().stopAutoReinitializer(); hdt.stopASAP(); hdt = null; } @@ -69,7 +69,7 @@ public void stop() { @Override public void setEnabled(boolean enabled) { if (enabled) - start(); + startInternal(); else stop(); } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java index 18ce8c29bd..3cade06430 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java @@ -18,7 +18,7 @@ public interface HotDeployer { - void start(); + void start(Router router); void stop(); @@ -28,6 +28,5 @@ default boolean isEnabled() { return false; } - default void init(Router router) {} } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java index 2e732c02ec..e903779183 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java @@ -14,9 +14,11 @@ package com.predic8.membrane.core.router.hotdeploy; +import com.predic8.membrane.core.*; + public class NullHotDeployer implements HotDeployer { @Override - public void start() { + public void start(Router router) { } @@ -24,7 +26,6 @@ public void start() { public void stop() { } - @Override public void setEnabled(boolean enabled) { diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index 31ef0a2c9c..842a7964ac 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -23,7 +23,7 @@ public class SimpleTest { @BeforeAll static void setUp() { - router = Router.initByXML("classpath:/test-proxies.xml"); + router = RouterBootstrap.initByXML("classpath:/test-proxies.xml"); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java index cf155b2b55..8738cefffc 100644 --- a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java @@ -37,7 +37,7 @@ void tearDownEach() { } private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { - AccessControlInterceptor aci = buildAci(f.apply(router), router); + AccessControlInterceptor aci = buildAci(f.apply(router)); aci.setUseXForwardedForAsClientAddr(useForwardedFor); return aci; } @@ -46,11 +46,11 @@ AccessControlInterceptor createIpACI(String scheme, ParseType ptype, boolean isR return createRouter(isReverseDNS, useForwardedFor, router -> getIpResource(scheme, ptype, router)); } - AccessControlInterceptor createHostnameACI(String scheme, boolean isReverseDNS) throws Exception { + AccessControlInterceptor createHostnameACI(String scheme, boolean isReverseDNS) { return createRouter(isReverseDNS, false, router -> getHostnameResource(scheme, router)); } - private static AccessControlInterceptor buildAci(Resource resource, Router router) { + private static AccessControlInterceptor buildAci(Resource resource) { return new ACLTest() {{ setAccessControl(new AccessControl(router) {{ addResource(resource); diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 99a835d060..1b76f4c227 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -29,7 +29,7 @@ public class ReadRulesConfigurationTest { @BeforeAll static void setUp() { - router = Router.initByXML("classpath:/proxies.xml"); + router = RouterBootstrap.initByXML("classpath:/proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java index 4b775a54f0..ac55f12e3e 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java @@ -30,7 +30,7 @@ public class ReadRulesWithInterceptorsConfigurationTest { @BeforeAll static void setUp() { - router = Router.initByXML("src/test/resources/ref.proxies.xml"); + router = RouterBootstrap.initByXML("src/test/resources/ref.proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index 1e07ccb718..2d3ded7276 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -29,7 +29,7 @@ public class SpringReferencesTest { @BeforeAll public static void before() { - r = Router.initByXML("classpath:/proxies-using-spring-refs.xml"); + r = RouterBootstrap.initByXML("classpath:/proxies-using-spring-refs.xml"); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java index b7c4c72bd8..cfc6f147fa 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java @@ -28,7 +28,6 @@ import static org.apache.http.params.CoreProtocolPNames.*; import static org.junit.jupiter.api.Assertions.*; -@SuppressWarnings("deprecation") public class Http10Test { private static HttpRouter router; private static HttpRouter router2; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java index 62ab4c1fe7..0100e07b4a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java @@ -26,7 +26,7 @@ public class InternalInvocationTest { @BeforeEach public void setUp() throws Exception { - router = Router.initByXML("classpath:/internal-invocation/proxies.xml"); + router = RouterBootstrap.initByXML("classpath:/internal-invocation/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index 2fc558f885..06ae01c419 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -36,7 +36,7 @@ class UserFeatureTest { @BeforeAll static void setUp() { - router = Router.initByXML("classpath:/userFeature/proxies.xml"); + router = RouterBootstrap.initByXML("classpath:/userFeature/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index e14d5e4493..1a5593a56b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -13,31 +13,23 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.adminapi; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.exchange.Exchange; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.exchangestore.*; -import com.predic8.membrane.core.http.Request; -import com.predic8.membrane.core.interceptor.AbstractInterceptor; -import com.predic8.membrane.core.interceptor.Outcome; -import com.predic8.membrane.core.proxies.NullProxy; -import com.predic8.membrane.core.proxies.ServiceProxy; -import com.predic8.membrane.core.proxies.ServiceProxyKey; -import com.predic8.membrane.core.transport.http.FakeHttpHandler; -import com.predic8.membrane.core.transport.http.HttpClient; -import com.predic8.membrane.core.transport.http.TwoWayStreaming; -import com.predic8.membrane.core.transport.ws.WebSocketFrameAssembler; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.ws.*; +import org.junit.jupiter.api.*; import java.io.*; -import java.net.SocketException; -import java.net.URISyntaxException; -import java.util.concurrent.atomic.AtomicBoolean; +import java.net.*; +import java.util.concurrent.atomic.*; -import static com.predic8.membrane.core.exchange.Exchange.ALLOW_WEBSOCKET; +import static com.predic8.membrane.core.exchange.Exchange.*; import static com.predic8.membrane.core.http.Header.*; -import static com.predic8.membrane.core.transport.ws.WebSocketConnection.WEBSOCKET_CLOSED_POLL_INTERVAL_MILLISECONDS; +import static com.predic8.membrane.core.transport.ws.WebSocketConnection.*; import static org.junit.jupiter.api.Assertions.*; class AdminApiInterceptorTest { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index eda9dbbd37..a9300777eb 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -14,15 +14,11 @@ package com.predic8.membrane.core.interceptor.opentelemetry; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.proxies.Proxy; -import com.predic8.membrane.core.proxies.ServiceProxy; -import com.predic8.membrane.core.proxies.ServiceProxyKey; +import com.predic8.membrane.core.proxies.*; import org.junit.jupiter.api.*; import java.io.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.SPRING; - class OpenTelemetryInterceptorTest { private Router router; diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java index 027a93f34d..f328589e11 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java @@ -30,7 +30,7 @@ public class ProxyRuleTest { @BeforeAll public static void setUp() { - router = Router.initByXML("src/test/resources/proxy-rules-test-monitor-beans.xml"); + router = RouterBootstrap.initByXML("src/test/resources/proxy-rules-test-monitor-beans.xml"); proxy = new ProxyRule(new ProxyRuleKey(8888)); proxy.setName("Rule 1"); // TODO: this is not possible anymore rule.setInboundTLS(true); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index b281df702b..c54fd38932 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -14,36 +14,25 @@ package com.predic8.membrane.core.proxies; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.config.security.*; import com.predic8.membrane.core.config.security.KeyStore; -import com.predic8.membrane.core.config.security.SSLParser; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Response; -import com.predic8.membrane.core.interceptor.AbstractInterceptor; -import com.predic8.membrane.core.interceptor.Outcome; -import org.apache.http.HttpHost; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.conn.scheme.Scheme; -import org.apache.http.conn.ssl.AllowAllHostnameVerifier; -import org.apache.http.conn.ssl.SSLSocketFactory; -import org.apache.http.conn.ssl.TrustAllStrategy; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClientBuilder; -import org.apache.http.util.EntityUtils; -import org.junit.jupiter.api.AfterAll; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; - -import java.io.IOException; -import java.security.KeyManagementException; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.UnrecoverableKeyException; -import java.util.concurrent.atomic.AtomicReference; - -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; +import org.apache.http.*; +import org.apache.http.client.config.*; +import org.apache.http.client.methods.*; +import org.apache.http.conn.ssl.*; +import org.apache.http.impl.client.*; +import org.apache.http.util.*; +import org.junit.jupiter.api.*; + +import java.io.*; +import java.security.*; +import java.util.concurrent.atomic.*; + +import static com.predic8.membrane.core.interceptor.Outcome.*; import static org.junit.jupiter.api.Assertions.*; public class ProxyTest { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index dec13e1c28..c78339de43 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -29,7 +29,7 @@ */ class TargetURLExpressionTest { - private static Router router; + private Router router; @BeforeEach void setUp() { @@ -38,12 +38,11 @@ void setUp() { @AfterEach void tearDown() { - router.stop(); + router.shutdown(); } @Test void targetWithExpression() throws URISyntaxException { - router = new Router(); Exchange rq = get("http://localhost:2000/").buildExchange(); APIProxy api = new APIProxy() {{ setTarget(new Target() {{ @@ -53,13 +52,10 @@ void targetWithExpression() throws URISyntaxException { rq.setProxy(api); api.init(router); - DispatchingInterceptor di = new DispatchingInterceptor() {{ - router = TargetURLExpressionTest.router; - }}; + DispatchingInterceptor di = new DispatchingInterceptor(); + di.init(router); di.handleRequest(rq); assertEquals("http://localhost:3000/", rq.getDestinations().getFirst()); } - - } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index eb6d6ca0bc..dfa5d9e6b5 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -88,13 +88,13 @@ private void test() { List proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); assertFalse(proxies.getFirst().isActive()); - r.tryReinitialization(); + r.getReinitializer().tryReinitialization(); proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); assertFalse(proxies.getFirst().isActive()); r2.start(); - r.tryReinitialization(); + r.getReinitializer().tryReinitialization(); proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java index c75794cabd..e19b5acbf9 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java @@ -151,7 +151,7 @@ void outsideRouter() { } private void setupRouter(String globalHcc) { - router = Router.initFromXMLString(globalHcc); + router = RouterBootstrap.initFromXMLString(globalHcc); assertNotNull(router.getHttpClientConfig()); assertNotNull(router.getResolverMap().getHTTPSchemaResolver().getHttpClientConfig()); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index 48fc876cdb..54b45e0670 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -118,36 +118,35 @@ private static Closeable startTCPForwarder(int port) throws IOException { AtomicInteger counter = new AtomicInteger(); StreamPump.StreamPumpStats sps = new StreamPump.StreamPumpStats(); ServiceProxy mock = new ServiceProxy(); - try (ServerSocket ss = new ServerSocket(port)) { - Thread t = new Thread(() -> { - try { - while (true) { - Socket inbound; - try { - inbound = ss.accept(); - } catch (Exception e) { - if (e.getMessage().contains("Socket closed")) - return; - throw e; - } - int port1 = 3042 + counter.incrementAndGet() % 2; - try (Socket outbout = new Socket("localhost", port1)) { - Thread s = new Thread(new StreamPump(inbound.getInputStream(), outbout.getOutputStream(), sps, "a", mock)); - s.start(); - Thread s2 = new Thread(new StreamPump(outbout.getInputStream(), inbound.getOutputStream(), sps, "b", mock)); - s2.start(); - } + ServerSocket ss = new ServerSocket(port); + Thread t = new Thread(() -> { + try { + while (true) { + Socket inbound; + try { + inbound = ss.accept(); + } catch (Exception e) { + if (e.getMessage().contains("Socket closed")) + return; + throw e; + } + int port1 = 3042 + counter.incrementAndGet() % 2; + try (Socket outbound = new Socket("localhost", port1)) { + Thread s = new Thread(new StreamPump(inbound.getInputStream(), outbound.getOutputStream(), sps, "a", mock)); + s.start(); + Thread s2 = new Thread(new StreamPump(outbound.getInputStream(), inbound.getOutputStream(), sps, "b", mock)); + s2.start(); } - } catch (Exception e) { - e.printStackTrace(); } - }); - t.start(); - return () -> { - ss.close(); - t.interrupt(); - }; - } + } catch (Exception e) { + e.printStackTrace(); + } + }); + t.start(); + return () -> { + ss.close(); + t.interrupt(); + }; } @Disabled diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index fa4346990c..40c5c3b7c9 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -45,7 +45,7 @@ public static void teardown() { @BeforeEach public void startRouter() { - router = Router.initByXML("classpath:/soap-proxy.xml"); + router = RouterBootstrap.initByXML("classpath:/soap-proxy.xml"); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index 59740b0194..f9aa0032a6 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -40,7 +40,7 @@ public class MultipleLoadBalancersTest { protected static HttpRouter balancer; @AfterAll - public static void tearDown() throws Exception { + static void tearDown() throws Exception { service1.close(); service2.close(); service11.close(); @@ -50,22 +50,22 @@ public static void tearDown() throws Exception { private static class MockService { final int port; - final HttpRouter service1; + final HttpRouter router; final DummyWebServiceInterceptor mockInterceptor1; MockService(int port) throws Exception { this.port = port; - service1 = new HttpRouter(); + router = new HttpRouter(); mockInterceptor1 = new DummyWebServiceInterceptor(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80); sp1.getFlow().add(mockInterceptor1); - service1.add(sp1); - service1.start(); + router.add(sp1); + router.start(); } public void close() { - service1.shutdown(); + router.shutdown(); } } @@ -80,7 +80,7 @@ private static LoadBalancingInterceptor createBalancingInterceptor(int port, Str @BeforeAll - public static void setUp() throws Exception { + static void setUp() throws Exception { service1 = new MockService(2001); service2 = new MockService(2002); @@ -111,7 +111,7 @@ private void assertMockCounters(int n1, int n2, int n11, int n12) { } @Test - public void testRoundRobinDispachingStrategy() throws Exception { + void roundRobinDispatchingStrategy() throws Exception { balancingInterceptor1.setDispatchingStrategy(roundRobinStrategy1); balancingInterceptor2.setDispatchingStrategy(roundRobinStrategy2); diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index e6bf6cd1eb..d3e4028e6b 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -12,6 +12,12 @@ - Correct YAML example on GitHub README - Rename in apis.yaml +# 7.X + +- JMXExporter: + - Tutorial + - Documentation + - See JmxExporter # 7.1.0 @@ -44,7 +50,7 @@ ## (Breaking) Interface Changes - +- JMX: Name changes to "io.membrane-api:00=routers, name=" - Removed GateKeeperClientInterceptor - Removed support for `internal:` syntax in target URLs, leaving `internal://` as the only valid way to call internal APIs. - Remove WADLInterceptor diff --git a/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java b/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java index 3f84afe9d9..ef69c0c3e1 100644 --- a/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java +++ b/maven-plugin/src/main/java/com/predic8/membrane/plugin/RouterFacade.java @@ -28,7 +28,7 @@ private RouterFacade(Router router) { } static RouterFacade createStarted(String proxiesPath) { - return new RouterFacade(Router.initByXML(proxiesPath)); + return new RouterFacade(RouterBootstrap.initByXML(proxiesPath)); } void stop() { From e221d3a812865df047e8f32b7d82094f483de5c4 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 12:35:21 +0100 Subject: [PATCH 24/40] refactor: make `router` field `final` in `RuleReinitializer` to ensure immutability and improve thread-safety --- .../main/java/com/predic8/membrane/core/RuleReinitializer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java index 8a09952448..c610df5a2a 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -23,7 +23,7 @@ public class RuleReinitializer { private static final Logger log = LoggerFactory.getLogger(RuleReinitializer.class); - private Router router; + private final Router router; private Timer timer; From 6dd1ab6ca5148c76803f27a1292e447c9f922fc7 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 13:32:29 +0100 Subject: [PATCH 25/40] refactor: improve `Router` lifecycle methods, enhance thread-safety, and streamline `RuleReinitializer` logic --- .../com/predic8/membrane/core/HttpRouter.java | 3 +- .../com/predic8/membrane/core/Router.java | 44 ++++++++++++------- .../membrane/core/RuleReinitializer.java | 25 ++++++----- .../router/hotdeploy/DefaultHotDeployer.java | 10 +++-- .../config/ReadRulesConfigurationTest.java | 6 ++- .../oauth2/client/b2c/B2CMembrane.java | 1 + ...WTInterceptorAndSecurityValidatorTest.java | 1 + .../proxies/UnavailableSoapProxyTest.java | 4 +- ...th2AuthorizationServerInterceptorBase.java | 1 + 9 files changed, 59 insertions(+), 36 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index fb62f607b4..dafc3fe18f 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -15,6 +15,7 @@ package com.predic8.membrane.core; import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.*; import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.http.client.*; @@ -29,7 +30,7 @@ public HttpRouter() { public HttpRouter(ProxyConfiguration proxyConfiguration) { transport = createTransport(); - resolverMap.getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); } @Override diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 01fc2dd8a9..6bc1f03f85 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -126,7 +126,7 @@ public class Router implements ApplicationContextAware, BeanRegistryAware, BeanN private final TimerManager timerManager = new TimerManager(); private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); - protected final ResolverMap resolverMap; + protected ResolverMap resolverMap; protected final ExecutorService backgroundInitializer = newSingleThreadExecutor(new HttpServerThreadFactory("Router Background Initializer")); @@ -139,6 +139,7 @@ public class Router implements ApplicationContextAware, BeanRegistryAware, BeanN @GuardedBy("lock") private boolean running; + @GuardedBy("lock") private boolean initialized; /** @@ -173,9 +174,17 @@ public Router() { public void init() { log.debug("Initializing."); + getRegistry().registerIfAbsent(ResolverMap.class, () -> { + ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); + rs.addRuleResolver(this); + return rs; + }); + // TODO: Temporary guard, to check correct behaviour, remove later - if (initialized) - throw new IllegalStateException("Router already initialized."); + synchronized (lock) { + if (initialized) + throw new IllegalStateException("Router already initialized."); + } getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); getRegistry().registerIfAbsent(RuleManager.class, () -> { @@ -183,7 +192,7 @@ public void init() { rm.setRouter(this); return rm; }); - getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); + getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); // Transport last if (transport == null) { @@ -193,7 +202,9 @@ public void init() { initProxies(); - initialized = true; + synchronized (lock) { + initialized = true; + } reinitializer = new RuleReinitializer(this); // Bean } @@ -218,8 +229,10 @@ public void start() { log.debug("Starting."); displayTraceWarning(); - if (!initialized) - init(); + synchronized (lock) { + if (!initialized) + init(); + } try { @@ -231,7 +244,7 @@ public void start() { hotDeployer.start(this); if (config.getRetryInitInterval() > 0) - reinitializer.startAutoReinitializer(); + reinitializer.start(); } catch (DuplicatePathException e) { handleDuplicateOpenAPIPaths(e); } catch (OpenAPIParsingException e) { @@ -274,12 +287,11 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } public RuleManager getRuleManager() { - var rm = getRegistry().getBean(RuleManager.class); - if (rm.isPresent()) return rm.get(); - RuleManager rmi = new RuleManager(); - rmi.setRouter(this); - getRegistry().register("ruleManager", rmi); - return rmi; + return getRegistry().registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(this); + return rm; + }); } public void setRuleManager(RuleManager ruleManager) { @@ -319,7 +331,7 @@ public void setTransport(Transport transport) { } public HttpClientConfiguration getHttpClientConfig() { - return resolverMap.getHTTPSchemaResolver().getHttpClientConfig(); + return getResolverMap().getHTTPSchemaResolver().getHttpClientConfig(); } /** @@ -329,7 +341,7 @@ public HttpClientConfiguration getHttpClientConfig() { */ @MCChildElement() public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { - resolverMap.getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); + getResolverMap().getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); } public DNSCache getDnsCache() { diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java index c610df5a2a..ab321dd3a7 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -31,22 +31,28 @@ public RuleReinitializer(Router router) { this.router = router; } - void startAutoReinitializer() { + synchronized void start() { if (getInactiveRules().isEmpty()) return; - timer = new Timer("auto reinitializer", true); + timer = new Timer("reinitializer", true); timer.schedule(new TimerTask() { @Override public void run() { - tryReinitialization(); + retry(); } }, router.getConfig().getRetryInitInterval(), router.getConfig().getRetryInitInterval()); } - public void tryReinitialization() { + public synchronized void stop() { + if (timer != null) { + timer.cancel(); + } + } + + public void retry() { boolean stillFailing = false; - ArrayList inactive = getInactiveRules(); + List inactive = getInactiveRules(); if (!inactive.isEmpty()) { log.info("Trying to activate all inactive rules."); for (Proxy proxy : inactive) { @@ -66,18 +72,13 @@ public void tryReinitialization() { if (stillFailing) log.info("There are still inactive rules."); else { - stopAutoReinitializer(); + stop(); log.info("All rules have been initialized."); } } - public void stopAutoReinitializer() { - if (timer != null) { - timer.cancel(); - } - } - ArrayList getInactiveRules() { + List getInactiveRules() { ArrayList inactive = new ArrayList<>(); for (Proxy proxy : router.getRuleManager().getRules()) if (!proxy.isActive()) diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java index a0ea8b94c7..e72f16fee8 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java @@ -24,11 +24,13 @@ public class DefaultHotDeployer implements HotDeployer { private static final Logger log = LoggerFactory.getLogger(DefaultHotDeployer.class.getName()); - @GuardedBy("this") + @GuardedBy("lock") private HotDeploymentThread hdt; private Router router; + private final Object lock = new Object(); + @Override public void start(Router router) { this.router = router; @@ -37,7 +39,7 @@ public void start(Router router) { private void startInternal() { // Prevent multiple threads from starting hot deployment at the same time. - synchronized (this) { + synchronized (lock) { if (hdt != null) throw new IllegalStateException("Hot deployment already started."); @@ -60,7 +62,7 @@ public void stop() { if (hdt == null) return; - router.getReinitializer().stopAutoReinitializer(); + router.getReinitializer().stop(); hdt.stopASAP(); hdt = null; } @@ -68,7 +70,7 @@ public void stop() { @Override public void setEnabled(boolean enabled) { - if (enabled) + if (enabled && router != null) startInternal(); else stop(); diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 1b76f4c227..61ccf311f1 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -34,7 +34,7 @@ static void setUp() { } @AfterAll - public static void tearDown() { + static void tearDown() { router.shutdown(); } @@ -97,13 +97,17 @@ void testServiceProxyHostSet() { void testLocalServiceProxyInboundSSL() { if (proxies.get(2) instanceof SSLableProxy sp) { assertFalse(sp.isInboundSSL()); + return; } + fail(); } @Test void testLocalServiceProxyOutboundSSL() { if (proxies.get(2) instanceof SSLableProxy sp) { assertNull(sp.getSslOutboundContext()); + return; } + fail(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index bbe8340eab..7f5d59b73a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -24,6 +24,7 @@ import com.predic8.membrane.core.interceptor.oauth2client.*; import com.predic8.membrane.core.interceptor.session.*; import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; import org.jetbrains.annotations.*; import java.io.*; diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index d956074da6..146c5b4568 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -49,6 +49,7 @@ public class JWTInterceptorAndSecurityValidatorTest { @BeforeEach public void setUp() throws Exception { Router router = new Router(); + router.start(); proxy = createProxy(router, getSpec()); privateKey = RsaJwkGenerator.generateJwk(2048); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index dfa5d9e6b5..30a0e40a4f 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -88,13 +88,13 @@ private void test() { List proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); assertFalse(proxies.getFirst().isActive()); - r.getReinitializer().tryReinitialization(); + r.getReinitializer().retry(); proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); assertFalse(proxies.getFirst().isActive()); r2.start(); - r.getReinitializer().tryReinitialization(); + r.getReinitializer().retry(); proxies = r.getRuleManager().getRules(); assertEquals(1, proxies.size()); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index dcd6594470..2c6366f10c 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -204,6 +204,7 @@ public static Runnable runUntilGoodAuthOpenidRequest() { @BeforeEach public void setUp() throws Exception{ router = new HttpRouter(); + router.start(); initOasi(); initMas(); initLoginMockParametersForJohn(); From 2a6a7cc02d57ea6c360c90a11ed5611d43f32d72 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 13:32:57 +0100 Subject: [PATCH 26/40] refactor: remove unnecessary `Exception` declaration from `initOasi` method in test file --- .../oauth2/OAuth2AuthorizationServerInterceptorBase.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index 2c6366f10c..f6b7777596 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -282,7 +282,7 @@ private void initMas() throws Exception { //mas.init2(); // requires pull request 330 } - private void initOasi() throws Exception { + private void initOasi() { oasi = new OAuth2AuthorizationServerInterceptor() { @Override public String computeBasePath() { From be5387dc6aa08a4056fd3a80273184bdb7f5d1a5 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 14:46:59 +0100 Subject: [PATCH 27/40] refactor: enhance `Router` lifecycle handling, improve thread-safety, and update test setup/teardown methods --- .../annot/beanregistry/BeanContainer.java | 2 +- .../com/predic8/membrane/core/Router.java | 21 +++++++------------ .../membrane/core/RuleReinitializer.java | 8 +++++++ .../router/hotdeploy/DefaultHotDeployer.java | 2 +- ...WTInterceptorAndSecurityValidatorTest.java | 10 +++++++-- .../membrane/core/proxies/SOAPProxyTest.java | 3 +-- ...th2AuthorizationServerInterceptorBase.java | 7 ++++++- 7 files changed, 33 insertions(+), 20 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index a67abf8b1b..68faada426 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -41,6 +41,6 @@ public BeanDefinition getDefinition() { @Override public String toString() { - return "BeanContainer: %s of %s".formatted( definition.getName(),definition.getKind()); + return "BeanContainer: %s of %s singleton: %s".formatted( definition.getName(),definition.getKind(),singleton); } } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 6bc1f03f85..617183caa3 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -371,6 +371,8 @@ public ExecutorService getBackgroundInitializer() { /** * Adds a proxy to the router and initializes it. * + * TODO: Should we sync running cause a different Thread might call add? + * * @param proxy * @throws IOException */ @@ -378,20 +380,13 @@ public void add(Proxy proxy) throws IOException { log.debug("Adding proxy {}.", proxy.getName()); RuleManager ruleManager = getRuleManager(); - synchronized (lock) { - if (proxy instanceof SSLableProxy sp) { - if (running) { // TODO - ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); - } else - ruleManager.addProxy(sp, MANUAL); - } else { - ruleManager.addProxy(proxy, MANUAL); - } - if (running) { - // init() has already been called - proxy.init(this); - } + if (running && proxy instanceof SSLableProxy sp) { + sp.init(this); + ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); + } else { + ruleManager.addProxy(proxy, MANUAL); } + } private void startJmx() { diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java index ab321dd3a7..753670ca84 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -32,6 +32,10 @@ public RuleReinitializer(Router router) { } synchronized void start() { + log.info("Starting rule reinitializer."); + if (timer != null) + return; // Already started. + if (getInactiveRules().isEmpty()) return; @@ -48,8 +52,12 @@ public synchronized void stop() { if (timer != null) { timer.cancel(); } + timer = null; } + /** + * Should only be called from timer in this class + */ public void retry() { boolean stillFailing = false; List inactive = getInactiveRules(); diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java index e72f16fee8..33681135ef 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java @@ -58,7 +58,7 @@ private void startInternal() { @Override public void stop() { - synchronized (this) { + synchronized (lock) { if (hdt == null) return; diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index 146c5b4568..2a9898b991 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -42,13 +42,14 @@ public class JWTInterceptorAndSecurityValidatorTest { private static final String SPEC_LOCATION = getPathFromResource( "openapi/openapi-proxy/no-extensions.yml"); + private Router router; private APIProxy proxy; RsaJsonWebKey privateKey; @BeforeEach - public void setUp() throws Exception { - Router router = new Router(); + void setUp() throws Exception { + router = new HttpRouter(); router.start(); proxy = createProxy(router, getSpec()); @@ -58,6 +59,11 @@ public void setUp() throws Exception { proxy.getFlow().add(getJwtAuthInterceptor(router)); } + @AfterEach + void tearDown() { + router.shutdown(); + } + @Test void checkIfScopesAreStoredInProperty() throws Exception { Exchange exc = get("/foo").header("Authorization", "bearer " + getSignedJwt(privateKey, getJwtClaimsStringScopesList())).buildExchange(); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index dd1fcfd48f..71c9f126ee 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -39,8 +39,7 @@ public class SOAPProxyTest { void setUp() throws IOException { proxy = new SOAPProxy(); proxy.setPort(2000); - router = new Router(); - router.setTransport(new HttpTransport()); + router = new HttpRouter(); router.setExchangeStore(new ForgetfulExchangeStore()); APIProxy backend = new APIProxy(); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index f6b7777596..2784a18b42 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -202,7 +202,7 @@ public static Runnable runUntilGoodAuthOpenidRequest() { } @BeforeEach - public void setUp() throws Exception{ + void setUp() throws Exception{ router = new HttpRouter(); router.start(); initOasi(); @@ -210,6 +210,11 @@ public void setUp() throws Exception{ initLoginMockParametersForJohn(); } + @AfterEach + void tearDown() { + router.shutdown(); + } + public static Collection data() throws Exception { return List.of(); } From 86f18574419251400fc04a9b37c2fbed308242b5 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Mon, 29 Dec 2025 15:10:21 +0100 Subject: [PATCH 28/40] refactor: add TODO for replacing `backgroundInitializer` with virtual threads in `Router` to align with modern threading practices --- core/src/main/java/com/predic8/membrane/core/Router.java | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 617183caa3..6cf08a60e3 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -128,6 +128,11 @@ public class Router implements ApplicationContextAware, BeanRegistryAware, BeanN private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); protected ResolverMap resolverMap; + /** + * TODO: + * - Replace with: Executors.newVirtualThreadPerTaskExecutor(); + * - Remove from here and use virtualThread in those 4 places where it is used. + */ protected final ExecutorService backgroundInitializer = newSingleThreadExecutor(new HttpServerThreadFactory("Router Background Initializer")); From 9955a076915ea516676743ed28137a60eb9f9c11 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 09:16:44 +0100 Subject: [PATCH 29/40] refactor: replace `Router` with `HttpRouter` in test files and update initialization logic for consistency --- .../com/predic8/membrane/core/HttpRouter.java | 3 +- .../com/predic8/membrane/core/Router.java | 31 +++++++------------ .../core/interceptor/Interceptor.java | 6 ++-- .../apikey/ApiKeysInterceptorTest.java | 8 ++--- .../apikey/stores/ApiKeyFileStoreTest.java | 2 +- .../schemavalidation/SOAPFaultTest.java | 4 +-- .../SOAPMessageValidatorInterceptorTest.java | 2 +- .../ValidatorInterceptorTest.java | 9 +++--- .../server/WebServerInterceptorTest.java | 2 +- .../templating/StaticInterceptorTest.java | 6 ++-- .../serviceproxy/APIProxyOpenAPITest.java | 2 +- .../APIProxySpringConfigurationTest.java | 14 +++++---- .../AbstractProxySpringConfigurationTest.java | 4 ++- .../serviceproxy/ApiDocsInterceptorTest.java | 2 +- .../openapi/serviceproxy/OpenAPI31Test.java | 2 +- .../serviceproxy/OpenAPIInterceptorTest.java | 2 +- .../OpenAPIRecordFactoryTest.java | 2 +- .../XMembraneExtensionSecurityTest.java | 2 +- .../AbstractSecurityValidatorTest.java | 2 +- .../BasicAuthSecurityValidationTest.java | 9 +++--- ...WTInterceptorAndSecurityValidatorTest.java | 1 - 21 files changed, 56 insertions(+), 59 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index dafc3fe18f..7f8d2f81e2 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -30,7 +30,8 @@ public HttpRouter() { public HttpRouter(ProxyConfiguration proxyConfiguration) { transport = createTransport(); - getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + if (proxyConfiguration != null) + getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); } @Override diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 6cf08a60e3..e93072382f 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -128,15 +128,6 @@ public class Router implements ApplicationContextAware, BeanRegistryAware, BeanN private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); protected ResolverMap resolverMap; - /** - * TODO: - * - Replace with: Executors.newVirtualThreadPerTaskExecutor(); - * - Remove from here and use virtualThread in those 4 places where it is used. - */ - protected final ExecutorService backgroundInitializer = - newSingleThreadExecutor(new HttpServerThreadFactory("Router Background Initializer")); - - protected final Statistics statistics = new Statistics(); private final Object lock = new Object(); @@ -179,18 +170,23 @@ public Router() { public void init() { log.debug("Initializing."); - getRegistry().registerIfAbsent(ResolverMap.class, () -> { - ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); - rs.addRuleResolver(this); - return rs; - }); - // TODO: Temporary guard, to check correct behaviour, remove later synchronized (lock) { if (initialized) throw new IllegalStateException("Router already initialized."); } +// resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); +// resolverMap.addRuleResolver(this); + + getRegistry().registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); + + getRegistry().registerIfAbsent(ResolverMap.class, () -> { + ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); + rs.addRuleResolver(this); + return rs; + }); + getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); getRegistry().registerIfAbsent(RuleManager.class, () -> { RuleManager rm = new RuleManager(); @@ -363,16 +359,11 @@ public ResolverMap getResolverMap() { * When running as an embedded servlet, this has no effect. */ public void shutdown() { - backgroundInitializer.shutdown(); if (transport != null) transport.closeAll(); timerManager.shutdown(); } - public ExecutorService getBackgroundInitializer() { - return backgroundInitializer; - } - /** * Adds a proxy to the router and initializes it. * diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java index 29486c68e6..0f0ded2c10 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java @@ -53,6 +53,10 @@ public boolean isAbort() { } } + void init(Router router); + + void init(Router router, Proxy proxy); + Outcome handleRequest(Exchange exchange); Outcome handleResponse(Exchange exchange); @@ -93,7 +97,5 @@ public boolean isAbort() { */ String getHelpId(); - void init(Router router); - void init(Router router, Proxy proxy); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java index e3a4f3c8f5..775136bb25 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.apikey; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.interceptor.apikey.extractors.ApiKeyExpressionExtractor; import com.predic8.membrane.core.interceptor.apikey.extractors.ApiKeyHeaderExtractor; @@ -57,17 +57,17 @@ public class ApiKeysInterceptorTest { static void setup() { store = new ApiKeyFileStore(); store.setLocation(getKeyfilePath("apikeys/keys.txt")); - store.init(new Router()); + store.init(new HttpRouter()); mergeStore = new ApiKeyFileStore(); mergeStore.setLocation(getKeyfilePath("apikeys/merge-keys.txt")); - mergeStore.init(new Router()); + mergeStore.init(new HttpRouter()); ahe = new ApiKeyHeaderExtractor(); aqe = new ApiKeyQueryParamExtractor(); aee = new ApiKeyExpressionExtractor(); aee.setExpression("json['api-key']"); - aee.init(new Router()); + aee.init(new HttpRouter()); akiWithProp = new ApiKeysInterceptor(); akiWithProp.setExtractors(of(ahe)); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java index a701d45012..9d68e63425 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java @@ -100,7 +100,7 @@ void parseValues() { private static void loadFromFile(ApiKeyFileStore store, String path) { store.setLocation(requireNonNull(ApiKeyFileStoreTest.class.getClassLoader().getResource(path)).getPath()); - store.init(new Router()); + store.init(new HttpRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java index c647754eaf..1f27f35fd9 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.schemavalidation; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.util.SOAPUtil; import org.junit.jupiter.api.Test; @@ -32,7 +32,7 @@ public class SOAPFaultTest { public static final String ARTICLE_SERVICE_WSDL = getPathFromResource( "/validation/ArticleService.wsdl"); - final Router r = new Router(); + final Router r = new HttpRouter(); @Test public void testValidateFaults() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java index 0f1cdd6b2a..c8b75f954f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java @@ -39,7 +39,7 @@ public class SOAPMessageValidatorInterceptorTest { @BeforeAll static void setup() { - router = new Router(); + router = new HttpRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java index 7c4c25160c..74995ff069 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.interceptor.schemavalidation; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.http.Response; @@ -29,6 +29,7 @@ import java.nio.file.Files; import java.nio.file.Path; +import static com.predic8.membrane.core.http.Request.post; import static com.predic8.membrane.core.interceptor.Outcome.ABORT; import static com.predic8.membrane.core.interceptor.Outcome.CONTINUE; import static com.predic8.membrane.test.TestUtil.getPathFromResource; @@ -56,10 +57,10 @@ public class ValidatorInterceptorTest { @BeforeAll public static void setUp() throws URISyntaxException { - requestTB = Request.post("http://thomas-bayer.com").build(); - requestXService = Request.post("http://ws.xwebservices.com").build(); + requestTB = post("http://thomas-bayer.com").build(); + requestXService = post("http://ws.xwebservices.com").build(); exc = new Exchange(null); - router = new Router(); + router = new HttpRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java index c4fa5130a7..5f224a220c 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java @@ -32,7 +32,7 @@ class WebServerInterceptorTest { @BeforeEach void init() { - r = new Router(); + r = new HttpRouter(); ws = new WebServerInterceptor(r) {{ setDocBase(Objects.requireNonNull(this.getClass().getResource("/html/")).toString()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java index 01bb33c7dd..21ebb0e016 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java @@ -41,7 +41,7 @@ void beforeAll() throws URISyntaxException { @Test void readContentFromLocationPath() { - i.init(new Router()); + i.init(new HttpRouter()); i.handleRequest(exc); assertEquals(27, exc.getRequest().getBodyAsStringDecoded().length()); } @@ -50,7 +50,7 @@ void readContentFromLocationPath() { void pretty() { i.setPretty(TRUE); i.setContentType(APPLICATION_JSON); - i.init(new Router()); + i.init(new HttpRouter()); i.handleRequest(exc); @@ -81,7 +81,7 @@ void utf_16() throws Exception { private void checkWithCharset(String charset) throws Exception { i.setLocation(getAbsolutePath("/charsets/%s.txt".formatted(charset))); i.setCharset(charset); - i.init(new Router()); + i.init(new HttpRouter()); i.handleRequest(exc); assertEquals(REF_CHARS, exc.getRequest().getBodyAsStringDecoded()); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java index b05a0a575c..4602be75f5 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java @@ -42,7 +42,7 @@ public class APIProxyOpenAPITest { @BeforeEach public void setUp() { - router = new Router(); + router = new HttpRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java index 2dee805714..dba8bcb7a3 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java @@ -19,7 +19,7 @@ import com.predic8.membrane.core.interceptor.log.*; import org.junit.jupiter.api.*; -import static com.predic8.membrane.test.TestUtil.getPathFromResource; +import static com.predic8.membrane.test.TestUtil.*; import static org.junit.jupiter.api.Assertions.*; class APIProxySpringConfigurationTest extends AbstractProxySpringConfigurationTest { @@ -56,11 +56,13 @@ class APIProxySpringConfigurationTest extends AbstractProxySpringConfigurationTe void interceptorSequenceFromSpringConfiguration() { Router router = startSpringContextAndReturnRouter(publisherSeparate); APIProxy ap = getApiProxy(router); - assertEquals(4, ap.getFlow().size()); - assertInstanceOf(ApiKeysInterceptor.class, ap.getFlow().get(0)); - assertInstanceOf(HeaderFilterInterceptor.class, ap.getFlow().get(1)); - assertInstanceOf(OpenAPIPublisherInterceptor.class, ap.getFlow().get(2)); - assertInstanceOf(LogInterceptor.class, ap.getFlow().get(3)); + assertEquals(5, ap.getFlow().size()); + assertInstanceOf(OpenAPIInterceptor.class, ap.getFlow().get(0)); + assertInstanceOf(ApiKeysInterceptor.class, ap.getFlow().get(1)); + assertInstanceOf(HeaderFilterInterceptor.class, ap.getFlow().get(2)); + assertInstanceOf(OpenAPIPublisherInterceptor.class, ap.getFlow().get(3)); + assertInstanceOf(LogInterceptor.class, ap.getFlow().get(4)); + } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java index 538c85afc1..c9e9f842ae 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java @@ -36,7 +36,9 @@ protected static Router startSpringContextAndReturnRouter(String api) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(new ByteArrayResource(config.formatted(api).getBytes())); ctx.refresh(); - return ctx.getBean("router", Router.class); + var router = ctx.getBean("router", Router.class); + router.init(); + return router; } protected static APIProxy getApiProxy(Router router) { diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index a4284d77bc..bb2b60d6cd 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -45,7 +45,7 @@ class ApiDocsInterceptorTest { @BeforeEach public void setUp() throws Exception { - router = new Router(); + router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); exc.setRequest(new Request.Builder().get("/foo").build()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java index da6d393f64..3976cc964a 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java @@ -40,7 +40,7 @@ public class OpenAPI31Test { @BeforeEach void setUp() throws URISyntaxException { - Router router = new Router(); + Router router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); petstore_v3_1 = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index 435b4d6997..3ff3ef62b9 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -48,7 +48,7 @@ class OpenAPIInterceptorTest { @BeforeEach void setUp() { - router = new Router(); + router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); specInfoServers = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java index 7b44dcd5c5..b029e32924 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java @@ -30,7 +30,7 @@ class OpenAPIRecordFactoryTest { @BeforeAll static void setUp() { - Router router = new Router(); + Router router = new HttpRouter(); router.setBaseLocation("src/test/resources/openapi/specs/"); factory = new OpenAPIRecordFactory(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java index b6fc81409c..64e7845c52 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java @@ -32,7 +32,7 @@ public class XMembraneExtensionSecurityTest { @BeforeEach void setUp() { - Router router = new Router(); + Router router = new HttpRouter(); router.setBaseLocation(""); OpenAPIRecordFactory factory = new OpenAPIRecordFactory(router); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java index 90cd11bb06..d75ed04a6d 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java @@ -42,7 +42,7 @@ protected Exchange getExchange(String method, String path, SecurityScheme scheme } protected static Router getRouter() { - Router router = new Router(); + Router router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); return router; } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java index a07a7e3999..b565a4aa7c 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java @@ -28,6 +28,7 @@ import java.util.*; +import static com.predic8.membrane.core.http.Request.get; import static com.predic8.membrane.core.interceptor.Outcome.*; import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.*; import static com.predic8.membrane.core.openapi.util.OpenAPITestUtils.*; @@ -42,7 +43,7 @@ public class BasicAuthSecurityValidationTest { @BeforeEach void setUpSpec() { - Router router = new Router(); + Router router = new HttpRouter(); router.getConfig().setUriFactory(new URIFactory()); OpenAPISpec spec = new OpenAPISpec(); @@ -64,7 +65,7 @@ void setUpSpec() { @Test void noAuthHeader() throws Exception { - Exchange exc = Request.get("/v1/foo").buildExchange(); + Exchange exc = get("/v1/foo").buildExchange(); exc.setOriginalRequestUri("/v1/foo"); assertEquals(ABORT, baInterceptor.handleRequest(exc)); // TODO Should we return RETURN instead. How is it in OAuth2? } @@ -72,15 +73,13 @@ void noAuthHeader() throws Exception { @Test void withAuthorizationHeader() throws Exception { - Exchange exc = Request.get("/v1/foo").authorization("alice","secret").buildExchange(); + Exchange exc = get("/v1/foo").authorization("alice","secret").buildExchange(); exc.setOriginalRequestUri("/v1/foo"); Outcome outcome = baInterceptor.handleRequest(exc); - assertEquals(CONTINUE,outcome); outcome = oasInterceptor.handleRequest(exc); - assertEquals(CONTINUE, outcome); } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index 2a9898b991..da20af15bd 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -50,7 +50,6 @@ public class JWTInterceptorAndSecurityValidatorTest { @BeforeEach void setUp() throws Exception { router = new HttpRouter(); - router.start(); proxy = createProxy(router, getSpec()); privateKey = RsaJwkGenerator.generateJwk(2048); From cc5fa67da2a2cc93d4564cc673861bc016e54e00 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 09:22:59 +0100 Subject: [PATCH 30/40] refactor: improve thread-safety in `DefaultHotDeployer`, enhance logging, and fix `BeanContainer` string formatting --- .../membrane/annot/beanregistry/BeanContainer.java | 2 +- .../core/router/hotdeploy/DefaultHotDeployer.java | 9 ++++++--- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index 68faada426..0493c45f0c 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -41,6 +41,6 @@ public BeanDefinition getDefinition() { @Override public String toString() { - return "BeanContainer: %s of %s singleton: %s".formatted( definition.getName(),definition.getKind(),singleton); + return "BeanContainer: %s of %s singleton: %s".formatted( definition.getName(),definition.getKind(),singleton.get()); } } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java index 33681135ef..bedd8845d1 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java @@ -16,6 +16,7 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.spring.*; +import org.jetbrains.annotations.*; import org.slf4j.*; import javax.annotation.concurrent.*; @@ -32,7 +33,7 @@ public class DefaultHotDeployer implements HotDeployer { private final Object lock = new Object(); @Override - public void start(Router router) { + public void start(@NotNull Router router) { this.router = router; startInternal(); } @@ -40,8 +41,10 @@ public void start(Router router) { private void startInternal() { // Prevent multiple threads from starting hot deployment at the same time. synchronized (lock) { - if (hdt != null) - throw new IllegalStateException("Hot deployment already started."); + if (hdt != null) { + log.warn("Hot deployment already started."); + return; + } if (!(router.getBeanFactory() instanceof TrackingApplicationContext tac)) { log.warn(""" From 7a8e80c1517ba408c571a918621c8949cdc0846d Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 10:52:52 +0100 Subject: [PATCH 31/40] refactor: replace `Router` with `IRouter` for better abstraction and consistency across core components --- .../com/predic8/membrane/core/IRouter.java | 39 +++++++++++++++++++ .../com/predic8/membrane/core/Router.java | 5 --- .../AbstractPersistentExchangeStore.java | 2 +- .../ElasticSearchExchangeStore.java | 2 +- .../core/exchangestore/ExchangeStore.java | 2 +- .../exchangestore/MongoDBExchangeStore.java | 4 +- .../graphql/GraphQLoverHttpValidator.java | 4 +- .../core/interceptor/AbstractInterceptor.java | 9 ++--- .../core/interceptor/ApisJsonInterceptor.java | 2 +- .../core/interceptor/Interceptor.java | 6 +-- .../acl/AbstractClientAddress.java | 8 ++-- .../core/interceptor/acl/AccessControl.java | 8 ++-- .../acl/AccessControlInterceptor.java | 2 +- .../membrane/core/interceptor/acl/Any.java | 4 +- .../core/interceptor/acl/Hostname.java | 6 +-- .../membrane/core/interceptor/acl/Ip.java | 4 +- .../core/interceptor/acl/Resource.java | 8 ++-- .../administration/AdminPageBuilder.java | 4 +- .../interceptor/administration/RuleUtil.java | 2 +- .../extractors/ApiKeyExpressionExtractor.java | 4 +- .../apikey/extractors/ApiKeyExtractor.java | 4 +- .../apikey/stores/ApiKeyFileStore.java | 2 +- .../apikey/stores/ApiKeyStore.java | 2 +- .../apikey/stores/MongoDBApiKeyStore.java | 2 +- .../session/CachingUserDataProvider.java | 4 +- .../CustomStatementJdbcUserDataProvider.java | 6 +-- .../session/EmailTokenProvider.java | 2 +- .../session/EmptyTokenProvider.java | 4 +- .../session/FileUserDataProvider.java | 5 ++- .../session/JdbcUserDataProvider.java | 6 +-- .../session/JwtSessionManager.java | 4 +- .../session/LDAPUserDataProvider.java | 4 +- .../authentication/session/LoginDialog.java | 2 +- .../session/SessionManager.java | 2 +- .../session/StaticUserDataProvider.java | 4 +- .../session/TOTPTokenProvider.java | 4 +- .../session/TelekomSMSTokenProvider.java | 2 +- .../authentication/session/TokenProvider.java | 8 ++-- .../session/UnifyingUserDataProvider.java | 4 +- .../session/UserDataProvider.java | 2 +- .../WhateverMobileSMSTokenProvider.java | 4 +- .../xen/XenAuthenticationInterceptor.java | 6 +-- .../interceptor/balancer/BalancerUtil.java | 30 +++++++------- .../balancer/ByThreadStrategy.java | 4 +- .../balancer/DispatchingStrategy.java | 4 +- .../balancer/PolyglotSessionIdExtractor.java | 2 +- .../balancer/PriorityStrategy.java | 2 +- .../balancer/RoundRobinStrategy.java | 4 +- .../balancer/SessionIdExtractor.java | 4 +- .../FaultMonitoringStrategy.java | 5 ++- .../interceptor/cache/CacheInterceptor.java | 6 +-- .../flow/AbstractFlowInterceptor.java | 4 +- .../core/interceptor/flow/choice/Case.java | 2 +- .../flow/choice/InterceptorContainer.java | 4 +- .../GraalVMJavascriptLanguageAdapter.java | 2 +- .../javascript/LanguageAdapter.java | 6 +-- .../RhinoJavascriptLanguageAdapter.java | 2 +- .../core/interceptor/oauth2/ClaimList.java | 4 +- .../core/interceptor/oauth2/ClientList.java | 4 +- .../interceptor/oauth2/ConsentPageFile.java | 2 +- .../interceptor/oauth2/StaticClientList.java | 4 +- .../AuthorizationService.java | 6 +-- .../DynamicRegistration.java | 4 +- .../BearerJwtTokenGenerator.java | 4 +- .../tokengenerators/BearerTokenGenerator.java | 4 +- .../tokengenerators/TokenGenerator.java | 4 +- .../oauth2client/rf/SessionAuthorizer.java | 6 +-- .../schemavalidation/SchematronValidator.java | 2 +- .../session/InMemorySessionManager.java | 2 +- .../session/JwtSessionManager.java | 2 +- .../session/MemcachedSessionManager.java | 4 +- .../session/RedisSessionManager.java | 2 +- .../interceptor/session/SessionManager.java | 4 +- .../interceptor/xslt/XSLTTransformer.java | 2 +- .../core/lang/ExchangeExpression.java | 4 +- .../membrane/core/lang/ScriptingUtils.java | 2 +- .../lang/groovy/GroovyExchangeExpression.java | 2 +- .../serviceproxy/OpenAPIPublisher.java | 8 ++-- .../ws/WebSocketInterceptorInterface.java | 4 +- .../interceptors/WebSocketLogInterceptor.java | 4 +- .../WebSocketSpringInterceptor.java | 4 +- .../WebSocketStompReassembler.java | 4 +- .../apikey/ApiKeysInterceptorTest.java | 2 +- .../session/FakeSyncSessionStoreManager.java | 4 +- .../APIProxySpringConfigurationTest.java | 15 +------ .../serviceproxy/ApiDocsInterceptorTest.java | 2 +- .../Loadbalancing4XmlSessionExampleTest.java | 31 +++++++-------- 87 files changed, 227 insertions(+), 208 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/IRouter.java b/core/src/main/java/com/predic8/membrane/core/IRouter.java index 8ec0666771..0c3cf2cb60 100644 --- a/core/src/main/java/com/predic8/membrane/core/IRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/IRouter.java @@ -14,17 +14,56 @@ package com.predic8.membrane.core; +import com.predic8.membrane.core.exchangestore.*; +import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.transport.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.util.*; import org.springframework.context.*; import java.io.*; +import java.util.*; public interface IRouter extends Lifecycle { void init(); + /** + * TODO: What is the difference between this and stop? + */ void shutdown(); void add(Proxy proxy) throws IOException; + FlowController getFlowController(); + + ExchangeStore getExchangeStore(); + + RuleManager getRuleManager(); + + String getBaseLocation(); + + ResolverMap getResolverMap(); + + DNSCache getDnsCache(); + + Transport getTransport(); + + URIFactory getUriFactory(); + + boolean isProduction(); + + ApplicationContext getBeanFactory(); + + HttpClientFactory getHttpClientFactory(); + + TimerManager getTimerManager(); + + Statistics getStatistics(); + + // TODO: => to RuleManager? + Collection getRules(); + } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index e93072382f..0690910e87 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -42,12 +42,10 @@ import javax.annotation.concurrent.*; import java.io.*; import java.util.*; -import java.util.concurrent.*; import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static com.predic8.membrane.core.jmx.JmxExporter.*; import static com.predic8.membrane.core.util.DLPUtil.*; -import static java.util.concurrent.Executors.*; /* Responsibilities: @@ -176,9 +174,6 @@ public void init() { throw new IllegalStateException("Router already initialized."); } -// resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); -// resolverMap.addRuleResolver(this); - getRegistry().registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); getRegistry().registerIfAbsent(ResolverMap.class, () -> { diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java index e55b3425c3..4d501cabc7 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java @@ -42,7 +42,7 @@ public abstract class AbstractPersistentExchangeStore extends AbstractExchangeSt volatile boolean updateThreadWorking; @Override - public void init(Router router) { + public void init(IRouter router) { super.init(router); startTime = System.nanoTime(); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java index ba5d1b6304..b23250101b 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java @@ -76,7 +76,7 @@ public class ElasticSearchExchangeStore extends AbstractPersistentExchangeStore @Override - public void init(Router router) { + public void init(IRouter router) { if(client == null) client = router.getHttpClientFactory().createClient(null); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java index 60dd4f92f2..2291ed9432 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java @@ -57,7 +57,7 @@ public interface ExchangeStore { AbstractExchange getExchangeById(long id); - default void init(Router router) {} + default void init(IRouter router) {} List getClientStatistics(); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java index 1ad4eac40a..1d8ae6e3b9 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java @@ -22,7 +22,7 @@ import com.mongodb.client.model.ReplaceOptions; import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.AbstractExchange; import com.predic8.membrane.core.exchange.snapshots.AbstractExchangeSnapshot; import com.predic8.membrane.core.proxies.Proxy; @@ -51,7 +51,7 @@ public class MongoDBExchangeStore extends AbstractPersistentExchangeStore { .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @Override - public void init(Router router) { + public void init(IRouter router) { super.init(router); if (this.collection == null) { this.collection = MongoClients.create(connection) diff --git a/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java b/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java index 3fc3161cd9..2919468c18 100644 --- a/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java +++ b/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java @@ -58,10 +58,10 @@ public class GraphQLoverHttpValidator { private final int maxRecursion; private final int maxDepth; private final int maxMutations; - private final Router router; + private final IRouter router; private final FeatureBlocklist featureBlocklist; - public GraphQLoverHttpValidator(boolean allowExtensions, List allowedMethods, int maxRecursion, int maxDepth, int maxMutations, FeatureBlocklist featureBlocklist, Router router) { + public GraphQLoverHttpValidator(boolean allowExtensions, List allowedMethods, int maxRecursion, int maxDepth, int maxMutations, FeatureBlocklist featureBlocklist, IRouter router) { this.allowExtensions = allowExtensions; this.allowedMethods = allowedMethods; this.maxRecursion = maxRecursion; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java index 0c898eab62..3bb462fe70 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java @@ -18,7 +18,6 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.http.*; -import com.predic8.membrane.core.interceptor.flow.*; import com.predic8.membrane.core.proxies.*; import java.util.*; @@ -32,7 +31,7 @@ public class AbstractInterceptor implements Interceptor { private EnumSet flow = REQUEST_RESPONSE_ABORT_FLOW; - protected Router router; + protected IRouter router; public AbstractInterceptor() { super(); @@ -100,17 +99,17 @@ public final String getHelpId() { */ public void init() {} - public final void init(Router router) { + public final void init(IRouter router) { this.router = router; init(); } @Override - public void init(Router router, Proxy ignored) { + public void init(IRouter router, Proxy ignored) { init(router); } - public Router getRouter() { //wird von ReadRulesConfigurationTest aufgerufen. + public IRouter getRouter() { //wird von ReadRulesConfigurationTest aufgerufen. return router; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java index 8bdc3981de..31ab2653ab 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java @@ -70,7 +70,7 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } - public void initJson(Router router, Exchange exc) throws JsonProcessingException { + public void initJson(IRouter router, Exchange exc) throws JsonProcessingException { if (apisJson != null) { return; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java index 0f0ded2c10..b5be0407a7 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java @@ -53,9 +53,9 @@ public boolean isAbort() { } } - void init(Router router); + void init(IRouter router); - void init(Router router, Proxy proxy); + void init(IRouter router, Proxy proxy); Outcome handleRequest(Exchange exchange); Outcome handleResponse(Exchange exchange); @@ -73,7 +73,7 @@ public boolean isAbort() { String getDisplayName(); void setDisplayName(String name); - Router getRouter(); + IRouter getRouter(); void setAppliedFlow(EnumSet flow); EnumSet getAppliedFlow(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java index d1accfec21..7665480f9e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java @@ -13,17 +13,17 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.acl; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.AbstractXmlElement; import javax.xml.stream.XMLStreamReader; public abstract class AbstractClientAddress extends AbstractXmlElement { - protected final Router router; + protected final IRouter router; protected String schema; - public AbstractClientAddress(Router router) { + public AbstractClientAddress(IRouter router) { super(); this.router = router; } @@ -44,5 +44,5 @@ public void setSchema(String schema) { this.schema = schema; } - public void init(Router router) {} + public void init(IRouter router) {} } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java index 9949c4e11f..8c5bfe1e71 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java @@ -18,17 +18,17 @@ import javax.xml.stream.XMLStreamReader; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.AbstractXmlElement; public class AccessControl extends AbstractXmlElement { public static final String ELEMENT_NAME = "accessControl"; - private final Router router; + private final IRouter router; private final List resources = new ArrayList<>(); - public AccessControl(Router router) { + public AccessControl(IRouter router) { this.router = router; } @@ -61,7 +61,7 @@ public Resource getResourceFor(String uri) { throw new IllegalArgumentException("Resource not found for given path"); } - public void init(Router router) { + public void init(IRouter router) { for (Resource resource : resources) resource.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java index d10f4d2055..3913ead35e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java @@ -129,7 +129,7 @@ public void setAccessControl(AccessControl ac) { accessControl = ac; } - protected AccessControl parse(String fileName, Router router) { + protected AccessControl parse(String fileName, IRouter router) { try { XMLInputFactory factory = XMLInputFactoryFactory.inputFactory(); XMLStreamReader reader = null; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java index f13f8ed062..66c816342e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java @@ -14,13 +14,13 @@ package com.predic8.membrane.core.interceptor.acl; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; public class Any extends AbstractClientAddress { public static final String ELEMENT_NAME = "any"; - public Any(Router router) { + public Any(IRouter router) { super(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java index 82eac20914..5dbde7a79b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.acl; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import org.jetbrains.annotations.NotNull; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -56,7 +56,7 @@ private static InetAddress initV6() { private volatile long lastWarningSlowReverseDNSUsed; - public Hostname(Router router) { + public Hostname(IRouter router) { super(router); } @@ -102,7 +102,7 @@ public boolean matches(String hostname, String ip) { } @Override - public void init(Router router) { + public void init(IRouter router) { super.init(router); reverseDNS = router.getTransport() != null && router.getTransport().isReverseDNS(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java index 29b2347526..113f9ad52a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.acl; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import javax.xml.stream.XMLStreamReader; @@ -25,7 +25,7 @@ public class Ip extends AbstractClientAddress { private ParseType type = GLOB; - public Ip(Router router) { + public Ip(IRouter router) { super(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java index 61e4227fb2..3e23dbdeb3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java @@ -22,10 +22,10 @@ import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; +import com.predic8.membrane.core.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; -import com.predic8.membrane.core.Router; import com.predic8.membrane.core.config.AbstractXmlElement; import com.predic8.membrane.core.config.GenericComplexElement; import com.predic8.membrane.core.util.text.TextUtil; @@ -36,12 +36,12 @@ public class Resource extends AbstractXmlElement { public static final String ELEMENT_NAME = "resource"; - private final Router router; + private final IRouter router; private final List clientAddresses = new ArrayList<>(); protected Pattern uriPattern; - public Resource(Router router) { + public Resource(IRouter router) { this.router = router; } @@ -97,7 +97,7 @@ public String getUriPattern() { return uriPattern.pattern(); } - public void init(Router router) { + public void init(IRouter router) { for (AbstractClientAddress ca : clientAddresses) ca.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java index 0770715a0f..7f4a1442f8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java @@ -53,7 +53,7 @@ public class AdminPageBuilder extends Html { static final int TAB_ID_CLIENTS = 8; static final int TAB_ID_ABOUT = 9; - private final Router router; + private final IRouter router; private final Map params; private final StringWriter writer; private final String relativeRootPath; @@ -64,7 +64,7 @@ static public String createHRef(String ctrl, String action, String query) { return "/admin/" + ctrl + (action != null ? "/" + action : "") + (query != null ? "?" + query : ""); } - public AdminPageBuilder(StringWriter writer, Router router, String relativeRootPath, Map params, boolean readOnly) { + public AdminPageBuilder(StringWriter writer, IRouter router, String relativeRootPath, Map params, boolean readOnly) { super(writer); this.router = router; this.params = params; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java index 849e90a74e..c840d04719 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java @@ -22,7 +22,7 @@ public static String getRuleIdentifier(Proxy proxy) { return proxy.toString() + (proxy.getKey().getPort() == -1 ? "" : ":" + proxy.getKey().getPort()); } - public static Proxy findRuleByIdentifier(Router router, String name) { + public static Proxy findRuleByIdentifier(IRouter router, String name) { for (Proxy proxy : router.getRuleManager().getRules()) { if ( name.equals(getRuleIdentifier(proxy))) return proxy; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java index 13063d7188..5dc744acbe 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.interceptor.apikey.extractors; import com.predic8.membrane.annot.*; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.xml.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.interceptor.*; @@ -56,7 +56,7 @@ public class ApiKeyExpressionExtractor implements ApiKeyExtractor, Polyglot, XML private XmlConfig xmlConfig; @Override - public void init(Router router) { + public void init(IRouter router) { exchangeExpression = expression(new InterceptorAdapter(router, xmlConfig), language, expression); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java index 5f9a203fb6..b00c973c67 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java @@ -13,13 +13,13 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.apikey.extractors; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import java.util.Optional; public interface ApiKeyExtractor { - default void init(Router router) {} + default void init(IRouter router) {} Optional extract(Exchange exc); String getDescription(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java index 6f5f566e1e..1408d51aef 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java @@ -59,7 +59,7 @@ public class ApiKeyFileStore implements ApiKeyStore { private Map>> scopes; @Override - public void init(Router router) { + public void init(IRouter router) { try { scopes = readKeyData(readFile(location, router.getResolverMap(), router.getBaseLocation())); } catch (IOException e) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java index d414de5cfe..e5414b7454 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java @@ -25,7 +25,7 @@ public interface ApiKeyStore { * * @param router non-null router instance */ - default void init(Router router) { + default void init(IRouter router) { } /** diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java index 9435074860..e7ce405f70 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java @@ -58,7 +58,7 @@ public class MongoDBApiKeyStore implements ApiKeyStore { private MongoDatabase mongoDatabase; @Override - public void init(Router router) { + public void init(IRouter router) { try { mongoDatabase = MongoClients.create(connection).getDatabase(database); } catch (Exception e) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java index c0e81664e2..4d1e315a7c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java @@ -19,7 +19,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.predic8.membrane.annot.Required; @@ -77,7 +77,7 @@ public void setUserDataProvider(UserDataProvider userDataProvider) { @Override - public void init(Router router) { + public void init(IRouter router) { userDataProvider.init(router); cache = CacheBuilder.newBuilder() .maximumSize(this.getMaxSize()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java index 768e142d96..e990fbd153 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.predic8.membrane.annot.Required; @@ -30,7 +30,7 @@ public class CustomStatementJdbcUserDataProvider implements UserDataProvider { private static final Logger log = LoggerFactory.getLogger(CustomStatementJdbcUserDataProvider.class.getName()); - private Router router; + private IRouter router; DataSource datasource; @@ -40,7 +40,7 @@ public class CustomStatementJdbcUserDataProvider implements UserDataProvider { @Override - public void init(Router router) { + public void init(IRouter router) { this.router = router; sanitizeUserInputs(); getDatasourceIfNull(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java index a0518b4b6f..24c4f964c5 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java @@ -71,7 +71,7 @@ public class EmailTokenProvider extends NumericTokenProvider { private boolean ssl = true; @Override - public void init(Router router) { + public void init(IRouter router) { } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java index 540bd943e6..d48f0de5aa 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java @@ -17,13 +17,13 @@ import java.util.NoSuchElementException; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; @MCElement(name="emptyTokenProvider", component =false) public class EmptyTokenProvider implements TokenProvider { @Override - public void init(Router router) { + public void init(IRouter router) { // does nothing } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java index 031bc78729..6f8ee54587 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java @@ -15,7 +15,8 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; + import java.io.*; import java.nio.file.*; import java.util.*; @@ -108,7 +109,7 @@ public Map getUsersByName() { } @Override - public void init(Router router) { + public void init(IRouter router) { List lines; try { lines = Files.readAllLines(Paths.get(this.htpasswdPath)); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java index 04bcc81cbe..43307a1c0b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.registration.SecurityUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -34,10 +34,10 @@ public class JdbcUserDataProvider implements UserDataProvider { private String tableName; private String userColumnName; private String passwordColumnName; - private Router router; + private IRouter router; @Override - public void init(Router router) { + public void init(IRouter router) { this.router = router; sanitizeUserInputs(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java index d56c2e5548..462b7847d6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCElement; import com.predic8.membrane.annot.MCTextContent; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import org.jetbrains.annotations.*; import org.jose4j.json.JsonUtil; @@ -56,7 +56,7 @@ public void setKey(String key) { } @Override - public void init(Router router) { + public void init(IRouter router) { super.init(router); try { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java index 2b78fd9319..95213a975c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java @@ -36,6 +36,7 @@ import javax.naming.directory.SearchResult; import javax.net.SocketFactory; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.SSLParser; import com.predic8.membrane.core.transport.ssl.SSLContext; import com.predic8.membrane.core.transport.ssl.StaticSSLContext; @@ -46,7 +47,6 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; /** * @description A user data provider querying an LDAP server to authorize users and retrieve attributes. @@ -429,7 +429,7 @@ public void setSslParser(SSLParser sslParser) { } @Override - public void init(Router router) { + public void init(IRouter router) { if (passwordAttribute != null && readAttributesAsSelf) throw new RuntimeException("@passwordAttribute is not compatible with @readAttributesAsSelf."); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java index 3fef38f6b4..01589e7d31 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java @@ -84,7 +84,7 @@ public LoginDialog( wsi.setDocBase(dialogLocation); } - public void init(Router router) { + public void init(IRouter router) { uriFactory = router.getUriFactory(); wsi.init(router); try { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java index 3a2a4cfb55..a50823fdf4 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java @@ -61,7 +61,7 @@ protected void parseAttributes(XMLStreamReader token) { domain = token.getAttributeValue("", "domain"); } - public void init(Router router) { + public void init(IRouter router) { cookieName = StringUtils.defaultIfEmpty(cookieName, "SESSIONID"); timeout = timeout == 0 ? 300000 : timeout; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java index 3331e8e2be..69a4ca0199 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java @@ -17,7 +17,7 @@ import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; import com.predic8.membrane.annot.MCOtherAttributes; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import org.apache.commons.codec.digest.Crypt; import java.security.SecureRandom; @@ -191,7 +191,7 @@ public void setUsersByName(Map usersByName) { } @Override - public void init(Router router) { + public void init(IRouter router) { for (User user : users) getUsersByName().put(user.getUsername(), user); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java index f18b1c2833..bfce9e49e6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java @@ -17,7 +17,7 @@ import java.util.NoSuchElementException; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.authentication.session.totp.OtpProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -50,7 +50,7 @@ public class TOTPTokenProvider implements TokenProvider { final Logger log = LoggerFactory.getLogger(TOTPTokenProvider.class); @Override - public void init(Router router) { + public void init(IRouter router) { // does nothing } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java index 40211a7bd3..75473163c9 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java @@ -95,7 +95,7 @@ public enum EnvironmentType { private long tokenExpiration; @Override - public void init(Router router) { + public void init(IRouter router) { hc = router.getHttpClientFactory().createClient(null); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java index 2172fe2476..142af61962 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java @@ -15,12 +15,12 @@ import java.util.Map; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; public interface TokenProvider { - public void init(Router router); - public void requestToken(Map userAttributes); - public void verifyToken(Map userAttributes, String token); + void init(IRouter router); + void requestToken(Map userAttributes); + void verifyToken(Map userAttributes, String token); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java index 329726654a..4f79c1ccc5 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java @@ -23,7 +23,7 @@ import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; /** * @explanation

@@ -63,7 +63,7 @@ public void setUserDataProviders(List userDataProviders) { } @Override - public void init(Router router) { + public void init(IRouter router) { for (UserDataProvider udp : userDataProviders) udp.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java index 501994582f..8ae84dfceb 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java @@ -19,7 +19,7 @@ public interface UserDataProvider { - void init(Router router); + void init(IRouter router); /** * @throws NoSuchElementException diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java index d69bda4ca7..e6103af739 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.transport.http.HttpClient; @@ -69,7 +69,7 @@ public class WhateverMobileSMSTokenProvider extends SMSTokenProvider { private static final String GATEWAY2 = "https://" + HOST2 + "/sendsms"; @Override - public void init(Router router) { + public void init(IRouter router) { hc = router.getHttpClientFactory().createClient(null); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java index 445e58cedc..efb9ec7a45 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java @@ -100,7 +100,7 @@ public Outcome handleResponse(Exchange exc) { } public interface XenSessionManager { - void init(Router router) throws Exception; + void init(IRouter router) throws Exception; String getXenSessionId(String ourSessionId); String getExistingSessionId(String xenSessionId); String createSessionId(String xenSessionId); @@ -111,7 +111,7 @@ public static class InMemorySessionManager implements XenSessionManager { private final Map ourSessionIds = new ConcurrentHashMap<>(); private final Map xenSessionIds = new ConcurrentHashMap<>(); - public void init(Router router) { + public void init(IRouter router) { } public String getXenSessionId(String ourSessionId) { @@ -140,7 +140,7 @@ public static class JwtSessionManager implements XenSessionManager { private final SecureRandom random = new SecureRandom(); - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { String key = jwk.get(router.getResolverMap(), router.getBaseLocation()); if (key == null || key.isEmpty()) rsaJsonWebKey = generateKey(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java index dbe9e62164..a139496be3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java @@ -22,7 +22,7 @@ public class BalancerUtil { - public static List collectClusters(Router router) { + public static List collectClusters(IRouter router) { ArrayList result = new ArrayList<>(); for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); @@ -34,7 +34,7 @@ public static List collectClusters(Router router) { return result; } - public static List collectBalancers(Router router) { + public static List collectBalancers(IRouter router) { ArrayList result = new ArrayList<>(); for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); @@ -46,7 +46,7 @@ public static List collectBalancers(Router router) { return result; } - public static Balancer lookupBalancer(Router router, String name) { + public static Balancer lookupBalancer(IRouter router, String name) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors != null) @@ -58,7 +58,7 @@ public static Balancer lookupBalancer(Router router, String name) { throw new RuntimeException("balancer with name \"" + name + "\" not found."); } - public static LoadBalancingInterceptor lookupBalancerInterceptor(Router router, String name) { + public static LoadBalancingInterceptor lookupBalancerInterceptor(IRouter router, String name) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors != null) @@ -70,7 +70,7 @@ public static LoadBalancingInterceptor lookupBalancerInterceptor(Router router, throw new RuntimeException("balancer with name \"" + name + "\" not found."); } - public static boolean hasLoadBalancing(Router router) { + public static boolean hasLoadBalancing(IRouter router) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors == null) @@ -82,43 +82,43 @@ public static boolean hasLoadBalancing(Router router) { return false; } - public static void up(Router router, String balancerName, String cName, String host, int port) { + public static void up(IRouter router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).up(cName, host, port); } - public static void down(Router router, String balancerName, String cName, String host, int port) { + public static void down(IRouter router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).down(cName, host, port); } - public static void takeout(Router router, String balancerName, String cName, String host, int port) { + public static void takeout(IRouter router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).takeout(cName, host, port); } - public static List getAllNodesByCluster(Router router, String balancerName, String cName) { + public static List getAllNodesByCluster(IRouter router, String balancerName, String cName) { return lookupBalancer(router, balancerName).getAllNodesByCluster(cName); } - public static List getAvailableNodesByCluster(Router router, String balancerName, String cName) { + public static List getAvailableNodesByCluster(IRouter router, String balancerName, String cName) { return lookupBalancer(router, balancerName).getAvailableNodesByCluster(cName); } - public static void addSession2Cluster(Router router, String balancerName, String sessionId, String cName, Node n) { + public static void addSession2Cluster(IRouter router, String balancerName, String sessionId, String cName, Node n) { lookupBalancer(router, balancerName).addSession2Cluster(sessionId, cName, n); } - public static void removeNode(Router router, String balancerName, String cluster, String host, int port) { + public static void removeNode(IRouter router, String balancerName, String cluster, String host, int port) { lookupBalancer(router, balancerName).removeNode(cluster, host, port); } - public static Node getNode(Router router, String balancerName, String cluster, String host, int port) { + public static Node getNode(IRouter router, String balancerName, String cluster, String host, int port) { return lookupBalancer(router, balancerName).getNode(cluster, host, port); } - public static Map getSessions(Router router, String balancerName, String cluster) { + public static Map getSessions(IRouter router, String balancerName, String cluster) { return lookupBalancer(router, balancerName).getSessions(cluster); } - public static List getSessionsByNode(Router router, String balancerName, String cName, Node node) { + public static List getSessionsByNode(IRouter router, String balancerName, String cName, Node node) { return lookupBalancer(router, balancerName).getSessionsByNode(cName, node); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java index 33deae8e2e..ee08390ea7 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java @@ -19,7 +19,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.AbstractXmlElement; import com.predic8.membrane.core.exchange.AbstractExchange; @@ -122,7 +122,7 @@ protected String getElementName() { } @Override - public void init(Router router) { + public void init(IRouter router) { // do nothing } } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java index 2e834da607..cbc520bf08 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java @@ -13,13 +13,13 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.balancer; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.AbstractExchange; public interface DispatchingStrategy { - void init(Router router); + void init(IRouter router); Node dispatch(LoadBalancingInterceptor interceptor, AbstractExchange exc) throws EmptyNodeListException; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java index f718be179a..8590562bc8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java @@ -31,7 +31,7 @@ public class PolyglotSessionIdExtractor extends AbstractXmlElement implements Se private String sessionSource; private ExchangeExpression exchangeExpression; - public void init(Router router) { + public void init(IRouter router) { if (sessionSource != null && !sessionSource.isEmpty()) { exchangeExpression = expression(new InterceptorAdapter(router), language, sessionSource); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java index 8425d1ab71..9519c2eef3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java @@ -42,7 +42,7 @@ public class PriorityStrategy extends AbstractXmlElement implements DispatchingS private static final Logger log = LoggerFactory.getLogger(PriorityStrategy.class); @Override - public void init(Router router) {} + public void init(IRouter router) {} @Override public Node dispatch(LoadBalancingInterceptor interceptor, AbstractExchange exc) throws EmptyNodeListException { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java index 57725f9e73..665d72f2e8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java @@ -16,7 +16,7 @@ import javax.xml.stream.*; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.AbstractXmlElement; import com.predic8.membrane.core.exchange.AbstractExchange; @@ -71,7 +71,7 @@ protected String getElementName() { } @Override - public void init(Router router) { + public void init(IRouter router) { // do nothing } } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java index 736cd80e0c..a1aa23b4c1 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java @@ -14,13 +14,13 @@ package com.predic8.membrane.core.interceptor.balancer; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.interceptor.Interceptor.Flow; public interface SessionIdExtractor { - default void init(Router router) { + default void init(IRouter router) { } default boolean hasSessionId(Exchange exc, Flow flow) throws Exception { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java index 84dbd5a9f6..84b3027af2 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java @@ -16,7 +16,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.AbstractXmlElement; import com.predic8.membrane.core.exchange.AbstractExchange; import com.predic8.membrane.core.interceptor.balancer.*; @@ -122,7 +122,8 @@ public class FaultMonitoringStrategy extends AbstractXmlElement implements Dispa private final Random random = new Random(); private HttpClientStatusEventBus httpClientStatusEventBus; - public void init(Router router) { + @Override + public void init(IRouter router) { httpClientStatusEventBus = new HttpClientStatusEventBus(); httpClientStatusEventBus.registerListener(new MyHttpClientStatusEventListener()); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java index c90f9dcf25..2be9254608 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java @@ -17,7 +17,7 @@ import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; import com.predic8.membrane.annot.Required; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.http.HeaderField; @@ -67,7 +67,7 @@ public String getShortDescription() { } public static abstract class Store { - public void init(Router router) {} + public void init(IRouter router) {} public abstract Node get(String url); public abstract void put(String url, Node node); @@ -102,7 +102,7 @@ public void setDir(String dir) { } @Override - public void init(Router router) { + public void init(IRouter router) { dir = ResolverMap.combine(router.getBaseLocation(), dir); File d = new File(dir); if (!d.exists()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java index edee39ebb0..ac50affd2b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.interceptor.flow; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.ProxyAware; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.interceptor.AbstractInterceptor; @@ -60,7 +60,7 @@ protected static void createProblemDetails(String flow, Interceptor interceptor, } @Override - public void init(Router router, Proxy proxy) { + public void init(IRouter router, Proxy proxy) { for (Interceptor i : interceptors) { if(i instanceof ProxyAware pa) { pa.setProxy(proxy); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java index 696595d495..8ab88e24fb 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java @@ -36,7 +36,7 @@ public class Case extends InterceptorContainer implements XMLSupport { private ExchangeExpression exchangeExpression; private XmlConfig xmlConfig; - public void init(Router router) { + public void init(IRouter router) { exchangeExpression = expression( new InterceptorAdapter(router,xmlConfig), language, test); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java index d879bebbb3..3d9548de00 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java @@ -28,7 +28,7 @@ abstract class InterceptorContainer { private List interceptors; - Outcome invokeFlow(Exchange exc, Flow flow, Router router) { + Outcome invokeFlow(Exchange exc, Flow flow, IRouter router) { try { return switch (flow) { case REQUEST -> router.getFlowController().invokeRequestHandlers(exc, interceptors); @@ -41,7 +41,7 @@ Outcome invokeFlow(Exchange exc, Flow flow, Router router) { } } - private void handleInvocationProblemDetails(Exchange exc, Exception e, Router router) { + private void handleInvocationProblemDetails(Exchange exc, Exception e, IRouter router) { internal(router.isProduction(),"interceptor-container") .detail("Error invoking plugin.") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java index ecf9e8100d..96aab5efb9 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java @@ -25,7 +25,7 @@ public class GraalVMJavascriptLanguageAdapter extends LanguageAdapter { - public GraalVMJavascriptLanguageAdapter(Router router) { + public GraalVMJavascriptLanguageAdapter(IRouter router) { super(router); languageSupport = new GraalVMJavascriptSupport(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java index ca0d80e745..b7b87c02c8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java @@ -33,11 +33,11 @@ public abstract class LanguageAdapter { private static final Logger log = LoggerFactory.getLogger(LanguageAdapter.class); protected LanguageSupport languageSupport; - final protected Router router; + final protected IRouter router; protected static int preScriptLineLength; - public LanguageAdapter(Router router) { + public LanguageAdapter(IRouter router) { this.router = router; preScriptLineLength = Math.toIntExact(getPreScript().lines().count()); } @@ -54,7 +54,7 @@ protected String prepareScript(String script) { return getPreScript() + script + getPostScript(); } - public static LanguageAdapter instance(Router router) { + public static LanguageAdapter instance(IRouter router) { try { Class.forName("org.graalvm.polyglot.Context"); log.info("Found GraalVM Javascript engine."); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java index b638b14bb6..4b3145425a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java @@ -24,7 +24,7 @@ public class RhinoJavascriptLanguageAdapter extends LanguageAdapter { - public RhinoJavascriptLanguageAdapter(Router router) { + public RhinoJavascriptLanguageAdapter(IRouter router) { super(router); languageSupport = new RhinoJavascriptLanguageSupport(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java index 685112ae31..d954e53d43 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java @@ -16,7 +16,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.annot.Required; import java.util.*; @@ -79,7 +79,7 @@ public void setClaims(String claims) { private String value; private HashSet supportedClaims = new HashSet<>(); - public void init(Router router){ + public void init(IRouter router){ setScopes(scopes); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java index f289a39b53..82da84c670 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java @@ -13,14 +13,14 @@ package com.predic8.membrane.core.interceptor.oauth2; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import java.util.NoSuchElementException; public interface ClientList { - void init(Router router); + void init(IRouter router); /** * @throws NoSuchElementException diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java index 535d8f5a3b..c832b4fbe3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java @@ -41,7 +41,7 @@ public class ConsentPageFile { private Map json; - public void init(Router router, String url) throws IOException { + public void init(IRouter router, String url) throws IOException { resolver = router.getResolverMap(); if(url == null) { createDefaults(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java index 56c41beaef..25b3ed07a2 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import java.util.ArrayList; import java.util.HashMap; @@ -29,7 +29,7 @@ public class StaticClientList implements ClientList { private List clients = new ArrayList<>(); @Override - public void init(Router router) { + public void init(IRouter router) { setClients(clients); // fix because the setter is called with empty List } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java index 7aa855d502..1dadb70014 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.SSLParser; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; @@ -69,7 +69,7 @@ public abstract class AuthorizationService { protected Logger log; private HttpClient httpClient; - Router router; + IRouter router; protected HttpClientConfiguration httpClientConfiguration; private final Object lock = new Object(); @@ -91,7 +91,7 @@ public boolean supportsDynamicRegistration() { return supportsDynamicRegistration; } - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { log = LoggerFactory.getLogger(this.getClass().getName()); if (isUseJWTForClientAuth()) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java index 6ddef0f00e..4d4028e72c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java @@ -39,9 +39,9 @@ public class DynamicRegistration { private SSLContext sslContext; private HttpClient client; private HttpClientConfiguration httpClientConfiguration; - private Router router; + private IRouter router; - public void init(Router router) { + public void init(IRouter router) { this.router = router; if (sslParser != null) sslContext = new StaticSSLContext(sslParser, router.getResolverMap(), router.getBaseLocation()); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java index 9aaab05118..2286d60935 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java @@ -15,7 +15,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.Blob; import com.predic8.membrane.core.interceptor.session.JwtSessionManager; import org.jose4j.json.JsonUtil; @@ -50,7 +50,7 @@ public class BearerJwtTokenGenerator implements TokenGenerator { private long expiration; private boolean warningGeneratedKey = true; - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { if (jwk == null) { rsaJsonWebKey = generateKey(); if (warningGeneratedKey) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java index 5f74038020..56bb8a0d5d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.interceptor.oauth2.tokengenerators; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import java.math.BigInteger; import java.security.SecureRandom; @@ -65,7 +65,7 @@ public void setClientSecret(String clientSecret) { private final ConcurrentHashMap tokenToUser = new ConcurrentHashMap<>(); @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { // nothing to do } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java index e95cfdcfd2..ba2d881396 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java @@ -13,13 +13,13 @@ package com.predic8.membrane.core.interceptor.oauth2.tokengenerators; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import java.util.Map; import java.util.NoSuchElementException; public interface TokenGenerator { - public void init(Router router) throws Exception; + public void init(IRouter router) throws Exception; /** * @return the token type used, probably "Bearer". diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java index 6cc5e3e550..6014e9d505 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java @@ -15,7 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Response; import com.predic8.membrane.core.interceptor.Outcome; @@ -46,10 +46,10 @@ public class SessionAuthorizer { private boolean skip; private AuthorizationService auth; - private Router router; + private IRouter router; private OAuth2Statistics statistics; - public void init(AuthorizationService auth, Router router, OAuth2Statistics statistics) { + public void init(AuthorizationService auth, IRouter router, OAuth2Statistics statistics) { this.auth = auth; this.router = router; this.statistics = statistics; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java index 624278e556..ab0da12550 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java @@ -54,7 +54,7 @@ public String getName() { return "Schematron Validator"; } - public SchematronValidator(String schematron, ValidatorInterceptor.FailureHandler failureHandler, Router router, BeanFactory beanFactory) throws Exception { + public SchematronValidator(String schematron, ValidatorInterceptor.FailureHandler failureHandler, IRouter router, BeanFactory beanFactory) throws Exception { this.failureHandler = failureHandler; //works as standalone "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl" diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java index e23fc60dc1..c9e06b4d36 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java @@ -38,7 +38,7 @@ public class InMemorySessionManager extends SessionManager { protected final String cookieNamePrefix = UUID.randomUUID().toString().substring(0,8); @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { sessions = CacheBuilder.newBuilder() .expireAfterAccess(Duration.ofSeconds(getExpiresAfterSeconds())) .build(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java index d6f9b2115c..e4a93e3a77 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java @@ -59,7 +59,7 @@ public class JwtSessionManager extends SessionManager { Jwk jwk; boolean verbose = false; - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { if (validTime == null) validTime = Duration.ofSeconds(expiresAfterSeconds); if (renewalTime == null) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java index 711f4754fd..091954eb81 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.HeaderField; import com.predic8.membrane.core.util.MemcachedConnector; @@ -43,7 +43,7 @@ public class MemcachedSessionManager extends SessionManager { private final ObjectMapper objectMapper = new ObjectMapper(); @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { this.client = connector.getClient(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java index 5fba074176..b655744d15 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java @@ -47,7 +47,7 @@ public RedisSessionManager(){ @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { //Nothing to do } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java index 699b8f52fd..a2a12d9018 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java @@ -16,7 +16,7 @@ import com.google.common.cache.Cache; import com.google.common.cache.CacheBuilder; import com.predic8.membrane.annot.MCAttribute; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.http.HeaderField; @@ -81,7 +81,7 @@ private void normalizePublicURL() { issuer += "/"; } - public abstract void init(Router router) throws Exception; + public abstract void init(IRouter router) throws Exception; /** * Transforms a cookie value into its attributes. The cookie should be assumed valid as @isValidCookieForThisSessionManager was called beforehand diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java index cc06b726f3..aa072a47d3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java @@ -32,7 +32,7 @@ public class XSLTTransformer { private final ArrayBlockingQueue transformers; private final String styleSheet; - public XSLTTransformer(String styleSheet, final Router router, final int concurrency) throws Exception { + public XSLTTransformer(String styleSheet, final IRouter router, final int concurrency) throws Exception { fac = TransformerFactory.newInstance(); this.styleSheet = styleSheet; diff --git a/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java b/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java index 108876fa5e..c1fc0749cb 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java @@ -74,11 +74,11 @@ class InterceptorAdapter extends AbstractInterceptor implements XMLSupport { private XmlConfig xmlConfig; - public InterceptorAdapter(Router router) { + public InterceptorAdapter(IRouter router) { this.router = router; } - public InterceptorAdapter(Router router, XmlConfig xmlConfig) { + public InterceptorAdapter(IRouter router, XmlConfig xmlConfig) { this.router = router; this.xmlConfig = xmlConfig; } diff --git a/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java b/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java index 16be3a4f3d..61b73dd181 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java @@ -41,7 +41,7 @@ public class ScriptingUtils { private static final ObjectMapper om = new ObjectMapper(); - public static HashMap createParameterBindings(Router router, Exchange exc, Flow flow, boolean includeJsonObject) { + public static HashMap createParameterBindings(IRouter router, Exchange exc, Flow flow, boolean includeJsonObject) { Message msg = exc.getMessage(flow); diff --git a/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java b/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java index 6118de35de..85ccacbea1 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java @@ -33,7 +33,7 @@ public class GroovyExchangeExpression extends AbstractExchangeExpression { private static final Logger log = LoggerFactory.getLogger(GroovyExchangeExpression.class); private final Function, Object> script; - private final Router router; + private final IRouter router; public GroovyExchangeExpression(Interceptor interceptor, String source) { super(source); diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java index 395a86272f..5026b4c053 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java @@ -87,7 +87,7 @@ Outcome handleSwaggerUi(Exchange exc) { return RETURN; } - Outcome handleOverviewOpenAPIDoc(Exchange exc, Router router, Logger log) throws IOException, URISyntaxException { + Outcome handleOverviewOpenAPIDoc(Exchange exc, IRouter router, Logger log) throws IOException, URISyntaxException { Matcher m = PATTERN_META.matcher(exc.getRequest().getUri()); if (!m.matches()) { // No id specified if (acceptsHtmlExplicit(exc)) { @@ -116,7 +116,7 @@ private Outcome returnJsonOverview(Exchange exc, Logger log) throws JsonProcessi return RETURN; } - private Outcome returnHtmlOverview(Exchange exc, Router router) { + private Outcome returnHtmlOverview(Exchange exc, IRouter router) { exc.setResponse(ok().contentType(TEXT_HTML_UTF8).body(renderOverviewTemplate(router)).build()); return RETURN; } @@ -133,7 +133,7 @@ private Outcome returnNoFound(Exchange exc, String id) { return RETURN; } - private Outcome returnOpenApiAsYaml(Exchange exc, OpenAPIRecord rec, Router router) throws IOException, URISyntaxException { + private Outcome returnOpenApiAsYaml(Exchange exc, OpenAPIRecord rec, IRouter router) throws IOException, URISyntaxException { exc.setResponse(ok().yaml() .body(omYaml.writeValueAsBytes(rec.rewriteOpenAPI(exc, router.getUriFactory()))) .build()); @@ -144,7 +144,7 @@ private Template createTemplate(String filePath) throws ClassNotFoundException, return new StreamingTemplateEngine().createTemplate(new InputStreamReader(Objects.requireNonNull(getResourceAsStream(this, filePath)))); } - private String renderOverviewTemplate(Router router) { + private String renderOverviewTemplate(IRouter router) { Map tempCtx = new HashMap<>(); tempCtx.put("apis", apis); tempCtx.put("pathUi", PATH_UI); diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java index aab0aacdd5..233b619794 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java @@ -14,14 +14,14 @@ package com.predic8.membrane.core.transport.ws; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; /** * Created by Predic8 on 12.04.2017. */ public interface WebSocketInterceptorInterface { - void init(Router router) throws Exception; + void init(IRouter router) throws Exception; void handleFrame(WebSocketFrame frame, boolean frameTravelsToRight, WebSocketSender sender) throws Exception; diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java index 6dd7437efa..4f82c32005 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java @@ -16,7 +16,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.transport.ws.WebSocketFrame; import com.predic8.membrane.core.transport.ws.WebSocketInterceptorInterface; import com.predic8.membrane.core.transport.ws.WebSocketSender; @@ -37,7 +37,7 @@ public enum Encoding { private Encoding encoding = Encoding.RAW; @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java index ae14bd9257..c2fc5bbefc 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java @@ -18,7 +18,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.transport.ws.WebSocketFrame; import com.predic8.membrane.core.transport.ws.WebSocketInterceptorInterface; import com.predic8.membrane.core.transport.ws.WebSocketSender; @@ -55,7 +55,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { i.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java index c754faaade..e4b70cad24 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java @@ -16,7 +16,7 @@ import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Body; import com.predic8.membrane.core.http.Request; @@ -39,7 +39,7 @@ public class WebSocketStompReassembler implements WebSocketInterceptorInterface List interceptors = new ArrayList<>(); @Override - public void init(Router router) throws Exception { + public void init(IRouter router) throws Exception { for (Interceptor i : interceptors) i.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java index 775136bb25..11ac295ede 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java @@ -169,7 +169,7 @@ void handleUnauthorizedKey() { void handleDuplicateApiKeys() { var dupeStore = new ApiKeyFileStore(); dupeStore.setLocation(getKeyfilePath("apikeys/duplicate-api-keys.txt")); - assertThrows(RuntimeException.class, () -> dupeStore.init(new Router())); + assertThrows(RuntimeException.class, () -> dupeStore.init(new HttpRouter())); } private static String getKeyfilePath(String name) { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java index 8a52e8915e..e2bbf6f401 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.session; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import java.util.*; @@ -27,7 +27,7 @@ public class FakeSyncSessionStoreManager extends MemcachedSessionManager { private final ConcurrentHashMap remoteContent = new ConcurrentHashMap<>(); @Override - public void init(Router router) throws Exception {} + public void init(IRouter router) throws Exception {} @Override protected void addSessions(Session[] sessions) { diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java index dba8bcb7a3..48fa5e0968 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java @@ -57,7 +57,7 @@ void interceptorSequenceFromSpringConfiguration() { Router router = startSpringContextAndReturnRouter(publisherSeparate); APIProxy ap = getApiProxy(router); assertEquals(5, ap.getFlow().size()); - assertInstanceOf(OpenAPIInterceptor.class, ap.getFlow().get(0)); + assertInstanceOf(OpenAPIInterceptor.class, ap.getFlow().get(0)); // Should be added after init() is called on router (Inside bootstrap) assertInstanceOf(ApiKeysInterceptor.class, ap.getFlow().get(1)); assertInstanceOf(HeaderFilterInterceptor.class, ap.getFlow().get(2)); assertInstanceOf(OpenAPIPublisherInterceptor.class, ap.getFlow().get(3)); @@ -65,19 +65,6 @@ void interceptorSequenceFromSpringConfiguration() { } - @Test - void interceptorSequenceAferInit() { - Router router = startSpringContextAndReturnRouter(publisherSeparate); - APIProxy ap = getApiProxy(router); - ap.init(router); - assertEquals(5, ap.getFlow().size()); - assertInstanceOf(OpenAPIInterceptor.class, ap.getFlow().get(0)); // Got added - assertInstanceOf(ApiKeysInterceptor.class, ap.getFlow().get(1)); - assertInstanceOf(HeaderFilterInterceptor.class, ap.getFlow().get(2)); - assertInstanceOf(OpenAPIPublisherInterceptor.class, ap.getFlow().get(3)); - assertInstanceOf(LogInterceptor.class, ap.getFlow().get(4)); - } - @Test void noPublisherNoOpenAPIInterceptor() { Router router = startSpringContextAndReturnRouter(noPublisherNoOpenAPIInterceptor); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index bb2b60d6cd..884f24eab5 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -93,7 +93,7 @@ void initializeRuleApiSpecsTest() { @Test void initializeEmptyRuleApiSpecsTest() { ApiDocsInterceptor adi = new ApiDocsInterceptor(); - adi.init(new Router()); + adi.init(new HttpRouter()); assertEquals(new HashMap<>(), adi.initializeRuleApiSpecs()); } diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java index e71a557b63..f717b1c098 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/test/Loadbalancing4XmlSessionExampleTest.java @@ -24,17 +24,21 @@ public class Loadbalancing4XmlSessionExampleTest extends DistributionExtractingTestcase { + private static final String BODY_SESSION_1 = """ + {"id":"SESSION1"}"""; + private static final String BODY_SESSION_2 = """ + {"id":"SESSION2"}"""; + @Override protected String getExampleDirName() { return "loadbalancing/4-session"; } @Test - public void test() throws Exception { + void test() throws Exception { try(Process2 ignored = startServiceProxyScript()) { given().when() - .body(""" - {"id":"SESSION1"}""") + .body(BODY_SESSION_1) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -42,8 +46,7 @@ public void test() throws Exception { .body(containsString("Request count: 1")); given().when() - .body(""" - {"id":"SESSION1"}""") + .body(BODY_SESSION_1) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -51,8 +54,7 @@ public void test() throws Exception { .body(containsString("Request count: 2")); given().when() - .body(""" - {"id":"SESSION1"}""") + .body(BODY_SESSION_1) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -60,8 +62,7 @@ public void test() throws Exception { .body(containsString("Request count: 3")); given().when() - .body(""" - {"id":"SESSION1"}""") + .body(BODY_SESSION_1) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -69,8 +70,7 @@ public void test() throws Exception { .body(containsString("Request count: 4")); given().when() - .body(""" - {"id":"SESSION2"}""") + .body(BODY_SESSION_2) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -78,8 +78,7 @@ public void test() throws Exception { .body(containsString("Request count: 1")); given().when() - .body(""" - {"id":"SESSION2"}""") + .body(BODY_SESSION_2) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -87,8 +86,7 @@ public void test() throws Exception { .body(containsString("Request count: 2")); given().when() - .body(""" - {"id":"SESSION2"}""") + .body(BODY_SESSION_2) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() @@ -96,8 +94,7 @@ public void test() throws Exception { .body(containsString("Request count: 3")); given().when() - .body(""" - {"id":"SESSION2"}""") + .body(BODY_SESSION_2) .contentType(APPLICATION_JSON) .post("http://localhost:8080") .then() From 6539c3d640498eef643f244e160253993a5098a4 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 15:48:19 +0100 Subject: [PATCH 32/40] refactor: introduce `AbstractRouter` for shared functionality, replace `Router` with `IRouter` or specialized implementations, and align tests accordingly --- .../predic8/membrane/core/AbstractRouter.java | 17 + .../com/predic8/membrane/core/HttpRouter.java | 173 ++++++- .../com/predic8/membrane/core/IRouter.java | 13 +- .../com/predic8/membrane/core/Router.java | 27 +- .../predic8/membrane/core/cli/RouterCLI.java | 70 +-- .../core/interceptor/FlowController.java | 4 +- .../session/FileUserDataProvider.java | 2 +- .../session/StaticUserDataProvider.java | 2 - .../tokengenerators/TokenGenerator.java | 2 +- .../server/WebServerInterceptor.java | 2 +- .../serviceproxy/OpenAPIRecordFactory.java | 4 +- .../membrane/core/proxies/AbstractProxy.java | 4 +- .../core/proxies/AbstractServiceProxy.java | 2 +- .../predic8/membrane/core/proxies/Proxy.java | 2 +- .../membrane/core/proxies/SSLProxy.java | 6 +- .../RouterIpResolverInterceptor.java | 4 +- .../core/sslinterceptor/SSLInterceptor.java | 4 +- .../membrane/AbstractTestWithRouter.java | 4 +- .../com/predic8/membrane/core/MockRouter.java | 4 +- .../com/predic8/membrane/core/RouterTest.java | 6 +- .../com/predic8/membrane/core/TestRouter.java | 5 + .../predic8/membrane/core/acl/ACLTest.java | 10 +- .../core/azure/AzureDnsApiSimulator.java | 7 +- .../core/exchangestore/AbortExchangeTest.java | 9 +- .../ElasticSearchExchangeStoreTest.java | 26 +- .../membrane/core/http/ChunkedBodyTest.java | 131 ++--- .../membrane/core/http/Http10Test.java | 8 +- .../membrane/core/http/Http11Test.java | 8 +- .../membrane/core/http/MethodTest.java | 4 +- .../interceptor/AdjustContentLengthTest.java | 4 +- .../adminapi/AdminApiInterceptorTest.java | 10 +- .../balancer/ClusterBalancerTest.java | 12 +- .../ClusterNotificationInterceptorTest.java | 10 +- .../LoadBalancingWithClusterManagerTest.java | 29 +- .../AbstractInterceptorFlowTest.java | 14 +- ...InternalServiceRoutingInterceptorTest.java | 4 +- .../OAuth2ResourceErrorForwardingTest.java | 27 +- .../client/OAuth2ResourceRpIniLogoutTest.java | 10 +- .../oauth2/client/OAuth2ResourceTest.java | 55 +- .../oauth2/client/b2c/B2CMembrane.java | 16 +- .../client/b2c/MockAuthorizationServer.java | 15 +- .../client/b2c/OAuth2ResourceB2CUnitTest.java | 41 +- .../OpenTelemetryInterceptorTest.java | 2 +- .../schemavalidation/SOAPFaultTest.java | 2 +- .../SOAPMessageValidatorInterceptorTest.java | 2 +- .../ValidatorInterceptorTest.java | 2 +- .../server/WSDLPublisherInterceptorTest.java | 4 +- .../server/WebServerInterceptorTest.java | 2 +- .../session/SessionInterceptorTest.java | 4 +- .../soap/SoapAndInternalProxyTest.java | 5 +- .../tunnel/WebsocketStompTest.java | 2 +- .../client/KubernetesClientTest.java | 7 +- .../serviceproxy/APIProxyOpenAPITest.java | 2 +- .../serviceproxy/ApiDocsInterceptorTest.java | 4 +- .../serviceproxy/OpenAPI31ReferencesTest.java | 4 +- .../openapi/serviceproxy/OpenAPI31Test.java | 7 +- .../serviceproxy/OpenAPIInterceptorTest.java | 3 +- .../OpenAPIRecordFactoryTest.java | 2 +- .../openapi/serviceproxy/Swagger20Test.java | 7 +- .../XMembraneExtensionSecurityTest.java | 2 +- .../core/openapi/util/OpenAPITestUtils.java | 2 +- .../exceptions/ExceptionInterceptorTest.java | 2 +- .../AbstractSecurityValidatorTest.java | 6 +- .../BasicAuthSecurityValidationTest.java | 3 +- ...WTInterceptorAndSecurityValidatorTest.java | 4 +- .../security/OAuth2SecurityValidatorTest.java | 2 +- .../core/proxies/APIProxyKeyTest.java | 4 +- .../core/proxies/InternalProxyTest.java | 4 +- .../membrane/core/proxies/ProxyTest.java | 4 +- .../membrane/core/proxies/SOAPProxyTest.java | 5 +- ...SOAPProxyWSDLPublisherInterceptorTest.java | 5 +- .../core/proxies/ServiceProxyTest.java | 4 +- .../ServiceProxyWSDLInterceptorsTest.java | 4 +- .../proxies/UnavailableSoapProxyTest.java | 6 +- .../membrane/core/resolver/ResolverTest.java | 473 +++++++++--------- .../core/security/KeyStoreUtilTest.java | 5 +- .../transport/http/BoundConnectionTest.java | 4 +- .../http/ConcurrentConnectionLimitTest.java | 6 +- .../core/transport/http/ConnectionTest.java | 4 +- .../transport/http/Http2DowngradeTest.java | 4 +- .../transport/http/HttpKeepAliveTest.java | 4 +- .../core/transport/http/HttpTimeoutTest.java | 48 +- .../http/IllegalCharactersInURLTest.java | 4 +- .../transport/http/ServiceInvocationTest.java | 8 +- .../http2/Http2ClientServerTest.java | 4 +- .../transport/ssl/HttpsKeepAliveTest.java | 4 +- .../core/transport/ssl/SSLContextTest.java | 5 +- .../transport/ssl/SessionResumptionTest.java | 8 +- .../ssl/acme/AcmeServerSimulator.java | 7 +- .../core/transport/ssl/acme/AcmeStepTest.java | 24 +- .../core/ws/SoapProxyInvocationTest.java | 8 +- .../ProxySSLConnectionMethodTest.java | 5 +- ...tedMemoryExchangeStoreIntegrationTest.java | 2 +- .../interceptor/AcmeRenewTest.java | 3 +- .../OpenApiRewriteIntegrationTest.java | 5 +- .../interceptor/SOAPProxyIntegrationTest.java | 4 +- ...th2AuthorizationServerInterceptorBase.java | 2 +- ...nterceptorFaultMonitoringStrategyTest.java | 26 +- .../LoadBalancingInterceptorTest.java | 18 +- .../MultipleLoadBalancersTest.java | 8 +- .../WsaEndpointRewriterInterceptorTest.java | 2 +- 101 files changed, 904 insertions(+), 716 deletions(-) create mode 100644 core/src/main/java/com/predic8/membrane/core/AbstractRouter.java create mode 100644 core/src/test/java/com/predic8/membrane/core/TestRouter.java diff --git a/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java new file mode 100644 index 0000000000..d93362826d --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java @@ -0,0 +1,17 @@ +package com.predic8.membrane.core; + +import com.predic8.membrane.core.proxies.*; +import org.slf4j.*; + +public abstract class AbstractRouter implements IRouter { + + private static final Logger log = LoggerFactory.getLogger(Router.class); + + protected void initProxies() { + log.debug("Initializing proxies."); + for (Proxy proxy : getRuleManager().getRules()) { + log.debug("Initializing proxy {}.", proxy.getName()); + proxy.init(this); + } + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index 7f8d2f81e2..e5df4da7ff 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -14,15 +14,45 @@ package com.predic8.membrane.core; +import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.kubernetes.client.*; +import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.*; import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.http.client.*; +import com.predic8.membrane.core.util.*; +import org.springframework.context.*; +import java.io.*; import java.util.*; -public class HttpRouter extends Router { +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; + +public class HttpRouter extends AbstractRouter { + + private FlowController flowController = new FlowController(this); + private ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); + private RuleManager ruleManager = new RuleManager(); + + private final TimerManager timerManager = new TimerManager(); + private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); + private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); + private ResolverMap resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); + + private HttpTransport transport; + + private DNSCache dnsCache = new DNSCache(); + + private URIFactory uriFactory = new URIFactory(); + + private final Statistics statistics = new Statistics(); + private ApplicationContext applicationContext; + + private String baseLocation; + + private Configuration configuration = new Configuration(); public HttpRouter() { this(null); @@ -34,9 +64,109 @@ public HttpRouter(ProxyConfiguration proxyConfiguration) { getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); } + @Override + public void init() { + initProxies(); + } + + @Override + public void shutdown() { + + } + + @Override + public void waitFor() { + + } + + @Override + public void add(Proxy proxy) throws IOException { + ruleManager.addProxy(proxy, MANUAL); + } + + @Override + public Configuration getConfig() { + return configuration; + } + + @Override + public FlowController getFlowController() { + return flowController; + } + + @Override + public ExchangeStore getExchangeStore() { + return exchangeStore; + } + + @Override + public RuleManager getRuleManager() { + return ruleManager; + } + + @Override + public String getBaseLocation() { + return baseLocation; + } + + @Override + public ResolverMap getResolverMap() { + return resolverMap; + } + + @Override + public DNSCache getDnsCache() { + return dnsCache; + } + @Override public HttpTransport getTransport() { - return (HttpTransport) transport; + return transport; + } + + @Override + public URIFactory getUriFactory() { + return uriFactory; + } + + @Override + public boolean isProduction() { + return false; + } + + @Override + public ApplicationContext getBeanFactory() { + return applicationContext; + } + + @Override + public HttpClientFactory getHttpClientFactory() { + return null; + } + + @Override + public TimerManager getTimerManager() { + return timerManager; + } + + @Override + public Statistics getStatistics() { + return statistics; + } + + @Override + public KubernetesClientFactory getKubernetesClientFactory() { + return kubernetesClientFactory; + } + + @Override + public Collection getRules() { + throw new UnsupportedOperationException(); + } + + @Override + public RuleReinitializer getReinitializer() { + throw new UnsupportedOperationException(); } /** @@ -51,8 +181,8 @@ public void addUserFeatureInterceptor(Interceptor i) { /** * Same as the default config from monitor-beans.xml */ - private static Transport createTransport() { - Transport transport = new HttpTransport(); + private static HttpTransport createTransport() { + HttpTransport transport = new HttpTransport(); List interceptors = new ArrayList<>(); interceptors.add(new RuleMatchingInterceptor()); interceptors.add(new DispatchingInterceptor()); @@ -63,4 +193,39 @@ private static Transport createTransport() { transport.setFlow(interceptors); return transport; } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } + + @Override + public boolean isRunning() { + return false; + } + + public void setExchangeStore(ExchangeStore exchangeStore) { + this.exchangeStore = exchangeStore; + } + + public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { + throw new UnsupportedOperationException(); + } + + public HttpClientConfiguration getHttpClientConfig() { + return resolverMap.getHTTPSchemaResolver().getHttpClientConfig(); + } + + public void setApplicationContext(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + public void setBaseLocation(String baseLocation) { + this.baseLocation = baseLocation; + } } diff --git a/core/src/main/java/com/predic8/membrane/core/IRouter.java b/core/src/main/java/com/predic8/membrane/core/IRouter.java index 0c3cf2cb60..04b7854d5f 100644 --- a/core/src/main/java/com/predic8/membrane/core/IRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/IRouter.java @@ -16,6 +16,7 @@ import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.kubernetes.client.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.*; @@ -35,12 +36,18 @@ public interface IRouter extends Lifecycle { */ void shutdown(); + void waitFor(); + void add(Proxy proxy) throws IOException; + Configuration getConfig(); + FlowController getFlowController(); ExchangeStore getExchangeStore(); + void setExchangeStore(ExchangeStore exchangeStore); + RuleManager getRuleManager(); String getBaseLocation(); @@ -49,7 +56,7 @@ public interface IRouter extends Lifecycle { DNSCache getDnsCache(); - Transport getTransport(); + HttpTransport getTransport(); URIFactory getUriFactory(); @@ -63,7 +70,11 @@ public interface IRouter extends Lifecycle { Statistics getStatistics(); + KubernetesClientFactory getKubernetesClientFactory(); + // TODO: => to RuleManager? Collection getRules(); + RuleReinitializer getReinitializer(); + } diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 0690910e87..457b3665aa 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -100,7 +100,7 @@ outputName = "router-conf.xsd", targetNamespace = "http://membrane-soa.org/proxies/1/") @MCElement(name = "router") -public class Router implements ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver, IRouter { +public class Router extends AbstractRouter implements ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver { private static final Logger log = LoggerFactory.getLogger(Router.class); @@ -119,7 +119,7 @@ public class Router implements ApplicationContextAware, BeanRegistryAware, BeanN // // Components // - protected Transport transport; + protected HttpTransport transport; private final TimerManager timerManager = new TimerManager(); private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); @@ -204,14 +204,6 @@ public void init() { reinitializer = new RuleReinitializer(this); // Bean } - private void initProxies() { - log.debug("Initializing proxies."); - for (Proxy proxy : getRuleManager().getRules()) { - log.debug("Initializing proxy {}.", proxy.getName()); - proxy.init(this); - } - } - /** * Starts the main processing logic of the application. * This method initializes essential components, validates the configuration, @@ -311,7 +303,8 @@ public void setExchangeStore(ExchangeStore exchangeStore) { getRegistry().register("exchangeStore", exchangeStore); } - public Transport getTransport() { + @Override + public HttpTransport getTransport() { return transport; } @@ -322,7 +315,7 @@ public Transport getTransport() { * is shown in proxies-full-sample.xml . */ @MCChildElement(order = 1, allowForeign = true) - public void setTransport(Transport transport) { + public void setTransport(HttpTransport transport) { this.transport = transport; } @@ -454,10 +447,14 @@ public String getId() { /** * waits until the router has shut down */ - public void waitFor() throws InterruptedException { + public void waitFor() { synchronized (lock) { - while (running) - lock.wait(); + while (running) { + try { + lock.wait(); + } catch (InterruptedException ignored) { + } + } } } diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 6558df045d..98bd4527e8 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -14,43 +14,32 @@ package com.predic8.membrane.core.cli; -import com.predic8.membrane.annot.beanregistry.BeanDefinition; -import com.predic8.membrane.annot.beanregistry.BeanRegistryImplementation; +import com.predic8.membrane.annot.beanregistry.*; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.config.spring.GrammarAutoGenerated; -import com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext; -import com.predic8.membrane.core.exceptions.SpringConfigurationErrorHandler; -import com.predic8.membrane.core.openapi.serviceproxy.APIProxy; -import com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec; -import com.predic8.membrane.core.resolver.ResolverMap; -import com.predic8.membrane.core.resolver.ResourceRetrievalException; -import org.apache.commons.cli.ParseException; -import org.jetbrains.annotations.NotNull; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.xml.XmlBeanDefinitionStoreException; - -import java.io.File; -import java.io.IOException; -import java.io.InputStream; -import java.util.List; -import java.util.Optional; +import com.predic8.membrane.core.config.spring.*; +import com.predic8.membrane.core.exceptions.*; +import com.predic8.membrane.core.openapi.serviceproxy.*; +import com.predic8.membrane.core.resolver.*; +import org.apache.commons.cli.*; +import org.jetbrains.annotations.*; +import org.slf4j.*; +import org.springframework.beans.factory.xml.*; + +import java.io.*; +import java.util.*; import static com.predic8.membrane.core.Constants.*; -import static com.predic8.membrane.core.cli.util.JwkGenerator.generateJWK; -import static com.predic8.membrane.core.cli.util.JwkGenerator.privateJWKtoPublic; -import static com.predic8.membrane.core.config.spring.CheckableBeanFactory.InvalidConfigurationException; -import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.handleXmlBeanDefinitionStoreException; -import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.YES; -import static com.predic8.membrane.core.openapi.util.OpenAPIUtil.isOpenAPIMisplacedError; -import static com.predic8.membrane.core.util.ExceptionUtil.concatMessageAndCauseMessages; -import static com.predic8.membrane.core.util.OSUtil.fixBackslashes; -import static com.predic8.membrane.core.util.URIUtil.pathFromFileURI; -import static com.predic8.membrane.core.util.text.TerminalColors.BRIGHT_CYAN; -import static com.predic8.membrane.core.util.text.TerminalColors.RESET; -import static java.lang.Integer.parseInt; -import static org.apache.commons.lang3.exception.ExceptionUtils.getMessage; -import static org.apache.commons.lang3.exception.ExceptionUtils.getRootCauseMessage; +import static com.predic8.membrane.core.cli.util.JwkGenerator.*; +import static com.predic8.membrane.core.config.spring.CheckableBeanFactory.*; +import static com.predic8.membrane.core.config.spring.TrackingFileSystemXmlApplicationContext.*; +import static com.predic8.membrane.core.openapi.serviceproxy.OpenAPISpec.YesNoOpenAPIOption.*; +import static com.predic8.membrane.core.openapi.util.OpenAPIUtil.*; +import static com.predic8.membrane.core.util.ExceptionUtil.*; +import static com.predic8.membrane.core.util.OSUtil.*; +import static com.predic8.membrane.core.util.URIUtil.*; +import static com.predic8.membrane.core.util.text.TerminalColors.*; +import static java.lang.Integer.*; +import static org.apache.commons.lang3.exception.ExceptionUtils.*; public class RouterCLI { @@ -86,12 +75,7 @@ private static void start(String[] args) { if (commandLine.getCommand().getName().equals("private-jwk-to-public")) { privateJwkToPublic(commandLine); } - - try { - getRouter(commandLine).waitFor(); - } catch (InterruptedException e) { - // do nothing - } + getRouter(commandLine).waitFor(); } private static void privateJwkToPublic(MembraneCommandLine commandLine) { @@ -127,7 +111,7 @@ public static String getExceptionMessageWithCauses(Throwable throwable) { return result.toString(); } - private static @NotNull Router getRouter(MembraneCommandLine commandLine) { + private static @NotNull IRouter getRouter(MembraneCommandLine commandLine) { try { return switch (commandLine.getCommand().getName()) { case "oas" -> initRouterByOpenApiSpec(commandLine); @@ -162,8 +146,8 @@ private static Router initRouterByConfig(MembraneCommandLine commandLine) throws throw new RuntimeException("Unsupported file extension."); } - private static Router initRouterByOpenApiSpec(MembraneCommandLine commandLine) throws Exception { - Router router = new HttpRouter(); + private static IRouter initRouterByOpenApiSpec(MembraneCommandLine commandLine) throws Exception { + IRouter router = new HttpRouter(); router.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy(commandLine)); router.init(); return router; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java index f0c6fc7b2c..1ace5c21fd 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java @@ -56,9 +56,9 @@ public class FlowController { private static final Logger log = LoggerFactory.getLogger(FlowController.class); - private final Router router; + private final IRouter router; - public FlowController(Router router) { + public FlowController(IRouter router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java index 6f8ee54587..92a2625f84 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java @@ -57,7 +57,7 @@ public Map verify(Map postData) { userAttributes = getUsersByName().get(username); if (userAttributes == null) throw new NoSuchElementException(); - String pw = null; + String pw; String postDataPassword = postData.get("password"); String userHash = userAttributes.getPassword(); String[] userHashSplit = userHash.split("\\$"); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java index 69a4ca0199..ada21cf8af 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java @@ -44,8 +44,6 @@ public class StaticUserDataProvider implements UserDataProvider { private List users = new ArrayList<>(); private Map usersByName = new HashMap<>(); - private SecureRandom random = new SecureRandom(); - private int saltByteSize = 128; @Override public Map verify(Map postData) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java index ba2d881396..e5ae3fc132 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java @@ -19,7 +19,7 @@ import java.util.NoSuchElementException; public interface TokenGenerator { - public void init(IRouter router) throws Exception; + void init(IRouter router) throws Exception; /** * @return the token type used, probably "Bearer". diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java index 17a7f4dcba..aa9cf3002d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java @@ -68,7 +68,7 @@ public WebServerInterceptor() { name = "web server"; } - public WebServerInterceptor(Router r) { + public WebServerInterceptor(IRouter r) { name = "web server"; this.router = r; } diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java index 4103440435..e083c798fc 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java @@ -46,9 +46,9 @@ public class OpenAPIRecordFactory { private static final ObjectMapper omYaml = ObjectMapperFactory.createYaml(); - private final Router router; + private final IRouter router; - public OpenAPIRecordFactory(Router router) { + public OpenAPIRecordFactory(IRouter router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java index b35df337de..e8e9633e03 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java @@ -43,7 +43,7 @@ public abstract class AbstractProxy implements Proxy { private boolean active; private String error; - protected Router router; + protected IRouter router; public AbstractProxy() { } @@ -89,7 +89,7 @@ public void setKey(RuleKey ruleKey) { /** * Called after parsing is complete and this has been added to the object tree (whose root is Router). */ - public final void init(Router router) { + public final void init(IRouter router) { this.router = router; try { init(); // Extension point for subclasses diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java index 44ffb320e9..d26f0d3cad 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java @@ -110,7 +110,7 @@ public static class Target implements XMLSupport { protected XmlConfig xmlConfig; - public void init(Router router) { + public void init(IRouter router) { if (url != null) { exchangeExpression = TemplateExchangeExpression.newInstance(new InterceptorAdapter(router, xmlConfig), language, url); } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java index 911280dba7..af3a518d5c 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java @@ -38,7 +38,7 @@ public interface Proxy extends Cloneable { RuleStatisticCollector getStatisticCollector(); - void init(Router router); + void init(IRouter router); boolean isTargetAdjustHostHeader(); diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java index b55688bb49..1a33fc6f91 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java @@ -18,7 +18,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.SSLParser; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.interceptor.*; @@ -192,10 +192,10 @@ public SSLProvider getSslOutboundContext() { return null; } - Router router; + IRouter router; @Override - public void init(Router router) { + public void init(IRouter router) { this.router = router; cm = new ConnectionManager(connectionConfiguration.getKeepAliveTimeout(), router.getTimerManager()); for (SSLInterceptor i : sslInterceptors) diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java index 2a5495b7e6..f7f378e434 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java @@ -18,7 +18,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.SSLParser; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Response; @@ -112,7 +112,7 @@ public void setSslParser(SSLParser sslParser) { } @Override - public void init(Router router) { + public void init(IRouter router) { httpClient = router.getHttpClientFactory().createClient(httpClientConfiguration); if (sslParser != null) sslContext = new StaticSSLContext(sslParser, router.getResolverMap(), router.getBaseLocation()); diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java index 2e25464d2f..fb3ee165f3 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java @@ -13,12 +13,12 @@ limitations under the License. */ package com.predic8.membrane.core.sslinterceptor; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.Outcome; import com.predic8.membrane.core.transport.ssl.SSLExchange; public interface SSLInterceptor { - void init(Router router); + void init(IRouter router); Outcome handleRequest(SSLExchange exc) throws Exception; } diff --git a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java index c7d991c020..f9be167808 100644 --- a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java +++ b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java @@ -18,11 +18,11 @@ public abstract class AbstractTestWithRouter { - protected Router router; + protected IRouter router; @BeforeEach void setUp() { - router = new HttpRouter(); + router = new TestRouter(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/MockRouter.java b/core/src/test/java/com/predic8/membrane/core/MockRouter.java index 05fd44d1e2..a1be4085e1 100644 --- a/core/src/test/java/com/predic8/membrane/core/MockRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/MockRouter.java @@ -15,7 +15,7 @@ import com.predic8.membrane.core.exchangestore.ForgetfulExchangeStore; import com.predic8.membrane.core.transport.Transport; -import com.predic8.membrane.core.transport.http.MockHttpTransport; +import com.predic8.membrane.core.transport.http.*; public class MockRouter extends Router { @@ -24,7 +24,7 @@ public MockRouter() { } @Override - public Transport getTransport() { + public HttpTransport getTransport() { return new MockHttpTransport(); } diff --git a/core/src/test/java/com/predic8/membrane/core/RouterTest.java b/core/src/test/java/com/predic8/membrane/core/RouterTest.java index 91dce137f7..70a4e5c0ca 100644 --- a/core/src/test/java/com/predic8/membrane/core/RouterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/RouterTest.java @@ -29,7 +29,7 @@ class RouterTest { public static final String INTERNAL_SECRET = "supersecret"; - static Router dev, prod; + static IRouter dev, prod; @BeforeAll static void setUp() throws IOException { @@ -112,8 +112,8 @@ void devXML() { // @formatter:on } - private static Router createRouter(int port, boolean production) throws IOException { - HttpRouter r = new HttpRouter(); + private static IRouter createRouter(int port, boolean production) throws IOException { + IRouter r = new Router(); r.getConfig().setProduction(production); APIProxy api = new APIProxy(); api.setKey(new APIProxyKey(port)); diff --git a/core/src/test/java/com/predic8/membrane/core/TestRouter.java b/core/src/test/java/com/predic8/membrane/core/TestRouter.java new file mode 100644 index 0000000000..2e27d018cb --- /dev/null +++ b/core/src/test/java/com/predic8/membrane/core/TestRouter.java @@ -0,0 +1,5 @@ +package com.predic8.membrane.core; + +public class TestRouter extends Router { + +} diff --git a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java index 8738cefffc..6dbc02454e 100644 --- a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java @@ -23,7 +23,7 @@ public abstract class ACLTest extends AccessControlInterceptor { - protected Router router; + protected IRouter router; @BeforeEach void setUpEach() { @@ -36,7 +36,7 @@ void tearDownEach() { router.stop(); } - private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { + private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { AccessControlInterceptor aci = buildAci(f.apply(router)); aci.setUseXForwardedForAsClientAddr(useForwardedFor); return aci; @@ -58,20 +58,20 @@ private static AccessControlInterceptor buildAci(Resource resource) { }}; } - private static Resource getIpResource(String scheme, ParseType ptype, Router router) { + private static Resource getIpResource(String scheme, ParseType ptype, IRouter router) { return createResource(new Ip(router) {{ setParseType(ptype); setSchema(scheme); }}, router); } - private static Resource getHostnameResource(String scheme, Router router) { + private static Resource getHostnameResource(String scheme, IRouter router) { return createResource(new Hostname(router) {{ setSchema(scheme); }}, router); } - private static Resource createResource(AbstractClientAddress address, Router router) { + private static Resource createResource(AbstractClientAddress address, IRouter router) { return new Resource(router) {{ addAddress(address); setUriPattern(compile(".*")); diff --git a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java index cc9795e7ae..f9d754b1d5 100644 --- a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java @@ -15,7 +15,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Response; import com.predic8.membrane.core.interceptor.AbstractInterceptor; @@ -34,7 +34,7 @@ public class AzureDnsApiSimulator { private static final Logger log = LoggerFactory.getLogger(AzureDnsApiSimulator.class); private final int port; - private HttpRouter router; + private IRouter router; private final Map>> tableStorage = new HashMap<>(); @@ -43,8 +43,7 @@ public AzureDnsApiSimulator(int port) { } public void start() throws IOException { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); var sp = new ServiceProxy(new ServiceProxyKey(port), "localhost", port); diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java index d532d6313f..bd1f18b367 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java @@ -32,15 +32,16 @@ public class AbortExchangeTest { - Router router; + TestRouter router; @BeforeEach public void setup() throws Exception { - router = new HttpRouter(); - + router = new TestRouter(); LimitedMemoryExchangeStore es = new LimitedMemoryExchangeStore(); router.setExchangeStore(es); - router.getTransport().getFlow().add(2, new ExchangeStoreInterceptor(es)); + var global = new GlobalInterceptor(); + global.getFlow().add(new ExchangeStoreInterceptor(es)); + router.getRegistry().register("global",global); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3031), "", -1); sp2.getFlow().add(new AbstractInterceptor() { diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java index 0a0465bcde..fb2963303a 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStoreTest.java @@ -48,9 +48,9 @@ class ElasticSearchExchangeStoreTest { private static final String REQUEST_BODY = """ {"where":"there"}"""; - private HttpRouter gateway; - private HttpRouter back; - private HttpRouter elasticMock; + private TestRouter gateway; + private TestRouter back; + private TestRouter elasticMock; private ElasticSearchExchangeStore es; private final List insertedObjects = new ArrayList<>(); @@ -75,8 +75,7 @@ public void done() { } private void initializeElasticSearchMock() throws IOException { - elasticMock = new HttpRouter(); - elasticMock.getConfig().setHotDeploy(false); + elasticMock = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3066), null, 0); sp.getFlow().add(createBodyLoggingInterceptor()); sp.getFlow().add(createElasticSearchMockInterceptor()); @@ -91,25 +90,22 @@ private void initializeElasticSearchMock() throws IOException { } private void initializeGateway(boolean addLoggingInterceptors) throws IOException { - gateway = new HttpRouter(); - gateway.getConfig().setHotDeploy(false); + gateway = new TestRouter(); es = new ElasticSearchExchangeStore(); es.setLocation("http://localhost:3066"); es.setUpdateIntervalMs(100); gateway.setExchangeStore(es); - int index = 4; - if (addLoggingInterceptors) - gateway.getTransport().getFlow().add(index++, createBodyLoggingInterceptor()); - gateway.getTransport().getFlow().add(index++, new ExchangeStoreInterceptor()); - if (addLoggingInterceptors) - gateway.getTransport().getFlow().add(index++, createBodyLoggingInterceptor()); gateway.add(new ServiceProxy(new ServiceProxyKey(3064), "localhost", 3065)); gateway.start(); + var global = new GlobalInterceptor(); + if (addLoggingInterceptors) { + global.getFlow().add(createBodyLoggingInterceptor()); + } + global.getFlow().add(new ExchangeStoreInterceptor()); } private void initializeBackend() throws IOException { - back = new HttpRouter(); - back.getConfig().setHotDeploy(false); + back = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); StaticInterceptor si = new StaticInterceptor(); si.setSrc(RESPONSE_BODY); diff --git a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java index 2ff7d1ca16..979a02ead1 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java @@ -17,15 +17,14 @@ import com.fasterxml.jackson.databind.*; import com.google.common.io.*; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.config.security.KeyStore; import com.predic8.membrane.core.config.security.*; +import com.predic8.membrane.core.config.security.KeyStore; import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.http.client.*; -import okhttp3.Call; -import okhttp3.OkHttpClient; +import okhttp3.*; import org.apache.commons.httpclient.methods.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; @@ -42,10 +41,10 @@ import static com.predic8.membrane.core.Constants.*; import static com.predic8.membrane.core.http.ChunkedBody.*; import static com.predic8.membrane.core.http.ChunksBuilder.*; -import static com.predic8.membrane.core.http.Request.get; +import static com.predic8.membrane.core.http.Request.*; import static com.predic8.membrane.core.interceptor.Outcome.*; import static com.predic8.membrane.core.transport.http2.Http2ServerHandler.*; -import static java.lang.Thread.sleep; +import static java.lang.Thread.*; import static java.nio.charset.StandardCharsets.*; import static org.junit.jupiter.api.Assertions.*; @@ -105,7 +104,7 @@ void testReadTrailer() throws Exception { @Test void testWriteTrailer() throws IOException { - HttpRouter router = setupRouter(false, false); + IRouter router = setupRouter(false, false); try { org.apache.commons.httpclient.HttpClient hc = new org.apache.commons.httpclient.HttpClient(); for (int i = 0; i < 2; i++) { @@ -121,9 +120,9 @@ void testWriteTrailer() throws IOException { } @Test - void testReadWriteTrailerHttp2() throws IOException { - HttpRouter router = setupRouter(false, true); - HttpRouter router2 = setupRouter(true, false); + void readWriteTrailerHttp2() throws IOException { + IRouter router = setupRouter(false, true); + IRouter router2 = setupRouter(true, false); try { org.apache.commons.httpclient.HttpClient hc = new org.apache.commons.httpclient.HttpClient(); for (int i = 0; i < 2; i++) { @@ -141,7 +140,7 @@ void testReadWriteTrailerHttp2() throws IOException { @Test void testWriteTrailerHttp2() throws IOException, NoSuchAlgorithmException, KeyManagementException { - HttpRouter router = setupRouter(true, false); + IRouter router = setupRouter(true, false); try { X509TrustManager trustAll = new X509TrustManager() { @Override @@ -174,7 +173,7 @@ public X509Certificate[] getAcceptedIssuers() { assertEquals("Mon, 12 Dec 2022 09:28:00 GMT", res.trailers().get("Expires")); } } - try(ExecutorService es = hc.dispatcher().executorService()) { + try (ExecutorService es = hc.dispatcher().executorService()) { es.shutdown(); } hc.connectionPool().evictAll(); @@ -183,9 +182,8 @@ public X509Certificate[] getAcceptedIssuers() { } } - private HttpRouter setupRouter(boolean http2, boolean http2Client) throws IOException { - HttpRouter router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + private IRouter setupRouter(boolean http2, boolean http2Client) throws IOException { + TestRouter router = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(http2 ? 3060 : 3059), "localhost", 3060); if (http2) { SSLParser sslParser = getSslParserForHttp2(); @@ -193,57 +191,68 @@ private HttpRouter setupRouter(boolean http2, boolean http2Client) throws IOExce } AtomicReference remoteSocketAddr = new AtomicReference<>(); if (http2Client) { - HTTPClientInterceptor interceptor = (HTTPClientInterceptor) router.getTransport().getFlow().stream().filter(i -> i instanceof HTTPClientInterceptor).findFirst().get(); - HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); - httpClientConfig.setUseExperimentalHttp2(true); - interceptor.setHttpClientConfig(httpClientConfig); +// HTTPClientInterceptor interceptor = (HTTPClientInterceptor) router.getTransport().getFlow().stream().filter(i -> i instanceof HTTPClientInterceptor).findFirst().get(); +// HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); +// httpClientConfig.setUseExperimentalHttp2(true); +// interceptor.setHttpClientConfig(httpClientConfig); SSLParser sslParser2 = getSslParserForHttp2Client(); sp.getTarget().setSslParser(sslParser2); } else { - sp.getFlow().add(new AbstractInterceptor() { - @Override - public Outcome handleRequest(Exchange exc) { - String remoteAddr = getRemoteAddr(exc); - if (remoteSocketAddr.get() == null) { - remoteSocketAddr.set(remoteAddr); - } else if (!remoteAddr.equals(remoteSocketAddr.get())) { - throw new RuntimeException("Keep-Alive is not working."); - } + sp.getFlow().add(getInterceptor(http2, remoteSocketAddr)); + } + router.add(sp); + router.start(); + if (http2Client) { + HTTPClientInterceptor interceptor = router.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); + HttpClientConfiguration cfg = new HttpClientConfiguration(); + cfg.setUseExperimentalHttp2(true); + interceptor.setHttpClientConfig(cfg); + interceptor.init(); // Copies the config into the HttpClient. It is needed to call because router.start() above already called init() + } + return router; + } - if (http2 && exc.getProperty(HTTP2_SERVER) == null) - throw new RuntimeException("HTTP/2 is not being used."); - if (!http2 && exc.getProperty(HTTP2_SERVER) != null) - throw new RuntimeException("HTTP/2 is being used."); - - Response r = Response.ok().build(); - r.getHeader().removeFields("Content-Length"); - r.getHeader().setValue("Transfer-Encoding", "chunked"); - r.getHeader().setValue("Content-Type", "text/plain"); - r.getHeader().setValue("Trailer", "Expires"); - r.setBody(new ChunkedBody(new ByteArrayInputStream(getContent()))); - exc.setResponse(r); - return RETURN; + private static @NotNull AbstractInterceptor getInterceptor(boolean http2, AtomicReference remoteSocketAddr) { + return new AbstractInterceptor() { + @Override + public Outcome handleRequest(Exchange exc) { + String remoteAddr = getRemoteAddr(exc); + if (remoteSocketAddr.get() == null) { + remoteSocketAddr.set(remoteAddr); + } else if (!remoteAddr.equals(remoteSocketAddr.get())) { + throw new RuntimeException("Keep-Alive is not working."); } - private static String getRemoteAddr(Exchange exc) { - return ((HttpServerHandler) exc.getHandler()).getSourceSocket().getRemoteSocketAddress().toString(); - } + if (http2 && exc.getProperty(HTTP2_SERVER) == null) + throw new RuntimeException("HTTP/2 is not being used."); + if (!http2 && exc.getProperty(HTTP2_SERVER) != null) + throw new RuntimeException("HTTP/2 is being used."); + + Response r = Response.ok().build(); + r.getHeader().removeFields("Content-Length"); + r.getHeader().setValue("Transfer-Encoding", "chunked"); + r.getHeader().setValue("Content-Type", "text/plain"); + r.getHeader().setValue("Trailer", "Expires"); + r.setBody(new ChunkedBody(new ByteArrayInputStream(getContent()))); + exc.setResponse(r); + return RETURN; + } - private static byte[] getContent() { - String cont; - try { - cont = Resources.toString(getResource("chunked-body-with-trailer.txt"), US_ASCII); - } catch (IOException e) { - throw new RuntimeException(e); - } - cont = cont.replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\\\n", "\n").replaceAll("\\\\r", "\r"); - return cont.getBytes(US_ASCII); + private static String getRemoteAddr(Exchange exc) { + return ((HttpServerHandler) exc.getHandler()).getSourceSocket().getRemoteSocketAddress().toString(); + } + + private static byte[] getContent() { + String cont; + try { + cont = Resources.toString(getResource("chunked-body-with-trailer.txt"), US_ASCII); + } catch (IOException e) { + throw new RuntimeException(e); } - }); - } - router.add(sp); - router.start(); - return router; + cont = cont.replaceAll("\n", "").replaceAll("\r", "").replaceAll("\\\\n", "\n").replaceAll("\\\\r", "\r"); + return cont.getBytes(US_ASCII); + } + }; } private static @NotNull SSLParser getSslParserForHttp2() { @@ -285,7 +294,7 @@ void readTrailerTest() throws IOException { ByteArrayInputStream is = new ByteArrayInputStream(trailer); assertEquals(61, readChunkSize(is)); // 3D = 61 readTrailer(is); - assertEquals( 0,is.available()); // Check that everything is read + assertEquals(0, is.available()); // Check that everything is read } @Test @@ -306,7 +315,7 @@ void readStream() throws IOException { // 0 + CRLF + CRLF is not read yet assertFalse(cb.read); - if(!(is instanceof BodyInputStream bodyIs)) { + if (!(is instanceof BodyInputStream bodyIs)) { fail(); return; } @@ -329,7 +338,7 @@ void readStreamRepeatedly() throws IOException { // Re-Read JSON from the body (both reads will leave the final end-chunk unread) assertEquals(42, om.readTree(cb.getContentAsStream()).get("foo").asInt()); - if(!(cb.getContentAsStream() instanceof BodyInputStream bodyIs)) { + if (!(cb.getContentAsStream() instanceof BodyInputStream bodyIs)) { fail(); return; } @@ -374,7 +383,7 @@ void readStreamWith2ConcatenatedJSON() throws IOException { // Read the second JSON from the body assertEquals(43, om.readTree(is).get("foo").asInt()); - if(!(is instanceof BodyInputStream bodyIs)) { + if (!(is instanceof BodyInputStream bodyIs)) { fail(); return; } diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java index cfc6f147fa..56b8f9e727 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java @@ -29,18 +29,18 @@ import static org.junit.jupiter.api.Assertions.*; public class Http10Test { - private static HttpRouter router; - private static HttpRouter router2; + private static Router router; + private static Router router2; @BeforeAll public static void setUp() throws Exception { ServiceProxy proxy2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 2000), null, 0); proxy2.getFlow().add(new SampleSoapServiceInterceptor()); - router2 = new HttpRouter(); + router2 = new TestRouter(); router2.add(proxy2); ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3000), "localhost", 2000); - router = new HttpRouter(); + router = new TestRouter(); router.add(proxy); router2.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java index 81607aaa94..82ed2d18c2 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java @@ -30,8 +30,8 @@ public class Http11Test { - private static HttpRouter router; - private static HttpRouter router2; + private static IRouter router; + private static IRouter router2; private static int port4k; @BeforeAll @@ -40,11 +40,11 @@ public static void setUp() throws Exception { int port5k = getFreePortEqualAbove(5000); ServiceProxy proxy2 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port5k), null, 0); proxy2.getFlow().add(new SampleSoapServiceInterceptor()); - router2 = new HttpRouter(); + router2 = new TestRouter(); router2.add(proxy2); router2.start(); ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port4k), "localhost", port5k); - router = new HttpRouter(); + router = new TestRouter(); router.add(proxy); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java index 0c5912a900..94243e6521 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java @@ -27,7 +27,7 @@ public class MethodTest { - private static HttpRouter router; + private static IRouter router; @BeforeAll public static void setUp() throws Exception { @@ -43,7 +43,7 @@ public Outcome handleRequest(Exchange exc) { } }); proxy.getFlow().add(new ExceptionTestInterceptor()); // Cause exception - router = new HttpRouter(); + router = new TestRouter(); router.add(proxy); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java index ebc368bc44..8f32d4bb6a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java @@ -26,11 +26,11 @@ public class AdjustContentLengthTest { - private static Router router; + private static IRouter router; @BeforeAll public static void setUp() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); router.add(createMonitorRule()); router.add(createEndpointRule()); router.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index 1a5593a56b..637172df67 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -29,17 +29,17 @@ import static com.predic8.membrane.core.exchange.Exchange.*; import static com.predic8.membrane.core.http.Header.*; +import static com.predic8.membrane.core.interceptor.Outcome.CONTINUE; import static com.predic8.membrane.core.transport.ws.WebSocketConnection.*; import static org.junit.jupiter.api.Assertions.*; class AdminApiInterceptorTest { - private static HttpRouter router; + private static IRouter router; @BeforeAll static void setUp() throws IOException { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); router.setExchangeStore(new LimitedMemoryExchangeStore()); // Needed by the AdminApiInterceptor ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3065), null, 0); sp.getFlow().add(new FastWebSocketClosingInterceptor()); // speeds up test execution @@ -56,7 +56,7 @@ static void tearDown() { } @Test - public void testWebSocket() throws Exception { + void webSocket() throws Exception { try (HttpClient client = new HttpClient()) { var testHandler = new TestHandler(); var exc = createWSRequest(testHandler); @@ -170,7 +170,7 @@ private static class FastWebSocketClosingInterceptor extends AbstractInterceptor @Override public Outcome handleRequest(Exchange exc) { exc.setProperty(WEBSOCKET_CLOSED_POLL_INTERVAL_MILLISECONDS, 10); // speeds up test execution - return Outcome.CONTINUE; + return CONTINUE; } } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java index d91c6bfc6d..edf87a56f0 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java @@ -30,10 +30,10 @@ public class ClusterBalancerTest { private static XMLElementSessionIdExtractor extractor; private static LoadBalancingInterceptor lb; - private static Router r; + private static IRouter r; @BeforeAll - public static void setUp() throws Exception { + static void setUp() throws Exception { extractor = new XMLElementSessionIdExtractor(); extractor.setLocalName("session"); @@ -48,19 +48,19 @@ public static void setUp() throws Exception { ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3011), "predic8.com", 80); sp.getFlow().add(lb); r.add(sp); - r.start(); + r.init(); BalancerUtil.up(r, "Default", "Default", "localhost", 2000); BalancerUtil.up(r, "Default", "Default", "localhost", 3000); } @AfterAll - public static void tearDown() throws Exception { + static void tearDown() throws Exception { r.shutdown(); } @Test - public void testClusterBalancerRequest() throws Exception { + void clusterBalancerRequest() throws Exception { Exchange exc = getExchangeWithSession(); lb.handleRequest(exc); @@ -108,7 +108,7 @@ public void testClusterBalancerNoSessionRequestResponse() throws Exception { } @Test - public void testNoNodeFound() throws Exception { + void noNodeFound() throws Exception { Exchange exc = getExchangeWithOutSession(); BalancerUtil.down(r, "Default", "Default", "localhost", 2000); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java index 81f32b3867..2fcf4c45fc 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java @@ -14,6 +14,7 @@ package com.predic8.membrane.core.interceptor.balancer; import com.predic8.membrane.core.*; +import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; import org.apache.commons.codec.*; import org.apache.commons.codec.binary.*; @@ -21,6 +22,7 @@ import org.apache.commons.httpclient.methods.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; +import org.mockito.internal.configuration.*; import javax.crypto.*; import javax.crypto.spec.*; @@ -35,17 +37,19 @@ import static org.junit.jupiter.api.Assertions.*; public class ClusterNotificationInterceptorTest { - private HttpRouter router; + private TestRouter router; private ClusterNotificationInterceptor interceptor; @BeforeEach public void setUp() throws Exception { ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3002), "thomas-bayer.com", 80); - router = new HttpRouter(); + router = new TestRouter(); router.add(proxy); interceptor = new ClusterNotificationInterceptor(); - router.addUserFeatureInterceptor(interceptor); + var global = new GlobalInterceptor(); + global.getFlow().add(interceptor); + router.getRegistry().register("global", global); LoadBalancingInterceptor lbi = new LoadBalancingInterceptor(); lbi.setName("Default"); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java index 87f57e9d17..744b8d27c3 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java @@ -14,10 +14,12 @@ package com.predic8.membrane.core.interceptor.balancer; import com.predic8.membrane.core.*; +import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.services.*; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.io.*; @@ -30,10 +32,10 @@ public class LoadBalancingWithClusterManagerTest { - private HttpRouter lb; - private HttpRouter node1; - private HttpRouter node2; - private HttpRouter node3; + private IRouter lb; + private Router node1; + private Router node2; + private Router node3; @AfterEach public void tearDown() { @@ -45,9 +47,9 @@ public void tearDown() { @Test void nodesTest() throws Exception { - node1 = new HttpRouter(); - node2 = new HttpRouter(); - node3 = new HttpRouter(); + node1 = createRouter(); + node2 = createRouter(); + node3 = createRouter(); DummyWebServiceInterceptor service1 = startNode(node1, 2000); DummyWebServiceInterceptor service2 = startNode(node2, 3000); @@ -92,6 +94,12 @@ void nodesTest() throws Exception { assertEquals(2, service3.getCount()); } + private static @NotNull Router createRouter() { + Router node1 = new TestRouter(); + node1.getRegistry().register("global", new GlobalInterceptor()); + return node1; + } + private void startLB() throws Exception { LoadBalancingInterceptor lbi = new LoadBalancingInterceptor(); @@ -109,15 +117,16 @@ private void startLB() throws Exception { ServiceProxy cniRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3012), "thomas-bayer.com", 80); cniRule.getFlow().add(cni); - lb = new HttpRouter(); + lb = new Router(); lb.add(lbiRule); lb.add(cniRule); lb.start(); } - private DummyWebServiceInterceptor startNode(HttpRouter node, int port) throws Exception { + private DummyWebServiceInterceptor startNode(Router node, int port) throws Exception { DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor(); - node.addUserFeatureInterceptor(service1); + var global = node.getRegistry().getBean(GlobalInterceptor.class); + global.orElseThrow().getFlow().add(service1); node.add(new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80)); node.start(); return service1; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java index 1d06e0f030..a8590972a7 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java @@ -32,15 +32,15 @@ public abstract class AbstractInterceptorFlowTest { - private static Router router; + private IRouter router; - @BeforeAll - static void setUp() { - router = new HttpRouter(); + @BeforeEach + void setUp() { + router = new TestRouter(); } - @AfterAll - static void tearDown() { + @AfterEach + void tearDown() { router.shutdown(); } @@ -55,7 +55,7 @@ protected String getResponse(Interceptor... interceptors) throws Exception { } private void setUpRouter(Interceptor[] interceptors) throws Exception { - router.setRules(EMPTY_LIST); + // router.setRules(EMPTY_LIST); router.add(getApiProxy(interceptors)); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index fb87aca28b..cb0c325e3e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -33,13 +33,13 @@ abstract class AbstractInternalServiceRoutingInterceptorTest { protected final CaptureRoutingTestInterceptor captureRoutingTestInterceptor = new CaptureRoutingTestInterceptor(); - private Router router; + private IRouter router; protected abstract void configure() throws Exception; @BeforeEach void setup() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); router.getConfig().setHotDeploy(false); configure(); router.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java index 83b65d876b..b6c409220a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java @@ -41,12 +41,12 @@ public class OAuth2ResourceErrorForwardingTest { protected final BrowserMock browser = new BrowserMock(); private final int limit = 500; - protected HttpRouter mockAuthServer; + protected IRouter mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private HttpRouter oauth2Resource; + private IRouter oauth2Resource; private final AtomicReference error = new AtomicReference<>(); private final AtomicReference errorDescription = new AtomicReference<>(); @@ -63,22 +63,21 @@ public void init() throws IOException { error.set(null); errorDescription.set(null); - mockAuthServer = new HttpRouter(); + mockAuthServer = new TestRouter(); + mockAuthServer.add(getMockAuthServiceProxy()); + mockAuthServer.start(); mockAuthServer.getTransport().setBacklog(10000); mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit); - mockAuthServer.add(getMockAuthServiceProxy()); - mockAuthServer.start(); - oauth2Resource = new HttpRouter(); - oauth2Resource.getTransport().setBacklog(10000); - oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.getConfig().setHotDeploy(false); - oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit); + oauth2Resource = new TestRouter(); + oauth2Resource.add(getErrorCaptor()); oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); + oauth2Resource.getTransport().setBacklog(10000); + oauth2Resource.getTransport().setSocketTimeout(10000); + oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit); } @AfterEach @@ -126,9 +125,9 @@ public synchronized Outcome handleRequest(Exchange exc) { throw new RuntimeException(e); } exc.setResponse(new FormPostGenerator(getClientAddress() + "/oauth2callback") - .withParameter("error", "DEMO-123") - .withParameter("error_description", "This is a demo error.") - .withParameter("state", params.get("state")).build()); + .withParameter("error", "DEMO-123") + .withParameter("error_description", "This is a demo error.") + .withParameter("state", params.get("state")).build()); } if (exc.getResponse() == null) diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java index 082b5ced9f..1b48d8019b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.interceptor.oauth2.client; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.http.Request; @@ -59,12 +59,12 @@ public class OAuth2ResourceRpIniLogoutTest { protected final BrowserMock browser = new BrowserMock(); - protected HttpRouter mockAuthServer; + protected IRouter mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private HttpRouter oauth2Resource; + private IRouter oauth2Resource; private final AtomicBoolean isLoggedOutAtOP = new AtomicBoolean(false); private RsaJsonWebKey rsaJsonWebKey; private String jwksResponse; @@ -81,12 +81,12 @@ protected String getClientAddress() { public void init() throws IOException, JoseException { createKey(); - mockAuthServer = new HttpRouter(); + mockAuthServer = new TestRouter(); mockAuthServer.getConfig().setHotDeploy(false); mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); - oauth2Resource = new HttpRouter(); + oauth2Resource = new TestRouter(); oauth2Resource.getConfig().setHotDeploy(false); oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java index c4d416f305..f1770cd63c 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java @@ -13,9 +13,9 @@ package com.predic8.membrane.core.interceptor.oauth2.client; -import com.fasterxml.jackson.core.type.TypeReference; +import com.fasterxml.jackson.core.type.*; import com.fasterxml.jackson.databind.*; -import com.google.code.yanf4j.util.ConcurrentHashSet; +import com.google.code.yanf4j.util.*; import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.http.*; @@ -37,51 +37,48 @@ import java.util.*; import java.util.concurrent.*; import java.util.concurrent.atomic.*; -import java.util.stream.IntStream; +import java.util.stream.*; import static com.predic8.membrane.core.http.MimeType.*; -import static com.predic8.membrane.core.http.Request.get; -import static com.predic8.membrane.core.http.Request.post; -import static com.predic8.membrane.core.interceptor.oauth2client.rf.OAuth2CallbackRequestHandler.MEMBRANE_MISSING_SESSION_DESCRIPTION; +import static com.predic8.membrane.core.http.Request.*; +import static com.predic8.membrane.core.interceptor.oauth2client.rf.OAuth2CallbackRequestHandler.*; import static org.junit.jupiter.api.Assertions.*; public abstract class OAuth2ResourceTest { protected final BrowserMock browser = new BrowserMock(); private final int limit = 100; - protected HttpRouter mockAuthServer; + protected IRouter mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final Logger LOG = LoggerFactory.getLogger(OAuth2ResourceTest.class); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private HttpRouter oauth2Resource; + private IRouter oauth2Resource; private String getServerAddress() { - return "http://" + serverHost + ":" + serverPort; + return "http://%s:%d".formatted(serverHost, serverPort); } protected String getClientAddress() { - return "http://" + serverHost + ":" + clientPort; + return "http://%s:%d".formatted(serverHost, clientPort); } @BeforeEach public void init() throws IOException { - mockAuthServer = new HttpRouter(); - mockAuthServer.getTransport().setBacklog(10000); - mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.getConfig().setHotDeploy(false); - mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit+1); + mockAuthServer = new TestRouter(); mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); + mockAuthServer.getTransport().setBacklog(10000); + mockAuthServer.getTransport().setSocketTimeout(10000); + mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(limit + 1); - oauth2Resource = new HttpRouter(); - oauth2Resource.getTransport().setBacklog(10000); - oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.getConfig().setHotDeploy(false); - oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit+1); + oauth2Resource = new TestRouter(); oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); + oauth2Resource.getTransport().setBacklog(10000); + oauth2Resource.getTransport().setSocketTimeout(10000); + oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(limit + 1); } @AfterEach @@ -96,7 +93,8 @@ public void done() { public void getOriginalRequest() throws Exception { var response = browser.apply(get(getClientAddress() + "/init")).getResponse(); assertEquals(200, response.getStatusCode()); - var body = om.readValue(response.getBodyAsStream(), new TypeReference>() {}); + var body = om.readValue(response.getBodyAsStream(), new TypeReference>() { + }); assertEquals("/init", body.get("path")); assertEquals("", body.get("body")); assertEquals("GET", body.get("method")); @@ -106,7 +104,8 @@ public void getOriginalRequest() throws Exception { public void postOriginalRequest() throws Exception { var response = browser.apply(post(getClientAddress() + "/init").body("demobody")).getResponse(); assertEquals(200, response.getStatusCode()); - var body = om.readValue(response.getBodyAsStream(), new TypeReference>() {}); + var body = om.readValue(response.getBodyAsStream(), new TypeReference>() { + }); assertEquals("/init", body.get("path")); assertEquals("demobody", body.get("body")); assertEquals("POST", body.get("method")); @@ -117,7 +116,8 @@ public void postOriginalRequest() throws Exception { void testUseRefreshTokenOnTokenExpiration() throws Exception { var response = browser.apply(get(getClientAddress() + "/init")).getResponse(); assertEquals(200, response.getStatusCode()); - var body = om.readValue(response.getBodyAsStream(), new TypeReference>() {}); + var body = om.readValue(response.getBodyAsStream(), new TypeReference>() { + }); assertEquals("/init", body.get("path")); CountDownLatch cdl = new CountDownLatch(limit); @@ -135,7 +135,8 @@ private String getToken(CountDownLatch cdl) { cdl.await(); String path = "/" + UUID.randomUUID(); var response = browser.apply(get(getClientAddress() + path)).getResponse(); - var body = om.readValue(response.getBodyAsStringDecoded(), new TypeReference>() {}); + var body = om.readValue(response.getBodyAsStringDecoded(), new TypeReference>() { + }); assertEquals(path, body.get("path")); return body.get("accessToken"); } catch (Exception e) { @@ -283,9 +284,9 @@ public synchronized Response handleRequestInternal(Exchange exc) throws URISynta } else if (exc.getRequestURI().startsWith("/auth?")) { Map params = URLParamUtil.getParams(new URIFactory(), exc, URLParamUtil.DuplicateKeyOrInvalidFormStrategy.ERROR); return new FormPostGenerator(getClientAddress() + "/oauth2callback") - .withParameter("state", params.get("state")) - .withParameter("code", params.get("1234")) - .build(); + .withParameter("state", params.get("state")) + .withParameter("code", params.get("1234")) + .build(); } else if (exc.getRequestURI().startsWith("/token")) { ObjectMapper om = new ObjectMapper(); var responseData = Map.ofEntries( diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index 7f5d59b73a..cc4eb0f62a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -24,7 +24,6 @@ import com.predic8.membrane.core.interceptor.oauth2client.*; import com.predic8.membrane.core.interceptor.session.*; import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.resolver.*; import org.jetbrains.annotations.*; import java.io.*; @@ -52,7 +51,7 @@ public class B2CMembrane { private final ObjectMapper om = new ObjectMapper(); - private HttpRouter oauth2Resource; + private IRouter oauth2Resource; private OAuth2Resource2Interceptor oAuth2Resource2Interceptor; public RequireAuth requireAuth; @@ -63,17 +62,13 @@ public B2CMembrane(B2CTestConfig tc, SessionManager sessionManager) { } public void init() throws IOException { - oauth2Resource = new HttpRouter(); - oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(10000); - oauth2Resource.getTransport().setBacklog(10000); - oauth2Resource.getTransport().setSocketTimeout(10000); - oauth2Resource.getConfig().setHotDeploy(false); - oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); + oauth2Resource = new TestRouter(); ServiceProxy sp1_oauth2resource2 = createOAuth2Resource2ServiceProxy(); ServiceProxy sp2_flowInitiator_logoutBeforeFlow = createFlowInitiatorServiceProxy("/pe/", tc.peFlowId, true); ServiceProxy sp3_flowInitiator_noLogout = createFlowInitiatorServiceProxy("/pe2/", tc.pe2FlowId, false); sp1_oauth2resource2.init(oauth2Resource); + ServiceProxy sp4_requireAuth = createRequireAuthServiceProxy(tc.api1Id, "/api/", ra -> { requireAuth = ra; ra.setScope("https://localhost/" + tc.api1Id + "/Read"); @@ -99,6 +94,11 @@ public void init() throws IOException { oauth2Resource.add(sp1_oauth2resource2); oauth2Resource.start(); + oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(10000); + oauth2Resource.getTransport().setBacklog(10000); + oauth2Resource.getTransport().setSocketTimeout(10000); + oauth2Resource.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); + } public void stop() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java index 7c093cc1f6..805f0719ac 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java @@ -52,7 +52,7 @@ public class MockAuthorizationServer { private final SecureRandom rand = new SecureRandom(); private final ObjectMapper om = new ObjectMapper(); - private HttpRouter mockAuthServer; + private IRouter mockAuthServer; private RsaJsonWebKey rsaJsonWebKey; private String jwksResponse; @@ -77,22 +77,21 @@ public void init() throws IOException, JoseException { issuer = baseServerAddr + "/v2.0/"; createKey(); - mockAuthServer = new HttpRouter(); - mockAuthServer.getTransport().setBacklog(10000); - mockAuthServer.getTransport().setSocketTimeout(10000); - mockAuthServer.getConfig().setHotDeploy(false); - mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); + mockAuthServer = new TestRouter(); mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.susiFlowId)); mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.peFlowId)); mockAuthServer.add(getMockAuthServiceProxy(SERVER_PORT, tc.pe2FlowId)); mockAuthServer.start(); + mockAuthServer.getTransport().setBacklog(10000); + mockAuthServer.getTransport().setSocketTimeout(10000); + mockAuthServer.getTransport().setConcurrentConnectionLimitPerIp(tc.limit * 100); } public void stop() { mockAuthServer.stop(); } - public Router getMockAuthServer() { + public IRouter getMockAuthServer() { return mockAuthServer; } @@ -148,7 +147,7 @@ public synchronized Response handleRequestInternal(Exchange exc) throws Exceptio return handleTokenRequest(flowId, exc); } else if (requestURI.contains("/logout")) { onLogout.run(); - return Response.redirect( params.get("post_logout_redirect_uri"), 302).build(); + return Response.redirect(params.get("post_logout_redirect_uri"), 302).build(); } else { return Response.notFound().build(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java index e08ddaea3a..488a8f8e9e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/OAuth2ResourceB2CUnitTest.java @@ -110,7 +110,7 @@ private List getLinesContaining(String haystackLines, String needle) { // this should avoid session fixation attacks @Test - public void newSessionCookieAfterLogin() throws URISyntaxException { + void newSessionCookieAfterLogin() throws URISyntaxException { // this initializes the session, but does not login the user (because redirects are not followed) browser.applyWithoutRedirect(get(tc.getClientAddress() + "/init")); @@ -136,7 +136,7 @@ public void newSessionCookieAfterLogin() throws URISyntaxException { } @Test - public void logout() throws Exception { + void logout() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); var ili = browser.apply(get(tc.getClientAddress() + "/is-logged-in")); @@ -161,7 +161,7 @@ public void logout() throws Exception { } @Test - public void logoutClearsOldCookie() throws Exception { + void logoutClearsOldCookie() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); var ili = browser.apply(get(tc.getClientAddress() + "/is-logged-in")); @@ -190,7 +190,7 @@ public void logoutClearsOldCookie() throws Exception { } @Test - public void staleSessionLogout() throws Exception { + void staleSessionLogout() throws Exception { var ili = browser.apply(get(tc.getClientAddress() + "/is-logged-in")); assertTrue(ili.getResponse().getBodyAsStringDecoded().contains("false")); @@ -206,7 +206,7 @@ public void staleSessionLogout() throws Exception { } @Test - public void requestAuth() throws Exception { + void requestAuth() throws Exception { var exc = browser.apply(get(tc.getClientAddress() + "/api/init")); assertEquals(200, exc.getResponse().getStatusCode()); @@ -218,7 +218,7 @@ public void requestAuth() throws Exception { } @Test - public void userFlowTest() throws Exception { + void userFlowTest() throws Exception { var exc = browser.apply(get(tc.getClientAddress() + "/init")); assertNull(getAccessToken(exc)); @@ -231,7 +231,7 @@ public void userFlowTest() throws Exception { } @Test - public void userFlowViaInitiatorTest() throws Exception { + void userFlowViaInitiatorTest() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); var exc = browser.apply(get(tc.getClientAddress() + "/pe/init")); @@ -250,7 +250,7 @@ private String getAccessToken(Exchange exc) throws JsonProcessingException { } @Test - public void multipleUserFlowsTest() throws Exception { + void multipleUserFlowsTest() throws Exception { var exc = browser.apply(get(tc.getClientAddress() + "/init")); browser.apply(get(tc.getClientAddress() + "/pe2/init")); @@ -264,7 +264,7 @@ public void multipleUserFlowsTest() throws Exception { } @Test - public void startingUserFlowButContinueToUseOldRefreshToken() throws Exception { + void startingUserFlowButContinueToUseOldRefreshToken() throws Exception { var exc = browser.apply(get(tc.getClientAddress() + "/init")); mockAuthorizationServer.abortSignIn.set(true); @@ -292,7 +292,7 @@ public void startingUserFlowButContinueToUseOldRefreshToken() throws Exception { } @Test - public void multipleUserFlowsWithErrorTest() throws Exception { + void multipleUserFlowsWithErrorTest() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); mockAuthorizationServer.returnOAuth2ErrorFromSignIn.set(true); @@ -308,7 +308,7 @@ public void multipleUserFlowsWithErrorTest() throws Exception { } @Test - public void stayLoggedInAfterProfileEditing2() throws Exception { + void stayLoggedInAfterProfileEditing2() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); mockAuthorizationServer.abortSignIn.set(true); @@ -327,7 +327,7 @@ public void stayLoggedInAfterProfileEditing2() throws Exception { } @Test - public void notLoggedInAfterProfileEditing() throws Exception { + void notLoggedInAfterProfileEditing() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); mockAuthorizationServer.abortSignIn.set(true); @@ -343,9 +343,8 @@ public void notLoggedInAfterProfileEditing() throws Exception { assertEquals("null", a2); // no access token, because user is logged out. } - @Test - public void loginParams() throws Exception { + void loginParams() throws Exception { var exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/init?login_hint=def&illegal=true")); String location = exc.getResponse().getHeader().getFirstValue("Location"); @@ -366,7 +365,7 @@ public void loginParams() throws Exception { } @Test - public void loginParamsPerFlow() throws Exception { + void loginParamsPerFlow() throws Exception { var exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/pe/init?domain_hint=flow&illegal=true")); var params = parseQueryString(new URIFactory().create(exc.getResponse().getHeader().getLocation()).getRawQuery(), ERROR); @@ -379,7 +378,7 @@ public void loginParamsPerFlow() throws Exception { } @Test - public void loginNotRequired() throws Exception { + void loginNotRequired() throws Exception { // access 1: not authenticated, expecting no token var exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api-no-auth-needed/")); @@ -399,7 +398,7 @@ public void loginNotRequired() throws Exception { } @Test - public void returning4xx() throws Exception { + void returning4xx() throws Exception { // access 1: not authenticated, expecting 4xx var exc = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api-no-redirect/")); @@ -418,7 +417,7 @@ public void returning4xx() throws Exception { } @Test - public void requireAuthRedirects() throws Exception { + void requireAuthRedirects() throws Exception { var excCallResource = browser.applyWithoutRedirect(get(tc.getClientAddress() + "/api/")); assertEquals(302, excCallResource.getResponse().getStatusCode()); assertTrue(excCallResource.getResponse().getHeader().getFirstValue(Header.LOCATION).contains( @@ -427,7 +426,7 @@ public void requireAuthRedirects() throws Exception { } @Test - public void errorDuringSignIn() throws Exception { + void errorDuringSignIn() throws Exception { mockAuthorizationServer.returnOAuth2ErrorFromSignIn.set(true); var exc = browser.apply(get(tc.getClientAddress() + "/api/")); @@ -437,7 +436,7 @@ public void errorDuringSignIn() throws Exception { } @Test - public void errorDuringSecondOAuth2FlowLogsUserOut() throws Exception { + void errorDuringSecondOAuth2FlowLogsUserOut() throws Exception { browser.apply(get(tc.getClientAddress() + "/init")); var ili = browser.apply(get(tc.getClientAddress() + "/is-logged-in")); @@ -451,7 +450,7 @@ public void errorDuringSecondOAuth2FlowLogsUserOut() throws Exception { } @Test - public void api1and2() throws Exception { + void api1and2() throws Exception { var exc = browser.apply(get(tc.getClientAddress() + "/api/")); Map body = om.readValue(exc.getResponse().getBodyAsStream(), Map.class); assertEquals("/api/", body.get("path")); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index a9300777eb..db0762470e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -21,7 +21,7 @@ class OpenTelemetryInterceptorTest { - private Router router; + private IRouter router; @Test void initTest() throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java index 1f27f35fd9..0336f8904b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java @@ -32,7 +32,7 @@ public class SOAPFaultTest { public static final String ARTICLE_SERVICE_WSDL = getPathFromResource( "/validation/ArticleService.wsdl"); - final Router r = new HttpRouter(); + final IRouter r = new HttpRouter(); @Test public void testValidateFaults() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java index c8b75f954f..0c6f6e6c45 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java @@ -35,7 +35,7 @@ public class SOAPMessageValidatorInterceptorTest { public static final String E_MAIL_SERVICE_WSDL = "src/test/resources/validation/XWebEmailValidation.wsdl.xml"; public static final String INLINE_ANYTYPE_WSDL = "src/test/resources/validation/inline-anytype.wsdl"; public static final String WSDL_MESSAGE_VALIDATION_FAILED = "WSDL message validation failed"; - public static Router router; + public static IRouter router; @BeforeAll static void setup() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java index 74995ff069..f5586f4a2e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java @@ -44,7 +44,7 @@ public class ValidatorInterceptorTest { private static Exchange exc; - private static Router router; + private static IRouter router; public static final String ARTICLE_SERVICE_WSDL = "classpath:/validation/ArticleService.wsdl"; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java index a6025e823b..60f963711f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java @@ -26,7 +26,7 @@ public class WSDLPublisherInterceptorTest { - private HttpRouter router; + private IRouter router; static List getPorts() { return Arrays.asList(new Object[][] { @@ -36,7 +36,7 @@ static List getPorts() { } void before(String wsdlLocation, int port) throws Exception { - router = new HttpRouter(); + router = new TestRouter(); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", port), "", -1); WSDLPublisherInterceptor wi = new WSDLPublisherInterceptor(); wi.setWsdl(wsdlLocation); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java index 5f224a220c..0060721471 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java @@ -28,7 +28,7 @@ class WebServerInterceptorTest { WebServerInterceptor ws; Exchange exc; - Router r; + IRouter r; @BeforeEach void init() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index 42fcdb8c89..e3a8447c8c 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -43,12 +43,12 @@ public class SessionInterceptorTest { - private HttpRouter router; + private IRouter router; private CloseableHttpClient httpClient; @BeforeEach public void setUp() { - router = new HttpRouter(); + router = new TestRouter(); httpClient = createHttpClient(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java index 833d1a4827..b599de50c7 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java @@ -34,12 +34,11 @@ */ public class SoapAndInternalProxyTest { - HttpRouter router; + IRouter router; @BeforeEach void setup() { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/tunnel/WebsocketStompTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/tunnel/WebsocketStompTest.java index dd3d040869..df132f6aa9 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/tunnel/WebsocketStompTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/tunnel/WebsocketStompTest.java @@ -22,7 +22,7 @@ public class WebsocketStompTest { @Test - public void testWebsocketStomp() throws Exception{ + void websocketStomp() throws Exception{ // Preparation: Start the Websocket-Stomp example from an external source // Starts embedded ActiveMQ and places "Hello world!" into the "foo" queue diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java index 4c17d84d2c..bd79628708 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java @@ -14,7 +14,7 @@ package com.predic8.membrane.core.kubernetes.client; import com.google.common.io.Resources; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Response; import com.predic8.membrane.core.interceptor.AbstractInterceptor; @@ -37,12 +37,11 @@ public class KubernetesClientTest { - private static HttpRouter router; + private static IRouter router; @BeforeAll public static void prepare() throws IOException { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3053), null, 0); sp.getFlow().add(new AbstractInterceptor() { @Override diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java index 4602be75f5..32bb5966ed 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java @@ -38,7 +38,7 @@ public class APIProxyOpenAPITest { private static final String SECURITY = "security"; private static final String DETAILS = "details"; - Router router; + IRouter router; @BeforeEach public void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index 884f24eab5..2a8ea6cecf 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -38,7 +38,7 @@ class ApiDocsInterceptorTest { private final ObjectMapper om = new ObjectMapper(); - Router router; + HttpRouter router; final Exchange exc = new Exchange(null); ApiDocsInterceptor interceptor; APIProxy rule; @@ -46,7 +46,6 @@ class ApiDocsInterceptorTest { @BeforeEach public void setUp() throws Exception { router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); exc.setRequest(new Request.Builder().get("/foo").build()); exc.setOriginalRequestUri("/foo"); @@ -56,7 +55,6 @@ public void setUp() throws Exception { rule = createProxy(router, spec); router.setExchangeStore(new ForgetfulExchangeStore()); - router.setTransport(new HttpTransport()); router.add(rule); router.init(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index 7c55bf99a1..ee5bc86973 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -34,13 +34,13 @@ public class OpenAPI31ReferencesTest { - static Router router; + static IRouter router; static APIProxy api; @BeforeAll public static void setUp() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); router.getConfig().setUriFactory(new URIFactory()); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java index 3976cc964a..3acad0b316 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java @@ -26,6 +26,7 @@ import java.net.*; import static com.predic8.membrane.core.http.Request.get; +import static com.predic8.membrane.core.interceptor.Outcome.RETURN; import static com.predic8.membrane.core.openapi.util.OpenAPITestUtils.createProxy; import static com.predic8.membrane.test.TestUtil.getPathFromResource; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,8 +41,7 @@ public class OpenAPI31Test { @BeforeEach void setUp() throws URISyntaxException { - Router router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); + IRouter router = new HttpRouter(); petstore_v3_1 = new OpenAPISpec(); petstore_v3_1.location = getPathFromResource("openapi/specs/petstore-v3.1.json"); @@ -55,7 +55,6 @@ void setUp() throws URISyntaxException { @Test void simple() { exc.getRequest().setUri("/pets"); - Outcome actual = interceptor.handleRequest(exc); - assertEquals(Outcome.RETURN, actual); + assertEquals(RETURN, interceptor.handleRequest(exc)); } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index 3ff3ef62b9..16858552d7 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -37,7 +37,7 @@ class OpenAPIInterceptorTest { - Router router; + IRouter router; OpenAPISpec specInfoServers; OpenAPISpec specInfo3Servers; OpenAPISpec specCustomers; @@ -49,7 +49,6 @@ class OpenAPIInterceptorTest { @BeforeEach void setUp() { router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); specInfoServers = new OpenAPISpec(); specInfoServers.location = getPathFromResource("openapi/specs/info-servers.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java index b029e32924..172ba64bc5 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java @@ -30,7 +30,7 @@ class OpenAPIRecordFactoryTest { @BeforeAll static void setUp() { - Router router = new HttpRouter(); + HttpRouter router = new HttpRouter(); router.setBaseLocation("src/test/resources/openapi/specs/"); factory = new OpenAPIRecordFactory(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java index 83857c85cb..049f871ef6 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java @@ -34,14 +34,11 @@ public class Swagger20Test { - Router router; + IRouter router; @BeforeEach public void setUp() throws Exception { - - router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); - + router = new TestRouter(); router.add(getApiProxy()); router.add(getTargetProxy()); router.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java index 64e7845c52..644cfe4a6c 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java @@ -32,7 +32,7 @@ public class XMembraneExtensionSecurityTest { @BeforeEach void setUp() { - Router router = new HttpRouter(); + HttpRouter router = new HttpRouter(); router.setBaseLocation(""); OpenAPIRecordFactory factory = new OpenAPIRecordFactory(router); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java b/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java index 7e931c55ba..d858fb3fe3 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java @@ -66,7 +66,7 @@ public static OpenAPI parseOpenAPI(String file) { } - public static APIProxy createProxy(Router router, OpenAPISpec spec) { + public static APIProxy createProxy(IRouter router, OpenAPISpec spec) { APIProxy proxy = new APIProxy(); proxy.setSpecs(singletonList(spec)); proxy.setKey(new APIProxyKey(2000)); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java index 6785866809..313d11511b 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java @@ -45,7 +45,7 @@ void setUpSpec() { spec.validateRequests = YES; spec.validateResponses = YES; - Router router = getRouter(); + IRouter router = getRouter(); interceptor = new OpenAPIInterceptor(createProxy(router, spec)); interceptor.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java index d75ed04a6d..fc943da246 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java @@ -41,9 +41,7 @@ protected Exchange getExchange(String method, String path, SecurityScheme scheme return exc; } - protected static Router getRouter() { - Router router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); - return router; + protected static IRouter getRouter() { + return new HttpRouter(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java index b565a4aa7c..9335e07b77 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java @@ -43,8 +43,7 @@ public class BasicAuthSecurityValidationTest { @BeforeEach void setUpSpec() { - Router router = new HttpRouter(); - router.getConfig().setUriFactory(new URIFactory()); + IRouter router = new HttpRouter(); OpenAPISpec spec = new OpenAPISpec(); spec.location = getPathFromResource("openapi/specs/security/http-basic.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index da20af15bd..4f0730981c 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -42,7 +42,7 @@ public class JWTInterceptorAndSecurityValidatorTest { private static final String SPEC_LOCATION = getPathFromResource( "openapi/openapi-proxy/no-extensions.yml"); - private Router router; + private IRouter router; private APIProxy proxy; RsaJsonWebKey privateKey; @@ -92,7 +92,7 @@ private void callInterceptorChain(Exchange exc) { } @NotNull - private JwtAuthInterceptor getJwtAuthInterceptor(Router router) { + private JwtAuthInterceptor getJwtAuthInterceptor(IRouter router) { JwtAuthInterceptor interceptor = createInterceptor(getPublicKey()); interceptor.setJwtRetriever(new HeaderJwtRetriever("Authorization","bearer")); interceptor.init(router); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java index 431f8258dd..f9f8cab111 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java @@ -41,7 +41,7 @@ void setUpSpec() { spec.validateRequests = YES; spec.validateSecurity = YES; - Router router = getRouter(); + IRouter router = getRouter(); interceptor = new OpenAPIInterceptor(createProxy(router, spec)); interceptor.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java index e89005f747..3049424bdb 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java @@ -28,11 +28,11 @@ public class APIProxyKeyTest { - private static Router router; + private static IRouter router; @BeforeEach public void setup() { - router = new HttpRouter(); + router = new TestRouter(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index d1636cace4..4f6ede5658 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -25,11 +25,11 @@ class InternalProxyTest { - private Router router; + private IRouter router; @BeforeEach void setup() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); router.add(new APIProxy() {{ key = new APIProxyKey(2001); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index c54fd38932..e1494c9b6f 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -37,13 +37,13 @@ public class ProxyTest { - static HttpRouter router; + static IRouter router; static final AtomicReference lastMethod = new AtomicReference<>(); @BeforeAll public static void init() throws IOException { - router = new HttpRouter(); + router = new TestRouter(); router.getConfig().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(3055)); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index 71c9f126ee..d126e88e4d 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -31,7 +31,7 @@ public class SOAPProxyTest { - Router router; + IRouter router; SOAPProxy proxy; @@ -39,8 +39,7 @@ public class SOAPProxyTest { void setUp() throws IOException { proxy = new SOAPProxy(); proxy.setPort(2000); - router = new HttpRouter(); - router.setExchangeStore(new ForgetfulExchangeStore()); + router = new Router(); APIProxy backend = new APIProxy(); backend.setKey(new APIProxyKey(2001)); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java index dae0c8f08a..b8a5814096 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java @@ -24,12 +24,11 @@ @SuppressWarnings("HttpUrlsUsage") public class SOAPProxyWSDLPublisherInterceptorTest { - static Router router; + static IRouter router; @BeforeAll static void setUp() { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java index 25d54ff2af..dabc392915 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java @@ -26,11 +26,11 @@ class ServiceProxyTest { - private static Router router; + private static IRouter router; @BeforeAll public static void setup() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); APIProxy proxyWithOutTarget = new APIProxy() {{ key = new APIProxyKey(2000); }}; diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java index 4f38e7d758..e62c543a23 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java @@ -28,11 +28,11 @@ @SuppressWarnings("HttpUrlsUsage") public class ServiceProxyWSDLInterceptorsTest { - Router router; + IRouter router; @BeforeEach void setUp() { - router = new HttpRouter(); + router = new TestRouter(); router.getConfig().setHotDeploy(false); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 30a0e40a4f..0a25ea3405 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -36,7 +36,7 @@ public class UnavailableSoapProxyTest { static void setup() throws Exception { ServiceProxy cityAPI = new ServiceProxy(new ServiceProxyKey(4000), null, 0); cityAPI.getFlow().add(new SampleSoapServiceInterceptor()); - backendRouter = new HttpRouter(); + backendRouter = new Router(); backendRouter.add(cityAPI); backendRouter.start(); } @@ -50,7 +50,7 @@ static void teardown() { @BeforeEach void startRouter() throws IOException { - r = new HttpRouter(); + r = new Router(); HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); r.setHttpClientConfig(httpClientConfig); @@ -71,7 +71,7 @@ void startRouter() throws IOException { SOAPProxy sp2 = new SOAPProxy(); sp2.setPort(2001); sp2.setWsdl("http://localhost:4000?wsdl"); - r2 = new HttpRouter(); + r2 = new Router(); r2.getConfig().setHotDeploy(false); r2.add(sp2); } diff --git a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java index e08edf3695..400aaca6d9 100644 --- a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java +++ b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java @@ -19,6 +19,7 @@ import com.predic8.membrane.core.interceptor.schemavalidation.*; import com.predic8.membrane.core.interceptor.server.*; import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.util.*; import com.predic8.schema.*; import com.predic8.wsdl.*; import org.junit.jupiter.api.*; @@ -30,246 +31,242 @@ import java.util.*; import static com.predic8.membrane.core.interceptor.Outcome.*; -import static com.predic8.membrane.test.TestUtil.getPathFromResource; +import static com.predic8.membrane.test.TestUtil.*; import static org.junit.jupiter.api.Assertions.*; public class ResolverTest { - /* - * The ResolverTest is a 5-dimensional parametrized test: - * 1. Deployment Type - * 2. Operating System - * 3. Basis URL Type - * 4. Relative URL Type - * 5. Resolver Interface used - * - * Not all combinations exist (or are currently supported). (See #setupLocations()) - */ - - - // DeploymentType (STANDALONE, J2EE, OSGI) is handled differently on the tests setup/execution level - - // OperatingSystemType (WINDOWS, LINUX) is handled by Jenkins - - public enum BasisUrlType { - HTTP, - FILE, - FILE_WINDOWS_DRIVE, - CLASSPATH, - BUNDLE, - NAME, - SAME_DIR, - PARENT_DIR, - ROOT_DIR, - WINDOWS_DRIVE, - WINDOWS_DRIVE_BACKSLASH - } - - @BeforeAll - public static void setup() throws Exception { - ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3029), "localhost", 8080); - - sp.getFlow().add(new AbstractInterceptor() { - @Override - public Outcome handleRequest(Exchange exc) { - hit = true; - return CONTINUE; - } - }); - - WebServerInterceptor i = new WebServerInterceptor(); - if (deployment.equals(STANDALONE)) - i.setDocBase(getPathFromResource("")); - else { - i.setDocBase("/test"); - router.getResolverMap().addSchemaResolver(resolverMap.getFileSchemaResolver()); - } - sp.getFlow().add(i); - - router.add(sp); - router.start(); - } - - @AfterAll - public static void teardown() { - router.shutdown(); - } - - // RelativeUrlType (SCHEMA, NAME, SAME_DIR, PARENT_DIR) is handled by the test methods as well as by the test resources - // (WSDL and XSD files referencing other files in these ways) - - // ResolverInterfaceType (MEMBRANE_SERVICE_PROXY, MEMBRANE_SOA_MODEL, LS_RESOURCE_RESOLVER) is handled by - // different test methods below - - public static List getConfigurations() { - List res = new ArrayList<>(); - for (BasisUrlType but : BasisUrlType.values()) - res.add(new Object[] { but }); - return res; - } - - public static final ResolverMap resolverMap = new ResolverMap(); - - private String wsdlLocation; - private String xsdLocation; - - @ParameterizedTest - @MethodSource("getConfigurations") - public void testLSResourceResolver(BasisUrlType basisUrlType) { - if (hit = !setupLocations(basisUrlType)) - return; - - try { - new XMLSchemaValidator(resolverMap, xsdLocation, null); - } catch (Exception e) { - throw new RuntimeException("xsdLocation = " + xsdLocation, e); - } - } - - @ParameterizedTest - @MethodSource("getConfigurations") - public void testMembraneServiceProxyCombine(BasisUrlType basisUrlType) throws IOException { - if (hit = !setupLocations(basisUrlType)) - return; - - assertNotNull(resolverMap.resolve(wsdlLocation)); - for (String relUrl : new String[] { "1.xsd", "./1.xsd", "../resolver/1.xsd", "http://localhost:3029/resolver/1.xsd" }) { - try { - assertNotNull(resolverMap.resolve(ResolverMap.combine(wsdlLocation, relUrl))); - } catch (Exception e) { - throw new RuntimeException("Error during combine(\"" + wsdlLocation + "\", \"" + relUrl + "\"):", e); - } - } - } - - @ParameterizedTest - @MethodSource("getConfigurations") - public void testMembraneSoaModel(BasisUrlType basisUrlType) { - if (hit = !setupLocations(basisUrlType)) - return; - - try { - WSDLParserContext ctx = new WSDLParserContext(); - ctx.setInput(wsdlLocation); - WSDLParser wsdlParser = new WSDLParser(); - wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver()); - Definitions definitions = wsdlParser.parse(ctx); - for (Schema schema : definitions.getSchemas()) - schema.getElements(); // trigger lazy-loading - } catch (Exception e) { - throw new RuntimeException("wsdlLocation = " + xsdLocation, e); - } - } - - @AfterEach - public void postpare() { - // since a.wsdl and 2.xsd reference a HTTP resource, it should get loaded - assertTrue(hit, "No HTTP resource was retrieved (while referenced)"); - } - - /** - * Sets wsdlLocation and xsdLocation, given the current test parameters - * @return whether the current test parameters is supported - */ - private boolean setupLocations(BasisUrlType basisUrlType) { - switch (basisUrlType) { - case BUNDLE: - return false; - case CLASSPATH: - wsdlLocation = "classpath:/resolver/a.wsdl"; - xsdLocation = "classpath:/resolver/2.xsd"; - return true; - case FILE: - if (!deployment.equals(STANDALONE)) - return false; - String current = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); - if (current.endsWith(".")) - current = current.substring(0, current.length()-1); - if (current.startsWith(":/", 1)) - current = current.substring(2); - wsdlLocation = "file://" + current + "src/test/resources/resolver/a.wsdl"; - xsdLocation = "file://" + current + "src/test/resources/resolver/2.xsd"; - return true; - case FILE_WINDOWS_DRIVE: - if (!deployment.equals(STANDALONE)) - return false; - basisUrlType = BasisUrlType.WINDOWS_DRIVE; - if (!setupLocations(basisUrlType)) - return false; - wsdlLocation = "file://" + wsdlLocation; - xsdLocation = "file://" + xsdLocation; - return true; - case WINDOWS_DRIVE: - if (!deployment.equals(STANDALONE)) - return false; - if (!isWindows()) - return false; - String current2 = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); - if (current2.endsWith(".")) - current2 = current2.substring(0, current2.length()-1); - wsdlLocation = current2 + "src/test/resources/resolver/a.wsdl"; - xsdLocation = current2 + "src/test/resources/resolver/2.xsd"; - return true; - case WINDOWS_DRIVE_BACKSLASH: - if (!deployment.equals(STANDALONE)) - return false; - basisUrlType = BasisUrlType.WINDOWS_DRIVE; - if (!setupLocations(basisUrlType)) - return false; - wsdlLocation = wsdlLocation.replaceAll("/", "\\\\"); - xsdLocation = xsdLocation.replaceAll("/", "\\\\"); - return true; - case ROOT_DIR: - String current3; - if (deployment.equals(STANDALONE)) { - current3 = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); - if (current3.endsWith(".")) - current3 = current3.substring(0, current3.length()-1); - if (current3.startsWith(":/", 1)) - current3 = current3.substring(2); - current3 = current3 + "src/test/resources"; - } else { - current3 = "/test"; - } - wsdlLocation = current3 + "/resolver/a.wsdl"; - xsdLocation = current3 + "/resolver/2.xsd"; - return true; - case HTTP: - wsdlLocation = "http://localhost:3029/resolver/a.wsdl"; - xsdLocation = "http://localhost:3029/resolver/2.xsd"; - return true; - case NAME: - if (!deployment.equals(STANDALONE)) - return false; // TODO: could be implemented - wsdlLocation = "src/test/resources/resolver/a.wsdl"; - xsdLocation = "src/test/resources/resolver/2.xsd"; - return true; - case PARENT_DIR: - if (!deployment.equals(STANDALONE)) - return false; // TODO: could be implemented - wsdlLocation = "../core/src/test/resources/resolver/a.wsdl"; - xsdLocation = "../core/src/test/resources/resolver/2.xsd"; - return true; - case SAME_DIR: - if (!deployment.equals(STANDALONE)) - return false; // TODO: could be implemented - wsdlLocation = "./src/test/resources/resolver/a.wsdl"; - xsdLocation = "./src/test/resources/resolver/2.xsd"; - return true; - default: - throw new InvalidParameterException("basisUrlType = " + basisUrlType); - } - } - - public static boolean isWindows() { - return System.getProperty("os.name").contains("Windows"); - } - - static final HttpRouter router = new HttpRouter(); - static volatile boolean hit = false; - - public static final String STANDALONE = "standalone"; - - public static final String deployment = STANDALONE; - + /* + * The ResolverTest is a 5-dimensional parametrized test: + * 1. Deployment Type + * 2. Operating System + * 3. Basis URL Type + * 4. Relative URL Type + * 5. Resolver Interface used + * + * Not all combinations exist (or are currently supported). (See #setupLocations()) + */ + + + // DeploymentType (STANDALONE, J2EE, OSGI) is handled differently on the tests setup/execution level + + // OperatingSystemType (WINDOWS, LINUX) is handled by Jenkins + + private static IRouter router; + private static volatile boolean hit = false; + + private static final String STANDALONE = "standalone"; + private static final String deployment = STANDALONE; + + public enum BasisUrlType { + HTTP, + FILE, + FILE_WINDOWS_DRIVE, + CLASSPATH, + BUNDLE, + NAME, + SAME_DIR, + PARENT_DIR, + ROOT_DIR, + WINDOWS_DRIVE, + WINDOWS_DRIVE_BACKSLASH + } + + @BeforeAll + public static void setup() throws Exception { + ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3029), "localhost", 8080); + + sp.getFlow().add(new AbstractInterceptor() { + @Override + public Outcome handleRequest(Exchange exc) { + hit = true; + return CONTINUE; + } + }); + + WebServerInterceptor i = new WebServerInterceptor(); + if (deployment.equals(STANDALONE)) + i.setDocBase(getPathFromResource("")); + else { + i.setDocBase("/test"); + router.getResolverMap().addSchemaResolver(resolverMap.getFileSchemaResolver()); + } + sp.getFlow().add(i); + + router = new TestRouter(); + router.add(sp); + router.start(); + } + + @AfterAll + public static void teardown() { + router.shutdown(); + } + + // RelativeUrlType (SCHEMA, NAME, SAME_DIR, PARENT_DIR) is handled by the test methods as well as by the test resources + // (WSDL and XSD files referencing other files in these ways) + + // ResolverInterfaceType (MEMBRANE_SERVICE_PROXY, MEMBRANE_SOA_MODEL, LS_RESOURCE_RESOLVER) is handled by + // different test methods below + + public static List getConfigurations() { + List res = new ArrayList<>(); + for (BasisUrlType but : BasisUrlType.values()) + res.add(new Object[]{but}); + return res; + } + + public static final ResolverMap resolverMap = new ResolverMap(); + + private String wsdlLocation; + private String xsdLocation; + + @ParameterizedTest + @MethodSource("getConfigurations") + public void testLSResourceResolver(BasisUrlType basisUrlType) { + if (hit = !setupLocations(basisUrlType)) + return; + + try { + new XMLSchemaValidator(resolverMap, xsdLocation, null); + } catch (Exception e) { + throw new RuntimeException("xsdLocation = " + xsdLocation, e); + } + } + + @ParameterizedTest + @MethodSource("getConfigurations") + public void testMembraneServiceProxyCombine(BasisUrlType basisUrlType) throws IOException { + if (hit = !setupLocations(basisUrlType)) + return; + + assertNotNull(resolverMap.resolve(wsdlLocation)); + for (String relUrl : new String[]{"1.xsd", "./1.xsd", "../resolver/1.xsd", "http://localhost:3029/resolver/1.xsd"}) { + try { + assertNotNull(resolverMap.resolve(ResolverMap.combine(wsdlLocation, relUrl))); + } catch (Exception e) { + throw new RuntimeException("Error during combine(\"" + wsdlLocation + "\", \"" + relUrl + "\"):", e); + } + } + } + + @ParameterizedTest + @MethodSource("getConfigurations") + public void testMembraneSoaModel(BasisUrlType basisUrlType) { + if (hit = !setupLocations(basisUrlType)) + return; + + try { + WSDLParserContext ctx = new WSDLParserContext(); + ctx.setInput(wsdlLocation); + WSDLParser wsdlParser = new WSDLParser(); + wsdlParser.setResourceResolver(resolverMap.toExternalResolver().toExternalResolver()); + Definitions definitions = wsdlParser.parse(ctx); + for (Schema schema : definitions.getSchemas()) + schema.getElements(); // trigger lazy-loading + } catch (Exception e) { + throw new RuntimeException("wsdlLocation = " + xsdLocation, e); + } + } + + @AfterEach + public void postpare() { + // since a.wsdl and 2.xsd reference a HTTP resource, it should get loaded + assertTrue(hit, "No HTTP resource was retrieved (while referenced)"); + } + + /** + * Sets wsdlLocation and xsdLocation, given the current test parameters + * + * @return whether the current test parameters is supported + */ + private boolean setupLocations(BasisUrlType basisUrlType) { + switch (basisUrlType) { + case BUNDLE: + return false; + case CLASSPATH: + wsdlLocation = "classpath:/resolver/a.wsdl"; + xsdLocation = "classpath:/resolver/2.xsd"; + return true; + case FILE: + if (!deployment.equals(STANDALONE)) + return false; + String current = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); + if (current.endsWith(".")) + current = current.substring(0, current.length() - 1); + if (current.startsWith(":/", 1)) + current = current.substring(2); + wsdlLocation = "file://" + current + "src/test/resources/resolver/a.wsdl"; + xsdLocation = "file://" + current + "src/test/resources/resolver/2.xsd"; + return true; + case FILE_WINDOWS_DRIVE: + if (!deployment.equals(STANDALONE)) + return false; + basisUrlType = BasisUrlType.WINDOWS_DRIVE; + if (!setupLocations(basisUrlType)) + return false; + wsdlLocation = "file://" + wsdlLocation; + xsdLocation = "file://" + xsdLocation; + return true; + case WINDOWS_DRIVE: + if (!deployment.equals(STANDALONE)) + return false; + if (!OSUtil.isWindows()) + return false; + String current2 = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); + if (current2.endsWith(".")) + current2 = current2.substring(0, current2.length() - 1); + wsdlLocation = current2 + "src/test/resources/resolver/a.wsdl"; + xsdLocation = current2 + "src/test/resources/resolver/2.xsd"; + return true; + case WINDOWS_DRIVE_BACKSLASH: + if (!deployment.equals(STANDALONE)) + return false; + basisUrlType = BasisUrlType.WINDOWS_DRIVE; + if (!setupLocations(basisUrlType)) + return false; + wsdlLocation = wsdlLocation.replaceAll("/", "\\\\"); + xsdLocation = xsdLocation.replaceAll("/", "\\\\"); + return true; + case ROOT_DIR: + String current3; + if (deployment.equals(STANDALONE)) { + current3 = new File(".").getAbsolutePath().replaceAll("\\\\", "/"); + if (current3.endsWith(".")) + current3 = current3.substring(0, current3.length() - 1); + if (current3.startsWith(":/", 1)) + current3 = current3.substring(2); + current3 = current3 + "src/test/resources"; + } else { + current3 = "/test"; + } + wsdlLocation = current3 + "/resolver/a.wsdl"; + xsdLocation = current3 + "/resolver/2.xsd"; + return true; + case HTTP: + wsdlLocation = "http://localhost:3029/resolver/a.wsdl"; + xsdLocation = "http://localhost:3029/resolver/2.xsd"; + return true; + case NAME: + if (!deployment.equals(STANDALONE)) + return false; // TODO: could be implemented + wsdlLocation = "src/test/resources/resolver/a.wsdl"; + xsdLocation = "src/test/resources/resolver/2.xsd"; + return true; + case PARENT_DIR: + if (!deployment.equals(STANDALONE)) + return false; // TODO: could be implemented + wsdlLocation = "../core/src/test/resources/resolver/a.wsdl"; + xsdLocation = "../core/src/test/resources/resolver/2.xsd"; + return true; + case SAME_DIR: + if (!deployment.equals(STANDALONE)) + return false; // TODO: could be implemented + wsdlLocation = "./src/test/resources/resolver/a.wsdl"; + xsdLocation = "./src/test/resources/resolver/2.xsd"; + return true; + default: + throw new InvalidParameterException("basisUrlType = " + basisUrlType); + } + } } diff --git a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java index b7cc62186d..539ebae2a8 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java @@ -13,8 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.security; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.KeyStore; import com.predic8.membrane.core.config.security.SSLParser; import org.junit.jupiter.api.AfterAll; @@ -36,7 +35,7 @@ class KeyStoreUtilTest { - private static Router router; + private static IRouter router; private static java.security.KeyStore keyStore; private static final String ALIAS = "key1"; private static final String KEYSTORE_PASSWORD = "secret"; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java index 0b63aa70c0..46494f049c 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java @@ -29,12 +29,12 @@ public class BoundConnectionTest { - HttpRouter router; + IRouter router; volatile long connectionHash = 0; @BeforeEach public void setUp() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", 3021), "localhost", 3022); router.add(sp1); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index a826380bfe..224b44a14a 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -28,7 +28,7 @@ public class ConcurrentConnectionLimitTest { - private HttpRouter router; + private IRouter router; private ExecutorService executor; private final int concurrency = 100; private final int concurrentLimit = 10; @@ -40,8 +40,7 @@ public class ConcurrentConnectionLimitTest { public void setup() throws Exception{ executor = Executors.newFixedThreadPool(concurrency); - router = new HttpRouter(); - router.getTransport().setConcurrentConnectionLimitPerIp(concurrentLimit); + router = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey("*", "*", ".*", port), "", -1); @@ -50,6 +49,7 @@ public void setup() throws Exception{ router.add(sp); router.start(); + router.getTransport().setConcurrentConnectionLimitPerIp(concurrentLimit); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java index 258a668195..0df6af01e9 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java @@ -26,13 +26,13 @@ public class ConnectionTest { Connection conLocalhost; Connection con127_0_0_1; - HttpRouter router; + IRouter router; @BeforeEach void setUp() throws Exception { ServiceProxy proxy2000 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 2000), "predic8.com", 80); - router = new HttpRouter(); + router = new TestRouter(); router.add(proxy2000); router.start(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java index 0abda9fc5a..772b8552e3 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java @@ -30,11 +30,11 @@ public class Http2DowngradeTest { - private static HttpRouter router; + private static IRouter router; @BeforeAll public static void beforeAll() throws IOException { - router = new HttpRouter(); + router = new TestRouter(); ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey(3064), null, 0); proxy.getFlow().add(new AbstractInterceptor() { @Override diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java index c82c1088c0..8fb54aa9a0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java @@ -40,14 +40,14 @@ public class HttpKeepAliveTest { private HashSet hashs; // tracks the hashcodes of all connections used - private HttpRouter service1; + private IRouter service1; private ServiceProxy sp1; @BeforeEach public void setUp() throws Exception { hashs = new HashSet<>(); - service1 = new HttpRouter(); + service1 = new TestRouter(); sp1 = new ServiceProxy(new ServiceProxyKey("localhost", METHOD_POST, ".*", 2003), "thomas-bayer.com", 80); sp1.getFlow().add(new AbstractInterceptor(){ diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java index 193939c5b6..d8a9dda7f4 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java @@ -20,6 +20,7 @@ import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.transport.http.client.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.io.*; @@ -34,7 +35,7 @@ public class HttpTimeoutTest { public final int BACKEND_DELAY_MILLIS = 300; - HttpRouter slowBackend, proxyRouter; + IRouter slowBackend, proxyRouter; @BeforeEach public void setUp() throws Exception { @@ -42,26 +43,41 @@ public void setUp() throws Exception { setupSlowBackend(); } + @AfterEach + public void tearDown() { + slowBackend.stop(); + proxyRouter.stop(); + } + private void setupMembrane() throws IOException { HttpClientConfiguration hcc = new HttpClientConfiguration(); hcc.getConnection().setSoTimeout(1); hcc.getRetryHandler().setRetries(1); - proxyRouter = new HttpRouter(); - proxyRouter.getConfig().setHotDeploy(false); - proxyRouter.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(hcc); - ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("*", - "*", ".*", 3023), "localhost", 3022); + proxyRouter = new TestRouter(); + ServiceProxy sp2 = getServiceProxy(3023, "localhost", 3022); proxyRouter.add(sp2); proxyRouter.start(); + var client = proxyRouter.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); + client.setHttpClientConfig(hcc); + client.init(); // Copies the config into the HttpClient. It is needed to call because router.start() above already called init() + } + + private static @NotNull ServiceProxy getServiceProxy(int port, String localhost, int targetPort) { + return new ServiceProxy(new ServiceProxyKey("*", + "*", ".*", port), localhost, targetPort); } private void setupSlowBackend() throws Exception { - slowBackend = new HttpRouter(); - slowBackend.getConfig().setHotDeploy(false); - ServiceProxy sp = new ServiceProxy(new ServiceProxyKey("*", - "*", ".*", 3022), "", -1); - sp.getFlow().add(new AbstractInterceptor(){ + slowBackend = new TestRouter(); + ServiceProxy sp = getServiceProxy(3022, "", -1); + sp.getFlow().add(getHandler()); + slowBackend.add(sp); + slowBackend.start(); + } + + private @NotNull AbstractInterceptor getHandler() { + return new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { try { @@ -77,15 +93,7 @@ public Outcome handleRequest(Exchange exc) { exc.setResponse(ok("OK.").build()); return RETURN; } - }); - slowBackend.add(sp); - slowBackend.start(); - } - - @AfterEach - public void tearDown() { - slowBackend.stop(); - proxyRouter.stop(); + }; } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java index 12cb574297..36f7b1a5f1 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java @@ -31,11 +31,11 @@ class IllegalCharactersInURLTest { - private HttpRouter r; + private IRouter r; @BeforeEach void init() throws Exception { - r = new HttpRouter(); + r = new TestRouter(); r.getConfig().setHotDeploy(false); r.add(new ServiceProxy(new ServiceProxyKey(3027), "localhost", 3028)); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey(3028), null, 80); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java index fb0a51c229..9792fc5564 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java @@ -30,7 +30,7 @@ public class ServiceInvocationTest { - private HttpRouter router; + private IRouter router; @BeforeEach void setUp() throws Exception { @@ -87,13 +87,13 @@ private PostMethod createPostMethod() { return post; } - private HttpRouter createRouter() throws Exception { - HttpRouter router = new HttpRouter(); + private IRouter createRouter() throws Exception { + IRouter router = new TestRouter(); router.add(createFirstRule()); router.add(createServiceRule()); router.add(createEndpointRule()); - router.getTransport().getFlow().add(router.getTransport().getFlow().size()-1, new MockInterceptor("transport-log")); router.start(); + router.getTransport().getFlow().add(router.getTransport().getFlow().size()-1, new MockInterceptor("transport-log")); return router; } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java index d6f2257ba5..360aab9b0f 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java @@ -40,7 +40,7 @@ public class Http2ClientServerTest { private volatile Consumer requestAsserter; private volatile AbstractHttpHandler handler; private HttpClient hc; - private HttpRouter router; + private IRouter router; private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); @BeforeEach @@ -48,7 +48,7 @@ public void setup() throws IOException { connectionHashes.clear(); SSLParser sslParser = getSslParser(); - router = new HttpRouter(); + router = new TestRouter(); router.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3049), "localhost", 80); sp.setSslInboundParser(sslParser); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java index b6183d05e0..77ef30e3dc 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java @@ -36,13 +36,13 @@ public class HttpsKeepAliveTest { - private static HttpRouter server; + private static IRouter server; private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); @BeforeAll public static void startServer() throws IOException { - server = new HttpRouter(); + server = new TestRouter(); server.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(); sp.setPort(3063); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java index 62d95b74d7..58374fd8e3 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java @@ -14,8 +14,7 @@ package com.predic8.membrane.core.transport.ssl; import com.google.common.io.Resources; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.*; import com.predic8.membrane.core.resolver.ResolverMap; import org.jetbrains.annotations.NotNull; @@ -41,7 +40,7 @@ public class SSLContextTest { - private static Router router; + private static IRouter router; @BeforeAll public static void before() { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index 54b45e0670..ab00149919 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -40,8 +40,8 @@ public class SessionResumptionTest { private static Closeable tcpForwarder; - private static Router router1; - private static Router router2; + private static IRouter router1; + private static IRouter router2; private static SSLContext clientTLSContext; @BeforeAll @@ -75,8 +75,8 @@ private static SSLContext createClientTLSContext() { return new StaticSSLContext(sslParser, new ResolverMap(), "."); } - private static Router createTLSServer(int port) { - Router router = new HttpRouter(); + private static IRouter createTLSServer(int port) { + IRouter router = new HttpRouter(); router.getConfig().setHotDeploy(false); ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(port), null, 0); SSLParser sslInboundParser = new SSLParser(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java index 089e9162b1..7e3eb04ab5 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java @@ -17,7 +17,7 @@ import com.fasterxml.jackson.databind.ObjectMapper; import com.google.common.collect.ImmutableMap; import com.google.common.io.Resources; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.AbstractInterceptor; @@ -57,7 +57,7 @@ public class AcmeServerSimulator { private final AtomicReference theNonce = new AtomicReference<>(); private final HttpClient hc = new HttpClient(); private final AtomicBoolean challengeSucceeded = new AtomicBoolean(); - private HttpRouter router; + private IRouter router; private final AcmeCASimulation ca = new AcmeCASimulation(); private String certificates; private final AtomicReference orderStatus = new AtomicReference<>("pending"); @@ -70,8 +70,7 @@ public AcmeServerSimulator(int port, int challengePort, boolean actuallyPerformC } public void start() throws IOException { - router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + router = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(port), "localhost", 80); sp.getFlow().add(new AbstractInterceptor() { final ObjectMapper om = new ObjectMapper(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java index 7ae0998900..4d9b10d6d3 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeStepTest.java @@ -25,6 +25,7 @@ import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.ssl.*; import org.bouncycastle.jce.provider.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.io.*; @@ -35,6 +36,7 @@ import static com.predic8.membrane.core.interceptor.Outcome.*; import static com.predic8.membrane.core.transport.ssl.acme.Authorization.*; import static com.predic8.membrane.core.transport.ssl.acme.Order.*; +import static com.predic8.membrane.core.transport.ssl.acme.Order.ORDER_STATUS_VALID; import static org.junit.jupiter.api.Assertions.*; public class AcmeStepTest { @@ -47,18 +49,18 @@ public class AcmeStepTest { public final String baseUrl = "http://localhost:3050/directory"; @BeforeEach - public void init() throws IOException { + void init() throws IOException { sim = new AcmeServerSimulator(3050, 3052, true); sim.start(); } @AfterEach - public void done() { + void done() { sim.stop(); } @Test - public void all() throws Exception { + void all() throws Exception { Acme acme = new Acme(); acme.setExperimental(true); acme.setDirectoryUrl(baseUrl); @@ -66,8 +68,7 @@ public void all() throws Exception { acme.setContacts("mailto:jsmith@example.com"); acme.setAcmeSynchronizedStorage(new MemoryStorage()); - HttpRouter router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + var router = new TestRouter(); SSLParser sslParser = new SSLParser(); sslParser.setAcme(acme); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey(3051), "localhost", 80); @@ -81,9 +82,7 @@ public Outcome handleRequest(Exchange exc) { }); sp1.setSslInboundParser(sslParser); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey(3052), "localhost", 80); - AcmeHttpChallengeInterceptor acmeHttpChallengeInterceptor = new AcmeHttpChallengeInterceptor(); - acmeHttpChallengeInterceptor.setIgnorePort(true); - sp2.getFlow().add(acmeHttpChallengeInterceptor); + sp2.getFlow().add(getChallengeInterceptor()); router.add(sp1); router.add(sp2); router.start(); @@ -133,8 +132,7 @@ public Outcome handleRequest(Exchange exc) { ol = acmeClient.getOrder(accountUrl, ol.getLocation()); } - - assertEquals(Order.ORDER_STATUS_VALID, ol.getOrder().getStatus()); + assertEquals(ORDER_STATUS_VALID, ol.getOrder().getStatus()); acmeClient.getAsse().setCertChain(hosts, acmeClient.downloadCertificate(accountUrl, ol.getOrder().getCertificate())); @@ -162,6 +160,12 @@ public Outcome handleRequest(Exchange exc) { } + private static @NotNull AcmeHttpChallengeInterceptor getChallengeInterceptor() { + var acmeHttpChallengeInterceptor = new AcmeHttpChallengeInterceptor(); + acmeHttpChallengeInterceptor.setIgnorePort(true); + return acmeHttpChallengeInterceptor; + } + private static long waitAndCompute(long wait) throws InterruptedException { Thread.sleep(wait); if (wait < 500) diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index 38b8884e45..d2afa5cd2d 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -55,8 +55,8 @@ public class SoapProxyInvocationTest { """; - static Router gw; - static Router backend; + static IRouter gw; + static IRouter backend; @BeforeAll public static void setup() throws Exception { @@ -65,7 +65,7 @@ public static void setup() throws Exception { } private static void setupGateway() throws Exception { - gw = new HttpRouter(); + gw = new TestRouter(); gw.getConfig().setHotDeploy(false); gw.add(createCitiesSoapProxyGateway()); gw.add(createTwoServicesSOAPProxyGateway("ServiceA")); @@ -89,7 +89,7 @@ private static void setupGateway() throws Exception { } private static void setupBackend() throws Exception { - backend = new HttpRouter(); + backend = new TestRouter(); backend.add(createAServiceProxy()); backend.add(createCitiesServiceProxy()); backend.start(); diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java index 365dce5c2a..7bd0e00219 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java @@ -14,8 +14,7 @@ package com.predic8.membrane.integration.withinternet; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchangestore.MemoryExchangeStore; import com.predic8.membrane.core.proxies.ProxyRule; import com.predic8.membrane.core.proxies.ProxyRuleKey; @@ -29,7 +28,7 @@ class ProxySSLConnectionMethodTest { - private Router router; + private HttpRouter router; @BeforeEach void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java index 2d8a533b2d..8cc2693c0d 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java @@ -81,7 +81,7 @@ public Outcome handleRequest(Exchange exc) { router2.init(); } - private static @NotNull HTTPClientInterceptor getHttpClientInterceptor(Router router) { + private static @NotNull HTTPClientInterceptor getHttpClientInterceptor(IRouter router) { return (HTTPClientInterceptor) router.getTransport().getFlow().stream().filter(i -> i instanceof HTTPClientInterceptor).findFirst().get(); } diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java index 2750f74d80..e047013582 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java @@ -85,7 +85,8 @@ public Outcome handleRequest(Exchange exc) { AcmeHttpChallengeInterceptor acmeHttpChallengeInterceptor = new AcmeHttpChallengeInterceptor(); acmeHttpChallengeInterceptor.setIgnorePort(true); sp2.getFlow().add(acmeHttpChallengeInterceptor); - router.setRules(ImmutableList.of(sp1, sp2)); + router.add(sp1); + router.add(sp2); router.start(); try { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java index 6b6de443a1..09aa5352dc 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java @@ -13,8 +13,7 @@ limitations under the License. */ package com.predic8.membrane.integration.withoutinternet.interceptor; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.flow.*; import com.predic8.membrane.core.interceptor.log.*; import com.predic8.membrane.core.openapi.serviceproxy.*; @@ -30,7 +29,7 @@ public class OpenApiRewriteIntegrationTest { - private final Router r = new HttpRouter(); + private final IRouter r = new HttpRouter(); @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index 40c5c3b7c9..21f78603bd 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -25,8 +25,8 @@ public class SOAPProxyIntegrationTest { - private static Router router; - private static Router targetRouter; + private static IRouter router; + private static IRouter targetRouter; @BeforeAll public static void setup() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index 2784a18b42..87adea52b9 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -39,7 +39,7 @@ public abstract class OAuth2AuthorizationServerInterceptorBase { - static Router router; + static IRouter router; static Exchange exc; static OAuth2AuthorizationServerInterceptor oasi; static MembraneAuthorizationService mas; diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java index e7a530463c..bb88404abe 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java @@ -56,10 +56,10 @@ class LoadBalancingInterceptorFaultMonitoringStrategyTest { private static final Logger log = LoggerFactory.getLogger(LoadBalancingInterceptorFaultMonitoringStrategyTest.class.getName()); LoadBalancingInterceptor balancingInterceptor; - HttpRouter balancer; + IRouter balancer; // The simulation nodes - private final List nodes = new ArrayList<>(); + private final List nodes = new ArrayList<>(); private void setUp(TestingContext ctx) throws Exception { nodes.clear(); @@ -75,15 +75,17 @@ private void setUp(TestingContext ctx) throws Exception { } } - private HttpRouter createLoadBalancer() throws Exception { - HttpRouter r = new HttpRouter(); + private IRouter createLoadBalancer() throws Exception { + IRouter r = new TestRouter(); ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3054), "thomas-bayer.com", 80); balancingInterceptor = new LoadBalancingInterceptor(); balancingInterceptor.setName("Default"); sp3.getFlow().add(balancingInterceptor); r.add(sp3); - r.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(getHttpClientConfigurationWithRetries()); r.start(); + var client = r.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); + client.setHttpClientConfig(getHttpClientConfigurationWithRetries()); + client.init(); return r; } @@ -97,29 +99,29 @@ private HttpRouter createLoadBalancer() throws Exception { return config; } - private Router createRouterForNode(TestingContext ctx, int i) throws Exception { - HttpRouter r = new HttpRouter(); + private IRouter createRouterForNode(TestingContext ctx, int i) throws Exception { + var r = new TestRouter(); r.add(createServiceProxy(ctx, i)); r.start(); return r; } private @NotNull ServiceProxy createServiceProxy(TestingContext ctx, int i) { - ServiceProxy serviceProxy = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", (2000 + i)), "thomas-bayer.com", 80); - serviceProxy.getFlow().add(new AbstractInterceptor() { + ServiceProxy sp = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", (2000 + i)), "thomas-bayer.com", 80); + sp.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleResponse(Exchange exc) { exc.getResponse().getHeader().setConnection("close"); return CONTINUE; } }); - serviceProxy.getFlow().add(new RandomlyFailingDummyWebServiceInterceptor(ctx.successChance)); - return serviceProxy; + sp.getFlow().add(new RandomlyFailingDummyWebServiceInterceptor(ctx.successChance)); + return sp; } @AfterEach void tearDown() { - for (Router httpRouter : nodes) { + for (IRouter httpRouter : nodes) { try { httpRouter.shutdown(); } catch (Exception e) { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 9af59c8c2e..9b2934b68b 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -47,15 +47,15 @@ public abstract class LoadBalancingInterceptorTest { private DispatchingStrategy roundRobin; private DispatchingStrategy byThreadStrategy; private DispatchingStrategy priorityStrategy; - private HttpRouter service1; - private HttpRouter service2; - protected HttpRouter balancer; + private IRouter service1; + private IRouter service2; + protected IRouter balancer; @BeforeEach public void setUp() throws Exception { int port2k = 2000; int port3k = 3000; - service1 = new HttpRouter(); + service1 = new TestRouter(); mockInterceptor1 = new DummyWebServiceInterceptor(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", port2k), "dummy", 80); @@ -70,7 +70,7 @@ public Outcome handleResponse(Exchange exc) { service1.add(sp1); service1.start(); - service2 = new HttpRouter(); + service2 = new TestRouter(); mockInterceptor2 = new DummyWebServiceInterceptor(); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", port3k), "dummy", 80); @@ -85,15 +85,15 @@ public Outcome handleResponse(Exchange exc) { service2.add(sp2); service2.start(); - balancer = new HttpRouter(); + balancer = new TestRouter(); ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3054), "dummy", 80); balancingInterceptor = new LoadBalancingInterceptor(); balancingInterceptor.setName("Default"); sp3.getFlow().add(balancingInterceptor); balancer.add(sp3); - enableFailOverOn5XX(); balancer.start(); + enableFailOverOn5XX(); lookupBalancer(balancer, "Default").up("Default", "localhost", port2k); lookupBalancer(balancer, "Default").up("Default", "localhost", port3k); @@ -104,7 +104,9 @@ public Outcome handleResponse(Exchange exc) { } private void enableFailOverOn5XX() { - getInterceptors(balancer.getTransport().getFlow(), HTTPClientInterceptor.class).getLast().setFailOverOn5XX(true); + var clientInterceptor = balancer.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); + clientInterceptor.setFailOverOn5XX(true); + clientInterceptor.init(); // Copies the config into the HttpClient. Needed because router.start() is already called } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index f9aa0032a6..78a68d8afa 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -37,7 +37,7 @@ public class MultipleLoadBalancersTest { protected static LoadBalancingInterceptor balancingInterceptor2; private static DispatchingStrategy roundRobinStrategy1; private static DispatchingStrategy roundRobinStrategy2; - protected static HttpRouter balancer; + protected static IRouter balancer; @AfterAll static void tearDown() throws Exception { @@ -50,12 +50,12 @@ static void tearDown() throws Exception { private static class MockService { final int port; - final HttpRouter router; + final IRouter router; final DummyWebServiceInterceptor mockInterceptor1; MockService(int port) throws Exception { this.port = port; - router = new HttpRouter(); + router = new TestRouter(); mockInterceptor1 = new DummyWebServiceInterceptor(); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), "thomas-bayer.com", 80); @@ -87,7 +87,7 @@ static void setUp() throws Exception { service11 = new MockService(2011); service12 = new MockService(2012); - balancer = new HttpRouter(); + balancer = new TestRouter(); balancingInterceptor1 = createBalancingInterceptor(3054, "Default"); balancingInterceptor2 = createBalancingInterceptor(7001, "Balancer2"); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java index 15732654e3..1b24293393 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java @@ -29,7 +29,7 @@ public class WsaEndpointRewriterInterceptorTest { @BeforeEach public void setUp() throws Exception { - Router router = new HttpRouter(); + IRouter router = new HttpRouter(); router.init(); rewriter = new WsaEndpointRewriterInterceptor(); rewriter.init(router); From 1afe5bef89ffd169be0bd7f08c0618331c1c73b0 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 18:31:49 +0100 Subject: [PATCH 33/40] refactor: remove `IRouter` interface, replace with `DefaultRouter` or specialized implementations, and align related components and tests --- .../predic8/membrane/core/AbstractRouter.java | 18 +- .../predic8/membrane/core/DefaultConfig.java | 2 +- .../predic8/membrane/core/DefaultRouter.java | 601 ++++++++++++++++++ .../membrane/core/DummyTestRouter.java | 230 +++++++ .../com/predic8/membrane/core/HttpRouter.java | 212 +----- .../com/predic8/membrane/core/IRouter.java | 80 --- .../com/predic8/membrane/core/Router.java | 576 +---------------- .../membrane/core/RouterBootstrap.java | 20 +- .../predic8/membrane/core/RuleManager.java | 4 +- .../membrane/core/RuleReinitializer.java | 4 +- .../predic8/membrane/core/cli/RouterCLI.java | 16 +- .../AbstractPersistentExchangeStore.java | 3 +- .../ElasticSearchExchangeStore.java | 2 +- .../core/exchangestore/ExchangeStore.java | 2 +- .../exchangestore/MongoDBExchangeStore.java | 2 +- .../graphql/GraphQLoverHttpValidator.java | 4 +- .../core/interceptor/AbstractInterceptor.java | 8 +- .../core/interceptor/ApisJsonInterceptor.java | 2 +- .../core/interceptor/FlowController.java | 4 +- .../core/interceptor/Interceptor.java | 6 +- .../acl/AbstractClientAddress.java | 6 +- .../core/interceptor/acl/AccessControl.java | 6 +- .../acl/AccessControlInterceptor.java | 2 +- .../membrane/core/interceptor/acl/Any.java | 2 +- .../core/interceptor/acl/Hostname.java | 4 +- .../membrane/core/interceptor/acl/Ip.java | 2 +- .../core/interceptor/acl/Resource.java | 6 +- .../administration/AdminPageBuilder.java | 4 +- .../interceptor/administration/RuleUtil.java | 2 +- .../extractors/ApiKeyExpressionExtractor.java | 2 +- .../apikey/extractors/ApiKeyExtractor.java | 2 +- .../apikey/stores/ApiKeyFileStore.java | 2 +- .../apikey/stores/ApiKeyStore.java | 4 +- .../apikey/stores/JDBCApiKeyStore.java | 4 +- .../apikey/stores/MongoDBApiKeyStore.java | 2 +- .../session/CachingUserDataProvider.java | 2 +- .../CustomStatementJdbcUserDataProvider.java | 4 +- .../session/EmailTokenProvider.java | 2 +- .../session/EmptyTokenProvider.java | 2 +- .../session/FileUserDataProvider.java | 2 +- .../session/JdbcUserDataProvider.java | 4 +- .../session/JwtSessionManager.java | 2 +- .../session/LDAPUserDataProvider.java | 2 +- .../authentication/session/LoginDialog.java | 2 +- .../session/SessionManager.java | 2 +- .../session/StaticUserDataProvider.java | 12 +- .../session/TOTPTokenProvider.java | 2 +- .../session/TelekomSMSTokenProvider.java | 2 +- .../authentication/session/TokenProvider.java | 2 +- .../session/UnifyingUserDataProvider.java | 2 +- .../session/UserDataProvider.java | 2 +- .../WhateverMobileSMSTokenProvider.java | 2 +- .../xen/XenAuthenticationInterceptor.java | 6 +- .../balancer/BalancerHealthMonitor.java | 6 +- .../interceptor/balancer/BalancerUtil.java | 30 +- .../balancer/ByThreadStrategy.java | 2 +- .../balancer/DispatchingStrategy.java | 2 +- .../balancer/PolyglotSessionIdExtractor.java | 2 +- .../balancer/PriorityStrategy.java | 2 +- .../balancer/RoundRobinStrategy.java | 2 +- .../balancer/SessionIdExtractor.java | 2 +- .../FaultMonitoringStrategy.java | 2 +- .../interceptor/cache/CacheInterceptor.java | 4 +- .../flow/AbstractFlowInterceptor.java | 2 +- .../core/interceptor/flow/choice/Case.java | 2 +- .../flow/choice/InterceptorContainer.java | 4 +- .../GraalVMJavascriptLanguageAdapter.java | 2 +- .../javascript/LanguageAdapter.java | 7 +- .../RhinoJavascriptLanguageAdapter.java | 2 +- .../core/interceptor/oauth2/ClaimList.java | 2 +- .../core/interceptor/oauth2/ClientList.java | 2 +- .../interceptor/oauth2/ConsentPageFile.java | 2 +- .../interceptor/oauth2/StaticClientList.java | 2 +- .../AuthorizationService.java | 5 +- .../DynamicRegistration.java | 4 +- .../BearerJwtTokenGenerator.java | 2 +- .../tokengenerators/BearerTokenGenerator.java | 2 +- .../tokengenerators/TokenGenerator.java | 2 +- .../oauth2client/rf/SessionAuthorizer.java | 4 +- .../oauth2server/LoginDialog2.java | 2 +- .../schemavalidation/SchematronValidator.java | 2 +- .../server/WebServerInterceptor.java | 2 +- .../session/InMemorySessionManager.java | 2 +- .../session/JwtSessionManager.java | 2 +- .../session/MemcachedSessionManager.java | 2 +- .../session/RedisSessionManager.java | 2 +- .../interceptor/session/SessionManager.java | 2 +- .../interceptor/xslt/XSLTTransformer.java | 2 +- .../predic8/membrane/core/jmx/JmxRouter.java | 6 +- .../membrane/core/jmx/JmxServiceProxy.java | 6 +- .../core/kubernetes/KubernetesWatcher.java | 4 +- .../core/lang/ExchangeExpression.java | 4 +- .../membrane/core/lang/ScriptingUtils.java | 2 +- .../lang/groovy/GroovyExchangeExpression.java | 2 +- .../serviceproxy/OpenAPIPublisher.java | 8 +- .../serviceproxy/OpenAPIRecordFactory.java | 4 +- .../membrane/core/proxies/AbstractProxy.java | 4 +- .../core/proxies/AbstractServiceProxy.java | 2 +- .../predic8/membrane/core/proxies/Proxy.java | 2 +- .../membrane/core/proxies/SOAPProxy.java | 3 +- .../membrane/core/proxies/SSLProxy.java | 4 +- .../membrane/core/resolver/ResolverMap.java | 2 +- .../membrane/core/resolver/RuleResolver.java | 4 +- .../router/hotdeploy/DefaultHotDeployer.java | 4 +- .../core/router/hotdeploy/HotDeployer.java | 2 +- .../router/hotdeploy/NullHotDeployer.java | 2 +- .../RouterIpResolverInterceptor.java | 2 +- .../core/sslinterceptor/SSLInterceptor.java | 2 +- .../membrane/core/transport/Transport.java | 7 +- .../core/transport/http/HttpTransport.java | 8 +- .../ws/WebSocketInterceptorInterface.java | 2 +- .../interceptors/WebSocketLogInterceptor.java | 2 +- .../WebSocketSpringInterceptor.java | 2 +- .../WebSocketStompReassembler.java | 2 +- .../core/util/jdbc/AbstractJdbcSupport.java | 6 +- .../membrane/AbstractTestWithRouter.java | 2 +- ...RouterTest.java => DefaultRouterTest.java} | 8 +- .../com/predic8/membrane/core/MockRouter.java | 7 +- .../core/RuleManagerUriTemplateTest.java | 3 +- .../com/predic8/membrane/core/SimpleTest.java | 2 +- .../com/predic8/membrane/core/TestRouter.java | 32 +- .../com/predic8/membrane/core/UnitTests.java | 1 - .../predic8/membrane/core/acl/ACLTest.java | 12 +- .../core/azure/AzureDnsApiSimulator.java | 2 +- .../config/ReadRulesConfigurationTest.java | 2 +- ...ulesWithInterceptorsConfigurationTest.java | 2 +- .../core/config/SpringReferencesTest.java | 2 +- .../GraphQLProtectionInterceptorTest.java | 6 +- .../graphql/GraphQLoverHttpValidatorTest.java | 2 +- .../membrane/core/http/ChunkedBodyTest.java | 10 +- .../membrane/core/http/Http10Test.java | 4 +- .../membrane/core/http/Http11Test.java | 4 +- .../membrane/core/http/MethodTest.java | 2 +- .../interceptor/AdjustContentLengthTest.java | 2 +- .../interceptor/ApisJsonInterceptorTest.java | 6 +- .../DispatchingInterceptorTest.java | 2 +- .../HTTPClientInterceptorTest.java | 6 +- .../interceptor/InternalInvocationTest.java | 2 +- .../RegExReplaceInterceptorTest.java | 2 +- .../core/interceptor/UserFeatureTest.java | 2 +- .../acl/AccessControlParserTest.java | 4 +- .../core/interceptor/acl/HostnameTest.java | 4 +- .../adminapi/AdminApiInterceptorTest.java | 2 +- .../apikey/ApiKeysInterceptorTest.java | 8 +- .../apikey/stores/ApiKeyFileStoreTest.java | 2 +- .../BasicAuthenticationInterceptorTest.java | 2 +- .../balancer/ClusterBalancerTest.java | 6 +- .../LoadBalancingWithClusterManagerTest.java | 16 +- .../PolyglotSessionIdExtractorTest.java | 4 +- .../ConditionalEvaluationTestContext.java | 2 +- .../flow/IfInterceptorSpELTest.java | 4 +- .../AbstractInterceptorFlowTest.java | 4 +- .../flow/invocation/FlowTestInterceptors.java | 2 +- ...InternalServiceRoutingInterceptorTest.java | 2 +- .../FormValidationInterceptorTest.java | 2 +- .../groovy/GroovyInterceptorTest.java | 4 +- .../javascript/JavascriptInterceptorTest.java | 2 +- .../json/JsonProtectionInterceptorTest.java | 2 +- .../jwt/JwtAuthInterceptorTest.java | 4 +- .../jwt/JwtAuthInterceptorUnitTests.java | 4 +- .../AbstractSetHeaderInterceptorTest.java | 4 +- .../AbstractSetPropertyInterceptorTest.java | 5 +- .../lang/SetBodyInterceptorTest.java | 6 +- .../oauth2/OAuth2RedirectTest.java | 10 +- .../MembraneAuthorizationServiceTest.java | 2 +- .../oauth2/client/AuthServerMock.java | 4 +- .../OAuth2ResourceErrorForwardingTest.java | 4 +- .../client/OAuth2ResourceRpIniLogoutTest.java | 4 +- .../oauth2/client/OAuth2ResourceTest.java | 4 +- .../oauth2/client/b2c/B2CMembrane.java | 2 +- .../client/b2c/MockAuthorizationServer.java | 4 +- .../OpenTelemetryInterceptorTest.java | 4 +- .../ReverseProxyingInterceptorTest.java | 2 +- .../rewrite/RewriteInterceptorTest.java | 2 +- .../interceptor/rewrite/RewriterTest.java | 2 +- .../schemavalidation/SOAPFaultTest.java | 2 +- .../SOAPMessageValidatorInterceptorTest.java | 4 +- .../ValidatorInterceptorTest.java | 4 +- .../server/WSDLPublisherInterceptorTest.java | 2 +- .../server/WebServerInterceptorTest.java | 9 +- .../session/FakeSyncSessionStoreManager.java | 2 +- .../session/SessionInterceptorTest.java | 2 +- .../shadowing/ShadowingInterceptorTest.java | 8 +- .../soap/SoapAndInternalProxyTest.java | 2 +- .../templating/StaticInterceptorTest.java | 6 +- .../templating/TemplateInterceptorTest.java | 4 +- .../xml/Json2XmlInterceptorTest.java | 2 +- .../xml/Xml2JsonInterceptorTest.java | 2 +- .../XMLProtectionInterceptorTest.java | 2 +- .../interceptor/xslt/XSLTInterceptorTest.java | 6 +- .../client/KubernetesClientTest.java | 2 +- .../lang/AbstractExchangeExpressionTest.java | 4 +- .../lang/TemplateExchangeExpressionTest.java | 4 +- .../SetPropertyInterceptorXPathTest.java | 3 +- .../serviceproxy/APIProxyOpenAPITest.java | 4 +- .../APIProxySpringConfigurationTest.java | 4 +- .../AbstractProxySpringConfigurationTest.java | 6 +- .../serviceproxy/ApiDocsInterceptorTest.java | 8 +- .../serviceproxy/OpenAPI31ReferencesTest.java | 2 +- .../openapi/serviceproxy/OpenAPI31Test.java | 5 +- .../serviceproxy/OpenAPIInterceptorTest.java | 4 +- .../OpenAPIPublisherInterceptorTest.java | 2 +- .../OpenAPIRecordFactoryTest.java | 2 +- .../serviceproxy/OpenAPIRecordTest.java | 4 +- .../openapi/serviceproxy/RewriteTest.java | 2 +- .../openapi/serviceproxy/Swagger20Test.java | 5 +- .../XMembraneExtensionSecurityTest.java | 2 +- .../core/openapi/util/OpenAPITestUtils.java | 2 +- .../exceptions/ExceptionInterceptorTest.java | 2 +- .../AbstractSecurityValidatorTest.java | 4 +- .../BasicAuthSecurityValidationTest.java | 4 +- ...WTInterceptorAndSecurityValidatorTest.java | 8 +- .../security/OAuth2SecurityValidatorTest.java | 2 +- .../core/proxies/APIProxyKeyTest.java | 2 +- .../core/proxies/InternalProxyTest.java | 2 +- .../membrane/core/proxies/ProxyRuleTest.java | 2 +- .../membrane/core/proxies/ProxySSLTest.java | 12 +- .../membrane/core/proxies/ProxyTest.java | 2 +- .../membrane/core/proxies/SOAPProxyTest.java | 6 +- ...SOAPProxyWSDLPublisherInterceptorTest.java | 2 +- .../core/proxies/ServiceProxyTest.java | 2 +- .../ServiceProxyWSDLInterceptorsTest.java | 2 +- .../core/proxies/TargetURLExpressionTest.java | 4 +- .../proxies/UnavailableSoapProxyTest.java | 10 +- .../membrane/core/resolver/ResolverTest.java | 2 +- .../core/security/JWTSecuritySchemeTest.java | 2 +- .../core/security/KeyStoreUtilTest.java | 4 +- .../transport/http/BoundConnectionTest.java | 2 +- .../http/ConcurrentConnectionLimitTest.java | 2 +- .../core/transport/http/ConnectionTest.java | 2 +- .../transport/http/Http2DowngradeTest.java | 2 +- .../transport/http/HttpKeepAliveTest.java | 2 +- .../core/transport/http/HttpTimeoutTest.java | 2 +- .../transport/http/HttpTransportTest.java | 2 +- .../http/IllegalCharactersInURLTest.java | 2 +- .../transport/http/ServiceInvocationTest.java | 6 +- .../client/HttpClientConfigurationTest.java | 2 +- .../http2/Http2ClientServerTest.java | 2 +- .../transport/ssl/HttpsKeepAliveTest.java | 3 +- .../core/transport/ssl/SSLContextTest.java | 4 +- .../transport/ssl/SessionResumptionTest.java | 8 +- .../ssl/acme/AcmeServerSimulator.java | 2 +- .../core/ws/SoapProxyInvocationTest.java | 4 +- .../JDBCApiKeyStorePerformanceTest.java | 4 +- .../predic8/membrane/integration/Util.java | 8 +- .../withinternet/LargeBodyTest.java | 40 +- .../OpenAPIRecordFactoryIntegrationTest.java | 2 +- .../ProxySSLConnectionMethodTest.java | 8 +- .../withinternet/ViaProxyTest.java | 69 +- .../RewriteInterceptorIntegrationTest.java | 53 +- ...tedMemoryExchangeStoreIntegrationTest.java | 48 +- .../MassivelyParallelTest.java | 15 +- .../withoutinternet/SessionManagerTest.java | 127 ++-- .../interceptor/AcmeRenewTest.java | 3 +- .../OpenApiRewriteIntegrationTest.java | 9 +- .../REST2SOAPInterceptorIntegrationTest.java | 9 +- .../interceptor/SOAPProxyIntegrationTest.java | 18 +- ...th2AuthorizationServerInterceptorBase.java | 4 +- .../interceptor/oauth2/OAuth2Test.java | 8 +- ...nterceptorFaultMonitoringStrategyTest.java | 12 +- .../LoadBalancingInterceptorTest.java | 7 +- .../MultipleLoadBalancersTest.java | 6 +- .../WsaEndpointRewriterInterceptorTest.java | 2 +- .../proxy-rules-test-monitor-beans.xml | 2 +- .../examples/ConfigSerializationTest.java | 4 +- .../env/HelpLinkExistenceTest.java | 5 +- .../com/predic8/membrane/load/LoadTester.java | 2 +- .../MembraneServletContextListener.java | 4 +- .../predic8/membrane/servlet/RouterUtil.java | 10 +- .../servlet/embedded/MembraneServlet.java | 4 +- 270 files changed, 1578 insertions(+), 1528 deletions(-) create mode 100644 core/src/main/java/com/predic8/membrane/core/DefaultRouter.java create mode 100644 core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java delete mode 100644 core/src/main/java/com/predic8/membrane/core/IRouter.java rename core/src/test/java/com/predic8/membrane/core/{RouterTest.java => DefaultRouterTest.java} (96%) diff --git a/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java index d93362826d..9966c60973 100644 --- a/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java @@ -1,11 +1,25 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core; import com.predic8.membrane.core.proxies.*; import org.slf4j.*; -public abstract class AbstractRouter implements IRouter { +public abstract class AbstractRouter implements Router { - private static final Logger log = LoggerFactory.getLogger(Router.class); + private static final Logger log = LoggerFactory.getLogger(DefaultRouter.class); protected void initProxies() { log.debug("Initializing proxies."); diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultConfig.java b/core/src/main/java/com/predic8/membrane/core/DefaultConfig.java index 750063b175..8b3bf684d9 100644 --- a/core/src/main/java/com/predic8/membrane/core/DefaultConfig.java +++ b/core/src/main/java/com/predic8/membrane/core/DefaultConfig.java @@ -66,7 +66,7 @@ private void defineRouter(BeanDefinitionRegistry beanDefinitionRegistry) { if (!beanDefinitionRegistry.containsBeanDefinition("router")) { beanDefinitionRegistry.registerBeanDefinition( "router", - root().clazz(Router.class).addRef("transport", "transport").addRef("exchangeStore", "memoryExchangeStore").build()); + root().clazz(DefaultRouter.class).addRef("transport", "transport").addRef("exchangeStore", "memoryExchangeStore").build()); } } diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java new file mode 100644 index 0000000000..9fa3dd7db7 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java @@ -0,0 +1,601 @@ +/* Copyright 2009, 2012 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.annot.*; +import com.predic8.membrane.annot.beanregistry.*; +import com.predic8.membrane.core.RuleManager.*; +import com.predic8.membrane.core.config.spring.*; +import com.predic8.membrane.core.exchangestore.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.interceptor.administration.*; +import com.predic8.membrane.core.jmx.*; +import com.predic8.membrane.core.kubernetes.*; +import com.predic8.membrane.core.kubernetes.client.*; +import com.predic8.membrane.core.openapi.*; +import com.predic8.membrane.core.openapi.serviceproxy.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.router.hotdeploy.*; +import com.predic8.membrane.core.transport.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.http.client.*; +import com.predic8.membrane.core.util.*; +import org.slf4j.*; +import org.springframework.beans.*; +import org.springframework.beans.factory.*; +import org.springframework.context.*; +import org.springframework.context.support.*; + +import javax.annotation.concurrent.*; +import java.io.*; +import java.util.*; + +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; +import static com.predic8.membrane.core.jmx.JmxExporter.*; +import static com.predic8.membrane.core.util.DLPUtil.*; + +/* + Responsibilities: + - Start and stop Membrane + - Start, stop internal services + - Control lifecycle of proxies + + TODO: + - ADR: First start router than init and add proxies or first init proxies and add them later? + + ADR: + - The Router is responsible for the lifecycle of the proxies + - Ports are opened in start() + - init() + - does not open ports + - inits the proxies + - In sequence as added or reverse or not defined? + - new Router(), add(proxy) init() start() + - add(proxy) could be called any time + - If router is started port will be opened if needed by the proxy + - What if a proxy needs to make a call to another proxy during init(Tests: e.g. B2C) + - Delete addProxyAndOpenPortIfNew() from RuleManager + + HTTPRouter: + - Purpose? Test? + + - JMX + - Beans added after Router.start() should also be exported as JMS beans + + */ + +/** + * @description

+ * Membrane API Gateway's main object. + *

+ *

+ * The router is a Spring Lifecycle object: It is automatically started and stopped according to the + * Lifecycle of the Spring Context containing it. In Membrane's standard setup + * Membrane itself controls the creation of the Spring Context and its Lifecycle. + *

+ *

+ * In this case, the router is hot deployable: It can monitor proxies.xml, the Spring + * configuration file, for changes and reinitialize the Spring Context, when a change is detected. Note + * that, during the Spring Context restart, the router object itself along with almost all other Membrane + * objects (interceptors, etc.) will be recreated. + *

+ *

Router must be a singleton with just one instance. Membrane should never have more than one router.

+ * @topic 1. Proxies and Flow + */ +@MCMain( + outputPackage = "com.predic8.membrane.core.config.spring", + outputName = "router-conf.xsd", + targetNamespace = "http://membrane-soa.org/proxies/1/") +@MCElement(name = "router") +public class DefaultRouter extends AbstractRouter implements ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver { + + private static final Logger log = LoggerFactory.getLogger(DefaultRouter.class); + + private ApplicationContext beanFactory; + + protected BeanRegistry registry; + + // + // Configuration + // + private String id; + private String baseLocation; + + private Configuration config = new Configuration(); + + // + // Components + // + protected Transport transport; + + private final TimerManager timerManager = new TimerManager(); + private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); + private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); + protected ResolverMap resolverMap; + + protected final Statistics statistics = new Statistics(); + + private final Object lock = new Object(); + + @GuardedBy("lock") + private boolean running; + + @GuardedBy("lock") + private boolean initialized; + + /** + * HotDeployer for changes on the XML configuration file. Does not cover YAML. + * Not synchronized, since only modified during initialization + * Initialized with NullHotDeployer to avoid NPEs + */ + private HotDeployer hotDeployer = new DefaultHotDeployer(); + + private RuleReinitializer reinitializer; + + public DefaultRouter() { + log.debug("Creating new router."); + resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); + resolverMap.addRuleResolver(this); + } + + // + // Initialization + // + + /** + * Initializes the {@code Router} + * - by setting up its associated components. + * - calling init() on each of its {@link Proxy} instances. + *

+ * This method ensures that the {@code Router} and its dependencies are prepared for operation. + * But it does not start the router itself. Use {@link #start()} to start the router. + * If start() is called a separate call to init() is not needed. + * The init() is useful for testing without the expensive start() call. + */ + public void init() { + log.debug("Initializing."); + + // TODO: Temporary guard, to check correct behaviour, remove later + synchronized (lock) { + if (initialized) + throw new IllegalStateException("Router already initialized."); + } + + getRegistry().registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); + + getRegistry().registerIfAbsent(ResolverMap.class, () -> { + ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); + rs.addRuleResolver(this); + return rs; + }); + + getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); + getRegistry().registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(this); + return rm; + }); + getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); + + // Transport last + if (transport == null) { + transport = new HttpTransport(); + } + transport.init(this); + + initProxies(); + + synchronized (lock) { + initialized = true; + } + reinitializer = new RuleReinitializer(this); // Bean + } + + /** + * Starts the main processing logic of the application. + * This method initializes essential components, validates the configuration, + * and starts background services required for the application's functionality. + * Key responsibilities: + * - Initializes the application if it hasn't been initialized yet. + * - Opens TCP ports + */ + @Override + public void start() { + log.debug("Starting."); + displayTraceWarning(); + + synchronized (lock) { + if (!initialized) + init(); + } + + try { + + getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); + + startJmx(); + getRuleManager().openPorts(); + + hotDeployer.start(this); + + if (config.getRetryInitInterval() > 0) + reinitializer.start(); + } catch (DuplicatePathException e) { + handleDuplicateOpenAPIPaths(e); + } catch (OpenAPIParsingException e) { + handleOpenAPIParsingException(e); + } catch (Exception e) { + log.error("Could not start router.", e); + if (e instanceof RuntimeException) + throw (RuntimeException) e; + throw new RuntimeException(e); + } + + synchronized (lock) { + running = true; + } + } + + /* + TODO: + - Why is the source hardcoded here. + - Why does it matter? + */ + public Collection getRules() { + log.debug("Getting rules."); + return getRuleManager().getRulesBySource(MANUAL); // TODO: Source? + } + + @MCChildElement(order = 3) + public void setRules(Collection proxies) { + getRuleManager().removeAllRules(); + for (Proxy proxy : proxies) + getRuleManager().addProxy(proxy, RuleDefinitionSource.SPRING); + } + + @SuppressWarnings("NullableProblems") + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + beanFactory = applicationContext; + if (applicationContext instanceof BaseLocationApplicationContext) + setBaseLocation(((BaseLocationApplicationContext) applicationContext).getBaseLocation()); + } + + public RuleManager getRuleManager() { + return getRegistry().registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(this); + return rm; + }); + } + + public void setRuleManager(RuleManager ruleManager) { + log.debug("Setting ruleManager."); + ruleManager.setRouter(this); + getRegistry().register("ruleManager", ruleManager); + } + + public ExchangeStore getExchangeStore() { + return getRegistry().getBean(ExchangeStore.class).orElseThrow(); + } + + /** + * @description Spring Bean ID of an {@link ExchangeStore}. The exchange store will be used by this router's + * components ({@link AdminConsoleInterceptor}, {@link ExchangeStoreInterceptor}, etc.) by default, if + * no other exchange store is explicitly set to be used by them. + * @default create a {@link LimitedMemoryExchangeStore} limited to the size of 1 MB. + */ + @MCAttribute + public void setExchangeStore(ExchangeStore exchangeStore) { + getRegistry().register("exchangeStore", exchangeStore); + } + + @Override + public Transport getTransport() { + return transport; + } + + /** + * @description Used to override the default 'transport' chain. The transport chain is the one global + * interceptor chain called *for every* incoming HTTP Exchanges. The transport chain uses <userFeature/> + * to call 'down' to a specific <api/>, <serviceProxy/> or similar. The default transport chain + * is shown in proxies-full-sample.xml . + */ + @MCChildElement(order = 1, allowForeign = true) + public void setTransport(Transport transport) { + this.transport = transport; + } + + public HttpClientConfiguration getHttpClientConfig() { + return getResolverMap().getHTTPSchemaResolver().getHttpClientConfig(); + } + + /** + * @description A 'global' (per router) <httpClientConfig>. This instance is used everywhere + * a HTTP Client is used. Usually, in every specific place, you can still configure a local + * <httpClientConfig> (with higher precedence compared to this global instance). + */ + @MCChildElement() + public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { + getResolverMap().getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); + } + + public DNSCache getDnsCache() { + return getRegistry().getBean(DNSCache.class).orElseThrow(); // TODO + } + + public ResolverMap getResolverMap() { + return resolverMap; + } + + /** + * Closes all ports (if any were opened) and waits for running exchanges to complete. + *

+ * When running as an embedded servlet, this has no effect. + */ + public void shutdown() { + if (transport != null) + transport.closeAll(); + timerManager.shutdown(); + } + + /** + * Adds a proxy to the router and initializes it. + * + * TODO: Should we sync running cause a different Thread might call add? + * + * @param proxy + * @throws IOException + */ + public void add(Proxy proxy) throws IOException { + log.debug("Adding proxy {}.", proxy.getName()); + RuleManager ruleManager = getRuleManager(); + + if (running && proxy instanceof SSLableProxy sp) { + sp.init(this); + ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); + } else { + ruleManager.addProxy(proxy, MANUAL); + } + + } + + private void startJmx() { + if (beanFactory == null) + return; + + try { + JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); + //exporter.removeBean(prefix + jmxRouterName); + exporter.addBean("io.membrane-api:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); + exporter.initAfterBeansAdded(); + } catch (NoSuchBeanDefinitionException ignored) { + // If bean is not available do not init jmx + } + } + + @Override + public void stop() { + getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::stop); + hotDeployer.stop(); + shutdown(); + + synchronized (lock) { + running = false; + lock.notifyAll(); + } + } + + @Override + public boolean isRunning() { + synchronized (lock) { + return running; + } + } + + public String getBaseLocation() { + return baseLocation; + } + + public void setBaseLocation(String baseLocation) { + this.baseLocation = baseLocation; + } + + public ApplicationContext getBeanFactory() { + return beanFactory; + } + + public boolean isProduction() { + return config.isProduction(); + } + + public Statistics getStatistics() { + return statistics; + } + + @SuppressWarnings("NullableProblems") + @Override + public void setBeanName(String s) { + this.id = s; + } + + /** + * @description Sets a global chain that applies to all requests and responses. + */ + @MCChildElement(order = 2) + public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { + getRegistry().register("globalInterceptor", globalInterceptor); + } + + public String getId() { + return id; + } + + /** + * waits until the router has shut down + */ + public void waitFor() { + synchronized (lock) { + while (running) { + try { + lock.wait(); + } catch (InterruptedException ignored) { + } + } + } + } + + public TimerManager getTimerManager() { + return timerManager; + } + + public KubernetesClientFactory getKubernetesClientFactory() { + return kubernetesClientFactory; + } + + public HttpClientFactory getHttpClientFactory() { + return httpClientFactory; + } + + public FlowController getFlowController() { + return getRegistry().registerIfAbsent(FlowController.class, () -> new FlowController(this)); + } + + public void handleAsynchronousInitializationResult(boolean success) { + log.debug("Asynchronous initialization finished."); + if (!success && !config.isRetryInit()) + System.exit(1); + ApiInfo.logInfosAboutStartedProxies(getRuleManager()); + } + + @Override + public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { + log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(), bean); + if (bean instanceof GlobalInterceptor) { + return; + } + + if (!(bean instanceof Proxy newProxy)) { + throw new IllegalArgumentException("Bean must be a Proxy instance, but got: " + bean.getClass().getName()); + } + + if (newProxy.getName() == null) + newProxy.setName(bdc.bd().getName()); + + // TODO: Comment or code Should be deleted before merge + // Comment is kept for discussion only. + // + // init() in Proxies was called twice, here and in Router.initRemainingRules + // We should only keep one place. Which one is up to discussion + // + // try { + // newProxy.init(this); + // } catch (ConfigurationException e) { + // SpringConfigurationErrorHandler.handleRootCause(e, log); + // throw e; + // } catch (Exception e) { + // throw new RuntimeException("Could not init rule.", e); + // } + + if (bdc.action().isAdded()) { + add(newProxy); + } else if (bdc.action().isDeleted()) + getRuleManager().removeRule((Proxy) oldBean); + else if (bdc.action().isModified()) { + getRuleManager().replaceRule((Proxy) oldBean, newProxy); + } + } + + @Override + public boolean isActivatable(BeanDefinition bd) { + return Proxy.class.isAssignableFrom(new GrammarAutoGenerated().getElement(bd.getKind())); + } + + public AbstractRefreshableApplicationContext getRef() { + if (beanFactory instanceof AbstractRefreshableApplicationContext bf) + return bf; + throw new RuntimeException("ApplicationContext is not a AbstractRefreshableApplicationContext. Please set ."); + } + + @Override + public void setRegistry(BeanRegistry registry) { + this.registry = registry; + } + + public BeanRegistry getRegistry() { + if (registry == null) + registry = new BeanRegistryImplementation(null, this, null); + return registry; + } + + public void applyConfiguration(Configuration configuration) { + hotDeployer = configuration.isHotDeploy() ? new DefaultHotDeployer() : new NullHotDeployer(); + this.config = configuration; + } + + public URIFactory getUriFactory() { + return config.getUriFactory(); + } + + /** + * Sets the configuration object for this router. + * Only used for xml + * + * @param config the configuration object + */ + @MCChildElement(order = -1) + public void setConfig(Configuration config) { + this.config = config; + } + + public Configuration getConfig() { + return config; + } + + public RuleReinitializer getReinitializer() { + return reinitializer; + } + + private static void handleOpenAPIParsingException(OpenAPIParsingException e) { + System.err.printf(""" + ================================================================================================ + + Configuration Error: Could not read or parse OpenAPI Document + + Reason: %s + + Location: %s + + Have a look at the proxies.xml file. + """, e.getMessage(), e.getLocation()); + throw new ExitException(); + } + + private static void handleDuplicateOpenAPIPaths(DuplicatePathException e) { + System.err.printf(""" + ================================================================================================ + + Configuration Error: Several OpenAPI Documents share the same path! + + An API routes and validates requests according to the path of the OpenAPI's servers.url fields. + Within one API the same path should be used only by one OpenAPI. Change the paths or place + openapi-elements into separate api-elements. + + Shared path: %s + %n""", e.getPath()); + throw new ExitException(); + } +} \ No newline at end of file diff --git a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java new file mode 100644 index 0000000000..a688768d04 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java @@ -0,0 +1,230 @@ +/* Copyright 2009, 2011, 2012 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.core.exchangestore.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.kubernetes.client.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.http.client.*; +import com.predic8.membrane.core.util.*; +import org.springframework.context.*; + +import java.io.*; +import java.util.*; + +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; + +public class DummyTestRouter extends AbstractRouter { + + private FlowController flowController = new FlowController(this); + private ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); + private RuleManager ruleManager = new RuleManager(); + + private final TimerManager timerManager = new TimerManager(); + private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); + private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); + private ResolverMap resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); + + private HttpTransport transport; + + private DNSCache dnsCache = new DNSCache(); + + private URIFactory uriFactory = new URIFactory(); + + private final Statistics statistics = new Statistics(); + private ApplicationContext applicationContext; + + private String baseLocation; + + private Configuration configuration = new Configuration(); + + public DummyTestRouter() { + this(null); + } + + public DummyTestRouter(ProxyConfiguration proxyConfiguration) { + transport = createTransport(); + if (proxyConfiguration != null) + getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + } + + @Override + public void init() { + initProxies(); + } + + @Override + public void shutdown() { + + } + + @Override + public void waitFor() { + + } + + @Override + public void add(Proxy proxy) throws IOException { + ruleManager.addProxy(proxy, MANUAL); + } + + @Override + public Configuration getConfig() { + return configuration; + } + + @Override + public FlowController getFlowController() { + return flowController; + } + + @Override + public ExchangeStore getExchangeStore() { + return exchangeStore; + } + + @Override + public RuleManager getRuleManager() { + return ruleManager; + } + + @Override + public String getBaseLocation() { + return baseLocation; + } + + @Override + public ResolverMap getResolverMap() { + return resolverMap; + } + + @Override + public DNSCache getDnsCache() { + return dnsCache; + } + + @Override + public HttpTransport getTransport() { + return transport; + } + + @Override + public URIFactory getUriFactory() { + return uriFactory; + } + + @Override + public boolean isProduction() { + return false; + } + + @Override + public ApplicationContext getBeanFactory() { + return applicationContext; + } + + @Override + public HttpClientFactory getHttpClientFactory() { + return null; + } + + @Override + public TimerManager getTimerManager() { + return timerManager; + } + + @Override + public Statistics getStatistics() { + return statistics; + } + + @Override + public KubernetesClientFactory getKubernetesClientFactory() { + return kubernetesClientFactory; + } + + @Override + public Collection getRules() { + throw new UnsupportedOperationException(); + } + + @Override + public RuleReinitializer getReinitializer() { + throw new UnsupportedOperationException(); + } + + /** + * TODO Only used for tests. It s brittle cause it is dependent on + * the list. In tests interceptors in the proxy can be used instead. + */ + public void addUserFeatureInterceptor(Interceptor i) { + List is = getTransport().getFlow(); + is.add(is.size() - 3, i); + } + + /** + * Same as the default config from monitor-beans.xml + */ + private static HttpTransport createTransport() { + HttpTransport transport = new HttpTransport(); + List interceptors = new ArrayList<>(); + interceptors.add(new RuleMatchingInterceptor()); + interceptors.add(new DispatchingInterceptor()); + interceptors.add(new UserFeatureInterceptor()); + interceptors.add(new InternalRoutingInterceptor()); + HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor(); + interceptors.add(httpClientInterceptor); + transport.setFlow(interceptors); + return transport; + } + + @Override + public void start() { + + } + + @Override + public void stop() { + + } + + @Override + public boolean isRunning() { + return false; + } + + public void setExchangeStore(ExchangeStore exchangeStore) { + this.exchangeStore = exchangeStore; + } + + public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { + throw new UnsupportedOperationException(); + } + + public HttpClientConfiguration getHttpClientConfig() { + return resolverMap.getHTTPSchemaResolver().getHttpClientConfig(); + } + + public void setApplicationContext(ApplicationContext applicationContext) { + this.applicationContext = applicationContext; + } + + public void setBaseLocation(String baseLocation) { + this.baseLocation = baseLocation; + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index e5df4da7ff..7096b67a14 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -1,4 +1,4 @@ -/* Copyright 2009, 2011, 2012 predic8 GmbH, www.predic8.com +/* Copyright 2025 predic8 GmbH, www.predic8.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,218 +14,12 @@ package com.predic8.membrane.core; -import com.predic8.membrane.core.exchangestore.*; -import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.kubernetes.client.*; -import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.resolver.*; -import com.predic8.membrane.core.transport.*; import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.transport.http.client.*; -import com.predic8.membrane.core.util.*; -import org.springframework.context.*; -import java.io.*; -import java.util.*; - -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; - -public class HttpRouter extends AbstractRouter { - - private FlowController flowController = new FlowController(this); - private ExchangeStore exchangeStore = new LimitedMemoryExchangeStore(); - private RuleManager ruleManager = new RuleManager(); - - private final TimerManager timerManager = new TimerManager(); - private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); - private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); - private ResolverMap resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); - - private HttpTransport transport; - - private DNSCache dnsCache = new DNSCache(); - - private URIFactory uriFactory = new URIFactory(); - - private final Statistics statistics = new Statistics(); - private ApplicationContext applicationContext; - - private String baseLocation; - - private Configuration configuration = new Configuration(); - - public HttpRouter() { - this(null); - } - - public HttpRouter(ProxyConfiguration proxyConfiguration) { - transport = createTransport(); - if (proxyConfiguration != null) - getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); - } - - @Override - public void init() { - initProxies(); - } - - @Override - public void shutdown() { - - } - - @Override - public void waitFor() { - - } - - @Override - public void add(Proxy proxy) throws IOException { - ruleManager.addProxy(proxy, MANUAL); - } - - @Override - public Configuration getConfig() { - return configuration; - } - - @Override - public FlowController getFlowController() { - return flowController; - } - - @Override - public ExchangeStore getExchangeStore() { - return exchangeStore; - } - - @Override - public RuleManager getRuleManager() { - return ruleManager; - } - - @Override - public String getBaseLocation() { - return baseLocation; - } - - @Override - public ResolverMap getResolverMap() { - return resolverMap; - } - - @Override - public DNSCache getDnsCache() { - return dnsCache; - } +public class HttpRouter extends DefaultRouter { @Override public HttpTransport getTransport() { - return transport; - } - - @Override - public URIFactory getUriFactory() { - return uriFactory; - } - - @Override - public boolean isProduction() { - return false; - } - - @Override - public ApplicationContext getBeanFactory() { - return applicationContext; - } - - @Override - public HttpClientFactory getHttpClientFactory() { - return null; - } - - @Override - public TimerManager getTimerManager() { - return timerManager; - } - - @Override - public Statistics getStatistics() { - return statistics; - } - - @Override - public KubernetesClientFactory getKubernetesClientFactory() { - return kubernetesClientFactory; - } - - @Override - public Collection getRules() { - throw new UnsupportedOperationException(); - } - - @Override - public RuleReinitializer getReinitializer() { - throw new UnsupportedOperationException(); - } - - /** - * TODO Only used for tests. It s brittle cause it is dependent on - * the list. In tests interceptors in the proxy can be used instead. - */ - public void addUserFeatureInterceptor(Interceptor i) { - List is = getTransport().getFlow(); - is.add(is.size() - 3, i); - } - - /** - * Same as the default config from monitor-beans.xml - */ - private static HttpTransport createTransport() { - HttpTransport transport = new HttpTransport(); - List interceptors = new ArrayList<>(); - interceptors.add(new RuleMatchingInterceptor()); - interceptors.add(new DispatchingInterceptor()); - interceptors.add(new UserFeatureInterceptor()); - interceptors.add(new InternalRoutingInterceptor()); - HTTPClientInterceptor httpClientInterceptor = new HTTPClientInterceptor(); - interceptors.add(httpClientInterceptor); - transport.setFlow(interceptors); - return transport; - } - - @Override - public void start() { - - } - - @Override - public void stop() { - - } - - @Override - public boolean isRunning() { - return false; - } - - public void setExchangeStore(ExchangeStore exchangeStore) { - this.exchangeStore = exchangeStore; - } - - public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { - throw new UnsupportedOperationException(); - } - - public HttpClientConfiguration getHttpClientConfig() { - return resolverMap.getHTTPSchemaResolver().getHttpClientConfig(); - } - - public void setApplicationContext(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - - public void setBaseLocation(String baseLocation) { - this.baseLocation = baseLocation; + return (HttpTransport) transport; } } diff --git a/core/src/main/java/com/predic8/membrane/core/IRouter.java b/core/src/main/java/com/predic8/membrane/core/IRouter.java deleted file mode 100644 index 04b7854d5f..0000000000 --- a/core/src/main/java/com/predic8/membrane/core/IRouter.java +++ /dev/null @@ -1,80 +0,0 @@ -/* Copyright 2025 predic8 GmbH, www.predic8.com - - Licensed under the Apache License, Version 2.0 (the "License"); - you may not use this file except in compliance with the License. - You may obtain a copy of the License at - - http://www.apache.org/licenses/LICENSE-2.0 - - Unless required by applicable law or agreed to in writing, software - distributed under the License is distributed on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - See the License for the specific language governing permissions and - limitations under the License. */ - -package com.predic8.membrane.core; - -import com.predic8.membrane.core.exchangestore.*; -import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.kubernetes.client.*; -import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.resolver.*; -import com.predic8.membrane.core.transport.*; -import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.util.*; -import org.springframework.context.*; - -import java.io.*; -import java.util.*; - -public interface IRouter extends Lifecycle { - - void init(); - - /** - * TODO: What is the difference between this and stop? - */ - void shutdown(); - - void waitFor(); - - void add(Proxy proxy) throws IOException; - - Configuration getConfig(); - - FlowController getFlowController(); - - ExchangeStore getExchangeStore(); - - void setExchangeStore(ExchangeStore exchangeStore); - - RuleManager getRuleManager(); - - String getBaseLocation(); - - ResolverMap getResolverMap(); - - DNSCache getDnsCache(); - - HttpTransport getTransport(); - - URIFactory getUriFactory(); - - boolean isProduction(); - - ApplicationContext getBeanFactory(); - - HttpClientFactory getHttpClientFactory(); - - TimerManager getTimerManager(); - - Statistics getStatistics(); - - KubernetesClientFactory getKubernetesClientFactory(); - - // TODO: => to RuleManager? - Collection getRules(); - - RuleReinitializer getReinitializer(); - -} diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 457b3665aa..d877e91db6 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -1,4 +1,4 @@ -/* Copyright 2009, 2012 predic8 GmbH, www.predic8.com +/* Copyright 2025 predic8 GmbH, www.predic8.com Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -14,588 +14,68 @@ package com.predic8.membrane.core; -import com.predic8.membrane.annot.*; -import com.predic8.membrane.annot.beanregistry.*; -import com.predic8.membrane.core.RuleManager.*; -import com.predic8.membrane.core.config.spring.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.interceptor.administration.*; -import com.predic8.membrane.core.jmx.*; -import com.predic8.membrane.core.kubernetes.*; import com.predic8.membrane.core.kubernetes.client.*; -import com.predic8.membrane.core.openapi.*; -import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; -import com.predic8.membrane.core.router.hotdeploy.*; import com.predic8.membrane.core.transport.*; import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.transport.http.client.*; import com.predic8.membrane.core.util.*; -import org.slf4j.*; -import org.springframework.beans.*; -import org.springframework.beans.factory.*; import org.springframework.context.*; -import org.springframework.context.support.*; -import javax.annotation.concurrent.*; import java.io.*; import java.util.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; -import static com.predic8.membrane.core.jmx.JmxExporter.*; -import static com.predic8.membrane.core.util.DLPUtil.*; +public interface Router extends Lifecycle { -/* - Responsibilities: - - Start and stop Membrane - - Start, stop internal services - - Control lifecycle of proxies - - TODO: - - ADR: First start router than init and add proxies or first init proxies and add them later? - - ADR: - - The Router is responsible for the lifecycle of the proxies - - Ports are opened in start() - - init() - - does not open ports - - inits the proxies - - In sequence as added or reverse or not defined? - - new Router(), add(proxy) init() start() - - add(proxy) could be called any time - - If router is started port will be opened if needed by the proxy - - What if a proxy needs to make a call to another proxy during init(Tests: e.g. B2C) - - Delete addProxyAndOpenPortIfNew() from RuleManager - - HTTPRouter: - - Purpose? Test? - - - JMX - - Beans added after Router.start() should also be exported as JMS beans - - */ - -/** - * @description

- * Membrane API Gateway's main object. - *

- *

- * The router is a Spring Lifecycle object: It is automatically started and stopped according to the - * Lifecycle of the Spring Context containing it. In Membrane's standard setup - * Membrane itself controls the creation of the Spring Context and its Lifecycle. - *

- *

- * In this case, the router is hot deployable: It can monitor proxies.xml, the Spring - * configuration file, for changes and reinitialize the Spring Context, when a change is detected. Note - * that, during the Spring Context restart, the router object itself along with almost all other Membrane - * objects (interceptors, etc.) will be recreated. - *

- *

Router must be a singleton with just one instance. Membrane should never have more than one router.

- * @topic 1. Proxies and Flow - */ -@MCMain( - outputPackage = "com.predic8.membrane.core.config.spring", - outputName = "router-conf.xsd", - targetNamespace = "http://membrane-soa.org/proxies/1/") -@MCElement(name = "router") -public class Router extends AbstractRouter implements ApplicationContextAware, BeanRegistryAware, BeanNameAware, BeanCacheObserver { - - private static final Logger log = LoggerFactory.getLogger(Router.class); - - private ApplicationContext beanFactory; - - protected BeanRegistry registry; - - // - // Configuration - // - private String id; - private String baseLocation; - - private Configuration config = new Configuration(); - - // - // Components - // - protected HttpTransport transport; - - private final TimerManager timerManager = new TimerManager(); - private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); - private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); - protected ResolverMap resolverMap; - - protected final Statistics statistics = new Statistics(); - - private final Object lock = new Object(); - - @GuardedBy("lock") - private boolean running; - - @GuardedBy("lock") - private boolean initialized; - - /** - * HotDeployer for changes on the XML configuration file. Does not cover YAML. - * Not synchronized, since only modified during initialization - * Initialized with NullHotDeployer to avoid NPEs - */ - private HotDeployer hotDeployer = new DefaultHotDeployer(); - - private RuleReinitializer reinitializer; - - public Router() { - log.debug("Creating new router."); - resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); - resolverMap.addRuleResolver(this); - } - - // - // Initialization - // - - /** - * Initializes the {@code Router} - * - by setting up its associated components. - * - calling init() on each of its {@link Proxy} instances. - *

- * This method ensures that the {@code Router} and its dependencies are prepared for operation. - * But it does not start the router itself. Use {@link #start()} to start the router. - * If start() is called a separate call to init() is not needed. - * The init() is useful for testing without the expensive start() call. - */ - public void init() { - log.debug("Initializing."); - - // TODO: Temporary guard, to check correct behaviour, remove later - synchronized (lock) { - if (initialized) - throw new IllegalStateException("Router already initialized."); - } - - getRegistry().registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); - - getRegistry().registerIfAbsent(ResolverMap.class, () -> { - ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); - rs.addRuleResolver(this); - return rs; - }); - - getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); - getRegistry().registerIfAbsent(RuleManager.class, () -> { - RuleManager rm = new RuleManager(); - rm.setRouter(this); - return rm; - }); - getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); - - // Transport last - if (transport == null) { - transport = new HttpTransport(); - } - transport.init(this); - - initProxies(); - - synchronized (lock) { - initialized = true; - } - reinitializer = new RuleReinitializer(this); // Bean - } - - /** - * Starts the main processing logic of the application. - * This method initializes essential components, validates the configuration, - * and starts background services required for the application's functionality. - * Key responsibilities: - * - Initializes the application if it hasn't been initialized yet. - * - Opens TCP ports - */ - @Override - public void start() { - log.debug("Starting."); - displayTraceWarning(); - - synchronized (lock) { - if (!initialized) - init(); - } - - try { - - getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::start); - - startJmx(); - getRuleManager().openPorts(); - - hotDeployer.start(this); - - if (config.getRetryInitInterval() > 0) - reinitializer.start(); - } catch (DuplicatePathException e) { - handleDuplicateOpenAPIPaths(e); - } catch (OpenAPIParsingException e) { - handleOpenAPIParsingException(e); - } catch (Exception e) { - log.error("Could not start router.", e); - if (e instanceof RuntimeException) - throw (RuntimeException) e; - throw new RuntimeException(e); - } - - synchronized (lock) { - running = true; - } - } - - /* - TODO: - - Why is the source hardcoded here. - - Why does it matter? - */ - public Collection getRules() { - log.debug("Getting rules."); - return getRuleManager().getRulesBySource(MANUAL); // TODO: Source? - } - - @MCChildElement(order = 3) - public void setRules(Collection proxies) { - getRuleManager().removeAllRules(); - for (Proxy proxy : proxies) - getRuleManager().addProxy(proxy, RuleDefinitionSource.SPRING); - } - - @SuppressWarnings("NullableProblems") - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - beanFactory = applicationContext; - if (applicationContext instanceof BaseLocationApplicationContext) - setBaseLocation(((BaseLocationApplicationContext) applicationContext).getBaseLocation()); - } - - public RuleManager getRuleManager() { - return getRegistry().registerIfAbsent(RuleManager.class, () -> { - RuleManager rm = new RuleManager(); - rm.setRouter(this); - return rm; - }); - } - - public void setRuleManager(RuleManager ruleManager) { - log.debug("Setting ruleManager."); - ruleManager.setRouter(this); - getRegistry().register("ruleManager", ruleManager); - } - - public ExchangeStore getExchangeStore() { - return getRegistry().getBean(ExchangeStore.class).orElseThrow(); - } - - /** - * @description Spring Bean ID of an {@link ExchangeStore}. The exchange store will be used by this router's - * components ({@link AdminConsoleInterceptor}, {@link ExchangeStoreInterceptor}, etc.) by default, if - * no other exchange store is explicitly set to be used by them. - * @default create a {@link LimitedMemoryExchangeStore} limited to the size of 1 MB. - */ - @MCAttribute - public void setExchangeStore(ExchangeStore exchangeStore) { - getRegistry().register("exchangeStore", exchangeStore); - } - - @Override - public HttpTransport getTransport() { - return transport; - } - - /** - * @description Used to override the default 'transport' chain. The transport chain is the one global - * interceptor chain called *for every* incoming HTTP Exchanges. The transport chain uses <userFeature/> - * to call 'down' to a specific <api/>, <serviceProxy/> or similar. The default transport chain - * is shown in proxies-full-sample.xml . - */ - @MCChildElement(order = 1, allowForeign = true) - public void setTransport(HttpTransport transport) { - this.transport = transport; - } - - public HttpClientConfiguration getHttpClientConfig() { - return getResolverMap().getHTTPSchemaResolver().getHttpClientConfig(); - } - - /** - * @description A 'global' (per router) <httpClientConfig>. This instance is used everywhere - * a HTTP Client is used. Usually, in every specific place, you can still configure a local - * <httpClientConfig> (with higher precedence compared to this global instance). - */ - @MCChildElement() - public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { - getResolverMap().getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); - } - - public DNSCache getDnsCache() { - return getRegistry().getBean(DNSCache.class).orElseThrow(); // TODO - } - - public ResolverMap getResolverMap() { - return resolverMap; - } - - /** - * Closes all ports (if any were opened) and waits for running exchanges to complete. - *

- * When running as an embedded servlet, this has no effect. - */ - public void shutdown() { - if (transport != null) - transport.closeAll(); - timerManager.shutdown(); - } + void init(); /** - * Adds a proxy to the router and initializes it. - * - * TODO: Should we sync running cause a different Thread might call add? - * - * @param proxy - * @throws IOException + * TODO: What is the difference between this and stop? */ - public void add(Proxy proxy) throws IOException { - log.debug("Adding proxy {}.", proxy.getName()); - RuleManager ruleManager = getRuleManager(); + void shutdown(); - if (running && proxy instanceof SSLableProxy sp) { - sp.init(this); - ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); - } else { - ruleManager.addProxy(proxy, MANUAL); - } + void waitFor(); - } + void add(Proxy proxy) throws IOException; - private void startJmx() { - if (beanFactory == null) - return; + Configuration getConfig(); - try { - JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); - //exporter.removeBean(prefix + jmxRouterName); - exporter.addBean("io.membrane-api:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); - exporter.initAfterBeansAdded(); - } catch (NoSuchBeanDefinitionException ignored) { - // If bean is not available do not init jmx - } - } + Transport getTransport(); - @Override - public void stop() { - getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::stop); - hotDeployer.stop(); - shutdown(); + FlowController getFlowController(); - synchronized (lock) { - running = false; - lock.notifyAll(); - } - } + ExchangeStore getExchangeStore(); - @Override - public boolean isRunning() { - synchronized (lock) { - return running; - } - } + void setExchangeStore(ExchangeStore exchangeStore); - public String getBaseLocation() { - return baseLocation; - } + RuleManager getRuleManager(); - public void setBaseLocation(String baseLocation) { - this.baseLocation = baseLocation; - } + ResolverMap getResolverMap(); - public ApplicationContext getBeanFactory() { - return beanFactory; - } + DNSCache getDnsCache(); - public boolean isProduction() { - return config.isProduction(); - } + String getBaseLocation(); - public Statistics getStatistics() { - return statistics; - } + URIFactory getUriFactory(); - @SuppressWarnings("NullableProblems") - @Override - public void setBeanName(String s) { - this.id = s; - } + // TODO move to configuration + boolean isProduction(); - /** - * @description Sets a global chain that applies to all requests and responses. - */ - @MCChildElement(order = 2) - public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { - getRegistry().register("globalInterceptor", globalInterceptor); - } - - public String getId() { - return id; - } - - /** - * waits until the router has shut down - */ - public void waitFor() { - synchronized (lock) { - while (running) { - try { - lock.wait(); - } catch (InterruptedException ignored) { - } - } - } - } - - public TimerManager getTimerManager() { - return timerManager; - } - - public KubernetesClientFactory getKubernetesClientFactory() { - return kubernetesClientFactory; - } - - public HttpClientFactory getHttpClientFactory() { - return httpClientFactory; - } - - public FlowController getFlowController() { - return getRegistry().registerIfAbsent(FlowController.class, () -> new FlowController(this)); - } - - public void handleAsynchronousInitializationResult(boolean success) { - log.debug("Asynchronous initialization finished."); - if (!success && !config.isRetryInit()) - System.exit(1); - ApiInfo.logInfosAboutStartedProxies(getRuleManager()); - } + ApplicationContext getBeanFactory(); - @Override - public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { - log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(), bean); - if (bean instanceof GlobalInterceptor) { - return; - } + HttpClientFactory getHttpClientFactory(); - if (!(bean instanceof Proxy newProxy)) { - throw new IllegalArgumentException("Bean must be a Proxy instance, but got: " + bean.getClass().getName()); - } + TimerManager getTimerManager(); - if (newProxy.getName() == null) - newProxy.setName(bdc.bd().getName()); - - // TODO: Comment or code Should be deleted before merge - // Comment is kept for discussion only. - // - // init() in Proxies was called twice, here and in Router.initRemainingRules - // We should only keep one place. Which one is up to discussion - // - // try { - // newProxy.init(this); - // } catch (ConfigurationException e) { - // SpringConfigurationErrorHandler.handleRootCause(e, log); - // throw e; - // } catch (Exception e) { - // throw new RuntimeException("Could not init rule.", e); - // } - - if (bdc.action().isAdded()) { - add(newProxy); - } else if (bdc.action().isDeleted()) - getRuleManager().removeRule((Proxy) oldBean); - else if (bdc.action().isModified()) { - getRuleManager().replaceRule((Proxy) oldBean, newProxy); - } - } - - @Override - public boolean isActivatable(BeanDefinition bd) { - return Proxy.class.isAssignableFrom(new GrammarAutoGenerated().getElement(bd.getKind())); - } - - public AbstractRefreshableApplicationContext getRef() { - if (beanFactory instanceof AbstractRefreshableApplicationContext bf) - return bf; - throw new RuntimeException("ApplicationContext is not a AbstractRefreshableApplicationContext. Please set ."); - } - - @Override - public void setRegistry(BeanRegistry registry) { - this.registry = registry; - } - - public BeanRegistry getRegistry() { - if (registry == null) - registry = new BeanRegistryImplementation(null, this, null); - return registry; - } - - public void applyConfiguration(Configuration configuration) { - hotDeployer = configuration.isHotDeploy() ? new DefaultHotDeployer() : new NullHotDeployer(); - this.config = configuration; - } - - public URIFactory getUriFactory() { - return config.getUriFactory(); - } - - /** - * Sets the configuration object for this router. - * Only used for xml - * - * @param config the configuration object - */ - @MCChildElement(order = -1) - public void setConfig(Configuration config) { - this.config = config; - } + Statistics getStatistics(); - public Configuration getConfig() { - return config; - } + KubernetesClientFactory getKubernetesClientFactory(); - public RuleReinitializer getReinitializer() { - return reinitializer; - } + // TODO: => to RuleManager? + Collection getRules(); - private static void handleOpenAPIParsingException(OpenAPIParsingException e) { - System.err.printf(""" - ================================================================================================ - - Configuration Error: Could not read or parse OpenAPI Document - - Reason: %s - - Location: %s - - Have a look at the proxies.xml file. - """, e.getMessage(), e.getLocation()); - throw new ExitException(); - } + RuleReinitializer getReinitializer(); - private static void handleDuplicateOpenAPIPaths(DuplicatePathException e) { - System.err.printf(""" - ================================================================================================ - - Configuration Error: Several OpenAPI Documents share the same path! - - An API routes and validates requests according to the path of the OpenAPI's servers.url fields. - Within one API the same path should be used only by one OpenAPI. Change the paths or place - openapi-elements into separate api-elements. - - Shared path: %s - %n""", e.getPath()); - throw new ExitException(); - } -} \ No newline at end of file +} diff --git a/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java b/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java index 07bae9f180..4234e49e73 100644 --- a/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java +++ b/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java @@ -23,43 +23,43 @@ import java.util.*; /** - * Bootstrapping a {@link Router} instance using Spring XML-based configuration. + * Bootstrapping a {@link DefaultRouter} instance using Spring XML-based configuration. */ public class RouterBootstrap { private static final Logger log = LoggerFactory.getLogger(RouterBootstrap.class); /** - * Initializes a {@link Router} instance from the specified Spring XML configuration resource. + * Initializes a {@link DefaultRouter} instance from the specified Spring XML configuration resource. * - * @param resource the path to the Spring XML configuration file that defines the {@link Router} bean - * @return the initialized {@link Router} instance - * @throws RuntimeException if no {@link Router} bean is found or more than one {@link Router} bean is found + * @param resource the path to the Spring XML configuration file that defines the {@link DefaultRouter} bean + * @return the initialized {@link DefaultRouter} instance + * @throws RuntimeException if no {@link DefaultRouter} bean is found or more than one {@link DefaultRouter} bean is found */ - public static Router initByXML(String resource) { + public static DefaultRouter initByXML(String resource) { log.debug("loading spring config: {}", resource); TrackingFileSystemXmlApplicationContext bf = new TrackingFileSystemXmlApplicationContext(new String[]{resource}, false); bf.refresh(); - if (bf.getBeansOfType(Router.class).size() > 1) { + if (bf.getBeansOfType(DefaultRouter.class).size() > 1) { throw new RuntimeException( "More than one router bean found in the Spring configuration (%s). This is no longer supported." .formatted(Arrays.toString(bf.getBeanDefinitionNames())) ); } - Router router = bf.getBean("router", Router.class); + DefaultRouter router = bf.getBean("router", DefaultRouter.class); bf.start(); // Starting ApplicationContext will also call router.start(). Init should happen before. return router; } - public static Router initFromXMLString(String xmlString) { + public static DefaultRouter initFromXMLString(String xmlString) { log.debug("Loading spring config from string"); GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(new ByteArrayResource(xmlString.getBytes(StandardCharsets.UTF_8))); ctx.refresh(); ctx.start(); - return ctx.getBean(Router.class); + return ctx.getBean(DefaultRouter.class); } } diff --git a/core/src/main/java/com/predic8/membrane/core/RuleManager.java b/core/src/main/java/com/predic8/membrane/core/RuleManager.java index 82069fec42..018b0c7ea3 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleManager.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleManager.java @@ -36,7 +36,7 @@ public class RuleManager { private static final Logger log = LoggerFactory.getLogger(RuleManager.class.getName()); - private Router router; + private DefaultRouter router; protected final List proxies = new Vector<>(); private final List ruleSources = new ArrayList<>(); @@ -297,7 +297,7 @@ public synchronized void removeAllRules() { removeRule(proxies.getFirst()); } - public void setRouter(Router router) { + public void setRouter(DefaultRouter router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java index 753670ca84..1293652367 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -23,11 +23,11 @@ public class RuleReinitializer { private static final Logger log = LoggerFactory.getLogger(RuleReinitializer.class); - private final Router router; + private final DefaultRouter router; private Timer timer; - public RuleReinitializer(Router router) { + public RuleReinitializer(DefaultRouter router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 98bd4527e8..ebb195b34b 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -111,7 +111,7 @@ public static String getExceptionMessageWithCauses(Throwable throwable) { return result.toString(); } - private static @NotNull IRouter getRouter(MembraneCommandLine commandLine) { + private static @NotNull Router getRouter(MembraneCommandLine commandLine) { try { return switch (commandLine.getCommand().getName()) { case "oas" -> initRouterByOpenApiSpec(commandLine); @@ -133,7 +133,7 @@ public static String getExceptionMessageWithCauses(Throwable throwable) { return null; } - private static Router initRouterByConfig(MembraneCommandLine commandLine) throws Exception { + private static DefaultRouter initRouterByConfig(MembraneCommandLine commandLine) throws Exception { String config = getRulesFile(commandLine); if (config.endsWith(".xml")) { var router = initRouterByXml(config); @@ -146,19 +146,19 @@ private static Router initRouterByConfig(MembraneCommandLine commandLine) throws throw new RuntimeException("Unsupported file extension."); } - private static IRouter initRouterByOpenApiSpec(MembraneCommandLine commandLine) throws Exception { - IRouter router = new HttpRouter(); + private static Router initRouterByOpenApiSpec(MembraneCommandLine commandLine) throws Exception { + Router router = new DummyTestRouter(); router.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy(commandLine)); router.init(); return router; } - private static Router initRouterByYAML(MembraneCommandLine commandLine, String option) throws Exception { + private static DefaultRouter initRouterByYAML(MembraneCommandLine commandLine, String option) throws Exception { return initRouterByYAML(commandLine.getCommand().getOptionValue(option)); } - private static Router initRouterByYAML(String location) throws Exception { - var router = new Router(); + private static DefaultRouter initRouterByYAML(String location) throws Exception { + var router = new DefaultRouter(); router.setBaseLocation(location); GrammarAutoGenerated grammar = new GrammarAutoGenerated(); @@ -211,7 +211,7 @@ private static String getLocation(MembraneCommandLine commandLine) throws IOExce return new File(getUserDir(), location).getCanonicalPath(); } - private static Router initRouterByXml(String config) throws Exception { + private static DefaultRouter initRouterByXml(String config) throws Exception { try { return RouterBootstrap.initByXML(config); } catch (XmlBeanDefinitionStoreException e) { diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java index 4d501cabc7..f2e55df17d 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java @@ -22,7 +22,6 @@ import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; -import org.slf4j.*; import java.util.*; import java.util.concurrent.*; @@ -42,7 +41,7 @@ public abstract class AbstractPersistentExchangeStore extends AbstractExchangeSt volatile boolean updateThreadWorking; @Override - public void init(IRouter router) { + public void init(Router router) { super.init(router); startTime = System.nanoTime(); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java index b23250101b..ba5d1b6304 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java @@ -76,7 +76,7 @@ public class ElasticSearchExchangeStore extends AbstractPersistentExchangeStore @Override - public void init(IRouter router) { + public void init(Router router) { if(client == null) client = router.getHttpClientFactory().createClient(null); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java index 2291ed9432..60dd4f92f2 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/ExchangeStore.java @@ -57,7 +57,7 @@ public interface ExchangeStore { AbstractExchange getExchangeById(long id); - default void init(IRouter router) {} + default void init(Router router) {} List getClientStatistics(); diff --git a/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java b/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java index 1d8ae6e3b9..97735ae2fa 100644 --- a/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java +++ b/core/src/main/java/com/predic8/membrane/core/exchangestore/MongoDBExchangeStore.java @@ -51,7 +51,7 @@ public class MongoDBExchangeStore extends AbstractPersistentExchangeStore { .configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false); @Override - public void init(IRouter router) { + public void init(Router router) { super.init(router); if (this.collection == null) { this.collection = MongoClients.create(connection) diff --git a/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java b/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java index 2919468c18..3fc3161cd9 100644 --- a/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java +++ b/core/src/main/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidator.java @@ -58,10 +58,10 @@ public class GraphQLoverHttpValidator { private final int maxRecursion; private final int maxDepth; private final int maxMutations; - private final IRouter router; + private final Router router; private final FeatureBlocklist featureBlocklist; - public GraphQLoverHttpValidator(boolean allowExtensions, List allowedMethods, int maxRecursion, int maxDepth, int maxMutations, FeatureBlocklist featureBlocklist, IRouter router) { + public GraphQLoverHttpValidator(boolean allowExtensions, List allowedMethods, int maxRecursion, int maxDepth, int maxMutations, FeatureBlocklist featureBlocklist, Router router) { this.allowExtensions = allowExtensions; this.allowedMethods = allowedMethods; this.maxRecursion = maxRecursion; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java index 3bb462fe70..08139df867 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java @@ -31,7 +31,7 @@ public class AbstractInterceptor implements Interceptor { private EnumSet flow = REQUEST_RESPONSE_ABORT_FLOW; - protected IRouter router; + protected Router router; public AbstractInterceptor() { super(); @@ -99,17 +99,17 @@ public final String getHelpId() { */ public void init() {} - public final void init(IRouter router) { + public final void init(Router router) { this.router = router; init(); } @Override - public void init(IRouter router, Proxy ignored) { + public void init(Router router, Proxy ignored) { init(router); } - public IRouter getRouter() { //wird von ReadRulesConfigurationTest aufgerufen. + public Router getRouter() { //wird von ReadRulesConfigurationTest aufgerufen. return router; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java index 31ab2653ab..8bdc3981de 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java @@ -70,7 +70,7 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } - public void initJson(IRouter router, Exchange exc) throws JsonProcessingException { + public void initJson(Router router, Exchange exc) throws JsonProcessingException { if (apisJson != null) { return; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java index 1ace5c21fd..f0c6fc7b2c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java @@ -56,9 +56,9 @@ public class FlowController { private static final Logger log = LoggerFactory.getLogger(FlowController.class); - private final IRouter router; + private final Router router; - public FlowController(IRouter router) { + public FlowController(Router router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java index b5be0407a7..0f0ded2c10 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java @@ -53,9 +53,9 @@ public boolean isAbort() { } } - void init(IRouter router); + void init(Router router); - void init(IRouter router, Proxy proxy); + void init(Router router, Proxy proxy); Outcome handleRequest(Exchange exchange); Outcome handleResponse(Exchange exchange); @@ -73,7 +73,7 @@ public boolean isAbort() { String getDisplayName(); void setDisplayName(String name); - IRouter getRouter(); + Router getRouter(); void setAppliedFlow(EnumSet flow); EnumSet getAppliedFlow(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java index 7665480f9e..444cb58de2 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AbstractClientAddress.java @@ -20,10 +20,10 @@ public abstract class AbstractClientAddress extends AbstractXmlElement { - protected final IRouter router; + protected final Router router; protected String schema; - public AbstractClientAddress(IRouter router) { + public AbstractClientAddress(Router router) { super(); this.router = router; } @@ -44,5 +44,5 @@ public void setSchema(String schema) { this.schema = schema; } - public void init(IRouter router) {} + public void init(Router router) {} } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java index 8c5bfe1e71..6c9bedce2a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControl.java @@ -25,10 +25,10 @@ public class AccessControl extends AbstractXmlElement { public static final String ELEMENT_NAME = "accessControl"; - private final IRouter router; + private final Router router; private final List resources = new ArrayList<>(); - public AccessControl(IRouter router) { + public AccessControl(Router router) { this.router = router; } @@ -61,7 +61,7 @@ public Resource getResourceFor(String uri) { throw new IllegalArgumentException("Resource not found for given path"); } - public void init(IRouter router) { + public void init(Router router) { for (Resource resource : resources) resource.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java index 3913ead35e..d10f4d2055 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java @@ -129,7 +129,7 @@ public void setAccessControl(AccessControl ac) { accessControl = ac; } - protected AccessControl parse(String fileName, IRouter router) { + protected AccessControl parse(String fileName, Router router) { try { XMLInputFactory factory = XMLInputFactoryFactory.inputFactory(); XMLStreamReader reader = null; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java index 66c816342e..1441e50cfc 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Any.java @@ -20,7 +20,7 @@ public class Any extends AbstractClientAddress { public static final String ELEMENT_NAME = "any"; - public Any(IRouter router) { + public Any(Router router) { super(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java index 5dbde7a79b..62d20ed25a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Hostname.java @@ -56,7 +56,7 @@ private static InetAddress initV6() { private volatile long lastWarningSlowReverseDNSUsed; - public Hostname(IRouter router) { + public Hostname(Router router) { super(router); } @@ -102,7 +102,7 @@ public boolean matches(String hostname, String ip) { } @Override - public void init(IRouter router) { + public void init(Router router) { super.init(router); reverseDNS = router.getTransport() != null && router.getTransport().isReverseDNS(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java index 113f9ad52a..b0e2427bab 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Ip.java @@ -25,7 +25,7 @@ public class Ip extends AbstractClientAddress { private ParseType type = GLOB; - public Ip(IRouter router) { + public Ip(Router router) { super(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java index 3e23dbdeb3..245ab3462f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/acl/Resource.java @@ -36,12 +36,12 @@ public class Resource extends AbstractXmlElement { public static final String ELEMENT_NAME = "resource"; - private final IRouter router; + private final Router router; private final List clientAddresses = new ArrayList<>(); protected Pattern uriPattern; - public Resource(IRouter router) { + public Resource(Router router) { this.router = router; } @@ -97,7 +97,7 @@ public String getUriPattern() { return uriPattern.pattern(); } - public void init(IRouter router) { + public void init(Router router) { for (AbstractClientAddress ca : clientAddresses) ca.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java index 7f4a1442f8..0770715a0f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/AdminPageBuilder.java @@ -53,7 +53,7 @@ public class AdminPageBuilder extends Html { static final int TAB_ID_CLIENTS = 8; static final int TAB_ID_ABOUT = 9; - private final IRouter router; + private final Router router; private final Map params; private final StringWriter writer; private final String relativeRootPath; @@ -64,7 +64,7 @@ static public String createHRef(String ctrl, String action, String query) { return "/admin/" + ctrl + (action != null ? "/" + action : "") + (query != null ? "?" + query : ""); } - public AdminPageBuilder(StringWriter writer, IRouter router, String relativeRootPath, Map params, boolean readOnly) { + public AdminPageBuilder(StringWriter writer, Router router, String relativeRootPath, Map params, boolean readOnly) { super(writer); this.router = router; this.params = params; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java index c840d04719..849e90a74e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/RuleUtil.java @@ -22,7 +22,7 @@ public static String getRuleIdentifier(Proxy proxy) { return proxy.toString() + (proxy.getKey().getPort() == -1 ? "" : ":" + proxy.getKey().getPort()); } - public static Proxy findRuleByIdentifier(IRouter router, String name) { + public static Proxy findRuleByIdentifier(Router router, String name) { for (Proxy proxy : router.getRuleManager().getRules()) { if ( name.equals(getRuleIdentifier(proxy))) return proxy; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java index 5dc744acbe..eeeecefd17 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExpressionExtractor.java @@ -56,7 +56,7 @@ public class ApiKeyExpressionExtractor implements ApiKeyExtractor, Polyglot, XML private XmlConfig xmlConfig; @Override - public void init(IRouter router) { + public void init(Router router) { exchangeExpression = expression(new InterceptorAdapter(router, xmlConfig), language, expression); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java index b00c973c67..eecb159bab 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/extractors/ApiKeyExtractor.java @@ -19,7 +19,7 @@ import java.util.Optional; public interface ApiKeyExtractor { - default void init(IRouter router) {} + default void init(Router router) {} Optional extract(Exchange exc); String getDescription(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java index 1408d51aef..6f5f566e1e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStore.java @@ -59,7 +59,7 @@ public class ApiKeyFileStore implements ApiKeyStore { private Map>> scopes; @Override - public void init(IRouter router) { + public void init(Router router) { try { scopes = readKeyData(readFile(location, router.getResolverMap(), router.getBaseLocation())); } catch (IOException e) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java index e5414b7454..a00298f497 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyStore.java @@ -20,12 +20,12 @@ public interface ApiKeyStore { /** - * Lifecycle hook invoked once to provide the {@link Router} context. + * Lifecycle hook invoked once to provide the {@link DefaultRouter} context. * Default is a no-op to preserve backward compatibility; implementations may override. * * @param router non-null router instance */ - default void init(IRouter router) { + default void init(Router router) { } /** diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/JDBCApiKeyStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/JDBCApiKeyStore.java index 08158a00cc..af498a153d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/JDBCApiKeyStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/JDBCApiKeyStore.java @@ -17,7 +17,7 @@ import com.predic8.membrane.annot.MCAttribute; import com.predic8.membrane.annot.MCChildElement; import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.util.ConfigurationException; import com.predic8.membrane.core.util.jdbc.AbstractJdbcSupport; import org.jetbrains.annotations.NotNull; @@ -67,7 +67,7 @@ apikey VARCHAR(255) NOT NULL PRIMARY KEY """; @Override - public void init(Router router) { + public void init(DefaultRouter router) { super.init(router); createTablesIfNotExist(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java index e7ce405f70..9435074860 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/apikey/stores/MongoDBApiKeyStore.java @@ -58,7 +58,7 @@ public class MongoDBApiKeyStore implements ApiKeyStore { private MongoDatabase mongoDatabase; @Override - public void init(IRouter router) { + public void init(Router router) { try { mongoDatabase = MongoClients.create(connection).getDatabase(database); } catch (Exception e) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java index 4d1e315a7c..e991cef61c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CachingUserDataProvider.java @@ -77,7 +77,7 @@ public void setUserDataProvider(UserDataProvider userDataProvider) { @Override - public void init(IRouter router) { + public void init(Router router) { userDataProvider.init(router); cache = CacheBuilder.newBuilder() .maximumSize(this.getMaxSize()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java index e990fbd153..1803216b9f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/CustomStatementJdbcUserDataProvider.java @@ -30,7 +30,7 @@ public class CustomStatementJdbcUserDataProvider implements UserDataProvider { private static final Logger log = LoggerFactory.getLogger(CustomStatementJdbcUserDataProvider.class.getName()); - private IRouter router; + private Router router; DataSource datasource; @@ -40,7 +40,7 @@ public class CustomStatementJdbcUserDataProvider implements UserDataProvider { @Override - public void init(IRouter router) { + public void init(Router router) { this.router = router; sanitizeUserInputs(); getDatasourceIfNull(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java index 24c4f964c5..a0518b4b6f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmailTokenProvider.java @@ -71,7 +71,7 @@ public class EmailTokenProvider extends NumericTokenProvider { private boolean ssl = true; @Override - public void init(IRouter router) { + public void init(Router router) { } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java index d48f0de5aa..a7407eddfd 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/EmptyTokenProvider.java @@ -23,7 +23,7 @@ public class EmptyTokenProvider implements TokenProvider { @Override - public void init(IRouter router) { + public void init(Router router) { // does nothing } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java index 92a2625f84..8dff83d166 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/FileUserDataProvider.java @@ -109,7 +109,7 @@ public Map getUsersByName() { } @Override - public void init(IRouter router) { + public void init(Router router) { List lines; try { lines = Files.readAllLines(Paths.get(this.htpasswdPath)); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java index 43307a1c0b..b493b685d6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JdbcUserDataProvider.java @@ -34,10 +34,10 @@ public class JdbcUserDataProvider implements UserDataProvider { private String tableName; private String userColumnName; private String passwordColumnName; - private IRouter router; + private Router router; @Override - public void init(IRouter router) { + public void init(Router router) { this.router = router; sanitizeUserInputs(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java index 462b7847d6..db67506ec0 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/JwtSessionManager.java @@ -56,7 +56,7 @@ public void setKey(String key) { } @Override - public void init(IRouter router) { + public void init(Router router) { super.init(router); try { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java index 95213a975c..1bac01a14d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LDAPUserDataProvider.java @@ -429,7 +429,7 @@ public void setSslParser(SSLParser sslParser) { } @Override - public void init(IRouter router) { + public void init(Router router) { if (passwordAttribute != null && readAttributesAsSelf) throw new RuntimeException("@passwordAttribute is not compatible with @readAttributesAsSelf."); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java index 01589e7d31..3fef38f6b4 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginDialog.java @@ -84,7 +84,7 @@ public LoginDialog( wsi.setDocBase(dialogLocation); } - public void init(IRouter router) { + public void init(Router router) { uriFactory = router.getUriFactory(); wsi.init(router); try { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java index a50823fdf4..3a2a4cfb55 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/SessionManager.java @@ -61,7 +61,7 @@ protected void parseAttributes(XMLStreamReader token) { domain = token.getAttributeValue("", "domain"); } - public void init(IRouter router) { + public void init(Router router) { cookieName = StringUtils.defaultIfEmpty(cookieName, "SESSIONID"); timeout = timeout == 0 ? 300000 : timeout; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java index ada21cf8af..4643545467 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/StaticUserDataProvider.java @@ -13,16 +13,12 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.authentication.session; -import com.predic8.membrane.annot.MCAttribute; -import com.predic8.membrane.annot.MCChildElement; -import com.predic8.membrane.annot.MCElement; -import com.predic8.membrane.annot.MCOtherAttributes; +import com.predic8.membrane.annot.*; import com.predic8.membrane.core.*; -import org.apache.commons.codec.digest.Crypt; +import org.apache.commons.codec.digest.*; -import java.security.SecureRandom; import java.util.*; -import java.util.regex.Pattern; +import java.util.regex.*; /** * @description A user data provider listing all user data in-place in the config file. @@ -189,7 +185,7 @@ public void setUsersByName(Map usersByName) { } @Override - public void init(IRouter router) { + public void init(Router router) { for (User user : users) getUsersByName().put(user.getUsername(), user); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java index bfce9e49e6..848e4d327f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TOTPTokenProvider.java @@ -50,7 +50,7 @@ public class TOTPTokenProvider implements TokenProvider { final Logger log = LoggerFactory.getLogger(TOTPTokenProvider.class); @Override - public void init(IRouter router) { + public void init(Router router) { // does nothing } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java index 75473163c9..40211a7bd3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TelekomSMSTokenProvider.java @@ -95,7 +95,7 @@ public enum EnvironmentType { private long tokenExpiration; @Override - public void init(IRouter router) { + public void init(Router router) { hc = router.getHttpClientFactory().createClient(null); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java index 142af61962..ba5d0cc317 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/TokenProvider.java @@ -19,7 +19,7 @@ public interface TokenProvider { - void init(IRouter router); + void init(Router router); void requestToken(Map userAttributes); void verifyToken(Map userAttributes, String token); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java index 4f79c1ccc5..64b8fe62a3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UnifyingUserDataProvider.java @@ -63,7 +63,7 @@ public void setUserDataProviders(List userDataProviders) { } @Override - public void init(IRouter router) { + public void init(Router router) { for (UserDataProvider udp : userDataProviders) udp.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java index 8ae84dfceb..501994582f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/UserDataProvider.java @@ -19,7 +19,7 @@ public interface UserDataProvider { - void init(IRouter router); + void init(Router router); /** * @throws NoSuchElementException diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java index e6103af739..8964a9abce 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/WhateverMobileSMSTokenProvider.java @@ -69,7 +69,7 @@ public class WhateverMobileSMSTokenProvider extends SMSTokenProvider { private static final String GATEWAY2 = "https://" + HOST2 + "/sendsms"; @Override - public void init(IRouter router) { + public void init(Router router) { hc = router.getHttpClientFactory().createClient(null); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java index efb9ec7a45..445e58cedc 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/xen/XenAuthenticationInterceptor.java @@ -100,7 +100,7 @@ public Outcome handleResponse(Exchange exc) { } public interface XenSessionManager { - void init(IRouter router) throws Exception; + void init(Router router) throws Exception; String getXenSessionId(String ourSessionId); String getExistingSessionId(String xenSessionId); String createSessionId(String xenSessionId); @@ -111,7 +111,7 @@ public static class InMemorySessionManager implements XenSessionManager { private final Map ourSessionIds = new ConcurrentHashMap<>(); private final Map xenSessionIds = new ConcurrentHashMap<>(); - public void init(IRouter router) { + public void init(Router router) { } public String getXenSessionId(String ourSessionId) { @@ -140,7 +140,7 @@ public static class JwtSessionManager implements XenSessionManager { private final SecureRandom random = new SecureRandom(); - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { String key = jwk.get(router.getResolverMap(), router.getBaseLocation()); if (key == null || key.isEmpty()) rsaJsonWebKey = generateKey(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerHealthMonitor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerHealthMonitor.java index cef060b03d..eff6c3226d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerHealthMonitor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerHealthMonitor.java @@ -56,7 +56,7 @@ public class BalancerHealthMonitor implements ApplicationContextAware, Initializ */ public static final int INITIAL_DELAY = 5000; - private Router router; + private DefaultRouter router; private int interval = 10000; private HttpClient client; @@ -158,7 +158,7 @@ private Exchange doCall(String url) throws Exception { @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - this.router = applicationContext.getBean(Router.class); + this.router = applicationContext.getBean(DefaultRouter.class); } @Override @@ -204,7 +204,7 @@ public HttpClientConfiguration getHttpClientConfig() { } /** - * @see Router#getHttpClientFactory() + * @see DefaultRouter#getHttpClientFactory() * @see HttpClientConfiguration * * @description Optional HTTP client configuration for health probes (e.g., timeouts, TLS). diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java index a139496be3..dbe9e62164 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/BalancerUtil.java @@ -22,7 +22,7 @@ public class BalancerUtil { - public static List collectClusters(IRouter router) { + public static List collectClusters(Router router) { ArrayList result = new ArrayList<>(); for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); @@ -34,7 +34,7 @@ public static List collectClusters(IRouter router) { return result; } - public static List collectBalancers(IRouter router) { + public static List collectBalancers(Router router) { ArrayList result = new ArrayList<>(); for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); @@ -46,7 +46,7 @@ public static List collectBalancers(IRouter router) { return result; } - public static Balancer lookupBalancer(IRouter router, String name) { + public static Balancer lookupBalancer(Router router, String name) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors != null) @@ -58,7 +58,7 @@ public static Balancer lookupBalancer(IRouter router, String name) { throw new RuntimeException("balancer with name \"" + name + "\" not found."); } - public static LoadBalancingInterceptor lookupBalancerInterceptor(IRouter router, String name) { + public static LoadBalancingInterceptor lookupBalancerInterceptor(Router router, String name) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors != null) @@ -70,7 +70,7 @@ public static LoadBalancingInterceptor lookupBalancerInterceptor(IRouter router, throw new RuntimeException("balancer with name \"" + name + "\" not found."); } - public static boolean hasLoadBalancing(IRouter router) { + public static boolean hasLoadBalancing(Router router) { for (Proxy r : router.getRuleManager().getRules()) { List interceptors = r.getFlow(); if (interceptors == null) @@ -82,43 +82,43 @@ public static boolean hasLoadBalancing(IRouter router) { return false; } - public static void up(IRouter router, String balancerName, String cName, String host, int port) { + public static void up(Router router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).up(cName, host, port); } - public static void down(IRouter router, String balancerName, String cName, String host, int port) { + public static void down(Router router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).down(cName, host, port); } - public static void takeout(IRouter router, String balancerName, String cName, String host, int port) { + public static void takeout(Router router, String balancerName, String cName, String host, int port) { lookupBalancer(router, balancerName).takeout(cName, host, port); } - public static List getAllNodesByCluster(IRouter router, String balancerName, String cName) { + public static List getAllNodesByCluster(Router router, String balancerName, String cName) { return lookupBalancer(router, balancerName).getAllNodesByCluster(cName); } - public static List getAvailableNodesByCluster(IRouter router, String balancerName, String cName) { + public static List getAvailableNodesByCluster(Router router, String balancerName, String cName) { return lookupBalancer(router, balancerName).getAvailableNodesByCluster(cName); } - public static void addSession2Cluster(IRouter router, String balancerName, String sessionId, String cName, Node n) { + public static void addSession2Cluster(Router router, String balancerName, String sessionId, String cName, Node n) { lookupBalancer(router, balancerName).addSession2Cluster(sessionId, cName, n); } - public static void removeNode(IRouter router, String balancerName, String cluster, String host, int port) { + public static void removeNode(Router router, String balancerName, String cluster, String host, int port) { lookupBalancer(router, balancerName).removeNode(cluster, host, port); } - public static Node getNode(IRouter router, String balancerName, String cluster, String host, int port) { + public static Node getNode(Router router, String balancerName, String cluster, String host, int port) { return lookupBalancer(router, balancerName).getNode(cluster, host, port); } - public static Map getSessions(IRouter router, String balancerName, String cluster) { + public static Map getSessions(Router router, String balancerName, String cluster) { return lookupBalancer(router, balancerName).getSessions(cluster); } - public static List getSessionsByNode(IRouter router, String balancerName, String cName, Node node) { + public static List getSessionsByNode(Router router, String balancerName, String cName, Node node) { return lookupBalancer(router, balancerName).getSessionsByNode(cName, node); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java index ee08390ea7..e024aa96c5 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ByThreadStrategy.java @@ -122,7 +122,7 @@ protected String getElementName() { } @Override - public void init(IRouter router) { + public void init(Router router) { // do nothing } } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java index cbc520bf08..7f3091b16c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/DispatchingStrategy.java @@ -19,7 +19,7 @@ public interface DispatchingStrategy { - void init(IRouter router); + void init(Router router); Node dispatch(LoadBalancingInterceptor interceptor, AbstractExchange exc) throws EmptyNodeListException; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java index 8590562bc8..f718be179a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractor.java @@ -31,7 +31,7 @@ public class PolyglotSessionIdExtractor extends AbstractXmlElement implements Se private String sessionSource; private ExchangeExpression exchangeExpression; - public void init(IRouter router) { + public void init(Router router) { if (sessionSource != null && !sessionSource.isEmpty()) { exchangeExpression = expression(new InterceptorAdapter(router), language, sessionSource); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java index 9519c2eef3..8425d1ab71 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/PriorityStrategy.java @@ -42,7 +42,7 @@ public class PriorityStrategy extends AbstractXmlElement implements DispatchingS private static final Logger log = LoggerFactory.getLogger(PriorityStrategy.class); @Override - public void init(IRouter router) {} + public void init(Router router) {} @Override public Node dispatch(LoadBalancingInterceptor interceptor, AbstractExchange exc) throws EmptyNodeListException { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java index 665d72f2e8..1c5cf46a38 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/RoundRobinStrategy.java @@ -71,7 +71,7 @@ protected String getElementName() { } @Override - public void init(IRouter router) { + public void init(Router router) { // do nothing } } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java index a1aa23b4c1..de71248d41 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/SessionIdExtractor.java @@ -20,7 +20,7 @@ public interface SessionIdExtractor { - default void init(IRouter router) { + default void init(Router router) { } default boolean hasSessionId(Exchange exc, Flow flow) throws Exception { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java index 84b3027af2..a4bd00fd9f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/faultmonitoring/FaultMonitoringStrategy.java @@ -123,7 +123,7 @@ public class FaultMonitoringStrategy extends AbstractXmlElement implements Dispa private HttpClientStatusEventBus httpClientStatusEventBus; @Override - public void init(IRouter router) { + public void init(Router router) { httpClientStatusEventBus = new HttpClientStatusEventBus(); httpClientStatusEventBus.registerListener(new MyHttpClientStatusEventListener()); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java index 2be9254608..dfb85269af 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/cache/CacheInterceptor.java @@ -67,7 +67,7 @@ public String getShortDescription() { } public static abstract class Store { - public void init(IRouter router) {} + public void init(Router router) {} public abstract Node get(String url); public abstract void put(String url, Node node); @@ -102,7 +102,7 @@ public void setDir(String dir) { } @Override - public void init(IRouter router) { + public void init(Router router) { dir = ResolverMap.combine(router.getBaseLocation(), dir); File d = new File(dir); if (!d.exists()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java index ac50affd2b..7efa576deb 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java @@ -60,7 +60,7 @@ protected static void createProblemDetails(String flow, Interceptor interceptor, } @Override - public void init(IRouter router, Proxy proxy) { + public void init(Router router, Proxy proxy) { for (Interceptor i : interceptors) { if(i instanceof ProxyAware pa) { pa.setProxy(proxy); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java index 8ab88e24fb..696595d495 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/Case.java @@ -36,7 +36,7 @@ public class Case extends InterceptorContainer implements XMLSupport { private ExchangeExpression exchangeExpression; private XmlConfig xmlConfig; - public void init(IRouter router) { + public void init(Router router) { exchangeExpression = expression( new InterceptorAdapter(router,xmlConfig), language, test); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java index 3d9548de00..d879bebbb3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java @@ -28,7 +28,7 @@ abstract class InterceptorContainer { private List interceptors; - Outcome invokeFlow(Exchange exc, Flow flow, IRouter router) { + Outcome invokeFlow(Exchange exc, Flow flow, Router router) { try { return switch (flow) { case REQUEST -> router.getFlowController().invokeRequestHandlers(exc, interceptors); @@ -41,7 +41,7 @@ Outcome invokeFlow(Exchange exc, Flow flow, IRouter router) { } } - private void handleInvocationProblemDetails(Exchange exc, Exception e, IRouter router) { + private void handleInvocationProblemDetails(Exchange exc, Exception e, Router router) { internal(router.isProduction(),"interceptor-container") .detail("Error invoking plugin.") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java index 96aab5efb9..ecf9e8100d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java @@ -25,7 +25,7 @@ public class GraalVMJavascriptLanguageAdapter extends LanguageAdapter { - public GraalVMJavascriptLanguageAdapter(IRouter router) { + public GraalVMJavascriptLanguageAdapter(Router router) { super(router); languageSupport = new GraalVMJavascriptSupport(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java index b7b87c02c8..13fcaacc49 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/LanguageAdapter.java @@ -24,7 +24,6 @@ import org.slf4j.*; import org.springframework.context.*; -import java.io.*; import java.util.*; import java.util.function.*; @@ -33,11 +32,11 @@ public abstract class LanguageAdapter { private static final Logger log = LoggerFactory.getLogger(LanguageAdapter.class); protected LanguageSupport languageSupport; - final protected IRouter router; + final protected Router router; protected static int preScriptLineLength; - public LanguageAdapter(IRouter router) { + public LanguageAdapter(Router router) { this.router = router; preScriptLineLength = Math.toIntExact(getPreScript().lines().count()); } @@ -54,7 +53,7 @@ protected String prepareScript(String script) { return getPreScript() + script + getPostScript(); } - public static LanguageAdapter instance(IRouter router) { + public static LanguageAdapter instance(Router router) { try { Class.forName("org.graalvm.polyglot.Context"); log.info("Found GraalVM Javascript engine."); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java index 4b3145425a..b638b14bb6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java @@ -24,7 +24,7 @@ public class RhinoJavascriptLanguageAdapter extends LanguageAdapter { - public RhinoJavascriptLanguageAdapter(IRouter router) { + public RhinoJavascriptLanguageAdapter(Router router) { super(router); languageSupport = new RhinoJavascriptLanguageSupport(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java index d954e53d43..76178d2869 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClaimList.java @@ -79,7 +79,7 @@ public void setClaims(String claims) { private String value; private HashSet supportedClaims = new HashSet<>(); - public void init(IRouter router){ + public void init(Router router){ setScopes(scopes); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java index 82da84c670..0920798bd6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ClientList.java @@ -20,7 +20,7 @@ public interface ClientList { - void init(IRouter router); + void init(Router router); /** * @throws NoSuchElementException diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java index c832b4fbe3..535d8f5a3b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/ConsentPageFile.java @@ -41,7 +41,7 @@ public class ConsentPageFile { private Map json; - public void init(IRouter router, String url) throws IOException { + public void init(Router router, String url) throws IOException { resolver = router.getResolverMap(); if(url == null) { createDefaults(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java index 25b3ed07a2..2a136f220b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/StaticClientList.java @@ -29,7 +29,7 @@ public class StaticClientList implements ClientList { private List clients = new ArrayList<>(); @Override - public void init(IRouter router) { + public void init(Router router) { setClients(clients); // fix because the setter is called with empty List } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java index 1dadb70014..54fa477187 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/AuthorizationService.java @@ -58,7 +58,6 @@ import static com.predic8.membrane.core.interceptor.oauth2.OAuth2TokenBody.authorizationCodeBodyBuilder; import static com.predic8.membrane.core.interceptor.oauth2.OAuth2TokenBody.refreshTokenBodyBuilder; import static com.predic8.membrane.core.interceptor.oauth2client.rf.JsonUtils.isJson; -import static com.predic8.membrane.core.interceptor.oauth2client.rf.OAuth2CallbackRequestHandler.MEMBRANE_MISSING_SESSION_DESCRIPTION; import static org.apache.commons.codec.binary.Base64.encodeBase64; public abstract class AuthorizationService { @@ -69,7 +68,7 @@ public abstract class AuthorizationService { protected Logger log; private HttpClient httpClient; - IRouter router; + Router router; protected HttpClientConfiguration httpClientConfiguration; private final Object lock = new Object(); @@ -91,7 +90,7 @@ public boolean supportsDynamicRegistration() { return supportsDynamicRegistration; } - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { log = LoggerFactory.getLogger(this.getClass().getName()); if (isUseJWTForClientAuth()) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java index 4d4028e72c..6ddef0f00e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/DynamicRegistration.java @@ -39,9 +39,9 @@ public class DynamicRegistration { private SSLContext sslContext; private HttpClient client; private HttpClientConfiguration httpClientConfiguration; - private IRouter router; + private Router router; - public void init(IRouter router) { + public void init(Router router) { this.router = router; if (sslParser != null) sslContext = new StaticSSLContext(sslParser, router.getResolverMap(), router.getBaseLocation()); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java index 2286d60935..dea9aa879d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerJwtTokenGenerator.java @@ -50,7 +50,7 @@ public class BearerJwtTokenGenerator implements TokenGenerator { private long expiration; private boolean warningGeneratedKey = true; - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { if (jwk == null) { rsaJsonWebKey = generateKey(); if (warningGeneratedKey) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java index 56bb8a0d5d..37c0197d08 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/BearerTokenGenerator.java @@ -65,7 +65,7 @@ public void setClientSecret(String clientSecret) { private final ConcurrentHashMap tokenToUser = new ConcurrentHashMap<>(); @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { // nothing to do } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java index e5ae3fc132..88d8ee0482 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokengenerators/TokenGenerator.java @@ -19,7 +19,7 @@ import java.util.NoSuchElementException; public interface TokenGenerator { - void init(IRouter router) throws Exception; + void init(Router router) throws Exception; /** * @return the token type used, probably "Bearer". diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java index 6014e9d505..08214dfde9 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/rf/SessionAuthorizer.java @@ -46,10 +46,10 @@ public class SessionAuthorizer { private boolean skip; private AuthorizationService auth; - private IRouter router; + private Router router; private OAuth2Statistics statistics; - public void init(AuthorizationService auth, IRouter router, OAuth2Statistics statistics) { + public void init(AuthorizationService auth, Router router, OAuth2Statistics statistics) { this.auth = auth; this.router = router; this.statistics = statistics; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2server/LoginDialog2.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2server/LoginDialog2.java index 4c0a6aa414..01d1413134 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2server/LoginDialog2.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2server/LoginDialog2.java @@ -77,7 +77,7 @@ public LoginDialog2( wsi.setDocBase(dialogLocation); } - public void init(Router router) throws Exception { + public void init(DefaultRouter router) throws Exception { uriFactory = router.getUriFactory(); wsi.init(router); router.getResolverMap().resolve(ResolverMap.combine(router.getBaseLocation(), wsi.getDocBase(), "index.html")).close(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java index ab0da12550..624278e556 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/SchematronValidator.java @@ -54,7 +54,7 @@ public String getName() { return "Schematron Validator"; } - public SchematronValidator(String schematron, ValidatorInterceptor.FailureHandler failureHandler, IRouter router, BeanFactory beanFactory) throws Exception { + public SchematronValidator(String schematron, ValidatorInterceptor.FailureHandler failureHandler, Router router, BeanFactory beanFactory) throws Exception { this.failureHandler = failureHandler; //works as standalone "com.sun.org.apache.xalan.internal.xsltc.trax.TransformerFactoryImpl" diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java index aa9cf3002d..17a7f4dcba 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java @@ -68,7 +68,7 @@ public WebServerInterceptor() { name = "web server"; } - public WebServerInterceptor(IRouter r) { + public WebServerInterceptor(Router r) { name = "web server"; this.router = r; } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java index c9e06b4d36..e23fc60dc1 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/InMemorySessionManager.java @@ -38,7 +38,7 @@ public class InMemorySessionManager extends SessionManager { protected final String cookieNamePrefix = UUID.randomUUID().toString().substring(0,8); @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { sessions = CacheBuilder.newBuilder() .expireAfterAccess(Duration.ofSeconds(getExpiresAfterSeconds())) .build(); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java index e4a93e3a77..d6f9b2115c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/JwtSessionManager.java @@ -59,7 +59,7 @@ public class JwtSessionManager extends SessionManager { Jwk jwk; boolean verbose = false; - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { if (validTime == null) validTime = Duration.ofSeconds(expiresAfterSeconds); if (renewalTime == null) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java index 091954eb81..50d4e9d92e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/MemcachedSessionManager.java @@ -43,7 +43,7 @@ public class MemcachedSessionManager extends SessionManager { private final ObjectMapper objectMapper = new ObjectMapper(); @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { this.client = connector.getClient(); } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java index b655744d15..5fba074176 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/RedisSessionManager.java @@ -47,7 +47,7 @@ public RedisSessionManager(){ @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { //Nothing to do } diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java b/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java index a2a12d9018..8e7bf825d4 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/session/SessionManager.java @@ -81,7 +81,7 @@ private void normalizePublicURL() { issuer += "/"; } - public abstract void init(IRouter router) throws Exception; + public abstract void init(Router router) throws Exception; /** * Transforms a cookie value into its attributes. The cookie should be assumed valid as @isValidCookieForThisSessionManager was called beforehand diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java index aa072a47d3..cc06b726f3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTTransformer.java @@ -32,7 +32,7 @@ public class XSLTTransformer { private final ArrayBlockingQueue transformers; private final String styleSheet; - public XSLTTransformer(String styleSheet, final IRouter router, final int concurrency) throws Exception { + public XSLTTransformer(String styleSheet, final Router router, final int concurrency) throws Exception { fac = TransformerFactory.newInstance(); this.styleSheet = styleSheet; diff --git a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java index 10a3eb2bf9..267e6e1567 100644 --- a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java @@ -13,7 +13,7 @@ package com.predic8.membrane.core.jmx; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.proxies.Proxy; import com.predic8.membrane.core.proxies.ServiceProxy; import org.springframework.jmx.export.annotation.ManagedAttribute; @@ -23,10 +23,10 @@ public class JmxRouter { - private final Router router; + private final DefaultRouter router; private final JmxExporter exporter; - public JmxRouter(Router router, JmxExporter exporter) { + public JmxRouter(DefaultRouter router, JmxExporter exporter) { this.router = router; this.exporter = exporter; exportServiceProxyList(); diff --git a/core/src/main/java/com/predic8/membrane/core/jmx/JmxServiceProxy.java b/core/src/main/java/com/predic8/membrane/core/jmx/JmxServiceProxy.java index 2783c40a9c..c0b52846b6 100644 --- a/core/src/main/java/com/predic8/membrane/core/jmx/JmxServiceProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/jmx/JmxServiceProxy.java @@ -13,7 +13,7 @@ package com.predic8.membrane.core.jmx; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.proxies.ServiceProxy; import org.springframework.jmx.export.annotation.ManagedAttribute; import org.springframework.jmx.export.annotation.ManagedOperation; @@ -25,9 +25,9 @@ public class JmxServiceProxy { private final ServiceProxy rule; - private final Router router; + private final DefaultRouter router; - public JmxServiceProxy(ServiceProxy rule, Router router) { + public JmxServiceProxy(ServiceProxy rule, DefaultRouter router) { this.rule = rule; this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java index 9d39d62b98..6b4d422c24 100644 --- a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java +++ b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java @@ -37,14 +37,14 @@ public class KubernetesWatcher { private static final Logger LOG = LoggerFactory.getLogger(KubernetesWatcher.class); - private final Router router; + private final DefaultRouter router; private final BeanCollector beanRegistry; private final GrammarAutoGenerated grammar; private KubernetesClient client; private ExecutorService executors; private final ConcurrentHashMap watches = new ConcurrentHashMap<>(); - public KubernetesWatcher(Router router) { + public KubernetesWatcher(DefaultRouter router) { this.router = router; this.grammar = new GrammarAutoGenerated(); var br = new BeanRegistryImplementation(router, router, grammar); diff --git a/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java b/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java index c1fc0749cb..108876fa5e 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/ExchangeExpression.java @@ -74,11 +74,11 @@ class InterceptorAdapter extends AbstractInterceptor implements XMLSupport { private XmlConfig xmlConfig; - public InterceptorAdapter(IRouter router) { + public InterceptorAdapter(Router router) { this.router = router; } - public InterceptorAdapter(IRouter router, XmlConfig xmlConfig) { + public InterceptorAdapter(Router router, XmlConfig xmlConfig) { this.router = router; this.xmlConfig = xmlConfig; } diff --git a/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java b/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java index 61b73dd181..16be3a4f3d 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/ScriptingUtils.java @@ -41,7 +41,7 @@ public class ScriptingUtils { private static final ObjectMapper om = new ObjectMapper(); - public static HashMap createParameterBindings(IRouter router, Exchange exc, Flow flow, boolean includeJsonObject) { + public static HashMap createParameterBindings(Router router, Exchange exc, Flow flow, boolean includeJsonObject) { Message msg = exc.getMessage(flow); diff --git a/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java b/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java index 85ccacbea1..6118de35de 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/groovy/GroovyExchangeExpression.java @@ -33,7 +33,7 @@ public class GroovyExchangeExpression extends AbstractExchangeExpression { private static final Logger log = LoggerFactory.getLogger(GroovyExchangeExpression.class); private final Function, Object> script; - private final IRouter router; + private final Router router; public GroovyExchangeExpression(Interceptor interceptor, String source) { super(source); diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java index 5026b4c053..395a86272f 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisher.java @@ -87,7 +87,7 @@ Outcome handleSwaggerUi(Exchange exc) { return RETURN; } - Outcome handleOverviewOpenAPIDoc(Exchange exc, IRouter router, Logger log) throws IOException, URISyntaxException { + Outcome handleOverviewOpenAPIDoc(Exchange exc, Router router, Logger log) throws IOException, URISyntaxException { Matcher m = PATTERN_META.matcher(exc.getRequest().getUri()); if (!m.matches()) { // No id specified if (acceptsHtmlExplicit(exc)) { @@ -116,7 +116,7 @@ private Outcome returnJsonOverview(Exchange exc, Logger log) throws JsonProcessi return RETURN; } - private Outcome returnHtmlOverview(Exchange exc, IRouter router) { + private Outcome returnHtmlOverview(Exchange exc, Router router) { exc.setResponse(ok().contentType(TEXT_HTML_UTF8).body(renderOverviewTemplate(router)).build()); return RETURN; } @@ -133,7 +133,7 @@ private Outcome returnNoFound(Exchange exc, String id) { return RETURN; } - private Outcome returnOpenApiAsYaml(Exchange exc, OpenAPIRecord rec, IRouter router) throws IOException, URISyntaxException { + private Outcome returnOpenApiAsYaml(Exchange exc, OpenAPIRecord rec, Router router) throws IOException, URISyntaxException { exc.setResponse(ok().yaml() .body(omYaml.writeValueAsBytes(rec.rewriteOpenAPI(exc, router.getUriFactory()))) .build()); @@ -144,7 +144,7 @@ private Template createTemplate(String filePath) throws ClassNotFoundException, return new StreamingTemplateEngine().createTemplate(new InputStreamReader(Objects.requireNonNull(getResourceAsStream(this, filePath)))); } - private String renderOverviewTemplate(IRouter router) { + private String renderOverviewTemplate(Router router) { Map tempCtx = new HashMap<>(); tempCtx.put("apis", apis); tempCtx.put("pathUi", PATH_UI); diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java index e083c798fc..4103440435 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactory.java @@ -46,9 +46,9 @@ public class OpenAPIRecordFactory { private static final ObjectMapper omYaml = ObjectMapperFactory.createYaml(); - private final IRouter router; + private final Router router; - public OpenAPIRecordFactory(IRouter router) { + public OpenAPIRecordFactory(Router router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java index e8e9633e03..b35df337de 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java @@ -43,7 +43,7 @@ public abstract class AbstractProxy implements Proxy { private boolean active; private String error; - protected IRouter router; + protected Router router; public AbstractProxy() { } @@ -89,7 +89,7 @@ public void setKey(RuleKey ruleKey) { /** * Called after parsing is complete and this has been added to the object tree (whose root is Router). */ - public final void init(IRouter router) { + public final void init(Router router) { this.router = router; try { init(); // Extension point for subclasses diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java index d26f0d3cad..44ffb320e9 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractServiceProxy.java @@ -110,7 +110,7 @@ public static class Target implements XMLSupport { protected XmlConfig xmlConfig; - public void init(IRouter router) { + public void init(Router router) { if (url != null) { exchangeExpression = TemplateExchangeExpression.newInstance(new InterceptorAdapter(router, xmlConfig), language, url); } diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java index af3a518d5c..911280dba7 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/Proxy.java @@ -38,7 +38,7 @@ public interface Proxy extends Cloneable { RuleStatisticCollector getStatisticCollector(); - void init(IRouter router); + void init(Router router); boolean isTargetAdjustHostHeader(); diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SOAPProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SOAPProxy.java index 5afa1f8982..2eb4c99d37 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SOAPProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SOAPProxy.java @@ -22,7 +22,6 @@ import com.predic8.membrane.core.interceptor.schemavalidation.ValidatorInterceptor; import com.predic8.membrane.core.interceptor.server.*; import com.predic8.membrane.core.interceptor.soap.*; -import com.predic8.membrane.core.openapi.serviceproxy.OpenAPIInterceptor; import com.predic8.membrane.core.openapi.util.*; import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.http.client.*; @@ -54,7 +53,7 @@ * - Provides a simple service explorer * @explanation If the WSDL specified by the wsdl attribute is unavailable at startup, the <soapProxy> * becomes inactive. Reinitialization can be triggered via the admin console or automatically by the - * {@link Router}, which periodically attempts to restore the proxy. + * {@link DefaultRouter}, which periodically attempts to restore the proxy. * @topic 1. Proxies and Flow */ @MCElement(name = "soapProxy") diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java index 1a33fc6f91..793aa1849b 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SSLProxy.java @@ -192,10 +192,10 @@ public SSLProvider getSslOutboundContext() { return null; } - IRouter router; + Router router; @Override - public void init(IRouter router) { + public void init(Router router) { this.router = router; cm = new ConnectionManager(connectionConfiguration.getKeepAliveTimeout(), router.getTimerManager()); for (SSLInterceptor i : sslInterceptors) diff --git a/core/src/main/java/com/predic8/membrane/core/resolver/ResolverMap.java b/core/src/main/java/com/predic8/membrane/core/resolver/ResolverMap.java index 3e5750a02b..9332178b3d 100644 --- a/core/src/main/java/com/predic8/membrane/core/resolver/ResolverMap.java +++ b/core/src/main/java/com/predic8/membrane/core/resolver/ResolverMap.java @@ -229,7 +229,7 @@ private SchemaResolver getSchemaResolver(String uri) { throw new RuntimeException("No SchemaResolver defined for " + uri); } - public void addRuleResolver(Router r) { + public void addRuleResolver(DefaultRouter r) { addSchemaResolver(new RuleResolver(r)); } diff --git a/core/src/main/java/com/predic8/membrane/core/resolver/RuleResolver.java b/core/src/main/java/com/predic8/membrane/core/resolver/RuleResolver.java index c3f4374f92..55f0bf577e 100644 --- a/core/src/main/java/com/predic8/membrane/core/resolver/RuleResolver.java +++ b/core/src/main/java/com/predic8/membrane/core/resolver/RuleResolver.java @@ -34,8 +34,8 @@ public class RuleResolver implements SchemaResolver { private static final Logger log = LoggerFactory.getLogger(RuleResolver.class); - final Router router; - public RuleResolver(Router router) { + final DefaultRouter router; + public RuleResolver(DefaultRouter router) { this.router = router; } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java index bedd8845d1..b3bad0a542 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/DefaultHotDeployer.java @@ -28,12 +28,12 @@ public class DefaultHotDeployer implements HotDeployer { @GuardedBy("lock") private HotDeploymentThread hdt; - private Router router; + private DefaultRouter router; private final Object lock = new Object(); @Override - public void start(@NotNull Router router) { + public void start(@NotNull DefaultRouter router) { this.router = router; startInternal(); } diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java index 3cade06430..3ecf941099 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/HotDeployer.java @@ -18,7 +18,7 @@ public interface HotDeployer { - void start(Router router); + void start(DefaultRouter router); void stop(); diff --git a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java index e903779183..35c4c6a761 100644 --- a/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java +++ b/core/src/main/java/com/predic8/membrane/core/router/hotdeploy/NullHotDeployer.java @@ -18,7 +18,7 @@ public class NullHotDeployer implements HotDeployer { @Override - public void start(Router router) { + public void start(DefaultRouter router) { } diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java index f7f378e434..b2539010ee 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/RouterIpResolverInterceptor.java @@ -112,7 +112,7 @@ public void setSslParser(SSLParser sslParser) { } @Override - public void init(IRouter router) { + public void init(Router router) { httpClient = router.getHttpClientFactory().createClient(httpClientConfiguration); if (sslParser != null) sslContext = new StaticSSLContext(sslParser, router.getResolverMap(), router.getBaseLocation()); diff --git a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java index fb3ee165f3..298ddd70aa 100644 --- a/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/sslinterceptor/SSLInterceptor.java @@ -18,7 +18,7 @@ import com.predic8.membrane.core.transport.ssl.SSLExchange; public interface SSLInterceptor { - void init(IRouter router); + void init(Router router); Outcome handleRequest(SSLExchange exc) throws Exception; } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java index baed3b59c4..f9581a11dd 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/Transport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/Transport.java @@ -25,7 +25,6 @@ import org.springframework.beans.factory.*; import java.io.*; -import java.lang.reflect.*; import java.util.*; public abstract class Transport { @@ -36,7 +35,7 @@ public abstract class Transport { protected final Set menuListeners = new HashSet<>(); private List interceptors = new Vector<>(); - private Router router; + private DefaultRouter router; private boolean reverseDNS = true; private int concurrentConnectionLimitPerIp = -1; @@ -54,7 +53,7 @@ public void setFlow(List flow) { this.interceptors = flow; } - public void init(Router router) { + public void init(DefaultRouter router) { this.router = router; if (interceptors.isEmpty()) { @@ -104,7 +103,7 @@ public void init(Router router) { return new ExchangeStoreInterceptor(router.getExchangeStore()); } - public Router getRouter() { + public DefaultRouter getRouter() { return router; } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java index 98c4472fcb..3cdba24b14 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java @@ -41,6 +41,8 @@ * The interceptors that are engaged with the transport are global and are invoked for each message flowing * through the router. *

+ * + * Besides HttpTransport there is also a ServletTransport. */ @MCElement(name="transport") public class HttpTransport extends Transport { @@ -60,7 +62,7 @@ public class HttpTransport extends Transport { new SynchronousQueue<>(), new HttpServerThreadFactory()); @Override - public void init(Router router) { + public void init(DefaultRouter router) { super.init(router); } @@ -108,7 +110,7 @@ public synchronized void closeAll(boolean waitForCompletion) { closePort(ipPort); } log.debug("Closing all stream pumps."); - Router router = getRouter(); + DefaultRouter router = getRouter(); if (router != null) router.getStatistics().getStreamPumpStats().closeAllStreamPumps(); @@ -284,7 +286,7 @@ public int getForceSocketCloseOnHotDeployAfter() { /** * @description When proxies.xml is changed and <router hotDeploy="true">, the Spring Context is automatically refreshed, - * which restarts the {@link Router} object (=Membrane API Gateway). Before the context refresh, all open socket connections + * which restarts the {@link DefaultRouter} object (=Membrane API Gateway). Before the context refresh, all open socket connections * have to be closed. Exchange objects which are still running might delay this process. Setting forceSocketCloseOnHotDeployAfter * to a non-zero number of milliseconds forces connections to be closed after this time. * @default 30000 diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java index 233b619794..08f4f9e76b 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/WebSocketInterceptorInterface.java @@ -21,7 +21,7 @@ */ public interface WebSocketInterceptorInterface { - void init(IRouter router) throws Exception; + void init(Router router) throws Exception; void handleFrame(WebSocketFrame frame, boolean frameTravelsToRight, WebSocketSender sender) throws Exception; diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java index 4f82c32005..ee5fe9eff4 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketLogInterceptor.java @@ -37,7 +37,7 @@ public enum Encoding { private Encoding encoding = Encoding.RAW; @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java index c2fc5bbefc..7df8bb2fcb 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketSpringInterceptor.java @@ -55,7 +55,7 @@ public void setApplicationContext(ApplicationContext applicationContext) throws } @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { i.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java index e4b70cad24..732f546274 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ws/interceptors/WebSocketStompReassembler.java @@ -39,7 +39,7 @@ public class WebSocketStompReassembler implements WebSocketInterceptorInterface List interceptors = new ArrayList<>(); @Override - public void init(IRouter router) throws Exception { + public void init(Router router) throws Exception { for (Interceptor i : interceptors) i.init(router); } diff --git a/core/src/main/java/com/predic8/membrane/core/util/jdbc/AbstractJdbcSupport.java b/core/src/main/java/com/predic8/membrane/core/util/jdbc/AbstractJdbcSupport.java index b9fb851b9f..908470963b 100644 --- a/core/src/main/java/com/predic8/membrane/core/util/jdbc/AbstractJdbcSupport.java +++ b/core/src/main/java/com/predic8/membrane/core/util/jdbc/AbstractJdbcSupport.java @@ -15,7 +15,7 @@ package com.predic8.membrane.core.util.jdbc; import com.predic8.membrane.annot.MCAttribute; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.util.ConfigurationException; import javax.sql.DataSource; @@ -24,7 +24,7 @@ public abstract class AbstractJdbcSupport { private DataSource datasource; - private Router router; + private DefaultRouter router; private static final String DATASOURCE_SAMPLE = """ Sample: @@ -48,7 +48,7 @@ public abstract class AbstractJdbcSupport {
"""; - public void init(Router router) { + public void init(DefaultRouter router) { this.router = router; getDatasourceIfNull(); } diff --git a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java index f9be167808..dbb035ad76 100644 --- a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java +++ b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java @@ -18,7 +18,7 @@ public abstract class AbstractTestWithRouter { - protected IRouter router; + protected Router router; @BeforeEach void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/RouterTest.java b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java similarity index 96% rename from core/src/test/java/com/predic8/membrane/core/RouterTest.java rename to core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java index 70a4e5c0ca..596eeebf2a 100644 --- a/core/src/test/java/com/predic8/membrane/core/RouterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java @@ -26,10 +26,10 @@ import static io.restassured.filter.log.LogDetail.*; import static org.hamcrest.Matchers.*; -class RouterTest { +class DefaultRouterTest { public static final String INTERNAL_SECRET = "supersecret"; - static IRouter dev, prod; + static Router dev, prod; @BeforeAll static void setUp() throws IOException { @@ -112,8 +112,8 @@ void devXML() { // @formatter:on } - private static IRouter createRouter(int port, boolean production) throws IOException { - IRouter r = new Router(); + private static Router createRouter(int port, boolean production) throws IOException { + Router r = new DefaultRouter(); r.getConfig().setProduction(production); APIProxy api = new APIProxy(); api.setKey(new APIProxyKey(port)); diff --git a/core/src/test/java/com/predic8/membrane/core/MockRouter.java b/core/src/test/java/com/predic8/membrane/core/MockRouter.java index a1be4085e1..ad7a4fa899 100644 --- a/core/src/test/java/com/predic8/membrane/core/MockRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/MockRouter.java @@ -13,11 +13,10 @@ limitations under the License. */ package com.predic8.membrane.core; -import com.predic8.membrane.core.exchangestore.ForgetfulExchangeStore; -import com.predic8.membrane.core.transport.Transport; +import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.transport.http.*; -public class MockRouter extends Router { +public class MockRouter extends DefaultRouter { public MockRouter() { setExchangeStore(new ForgetfulExchangeStore()); @@ -28,4 +27,4 @@ public HttpTransport getTransport() { return new MockHttpTransport(); } -} +} \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java b/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java index 5c2c8cb183..4503a410a1 100644 --- a/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java +++ b/core/src/test/java/com/predic8/membrane/core/RuleManagerUriTemplateTest.java @@ -13,7 +13,6 @@ limitations under the License. */ package com.predic8.membrane.core; -import com.predic8.membrane.*; import com.predic8.membrane.core.config.*; import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.proxies.Proxy; @@ -59,7 +58,7 @@ void pathDoesntMatchesUriTemplate(String uriTemplate,String path) throws Excepti private Proxy getMatchingProxy(String uriTemplate, String path, APIProxy p) throws URISyntaxException { p.setPath(new Path(false, uriTemplate)); - p.init(new Router()); + p.init(new DefaultRouter()); return new RuleManager() {{ proxies.add(p); }}.getMatchingRule(get(path).buildExchange()); diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index 842a7964ac..569bef6a47 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -19,7 +19,7 @@ public class SimpleTest { - private static Router router; + private static DefaultRouter router; @BeforeAll static void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/TestRouter.java b/core/src/test/java/com/predic8/membrane/core/TestRouter.java index 2e27d018cb..265fa104b1 100644 --- a/core/src/test/java/com/predic8/membrane/core/TestRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/TestRouter.java @@ -1,5 +1,35 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + package com.predic8.membrane.core; -public class TestRouter extends Router { +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.http.client.*; + +public class TestRouter extends DefaultRouter { + + public TestRouter() { + } + + public TestRouter(ProxyConfiguration proxyConfiguration) { + if (proxyConfiguration != null) + getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + } + + @Override + public HttpTransport getTransport() { + return (HttpTransport) transport; + } } diff --git a/core/src/test/java/com/predic8/membrane/core/UnitTests.java b/core/src/test/java/com/predic8/membrane/core/UnitTests.java index 2167afb4bf..5c66021a62 100644 --- a/core/src/test/java/com/predic8/membrane/core/UnitTests.java +++ b/core/src/test/java/com/predic8/membrane/core/UnitTests.java @@ -20,7 +20,6 @@ @ExcludePackages("com.predic8.membrane.integration") @ExcludeClassNamePatterns({ "com.predic8.membrane.core.transport.http.ConnectionTest", // #2180 should fix it - "com.predic8.membrane.integration.withinternet.interceptor.RewriteInterceptorIntegrationTest", // Rewrite as UnitTest with sampleSOAPService "com.predic8.membrane.core.interceptor.tunnel.WebsocketStompTest", // Fails: not standalone; depends on external WS+STOMP setup "com.predic8.membrane.core.interceptor.oauth2client.OAuth2Resource2InterceptorTest", // Disabled: incomplete setup; AuthorizationService (and other) not configured "com.predic8.membrane.core.util.MemcachedConnectorTest" // Disabled: not standalone; needs Memcached at 127.0.0.1:11211 (fails with Connection refused) diff --git a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java index 6dbc02454e..1a5f245401 100644 --- a/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/acl/ACLTest.java @@ -23,11 +23,11 @@ public abstract class ACLTest extends AccessControlInterceptor { - protected IRouter router; + protected Router router; @BeforeEach void setUpEach() { - router = new HttpRouter(); + router = new DummyTestRouter(); router.start(); } @@ -36,7 +36,7 @@ void tearDownEach() { router.stop(); } - private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { + private AccessControlInterceptor createRouter(boolean isReverseDNS, boolean useForwardedFor, Function f) { AccessControlInterceptor aci = buildAci(f.apply(router)); aci.setUseXForwardedForAsClientAddr(useForwardedFor); return aci; @@ -58,20 +58,20 @@ private static AccessControlInterceptor buildAci(Resource resource) { }}; } - private static Resource getIpResource(String scheme, ParseType ptype, IRouter router) { + private static Resource getIpResource(String scheme, ParseType ptype, Router router) { return createResource(new Ip(router) {{ setParseType(ptype); setSchema(scheme); }}, router); } - private static Resource getHostnameResource(String scheme, IRouter router) { + private static Resource getHostnameResource(String scheme, Router router) { return createResource(new Hostname(router) {{ setSchema(scheme); }}, router); } - private static Resource createResource(AbstractClientAddress address, IRouter router) { + private static Resource createResource(AbstractClientAddress address, Router router) { return new Resource(router) {{ addAddress(address); setUriPattern(compile(".*")); diff --git a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java index f9d754b1d5..27099706d9 100644 --- a/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/azure/AzureDnsApiSimulator.java @@ -34,7 +34,7 @@ public class AzureDnsApiSimulator { private static final Logger log = LoggerFactory.getLogger(AzureDnsApiSimulator.class); private final int port; - private IRouter router; + private Router router; private final Map>> tableStorage = new HashMap<>(); diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 61ccf311f1..61490b1066 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -23,7 +23,7 @@ public class ReadRulesConfigurationTest { - private static Router router; + private static DefaultRouter router; private static List proxies; diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java index ac55f12e3e..2f067bdfa2 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java @@ -24,7 +24,7 @@ public class ReadRulesWithInterceptorsConfigurationTest { - private static Router router; + private static DefaultRouter router; private static List proxies; diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index 2d3ded7276..091cb14768 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -25,7 +25,7 @@ public class SpringReferencesTest { - private static Router r; + private static DefaultRouter r; @BeforeAll public static void before() { diff --git a/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLProtectionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLProtectionInterceptorTest.java index 2ebd34b3ef..e4f1bf1f98 100644 --- a/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLProtectionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLProtectionInterceptorTest.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.graphql; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.DummyTestRouter; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.graphql.blocklist.FeatureBlocklist; import com.predic8.membrane.core.graphql.blocklist.filters.*; @@ -37,12 +37,12 @@ public class GraphQLProtectionInterceptorTest { private static GraphQLProtectionInterceptor i; - private static HttpRouter router; + private static DummyTestRouter router; @BeforeAll static void init() { - router = new HttpRouter(); + router = new DummyTestRouter(); i = new GraphQLProtectionInterceptor(); i.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidatorTest.java index fa0f252397..a55f5784d1 100644 --- a/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/graphql/GraphQLoverHttpValidatorTest.java @@ -30,7 +30,7 @@ public class GraphQLoverHttpValidatorTest { @BeforeEach void setup() { - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); validator1 = new GraphQLoverHttpValidator(false, Lists.newArrayList("GET", "POST"), 3, 3, 2, null, router); } diff --git a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java index 979a02ead1..823ba597a4 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/ChunkedBodyTest.java @@ -104,7 +104,7 @@ void testReadTrailer() throws Exception { @Test void testWriteTrailer() throws IOException { - IRouter router = setupRouter(false, false); + Router router = setupRouter(false, false); try { org.apache.commons.httpclient.HttpClient hc = new org.apache.commons.httpclient.HttpClient(); for (int i = 0; i < 2; i++) { @@ -121,8 +121,8 @@ void testWriteTrailer() throws IOException { @Test void readWriteTrailerHttp2() throws IOException { - IRouter router = setupRouter(false, true); - IRouter router2 = setupRouter(true, false); + Router router = setupRouter(false, true); + Router router2 = setupRouter(true, false); try { org.apache.commons.httpclient.HttpClient hc = new org.apache.commons.httpclient.HttpClient(); for (int i = 0; i < 2; i++) { @@ -140,7 +140,7 @@ void readWriteTrailerHttp2() throws IOException { @Test void testWriteTrailerHttp2() throws IOException, NoSuchAlgorithmException, KeyManagementException { - IRouter router = setupRouter(true, false); + Router router = setupRouter(true, false); try { X509TrustManager trustAll = new X509TrustManager() { @Override @@ -182,7 +182,7 @@ public X509Certificate[] getAcceptedIssuers() { } } - private IRouter setupRouter(boolean http2, boolean http2Client) throws IOException { + private Router setupRouter(boolean http2, boolean http2Client) throws IOException { TestRouter router = new TestRouter(); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(http2 ? 3060 : 3059), "localhost", 3060); if (http2) { diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java index 56b8f9e727..9abe9bf657 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java @@ -29,8 +29,8 @@ import static org.junit.jupiter.api.Assertions.*; public class Http10Test { - private static Router router; - private static Router router2; + private static DefaultRouter router; + private static DefaultRouter router2; @BeforeAll public static void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java index 82ed2d18c2..92bfbae50b 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java @@ -30,8 +30,8 @@ public class Http11Test { - private static IRouter router; - private static IRouter router2; + private static Router router; + private static Router router2; private static int port4k; @BeforeAll diff --git a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java index 94243e6521..1c977cfdca 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java @@ -27,7 +27,7 @@ public class MethodTest { - private static IRouter router; + private static Router router; @BeforeAll public static void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java index 8f32d4bb6a..8289c7e639 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java @@ -26,7 +26,7 @@ public class AdjustContentLengthTest { - private static IRouter router; + private static Router router; @BeforeAll public static void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptorTest.java index c193729924..06310ba187 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptorTest.java @@ -14,8 +14,8 @@ package com.predic8.membrane.core.interceptor; import com.fasterxml.jackson.databind.JsonNode; -import com.predic8.membrane.core.Router; -import com.predic8.membrane.core.RuleManager; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.config.Path; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request.Builder; @@ -51,7 +51,7 @@ static void setUp() throws ParseException { @Test void responseTest() throws Exception { Exchange exc = new Builder().buildExchange(); - Router r = mock(Router.class); + DefaultRouter r = mock(DefaultRouter.class); RuleManager rm = mock(RuleManager.class); APIProxy apiProxy = new APIProxy() {{ setPath(new Path(false, "/baz")); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/DispatchingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/DispatchingInterceptorTest.java index 326153d35a..c3bc1210d3 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/DispatchingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/DispatchingInterceptorTest.java @@ -40,7 +40,7 @@ class DispatchingInterceptorTest { @BeforeEach void setUp() { - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); dispatcher = new DispatchingInterceptor(); dispatcher.init(router); exc = new Exchange(null); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptorTest.java index 99181ba0a1..41e5e77b2b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptorTest.java @@ -36,7 +36,7 @@ void setUp() { @Test void protocolUpgradeRejected() throws URISyntaxException { - Router r = new Router(); + DefaultRouter r = new DefaultRouter(); hci.init(r); @@ -53,14 +53,14 @@ void protocolUpgradeRejected() throws URISyntaxException { @Test void passFailOverOn500Default() { - hci.init(new Router()); + hci.init(new DefaultRouter()); assertFalse(hci.getHttpClientConfig().getRetryHandler().isFailOverOn5XX()); } @Test void passFailOverOn500() { hci.setFailOverOn5XX(true); - hci.init(new Router()); + hci.init(new DefaultRouter()); assertTrue(hci.getHttpClientConfig().getRetryHandler().isFailOverOn5XX()); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java index 0100e07b4a..d1f14884aa 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java @@ -22,7 +22,7 @@ public class InternalInvocationTest { - private Router router; + private DefaultRouter router; @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptorTest.java index 53ecdd7a78..5ca0788fec 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptorTest.java @@ -34,7 +34,7 @@ void setUp() { interceptor = new RegExReplaceInterceptor(); interceptor.setRegex("\\bb.*?\\b"); interceptor.setReplace("boo"); - interceptor.init(new Router()); + interceptor.init(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index 06ae01c419..104b59b94b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -30,7 +30,7 @@ class UserFeatureTest { public static final String MOCK_5 = "mock5"; public static final String MOCK_6 = "mock6"; public static final String MOCK_2 = "mock2"; - private static Router router; + private static DefaultRouter router; static List labels, inverseLabels, inversAbortLabels; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/acl/AccessControlParserTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/acl/AccessControlParserTest.java index 4a54f9743e..e82de42f07 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/acl/AccessControlParserTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/acl/AccessControlParserTest.java @@ -18,7 +18,7 @@ import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.DummyTestRouter; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -34,7 +34,7 @@ public class AccessControlParserTest { @BeforeAll protected static void setUp() throws Exception { - resources = new AccessControlInterceptor().parse(FILE_NAME, new HttpRouter()).getResources(); + resources = new AccessControlInterceptor().parse(FILE_NAME, new DummyTestRouter()).getResources(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/acl/HostnameTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/acl/HostnameTest.java index fca0675f0d..316682c02b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/acl/HostnameTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/acl/HostnameTest.java @@ -20,14 +20,14 @@ public class HostnameTest { - static Router router; + static DefaultRouter router; static Hostname h1; static Hostname h2; @BeforeAll public static void setUp() throws Exception { - router = new Router(); + router = new DefaultRouter(); h1 = new Hostname(router); h1.setSchema("^localhost$"); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java index 637172df67..3f9e7e1a7b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptorTest.java @@ -35,7 +35,7 @@ class AdminApiInterceptorTest { - private static IRouter router; + private static Router router; @BeforeAll static void setUp() throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java index 11ac295ede..4e31e2d004 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptorTest.java @@ -57,17 +57,17 @@ public class ApiKeysInterceptorTest { static void setup() { store = new ApiKeyFileStore(); store.setLocation(getKeyfilePath("apikeys/keys.txt")); - store.init(new HttpRouter()); + store.init(new DummyTestRouter()); mergeStore = new ApiKeyFileStore(); mergeStore.setLocation(getKeyfilePath("apikeys/merge-keys.txt")); - mergeStore.init(new HttpRouter()); + mergeStore.init(new DummyTestRouter()); ahe = new ApiKeyHeaderExtractor(); aqe = new ApiKeyQueryParamExtractor(); aee = new ApiKeyExpressionExtractor(); aee.setExpression("json['api-key']"); - aee.init(new HttpRouter()); + aee.init(new DummyTestRouter()); akiWithProp = new ApiKeysInterceptor(); akiWithProp.setExtractors(of(ahe)); @@ -169,7 +169,7 @@ void handleUnauthorizedKey() { void handleDuplicateApiKeys() { var dupeStore = new ApiKeyFileStore(); dupeStore.setLocation(getKeyfilePath("apikeys/duplicate-api-keys.txt")); - assertThrows(RuntimeException.class, () -> dupeStore.init(new HttpRouter())); + assertThrows(RuntimeException.class, () -> dupeStore.init(new DummyTestRouter())); } private static String getKeyfilePath(String name) { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java index 9d68e63425..6eedee2630 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/apikey/stores/ApiKeyFileStoreTest.java @@ -100,7 +100,7 @@ void parseValues() { private static void loadFromFile(ApiKeyFileStore store, String path) { store.setLocation(requireNonNull(ApiKeyFileStoreTest.class.getClassLoader().getResource(path)).getPath()); - store.init(new HttpRouter()); + store.init(new DummyTestRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptorTest.java index 586212d4d7..c7f4416640 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptorTest.java @@ -39,7 +39,7 @@ static void setup() { new User("admin", "admin"), new User("admin", "$6$12345678$jwCsYagMo/KNcTDqnrWL25Dy3AfAT5U94abA5a/iPFO.Cx2zAkMpPxZBNKY/P/xiRrCfCFDxdBp7pvNEMoBcr0") )); - bai.init(new Router()); + bai.init(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java index edf87a56f0..b32e4a9274 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java @@ -30,7 +30,7 @@ public class ClusterBalancerTest { private static XMLElementSessionIdExtractor extractor; private static LoadBalancingInterceptor lb; - private static IRouter r; + private static Router r; @BeforeAll static void setUp() throws Exception { @@ -39,7 +39,7 @@ static void setUp() throws Exception { extractor.setLocalName("session"); extractor.setNamespace("http://predic8.com/session/"); - r = new HttpRouter(); + r = new DummyTestRouter(); lb = new LoadBalancingInterceptor(); lb.setSessionIdExtractor(extractor); @@ -55,7 +55,7 @@ static void setUp() throws Exception { } @AfterAll - static void tearDown() throws Exception { + static void tearDown() { r.shutdown(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java index 744b8d27c3..5f5b200788 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java @@ -32,10 +32,10 @@ public class LoadBalancingWithClusterManagerTest { - private IRouter lb; - private Router node1; - private Router node2; - private Router node3; + private Router lb; + private DefaultRouter node1; + private DefaultRouter node2; + private DefaultRouter node3; @AfterEach public void tearDown() { @@ -94,8 +94,8 @@ void nodesTest() throws Exception { assertEquals(2, service3.getCount()); } - private static @NotNull Router createRouter() { - Router node1 = new TestRouter(); + private static @NotNull DefaultRouter createRouter() { + DefaultRouter node1 = new TestRouter(); node1.getRegistry().register("global", new GlobalInterceptor()); return node1; } @@ -117,13 +117,13 @@ private void startLB() throws Exception { ServiceProxy cniRule = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3012), "thomas-bayer.com", 80); cniRule.getFlow().add(cni); - lb = new Router(); + lb = new DefaultRouter(); lb.add(lbiRule); lb.add(cniRule); lb.start(); } - private DummyWebServiceInterceptor startNode(Router node, int port) throws Exception { + private DummyWebServiceInterceptor startNode(DefaultRouter node, int port) throws Exception { DummyWebServiceInterceptor service1 = new DummyWebServiceInterceptor(); var global = node.getRegistry().getBean(GlobalInterceptor.class); global.orElseThrow().getFlow().add(service1); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractorTest.java index 34f96882c3..d333a0b5b2 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/PolyglotSessionIdExtractorTest.java @@ -13,7 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.balancer; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.http.Header; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.http.Response; @@ -35,7 +35,7 @@ static void setup() { extractor = new PolyglotSessionIdExtractor(); extractor.setLanguage(SPEL); extractor.setSessionSource("headers['%s']".formatted(X_SESSION)); - extractor.init(new Router()); + extractor.init(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/ConditionalEvaluationTestContext.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/ConditionalEvaluationTestContext.java index fe1c881b43..f3d9ea15b2 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/ConditionalEvaluationTestContext.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/ConditionalEvaluationTestContext.java @@ -40,7 +40,7 @@ static Outcome performEval(String condition, Object builder, Language lang, bool ifInt.setLanguage(lang); ifInt.setFlow(of(mockInt)); ifInt.setTest(condition); - ifInt.init(new HttpRouter()); + ifInt.init(new DummyTestRouter()); Outcome outcome; if (builder instanceof Builder b) { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java index def12abfb2..f4693dc31d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java @@ -31,11 +31,11 @@ public class IfInterceptorSpELTest extends ConditionalEvaluationTestContext { - static Router router; + static DefaultRouter router; @BeforeAll static void setup() { - router = new Router(); + router = new DefaultRouter(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java index a8590972a7..a5e664600d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java @@ -20,19 +20,17 @@ import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.transport.http.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.util.*; import static io.restassured.RestAssured.*; -import static java.util.Collections.*; import static org.junit.jupiter.api.Assertions.*; public abstract class AbstractInterceptorFlowTest { - private IRouter router; + private Router router; @BeforeEach void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/FlowTestInterceptors.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/FlowTestInterceptors.java index 8a83a7eb22..f47685a6e7 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/FlowTestInterceptors.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/FlowTestInterceptors.java @@ -73,7 +73,7 @@ public static Otherwise OTHERWISE(Interceptor... nestedInterceptors) { public static Interceptor GROOVY(String aSrc) { return new GroovyInterceptor() {{ - router = new HttpRouter(); + router = new DummyTestRouter(); setSrc(aSrc); init(); }}; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index cb0c325e3e..f38bfee9d0 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -33,7 +33,7 @@ abstract class AbstractInternalServiceRoutingInterceptorTest { protected final CaptureRoutingTestInterceptor captureRoutingTestInterceptor = new CaptureRoutingTestInterceptor(); - private IRouter router; + private Router router; protected abstract void configure() throws Exception; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptorTest.java index a5047a5c57..8d94325d99 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptorTest.java @@ -30,7 +30,7 @@ public class FormValidationInterceptorTest { @Test public void testValidation() throws Exception { FormValidationInterceptor interceptor = new FormValidationInterceptor(); - interceptor.init(new HttpRouter()); + interceptor.init(new DummyTestRouter()); Field article = new Field(); article.setName("article"); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/groovy/GroovyInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/groovy/GroovyInterceptorTest.java index d0c31e10c9..168e5b8a60 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/groovy/GroovyInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/groovy/GroovyInterceptorTest.java @@ -35,12 +35,12 @@ public class GroovyInterceptorTest { private final ApplicationContext applicationContext = mock(ApplicationContext.class); - HttpRouter router; + DummyTestRouter router; Exchange exc; @BeforeEach void setup() { - router = new HttpRouter(); + router = new DummyTestRouter(); router.setApplicationContext(applicationContext); when(applicationContext.getBean("abc")).thenReturn("OK"); exc = new Exchange(null); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/javascript/JavascriptInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/javascript/JavascriptInterceptorTest.java index 613647ea96..49f4ded84d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/javascript/JavascriptInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/javascript/JavascriptInterceptorTest.java @@ -42,7 +42,7 @@ public class JavascriptInterceptorTest { private final static ObjectMapper om = new ObjectMapper(); - final Router router = new Router(); + final DefaultRouter router = new DefaultRouter(); JavascriptInterceptor interceptor; Exchange exc; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java index 3d7bcf5b01..5a5bc2479b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java @@ -32,7 +32,7 @@ public class JsonProtectionInterceptorTest { static JsonProtectionInterceptor jpiDev; private static JsonProtectionInterceptor buildJPI(boolean prod) { - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); router.getConfig().setProduction(prod); JsonProtectionInterceptor jpi = new JsonProtectionInterceptor(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java index b092dd1c20..08806e6d8f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java @@ -15,7 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.resolver.ResolverMap; @@ -261,7 +261,7 @@ private JwtAuthInterceptor prepareInterceptor(RsaJsonWebKey publicOnly) throws E } private JwtAuthInterceptor initInterceptor(JwtAuthInterceptor interceptor) throws Exception { - Router routerMock = mock(Router.class); + DefaultRouter routerMock = mock(DefaultRouter.class); when(routerMock.getBaseLocation()).thenReturn(""); when(routerMock.getResolverMap()).thenReturn(new ResolverMap()); interceptor.init(routerMock); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorUnitTests.java b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorUnitTests.java index 174751eb63..6d1535b5a8 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorUnitTests.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorUnitTests.java @@ -16,7 +16,7 @@ import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.DummyTestRouter; import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.http.Request; import org.junit.jupiter.api.*; @@ -62,7 +62,7 @@ void noJwtInHeader() { +"\", \"e\":\"BB\"}"); jwks.getJwks().add(jwk); interceptor.setJwks(jwks); - interceptor.init(new HttpRouter()); + interceptor.init(new DummyTestRouter()); interceptor.handleRequest(exchange); assertEquals(ERROR_JWT_NOT_FOUND, getErrorResponse(exchange)); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetHeaderInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetHeaderInterceptorTest.java index ca68a5d507..137d58ba58 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetHeaderInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetHeaderInterceptorTest.java @@ -28,13 +28,13 @@ abstract class AbstractSetHeaderInterceptorTest { Exchange exchange; Message message; final AbstractSetterInterceptor interceptor = new SetHeaderInterceptor(); - static Router router; + static DefaultRouter router; protected abstract Language getLanguage(); @BeforeEach void setUp() throws Exception { - router = new Router(); + router = new DefaultRouter(); exchange = new Exchange(null) {{ setRequest(new Request.Builder().post("/boo") .header("host", "localhost:8080") diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetPropertyInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetPropertyInterceptorTest.java index faaf5ce284..2dc988df15 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetPropertyInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/AbstractSetPropertyInterceptorTest.java @@ -16,7 +16,6 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.lang.*; import org.junit.jupiter.api.*; @@ -28,7 +27,7 @@ abstract class AbstractSetPropertyInterceptorTest { - Router router; + DefaultRouter router; Exchange exc; AbstractSetterInterceptor interceptor; @@ -38,7 +37,7 @@ abstract class AbstractSetPropertyInterceptorTest { void setUp() throws URISyntaxException { interceptor = new SetPropertyInterceptor(); interceptor.setLanguage(getLanguage()); - router = new Router(); + router = new DefaultRouter(); exc = get("/dummy") .contentType(APPLICATION_JSON) .body(""" diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptorTest.java index e95b8e3c37..7e06878125 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptorTest.java @@ -44,7 +44,7 @@ void setup() throws URISyntaxException { @Test void nullResult() { sbi.setValue("null"); - sbi.init(new Router()); + sbi.init(new DefaultRouter()); sbi.handleRequest(exc); assertEquals("null", exc.getRequest().getBodyAsStringDecoded()); } @@ -52,7 +52,7 @@ void nullResult() { @Test void evalOfSimpleExpression() { sbi.setValue("${path}"); - sbi.init(new Router()); + sbi.init(new DefaultRouter()); sbi.handleRequest(exc); assertEquals("/foo", exc.getRequest().getBodyAsStringDecoded()); } @@ -60,7 +60,7 @@ void evalOfSimpleExpression() { @Test void response() { sbi.setValue("SC: ${statusCode}"); - sbi.init(new Router()); + sbi.init(new DefaultRouter()); sbi.handleResponse(exc); assertEquals("SC: 501", exc.getResponse().getBodyAsStringDecoded()); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java index e880433228..f1aaf55155 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java @@ -45,9 +45,9 @@ public abstract class OAuth2RedirectTest { static final URI AUTH_SERVER_BASE_URL = URI.create("http://localhost:2002"); static final URI BACKEND_BASE_URL = URI.create("http://localhost:2001"); static final URI CLIENT_BASE_URL = URI.create("http://localhost:2000"); - static Router authorizationServerRouter; - static Router oauth2ResourceRouter; - static Router backendRouter; + static DefaultRouter authorizationServerRouter; + static DefaultRouter oauth2ResourceRouter; + static DefaultRouter backendRouter; static final AtomicReference firstUrlHit = new AtomicReference<>(); static final AtomicReference targetUrlHit = new AtomicReference<>(); static final AtomicReference interceptorChainHit = new AtomicReference<>(); @@ -162,8 +162,8 @@ private static IfInterceptor createConditionalInterceptorWithReturnMessage(Strin }}; } - private static Router startProxyRule(SSLableProxy azureRule) throws Exception { - Router router = new Router(); + private static DefaultRouter startProxyRule(SSLableProxy azureRule) throws Exception { + DefaultRouter router = new DefaultRouter(); router.setExchangeStore(new ForgetfulExchangeStore()); router.setTransport(new HttpTransport()); router.add(azureRule); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/MembraneAuthorizationServiceTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/MembraneAuthorizationServiceTest.java index 2928ce55ba..9642fa0540 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/MembraneAuthorizationServiceTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/authorizationservice/MembraneAuthorizationServiceTest.java @@ -114,7 +114,7 @@ void configQuery() throws Exception { MembraneAuthorizationService mas = Mockito.spy(new MembraneAuthorizationService()); doReturn(new ByteArrayInputStream(CONFIG.getBytes())).when(mas).resolve(any(), Mockito.nullable(String.class), anyString()); mas.setSrc("dummy"); - mas.router = new Router(); + mas.router = new DefaultRouter(); return mas; } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java index 493c24fcb5..8fece714e5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java @@ -13,12 +13,12 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor.oauth2.client; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.DummyTestRouter; import com.predic8.membrane.core.proxies.ServiceProxy; import java.io.IOException; -public abstract class AuthServerMock extends HttpRouter { +public abstract class AuthServerMock extends DummyTestRouter { public AuthServerMock() throws IOException { getTransport().setBacklog(10_000); getTransport().setSocketTimeout(10_000); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java index b6c409220a..4fabd88b9a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceErrorForwardingTest.java @@ -41,12 +41,12 @@ public class OAuth2ResourceErrorForwardingTest { protected final BrowserMock browser = new BrowserMock(); private final int limit = 500; - protected IRouter mockAuthServer; + protected TestRouter mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private IRouter oauth2Resource; + private TestRouter oauth2Resource; private final AtomicReference error = new AtomicReference<>(); private final AtomicReference errorDescription = new AtomicReference<>(); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java index 1b48d8019b..3fd59eddd3 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java @@ -59,12 +59,12 @@ public class OAuth2ResourceRpIniLogoutTest { protected final BrowserMock browser = new BrowserMock(); - protected IRouter mockAuthServer; + protected Router mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private IRouter oauth2Resource; + private Router oauth2Resource; private final AtomicBoolean isLoggedOutAtOP = new AtomicBoolean(false); private RsaJsonWebKey rsaJsonWebKey; private String jwksResponse; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java index f1770cd63c..58719d3a90 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceTest.java @@ -48,13 +48,13 @@ public abstract class OAuth2ResourceTest { protected final BrowserMock browser = new BrowserMock(); private final int limit = 100; - protected IRouter mockAuthServer; + protected TestRouter mockAuthServer; protected final ObjectMapper om = new ObjectMapper(); final Logger LOG = LoggerFactory.getLogger(OAuth2ResourceTest.class); final int serverPort = 3062; private final String serverHost = "localhost"; private final int clientPort = 31337; - private IRouter oauth2Resource; + private TestRouter oauth2Resource; private String getServerAddress() { return "http://%s:%d".formatted(serverHost, serverPort); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java index cc4eb0f62a..3f46e0be38 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/B2CMembrane.java @@ -51,7 +51,7 @@ public class B2CMembrane { private final ObjectMapper om = new ObjectMapper(); - private IRouter oauth2Resource; + private TestRouter oauth2Resource; private OAuth2Resource2Interceptor oAuth2Resource2Interceptor; public RequireAuth requireAuth; diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java index 805f0719ac..538f96d7a2 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/b2c/MockAuthorizationServer.java @@ -52,7 +52,7 @@ public class MockAuthorizationServer { private final SecureRandom rand = new SecureRandom(); private final ObjectMapper om = new ObjectMapper(); - private IRouter mockAuthServer; + private TestRouter mockAuthServer; private RsaJsonWebKey rsaJsonWebKey; private String jwksResponse; @@ -91,7 +91,7 @@ public void stop() { mockAuthServer.stop(); } - public IRouter getMockAuthServer() { + public Router getMockAuthServer() { return mockAuthServer; } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index db0762470e..92ada0392b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -21,14 +21,14 @@ class OpenTelemetryInterceptorTest { - private IRouter router; + private Router router; @Test void initTest() throws IOException { Proxy r = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3141), null, 0); r.getFlow().add(new OpenTelemetryInterceptor()); - router = new HttpRouter(); + router = new DummyTestRouter(); router.add(r); router.init(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptorTest.java index ff7db9535c..7f11dbd771 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptorTest.java @@ -32,7 +32,7 @@ public class ReverseProxyingInterceptorTest { @Test public void localRedirect() { - rp.init(new Router()); + rp.init(new DefaultRouter()); // invalid by spec, redirection location should not be rewritten assertEquals("/local", getRewrittenRedirectionLocation("membrane", 2000, "http://target/foo", "/local")); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriteInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriteInterceptorTest.java index b3c5a82da2..36d99912d8 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriteInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriteInterceptorTest.java @@ -41,7 +41,7 @@ public class RewriteInterceptorTest { @BeforeEach void setUp() { - HttpRouter router = new HttpRouter(); + DummyTestRouter router = new DummyTestRouter(); di = new DispatchingInterceptor(); di.init(router); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriterTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriterTest.java index d39794667e..4a657d0669 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/rewrite/RewriterTest.java @@ -35,7 +35,7 @@ void setUp() { mappings.add(new Mapping("/hello/(.*)", "/$1", null)); rewriter.setMappings(mappings); - rewriter.init(new HttpRouter()); + rewriter.init(new DummyTestRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java index 0336f8904b..0c769e2c83 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPFaultTest.java @@ -32,7 +32,7 @@ public class SOAPFaultTest { public static final String ARTICLE_SERVICE_WSDL = getPathFromResource( "/validation/ArticleService.wsdl"); - final IRouter r = new HttpRouter(); + final Router r = new DummyTestRouter(); @Test public void testValidateFaults() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java index 0c6f6e6c45..7ccb95a1ef 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/SOAPMessageValidatorInterceptorTest.java @@ -35,11 +35,11 @@ public class SOAPMessageValidatorInterceptorTest { public static final String E_MAIL_SERVICE_WSDL = "src/test/resources/validation/XWebEmailValidation.wsdl.xml"; public static final String INLINE_ANYTYPE_WSDL = "src/test/resources/validation/inline-anytype.wsdl"; public static final String WSDL_MESSAGE_VALIDATION_FAILED = "WSDL message validation failed"; - public static IRouter router; + public static Router router; @BeforeAll static void setup() { - router = new HttpRouter(); + router = new DummyTestRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java index f5586f4a2e..5df75ec123 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptorTest.java @@ -44,7 +44,7 @@ public class ValidatorInterceptorTest { private static Exchange exc; - private static IRouter router; + private static Router router; public static final String ARTICLE_SERVICE_WSDL = "classpath:/validation/ArticleService.wsdl"; @@ -60,7 +60,7 @@ public static void setUp() throws URISyntaxException { requestTB = post("http://thomas-bayer.com").build(); requestXService = post("http://ws.xwebservices.com").build(); exc = new Exchange(null); - router = new HttpRouter(); + router = new DummyTestRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java index 60f963711f..6b1c57e465 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java @@ -26,7 +26,7 @@ public class WSDLPublisherInterceptorTest { - private IRouter router; + private Router router; static List getPorts() { return Arrays.asList(new Object[][] { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java index 0060721471..c3fb97b47c 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptorTest.java @@ -28,11 +28,11 @@ class WebServerInterceptorTest { WebServerInterceptor ws; Exchange exc; - IRouter r; + Router r; @BeforeEach void init() { - r = new HttpRouter(); + r = new DummyTestRouter(); ws = new WebServerInterceptor(r) {{ setDocBase(Objects.requireNonNull(this.getClass().getResource("/html/")).toString()); @@ -56,13 +56,10 @@ void noIndex() { } @Test - void generateIndex() throws Exception { + void generateIndex() { ws.setGenerateIndex(true); ws.handleRequest(exc); // No index file is set, but index page is being generated. Body lists the page.html resource. - String body = exc.getResponse().getBodyAsStringDecoded(); - // System.out.println("body = " + body); - assertTrue(exc.getResponse().getBodyAsStringDecoded().contains("page.html")); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java index e2bbf6f401..a38fe756a5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/FakeSyncSessionStoreManager.java @@ -27,7 +27,7 @@ public class FakeSyncSessionStoreManager extends MemcachedSessionManager { private final ConcurrentHashMap remoteContent = new ConcurrentHashMap<>(); @Override - public void init(IRouter router) throws Exception {} + public void init(Router router) throws Exception {} @Override protected void addSessions(Session[] sessions) { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index e3a8447c8c..a3f06c5ed7 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -43,7 +43,7 @@ public class SessionInterceptorTest { - private IRouter router; + private Router router; private CloseableHttpClient httpClient; @BeforeEach diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java index 9a86b88393..c771e02d2f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java @@ -37,8 +37,8 @@ class ShadowingInterceptorTest { Exchange exc; Header header; - static Router interceptorRouter; - static Router shadowingRouter; + static DefaultRouter interceptorRouter; + static DefaultRouter shadowingRouter; static ServiceProxy interceptorProxy; static ShadowingInterceptor shadowingInterceptor; @@ -67,7 +67,7 @@ void setUp() throws Exception { @BeforeAll static void startup() throws Exception { - interceptorRouter = new Router(); + interceptorRouter = new DefaultRouter(); interceptorRouter.getConfig().setHotDeploy(false); interceptorRouter.setExchangeStore(new ForgetfulExchangeStore()); interceptorRouter.setTransport(new HttpTransport()); @@ -90,7 +90,7 @@ static void startup() throws Exception { interceptorRouter.add(interceptorProxy); interceptorRouter.start(); - shadowingRouter = new Router(); + shadowingRouter = new DefaultRouter(); shadowingRouter.getConfig().setHotDeploy(false); shadowingRouter.setExchangeStore(new ForgetfulExchangeStore()); shadowingRouter.setTransport(new HttpTransport()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java index b599de50c7..07164cd11c 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java @@ -34,7 +34,7 @@ */ public class SoapAndInternalProxyTest { - IRouter router; + Router router; @BeforeEach void setup() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java index 21ebb0e016..93c9cd1fd8 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/StaticInterceptorTest.java @@ -41,7 +41,7 @@ void beforeAll() throws URISyntaxException { @Test void readContentFromLocationPath() { - i.init(new HttpRouter()); + i.init(new DummyTestRouter()); i.handleRequest(exc); assertEquals(27, exc.getRequest().getBodyAsStringDecoded().length()); } @@ -50,7 +50,7 @@ void readContentFromLocationPath() { void pretty() { i.setPretty(TRUE); i.setContentType(APPLICATION_JSON); - i.init(new HttpRouter()); + i.init(new DummyTestRouter()); i.handleRequest(exc); @@ -81,7 +81,7 @@ void utf_16() throws Exception { private void checkWithCharset(String charset) throws Exception { i.setLocation(getAbsolutePath("/charsets/%s.txt".formatted(charset))); i.setCharset(charset); - i.init(new HttpRouter()); + i.init(new DummyTestRouter()); i.handleRequest(exc); assertEquals(REF_CHARS, exc.getRequest().getBodyAsStringDecoded()); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java index b5a3f5cefd..1f86d3472e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptorTest.java @@ -49,12 +49,12 @@ public class TemplateInterceptorTest { TemplateInterceptor ti; Exchange exc = new Exchange(null); Request req; - static Router router; + static DefaultRouter router; static ResolverMap map; @BeforeAll static void setupFiles() { - router = mock(Router.class); + router = mock(DefaultRouter.class); map = new ResolverMap(); when(router.getResolverMap()).thenReturn(map); when(router.getUriFactory()).thenReturn(new URIFactory()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptorTest.java index 3d6620d5cb..c1380ca6c5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptorTest.java @@ -62,7 +62,7 @@ public class Json2XmlInterceptorTest { @BeforeEach void setUp() { interceptor = new Json2XmlInterceptor(); - interceptor.init(new Router()); + interceptor.init(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptorTest.java index 0b278c863e..acf9ad9fa6 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptorTest.java @@ -36,7 +36,7 @@ public class Xml2JsonInterceptorTest { @BeforeAll static void setup() { interceptor = new Xml2JsonInterceptor(); - interceptor.init(new Router()); + interceptor.init(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptorTest.java index 29d68e1d85..a6977af59e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptorTest.java @@ -38,7 +38,7 @@ static void setUp() throws Exception { exc.setOriginalHostHeader("thomas-bayer.com:80"); interceptor = new XMLProtectionInterceptor(); - interceptor.init(new Router()); + interceptor.init(new DefaultRouter()); } private void runOn(String resource, boolean expectSuccess) throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java index 4ad78bf191..8117fe7da2 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptorTest.java @@ -22,7 +22,7 @@ import org.junit.jupiter.api.Test; import org.xml.sax.InputSource; -import com.predic8.membrane.core.HttpRouter; +import com.predic8.membrane.core.DummyTestRouter; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Response; @@ -40,7 +40,7 @@ public void testRequest() throws Exception { XSLTInterceptor i = new XSLTInterceptor(); i.setXslt("classpath:/customer2person.xsl"); - i.init(new HttpRouter()); + i.init(new DummyTestRouter()); i.handleResponse(exc); //printBodyContent(); @@ -60,7 +60,7 @@ public void testXSLTParameter() throws Exception { XSLTInterceptor i = new XSLTInterceptor(); i.setXslt("classpath:/customer2personAddCompany.xsl"); - i.init(new HttpRouter()); + i.init(new DummyTestRouter()); i.handleResponse(exc); //printBodyContent(); diff --git a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java index bd79628708..6df0bfa913 100644 --- a/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java +++ b/core/src/test/java/com/predic8/membrane/core/kubernetes/client/KubernetesClientTest.java @@ -37,7 +37,7 @@ public class KubernetesClientTest { - private static IRouter router; + private static Router router; @BeforeAll public static void prepare() throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java index 8089eb10ff..8c7a6db196 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java @@ -30,13 +30,13 @@ public abstract class AbstractExchangeExpressionTest { - protected static Router router; + protected static DefaultRouter router; protected static Exchange exchange; protected static Flow flow; @BeforeEach void setUp() throws URISyntaxException { - router = new Router(); + router = new DefaultRouter(); exchange = getRequestBuilder() .header("name","Jelly Fish") .header("foo","42") diff --git a/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java index 7fc01e8eef..528e4c8add 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/TemplateExchangeExpressionTest.java @@ -28,7 +28,7 @@ class TemplateExchangeExpressionTest { Exchange exc; Language language; - Router router; + DefaultRouter router; @BeforeEach void setUp() throws Exception { @@ -37,7 +37,7 @@ void setUp() throws Exception { .buildExchange(); exc.setProperty("prop1", "Mars"); language = Language.SPEL; - router = new Router(); + router = new DefaultRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/lang/xpath/SetPropertyInterceptorXPathTest.java b/core/src/test/java/com/predic8/membrane/core/lang/xpath/SetPropertyInterceptorXPathTest.java index 915149fb6e..7a7a47ea40 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/xpath/SetPropertyInterceptorXPathTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/xpath/SetPropertyInterceptorXPathTest.java @@ -17,7 +17,6 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.xml.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.lang.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; @@ -114,7 +113,7 @@ void unknownPrefix() { i.setLanguage(XPATH); i.setFieldName("firstname"); i.setValue(value); - i.init(new Router()); + i.init(new DefaultRouter()); return i; } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java index 32bb5966ed..66b466570a 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxyOpenAPITest.java @@ -38,11 +38,11 @@ public class APIProxyOpenAPITest { private static final String SECURITY = "security"; private static final String DETAILS = "details"; - IRouter router; + Router router; @BeforeEach public void setUp() { - router = new HttpRouter(); + router = new DummyTestRouter(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java index 48fa5e0968..fe036da966 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/APIProxySpringConfigurationTest.java @@ -54,7 +54,7 @@ class APIProxySpringConfigurationTest extends AbstractProxySpringConfigurationTe @Test void interceptorSequenceFromSpringConfiguration() { - Router router = startSpringContextAndReturnRouter(publisherSeparate); + DefaultRouter router = startSpringContextAndReturnRouter(publisherSeparate); APIProxy ap = getApiProxy(router); assertEquals(5, ap.getFlow().size()); assertInstanceOf(OpenAPIInterceptor.class, ap.getFlow().get(0)); // Should be added after init() is called on router (Inside bootstrap) @@ -67,7 +67,7 @@ void interceptorSequenceFromSpringConfiguration() { @Test void noPublisherNoOpenAPIInterceptor() { - Router router = startSpringContextAndReturnRouter(noPublisherNoOpenAPIInterceptor); + DefaultRouter router = startSpringContextAndReturnRouter(noPublisherNoOpenAPIInterceptor); APIProxy ap = getApiProxy(router); ap.init(router); assertEquals(5, ap.getFlow().size()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java index c9e9f842ae..7172a33122 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/AbstractProxySpringConfigurationTest.java @@ -32,16 +32,16 @@ abstract class AbstractProxySpringConfigurationTest { """; - protected static Router startSpringContextAndReturnRouter(String api) { + protected static DefaultRouter startSpringContextAndReturnRouter(String api) { GenericXmlApplicationContext ctx = new GenericXmlApplicationContext(); ctx.load(new ByteArrayResource(config.formatted(api).getBytes())); ctx.refresh(); - var router = ctx.getBean("router", Router.class); + var router = ctx.getBean("router", DefaultRouter.class); router.init(); return router; } - protected static APIProxy getApiProxy(Router router) { + protected static APIProxy getApiProxy(DefaultRouter router) { return router.getRuleManager().getRuleByName("bool-api",APIProxy.class); } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index 2a8ea6cecf..b17966e927 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -18,8 +18,6 @@ import com.predic8.membrane.core.exchange.*; import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.http.*; -import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.util.*; import org.junit.jupiter.api.*; import java.io.*; @@ -38,14 +36,14 @@ class ApiDocsInterceptorTest { private final ObjectMapper om = new ObjectMapper(); - HttpRouter router; + DummyTestRouter router; final Exchange exc = new Exchange(null); ApiDocsInterceptor interceptor; APIProxy rule; @BeforeEach public void setUp() throws Exception { - router = new HttpRouter(); + router = new DummyTestRouter(); exc.setRequest(new Request.Builder().get("/foo").build()); exc.setOriginalRequestUri("/foo"); @@ -91,7 +89,7 @@ void initializeRuleApiSpecsTest() { @Test void initializeEmptyRuleApiSpecsTest() { ApiDocsInterceptor adi = new ApiDocsInterceptor(); - adi.init(new HttpRouter()); + adi.init(new DummyTestRouter()); assertEquals(new HashMap<>(), adi.initializeRuleApiSpecs()); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index ee5bc86973..5f5bf4cb54 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -34,7 +34,7 @@ public class OpenAPI31ReferencesTest { - static IRouter router; + static Router router; static APIProxy api; diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java index 3acad0b316..ae5a84442f 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31Test.java @@ -18,9 +18,6 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.http.*; -import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.util.*; import org.junit.jupiter.api.*; import java.net.*; @@ -41,7 +38,7 @@ public class OpenAPI31Test { @BeforeEach void setUp() throws URISyntaxException { - IRouter router = new HttpRouter(); + Router router = new DummyTestRouter(); petstore_v3_1 = new OpenAPISpec(); petstore_v3_1.location = getPathFromResource("openapi/specs/petstore-v3.1.json"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index 16858552d7..f59d3d103f 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -37,7 +37,7 @@ class OpenAPIInterceptorTest { - IRouter router; + Router router; OpenAPISpec specInfoServers; OpenAPISpec specInfo3Servers; OpenAPISpec specCustomers; @@ -48,7 +48,7 @@ class OpenAPIInterceptorTest { @BeforeEach void setUp() { - router = new HttpRouter(); + router = new DummyTestRouter(); specInfoServers = new OpenAPISpec(); specInfoServers.location = getPathFromResource("openapi/specs/info-servers.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java index f055f13b62..1902f14665 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java @@ -51,7 +51,7 @@ public class OpenAPIPublisherInterceptorTest { @BeforeEach void setUp() { - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); openAPIRecordFactory = new OpenAPIRecordFactory(router); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java index 172ba64bc5..f9da9b6d6d 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordFactoryTest.java @@ -30,7 +30,7 @@ class OpenAPIRecordFactoryTest { @BeforeAll static void setUp() { - HttpRouter router = new HttpRouter(); + DummyTestRouter router = new DummyTestRouter(); router.setBaseLocation("src/test/resources/openapi/specs/"); factory = new OpenAPIRecordFactory(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java index ab081d8576..cda97c273e 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java @@ -16,7 +16,7 @@ package com.predic8.membrane.core.openapi.serviceproxy; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.proxies.NullProxy; @@ -29,7 +29,7 @@ class OpenAPIRecordTest { @BeforeEach void setUp() { - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java index d47e8faedf..faaca427d2 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java @@ -49,7 +49,7 @@ void setUp() { rewriteAll.protocol = "https"; rewriteAll.basePath = "/foo"; - Router router = new Router(); + DefaultRouter router = new DefaultRouter(); router.getConfig().setUriFactory(new URIFactory()); router.setBaseLocation(""); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java index 049f871ef6..a7af39a2bf 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java @@ -19,10 +19,7 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.interceptor.flow.*; import com.predic8.membrane.core.interceptor.templating.*; -import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.proxies.AbstractServiceProxy.*; -import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.util.*; import org.hamcrest.*; import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; @@ -34,7 +31,7 @@ public class Swagger20Test { - IRouter router; + Router router; @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java index 644cfe4a6c..7af285c62b 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/XMembraneExtensionSecurityTest.java @@ -32,7 +32,7 @@ public class XMembraneExtensionSecurityTest { @BeforeEach void setUp() { - HttpRouter router = new HttpRouter(); + DummyTestRouter router = new DummyTestRouter(); router.setBaseLocation(""); OpenAPIRecordFactory factory = new OpenAPIRecordFactory(router); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java b/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java index d858fb3fe3..7e931c55ba 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/util/OpenAPITestUtils.java @@ -66,7 +66,7 @@ public static OpenAPI parseOpenAPI(String file) { } - public static APIProxy createProxy(IRouter router, OpenAPISpec spec) { + public static APIProxy createProxy(Router router, OpenAPISpec spec) { APIProxy proxy = new APIProxy(); proxy.setSpecs(singletonList(spec)); proxy.setKey(new APIProxyKey(2000)); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java index 313d11511b..6785866809 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/exceptions/ExceptionInterceptorTest.java @@ -45,7 +45,7 @@ void setUpSpec() { spec.validateRequests = YES; spec.validateResponses = YES; - IRouter router = getRouter(); + Router router = getRouter(); interceptor = new OpenAPIInterceptor(createProxy(router, spec)); interceptor.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java index fc943da246..4946268c59 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/AbstractSecurityValidatorTest.java @@ -41,7 +41,7 @@ protected Exchange getExchange(String method, String path, SecurityScheme scheme return exc; } - protected static IRouter getRouter() { - return new HttpRouter(); + protected static Router getRouter() { + return new DummyTestRouter(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java index 9335e07b77..41007fee43 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/BasicAuthSecurityValidationTest.java @@ -18,12 +18,10 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.authentication.*; import com.predic8.membrane.core.interceptor.authentication.session.*; import com.predic8.membrane.core.openapi.serviceproxy.*; -import com.predic8.membrane.core.util.*; import org.junit.jupiter.api.*; import java.util.*; @@ -43,7 +41,7 @@ public class BasicAuthSecurityValidationTest { @BeforeEach void setUpSpec() { - IRouter router = new HttpRouter(); + Router router = new DummyTestRouter(); OpenAPISpec spec = new OpenAPISpec(); spec.location = getPathFromResource("openapi/specs/security/http-basic.yml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index 4f0730981c..5ffc928f0b 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -18,12 +18,10 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.interceptor.jwt.*; import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.security.*; -import com.predic8.membrane.core.transport.http.*; import org.jetbrains.annotations.*; import org.jose4j.jwk.*; import org.jose4j.jws.*; @@ -42,14 +40,14 @@ public class JWTInterceptorAndSecurityValidatorTest { private static final String SPEC_LOCATION = getPathFromResource( "openapi/openapi-proxy/no-extensions.yml"); - private IRouter router; + private Router router; private APIProxy proxy; RsaJsonWebKey privateKey; @BeforeEach void setUp() throws Exception { - router = new HttpRouter(); + router = new DummyTestRouter(); proxy = createProxy(router, getSpec()); privateKey = RsaJwkGenerator.generateJwk(2048); @@ -92,7 +90,7 @@ private void callInterceptorChain(Exchange exc) { } @NotNull - private JwtAuthInterceptor getJwtAuthInterceptor(IRouter router) { + private JwtAuthInterceptor getJwtAuthInterceptor(Router router) { JwtAuthInterceptor interceptor = createInterceptor(getPublicKey()); interceptor.setJwtRetriever(new HeaderJwtRetriever("Authorization","bearer")); interceptor.init(router); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java index f9f8cab111..431f8258dd 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/OAuth2SecurityValidatorTest.java @@ -41,7 +41,7 @@ void setUpSpec() { spec.validateRequests = YES; spec.validateSecurity = YES; - IRouter router = getRouter(); + Router router = getRouter(); interceptor = new OpenAPIInterceptor(createProxy(router, spec)); interceptor.init(router); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java index 3049424bdb..c4997f7494 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java @@ -28,7 +28,7 @@ public class APIProxyKeyTest { - private static IRouter router; + private static Router router; @BeforeEach public void setup() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index 4f6ede5658..1f1eb64085 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -25,7 +25,7 @@ class InternalProxyTest { - private IRouter router; + private Router router; @BeforeEach void setup() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java index f328589e11..7b81fbb304 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java @@ -25,7 +25,7 @@ public class ProxyRuleTest { - private static Router router; + private static DefaultRouter router; private static ProxyRule proxy; @BeforeAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index a6fc4b4e01..44a5f9fc2e 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -43,11 +43,11 @@ public static Collection data() { @ParameterizedTest @MethodSource("data") void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int proxyPort) throws Exception { - Router backend = createBackend(backendUsesSSL, backendPort); + DefaultRouter backend = createBackend(backendUsesSSL, backendPort); AtomicInteger proxyCounter = new AtomicInteger(); - Router proxy = createProxy(proxyUsesSSL, proxyPort, proxyCounter); + DefaultRouter proxy = createProxy(proxyUsesSSL, proxyPort, proxyCounter); testClient(backendUsesSSL, backendPort, createAndConfigureClient(proxyUsesSSL, proxyPort), proxyCounter); @@ -55,8 +55,8 @@ void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int pro backend.shutdown(); } - private static @NotNull Router createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) throws IOException { - Router proxy = new Router(); + private static @NotNull DefaultRouter createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) throws IOException { + DefaultRouter proxy = new DefaultRouter(); proxy.getConfig().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(proxyPort)); rule.getFlow().add(new AbstractInterceptor() { @@ -109,9 +109,9 @@ private static void testClient(boolean backendUsesSSL, int backendPort, HttpClie return new HttpClient(httpClientConfiguration); } - private static @NotNull Router createBackend(boolean backendUsesSSL, int backendPort) throws IOException { + private static @NotNull DefaultRouter createBackend(boolean backendUsesSSL, int backendPort) throws IOException { // Step 1: create the backend - Router backend = new Router(); + DefaultRouter backend = new DefaultRouter(); backend.getConfig().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(backendPort), null, 0); if (backendUsesSSL) { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index e1494c9b6f..e60a980f87 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -37,7 +37,7 @@ public class ProxyTest { - static IRouter router; + static Router router; static final AtomicReference lastMethod = new AtomicReference<>(); @BeforeAll diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index d126e88e4d..d9bf6cb4db 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -14,12 +14,10 @@ package com.predic8.membrane.core.proxies; import com.predic8.membrane.core.*; -import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.flow.*; import com.predic8.membrane.core.interceptor.templating.*; import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.openapi.util.*; -import com.predic8.membrane.core.transport.http.*; import org.junit.jupiter.api.*; import java.io.*; @@ -31,7 +29,7 @@ public class SOAPProxyTest { - IRouter router; + Router router; SOAPProxy proxy; @@ -39,7 +37,7 @@ public class SOAPProxyTest { void setUp() throws IOException { proxy = new SOAPProxy(); proxy.setPort(2000); - router = new Router(); + router = new DefaultRouter(); APIProxy backend = new APIProxy(); backend.setKey(new APIProxyKey(2001)); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java index b8a5814096..805d9919d7 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyWSDLPublisherInterceptorTest.java @@ -24,7 +24,7 @@ @SuppressWarnings("HttpUrlsUsage") public class SOAPProxyWSDLPublisherInterceptorTest { - static IRouter router; + static Router router; @BeforeAll static void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java index dabc392915..cd0a04c59f 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java @@ -26,7 +26,7 @@ class ServiceProxyTest { - private static IRouter router; + private static Router router; @BeforeAll public static void setup() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java index e62c543a23..ce64cd733c 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java @@ -28,7 +28,7 @@ @SuppressWarnings("HttpUrlsUsage") public class ServiceProxyWSDLInterceptorsTest { - IRouter router; + Router router; @BeforeEach void setUp() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index c78339de43..0746cbf9d0 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -29,11 +29,11 @@ */ class TargetURLExpressionTest { - private Router router; + private DefaultRouter router; @BeforeEach void setUp() { - router = new Router(); + router = new DefaultRouter(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 0a25ea3405..48ce41531e 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -27,8 +27,8 @@ public class UnavailableSoapProxyTest { - private static Router r, r2; - private static Router backendRouter; + private static DefaultRouter r, r2; + private static DefaultRouter backendRouter; private SOAPProxy sp; private ServiceProxy sp3; @@ -36,7 +36,7 @@ public class UnavailableSoapProxyTest { static void setup() throws Exception { ServiceProxy cityAPI = new ServiceProxy(new ServiceProxyKey(4000), null, 0); cityAPI.getFlow().add(new SampleSoapServiceInterceptor()); - backendRouter = new Router(); + backendRouter = new DefaultRouter(); backendRouter.add(cityAPI); backendRouter.start(); } @@ -50,7 +50,7 @@ static void teardown() { @BeforeEach void startRouter() throws IOException { - r = new Router(); + r = new DefaultRouter(); HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); r.setHttpClientConfig(httpClientConfig); @@ -71,7 +71,7 @@ void startRouter() throws IOException { SOAPProxy sp2 = new SOAPProxy(); sp2.setPort(2001); sp2.setWsdl("http://localhost:4000?wsdl"); - r2 = new Router(); + r2 = new DefaultRouter(); r2.getConfig().setHotDeploy(false); r2.add(sp2); } diff --git a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java index 400aaca6d9..89e91588f1 100644 --- a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java +++ b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java @@ -52,7 +52,7 @@ public class ResolverTest { // OperatingSystemType (WINDOWS, LINUX) is handled by Jenkins - private static IRouter router; + private static Router router; private static volatile boolean hit = false; private static final String STANDALONE = "standalone"; diff --git a/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java b/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java index 160e8ba763..f2f3824d4d 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java @@ -60,7 +60,7 @@ private JwtAuthInterceptor prepareInterceptor(RsaJsonWebKey publicOnly) throws E } private JwtAuthInterceptor initInterceptor(JwtAuthInterceptor interceptor) throws Exception { - Router routerMock = mock(Router.class); + DefaultRouter routerMock = mock(DefaultRouter.class); when(routerMock.getBaseLocation()).thenReturn(""); when(routerMock.getResolverMap()).thenReturn(new ResolverMap()); interceptor.init(routerMock); diff --git a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java index 539ebae2a8..32d83f6569 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java @@ -35,7 +35,7 @@ class KeyStoreUtilTest { - private static IRouter router; + private static Router router; private static java.security.KeyStore keyStore; private static final String ALIAS = "key1"; private static final String KEYSTORE_PASSWORD = "secret"; @@ -43,7 +43,7 @@ class KeyStoreUtilTest { @BeforeAll static void setUp() throws Exception { - router = new HttpRouter(); + router = new DummyTestRouter(); SSLParser sslParser = new SSLParser(); sslParser.setKeyStore(new KeyStore()); sslParser.getKeyStore().setLocation("classpath:/alias-keystore.p12"); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java index 46494f049c..99706c3c76 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java @@ -29,7 +29,7 @@ public class BoundConnectionTest { - IRouter router; + Router router; volatile long connectionHash = 0; @BeforeEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index 224b44a14a..5d9a8ad8cb 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -28,7 +28,7 @@ public class ConcurrentConnectionLimitTest { - private IRouter router; + private Router router; private ExecutorService executor; private final int concurrency = 100; private final int concurrentLimit = 10; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java index 0df6af01e9..09cb62b503 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java @@ -26,7 +26,7 @@ public class ConnectionTest { Connection conLocalhost; Connection con127_0_0_1; - IRouter router; + Router router; @BeforeEach void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java index 772b8552e3..1cb5fecee5 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/Http2DowngradeTest.java @@ -30,7 +30,7 @@ public class Http2DowngradeTest { - private static IRouter router; + private static Router router; @BeforeAll public static void beforeAll() throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java index 8fb54aa9a0..f43fb5a629 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java @@ -40,7 +40,7 @@ public class HttpKeepAliveTest { private HashSet hashs; // tracks the hashcodes of all connections used - private IRouter service1; + private Router service1; private ServiceProxy sp1; @BeforeEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java index d8a9dda7f4..cb98d76b26 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTimeoutTest.java @@ -35,7 +35,7 @@ public class HttpTimeoutTest { public final int BACKEND_DELAY_MILLIS = 300; - IRouter slowBackend, proxyRouter; + Router slowBackend, proxyRouter; @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java index 5ac41b380c..9f810d6f66 100755 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpTransportTest.java @@ -33,7 +33,7 @@ public class HttpTransportTest { private final ResolverMap resolverMap = mock(ResolverMap.class); private final SSLProvider sslProvider = mock(SSLProvider.class); private final RuleManager ruleManager = mock(RuleManager.class); - private final Router router = mock(Router.class); + private final DefaultRouter router = mock(DefaultRouter.class); private final ExchangeStore exchangeStore = mock(ExchangeStore.class); private final Statistics statistics = new Statistics(); private HttpTransport transport; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java index 36f7b1a5f1..e9413acf6f 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java @@ -31,7 +31,7 @@ class IllegalCharactersInURLTest { - private IRouter r; + private Router r; @BeforeEach void init() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java index 9792fc5564..fa7ead742b 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java @@ -30,7 +30,7 @@ public class ServiceInvocationTest { - private IRouter router; + private Router router; @BeforeEach void setUp() throws Exception { @@ -87,8 +87,8 @@ private PostMethod createPostMethod() { return post; } - private IRouter createRouter() throws Exception { - IRouter router = new TestRouter(); + private Router createRouter() throws Exception { + Router router = new TestRouter(); router.add(createFirstRule()); router.add(createServiceRule()); router.add(createEndpointRule()); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java index e19b5acbf9..c9786dc6b6 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java @@ -30,7 +30,7 @@ */ class HttpClientConfigurationTest { - Router router; + DefaultRouter router; HttpClientConfiguration configuration; diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java index 360aab9b0f..afc7c61e03 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java @@ -40,7 +40,7 @@ public class Http2ClientServerTest { private volatile Consumer requestAsserter; private volatile AbstractHttpHandler handler; private HttpClient hc; - private IRouter router; + private Router router; private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); @BeforeEach diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java index 77ef30e3dc..94df25af53 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java @@ -17,7 +17,6 @@ import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.*; import com.predic8.membrane.core.exchange.*; -import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; @@ -36,7 +35,7 @@ public class HttpsKeepAliveTest { - private static IRouter server; + private static Router server; private static final ConcurrentHashMap connectionHashes = new ConcurrentHashMap<>(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java index 58374fd8e3..a1fc597e1c 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SSLContextTest.java @@ -40,11 +40,11 @@ public class SSLContextTest { - private static IRouter router; + private static Router router; @BeforeAll public static void before() { - router = new HttpRouter(); + router = new DummyTestRouter(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index ab00149919..3303e682cc 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -40,8 +40,8 @@ public class SessionResumptionTest { private static Closeable tcpForwarder; - private static IRouter router1; - private static IRouter router2; + private static Router router1; + private static Router router2; private static SSLContext clientTLSContext; @BeforeAll @@ -75,8 +75,8 @@ private static SSLContext createClientTLSContext() { return new StaticSSLContext(sslParser, new ResolverMap(), "."); } - private static IRouter createTLSServer(int port) { - IRouter router = new HttpRouter(); + private static Router createTLSServer(int port) { + Router router = new DummyTestRouter(); router.getConfig().setHotDeploy(false); ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(port), null, 0); SSLParser sslInboundParser = new SSLParser(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java index 7e3eb04ab5..e904c7721f 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/acme/AcmeServerSimulator.java @@ -57,7 +57,7 @@ public class AcmeServerSimulator { private final AtomicReference theNonce = new AtomicReference<>(); private final HttpClient hc = new HttpClient(); private final AtomicBoolean challengeSucceeded = new AtomicBoolean(); - private IRouter router; + private Router router; private final AcmeCASimulation ca = new AcmeCASimulation(); private String certificates; private final AtomicReference orderStatus = new AtomicReference<>("pending"); diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index d2afa5cd2d..124b0f4a78 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -55,8 +55,8 @@ public class SoapProxyInvocationTest { """; - static IRouter gw; - static IRouter backend; + static Router gw; + static Router backend; @BeforeAll public static void setup() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/evaluation/JDBCApiKeyStorePerformanceTest.java b/core/src/test/java/com/predic8/membrane/evaluation/JDBCApiKeyStorePerformanceTest.java index ae39b6e739..6ab9576cd9 100644 --- a/core/src/test/java/com/predic8/membrane/evaluation/JDBCApiKeyStorePerformanceTest.java +++ b/core/src/test/java/com/predic8/membrane/evaluation/JDBCApiKeyStorePerformanceTest.java @@ -14,7 +14,7 @@ package com.predic8.membrane.evaluation; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.interceptor.apikey.stores.JDBCApiKeyStore; import com.predic8.membrane.core.interceptor.apikey.stores.KeyTable; import com.predic8.membrane.core.interceptor.apikey.stores.ScopeTable; @@ -59,7 +59,7 @@ void setUp() throws SQLException { jdbcApiKeyStore = createApiKeyStore(); connection = getDataSource().getConnection(); - jdbcApiKeyStore.init(new Router()); + jdbcApiKeyStore.init(new DefaultRouter()); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/integration/Util.java b/core/src/test/java/com/predic8/membrane/integration/Util.java index 5e236c78e8..c05c6e62f0 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Util.java +++ b/core/src/test/java/com/predic8/membrane/integration/Util.java @@ -22,14 +22,12 @@ import java.util.*; public class Util { - public static HttpRouter basicRouter(Proxy... proxies){ - HttpRouter router = new HttpRouter(); - router.getTransport().setForceSocketCloseOnHotDeployAfter(1000); + public static Router basicRouter(Proxy... proxies){ + var router = new TestRouter(); router.getConfig().setHotDeploy(false); - Arrays.stream(proxies).forEach(rule -> router.getRuleManager().addProxy(rule, RuleManager.RuleDefinitionSource.MANUAL)); - router.start(); + router.getTransport().setForceSocketCloseOnHotDeployAfter(1000); return router; } diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java index 34d2086354..6a95bf550e 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java @@ -20,6 +20,7 @@ import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.http.client.*; +import org.jetbrains.annotations.*; import org.junit.jupiter.api.*; import java.io.*; @@ -27,14 +28,14 @@ import java.util.concurrent.atomic.*; import static com.predic8.membrane.core.http.Header.*; -import static com.predic8.membrane.core.http.Response.ok; -import static com.predic8.membrane.core.interceptor.Outcome.RETURN; -import static java.lang.Integer.MAX_VALUE; +import static com.predic8.membrane.core.http.Response.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; +import static java.lang.Integer.*; import static org.junit.jupiter.api.Assertions.*; public class LargeBodyTest { - private static HttpRouter router, router2; + private static TestRouter router, router2; private static HttpClientConfiguration hcc; private static final AtomicReference middleExchange = new AtomicReference<>(); @@ -45,7 +46,7 @@ public static void setup() throws Exception { hcc = new HttpClientConfiguration(); hcc.getRetryHandler().setRetries(1); - ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3040), "thomas-bayer.com", 80); + ServiceProxy proxy = getProxy(3040, "thomas-bayer.com", 80); proxy.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { @@ -53,14 +54,10 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } }); - router = new HttpRouter(); - setClientConfigHTTPClientOnInterceptor(router); - - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); - router.init(); + startNewRouter(router, proxy); - ServiceProxy proxy1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3041), "localhost", 3040); + ServiceProxy proxy1 = getProxy(3041, "localhost", 3040); proxy1.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { @@ -68,16 +65,25 @@ public Outcome handleRequest(Exchange exc) { return super.handleRequest(exc); } }); - router2 = new HttpRouter(); - setClientConfigHTTPClientOnInterceptor(router2); + startNewRouter(router2, proxy1); + } + + private static @NotNull ServiceProxy getProxy(int port, String targetHost, int targetPort) { + return new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), targetHost, targetPort); + } - router2.getRuleManager().addProxyAndOpenPortIfNew(proxy1); - router2.init(); + private static void startNewRouter(TestRouter router, ServiceProxy proxy) throws IOException { + router = new TestRouter(); + router.add(proxy); + router.start(); + setClientConfigHTTPClientOnInterceptor(router); } - private static void setClientConfigHTTPClientOnInterceptor(HttpRouter router2) { - router2.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).get().setHttpClientConfig(hcc); + private static void setClientConfigHTTPClientOnInterceptor(TestRouter router2) { + var i = router2.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); + i.setHttpClientConfig(hcc); + i.init(); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/OpenAPIRecordFactoryIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/OpenAPIRecordFactoryIntegrationTest.java index 4320edfb06..d73361dc51 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/OpenAPIRecordFactoryIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/OpenAPIRecordFactoryIntegrationTest.java @@ -27,7 +27,7 @@ public class OpenAPIRecordFactoryIntegrationTest { @BeforeAll static void setUp() { - factory = new OpenAPIRecordFactory(new Router()); + factory = new OpenAPIRecordFactory(new DefaultRouter()); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java index 7bd0e00219..757cc07a68 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java @@ -28,14 +28,14 @@ class ProxySSLConnectionMethodTest { - private HttpRouter router; + private Router router; @BeforeEach void setUp() throws Exception { - router = new HttpRouter(); + router = new TestRouter(); router.setExchangeStore(new MemoryExchangeStore()); - router.getRuleManager().addProxyAndOpenPortIfNew(new ProxyRule(new ProxyRuleKey(3129))); - router.init(); + router.add(new ProxyRule(new ProxyRuleKey(3129))); + router.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java index 142842f6e2..5ffc800841 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java @@ -19,43 +19,44 @@ import com.predic8.membrane.core.transport.http.client.*; import org.junit.jupiter.api.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.*; import static io.restassured.RestAssured.*; public class ViaProxyTest { - static HttpRouter proxyRouter; - static HttpRouter router; - - @BeforeAll - static void setUp() throws Exception { - ProxyConfiguration proxy = new ProxyConfiguration(); - proxy.setHost("localhost"); - proxy.setPort(3128); - - proxyRouter = new HttpRouter(proxy); - proxyRouter.getRuleManager().addProxy(new ProxyRule(new ProxyRuleKey(3128)), MANUAL); - proxyRouter.init(); - - ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", "GET", ".*", 4000), "api.predic8.de", 443); - rule.getTarget().setSslParser(new SSLParser()); - router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(rule); - router.init(); - } - - @Test - void testPost() { - when() - .get("http://localhost:4000/shop/v2/products") - .then() - .statusCode(200); - } - - @AfterAll - static void tearDown() { - router.shutdown(); - proxyRouter.shutdown(); - } + static Router proxyRouter; + static Router router; + + @BeforeAll + static void setUp() throws Exception { + ProxyConfiguration proxy = new ProxyConfiguration(); + proxy.setHost("localhost"); + proxy.setPort(3128); + + proxyRouter = new TestRouter(proxy); + proxyRouter.add(new ProxyRule(new ProxyRuleKey(3128))); + proxyRouter.start(); + + ServiceProxy rule = new ServiceProxy(new ServiceProxyKey("localhost", "GET", ".*", 4000), "api.predic8.de", 443); + rule.getTarget().setSslParser(new SSLParser()); + router = new TestRouter(); + router.add(rule); + router.start(); + } + + @AfterAll + static void tearDown() { + router.shutdown(); + proxyRouter.shutdown(); + } + + @Test + void post() { + when() + .get("http://localhost:4000/shop/v2/products") + .then() + .statusCode(200); + } + + } diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java index af01ca6355..50467aa87a 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java @@ -18,53 +18,72 @@ import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor; import com.predic8.membrane.core.interceptor.rewrite.RewriteInterceptor.*; +import com.predic8.membrane.core.openapi.serviceproxy.*; import com.predic8.membrane.core.proxies.*; import org.apache.commons.httpclient.*; import org.apache.commons.httpclient.methods.*; import org.apache.http.params.*; +import org.apache.http.util.*; import org.junit.jupiter.api.*; +import static com.predic8.membrane.core.http.Header.CONTENT_TYPE; +import static com.predic8.membrane.core.http.MimeType.TEXT_XML_UTF8; +import static org.apache.commons.httpclient.HttpVersion.HTTP_1_1; +import static org.apache.http.params.CoreProtocolPNames.PROTOCOL_VERSION; import static org.junit.jupiter.api.Assertions.*; public class RewriteInterceptorIntegrationTest { - private static HttpRouter router; + private static Router router; + + String soap = """ + + + + Bonn + + + s + """; @BeforeAll - public static void setUp() throws Exception { + static void setUp() throws Exception { RewriteInterceptor interceptor = new RewriteInterceptor(); - interceptor.getMappings().add(new Mapping("/blz-service\\?wsdl", "/axis2/services/BLZService?wsdl", null)); + interceptor.getMappings().add(new Mapping("/city\\?wsdl", "/city-service?wsdl", null)); - ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3006), "thomas-bayer.com", 80); + ServiceProxy proxy = new APIProxy(); + AbstractServiceProxy.Target target = new AbstractServiceProxy.Target(); + target.setUrl("https://www.predic8.de"); + proxy.setTarget(target); + proxy.setKey(new ServiceProxyKey("localhost", "*", ".*", 3006)); proxy.getFlow().add(interceptor); - router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); + router = new TestRouter(); + router.add(proxy); + router.start(); } @AfterAll - public static void tearDown() { + static void tearDown() { router.shutdown(); } @Test - public void testRewriting() throws Exception { + void testRewriting() throws Exception { HttpClient client = new HttpClient(); - client.getParams().setParameter(HttpProtocolParams.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); - int status = client.executeMethod(getPostMethod()); - + client.getParams().setParameter(PROTOCOL_VERSION, HTTP_1_1); + var post = getPostMethod(); + int status = client.executeMethod(post); assertEquals(200, status); + assertTrue(post.getResponseBodyAsString().contains("CitySoapBinding")); } private PostMethod getPostMethod() { - PostMethod post = new PostMethod("http://localhost:3006/blz-service?wsdl"); - post.setRequestEntity(new InputStreamRequestEntity(this.getClass().getResourceAsStream("/getBank.xml"))); - post.setRequestHeader(Header.CONTENT_TYPE, MimeType.TEXT_XML_UTF8); + PostMethod post = new PostMethod("http://localhost:3006/city?wsdl"); + post.setRequestEntity(new StringRequestEntity(soap)); + post.setRequestHeader(CONTENT_TYPE, TEXT_XML_UTF8); post.setRequestHeader(Header.SOAP_ACTION, ""); - return post; } - - } diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java index 8cc2693c0d..9b455a694d 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java @@ -29,17 +29,18 @@ import java.util.concurrent.atomic.*; import static com.predic8.membrane.core.http.Header.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; import static org.junit.jupiter.api.Assertions.*; public class LimitedMemoryExchangeStoreIntegrationTest { private static LimitedMemoryExchangeStore lmes; - private static HttpRouter router; - private static HttpRouter router2; + private static Router router; + private static Router router2; private static HttpClientConfiguration hcc; private static final AtomicReference middleExchange = new AtomicReference<>(); @BeforeAll - public static void setup() throws Exception { + static void setup() throws Exception { lmes = new LimitedMemoryExchangeStore(); lmes.setMaxSize(500000); @@ -47,22 +48,20 @@ public static void setup() throws Exception { hcc = new HttpClientConfiguration(); hcc.getRetryHandler().setRetries(1); - ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3045), "dummy", 80); + ServiceProxy proxy = getServiceProxy(3045, "dummy", 80); proxy.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { exc.setResponse(Response.ok().body("").build()); - return Outcome.RETURN; + return RETURN; } }); - router = new HttpRouter(); + router = new TestRouter(); + router.add(proxy); + router.start(); + setClientConfig(router,hcc); - getHttpClientInterceptor(router).setHttpClientConfig(hcc); - - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); - router.init(); - - ServiceProxy proxy1 = new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", 3046), "localhost", 3045); + ServiceProxy proxy1 = getServiceProxy(3046, "localhost", 3045); proxy1.getFlow().add(new AbstractInterceptor() { @Override public Outcome handleRequest(Exchange exc) { @@ -70,19 +69,26 @@ public Outcome handleRequest(Exchange exc) { return super.handleRequest(exc); } }); - router2 = new HttpRouter(); + router2 = new TestRouter(); router2.setExchangeStore(lmes); - - getHttpClientInterceptor(router2).setHttpClientConfig(hcc); - + router2.add(proxy1); + router2.start(); + setClientConfig(router2,hcc); router2.getTransport().getFlow().add(3, new ExchangeStoreInterceptor(lmes)); + } + + private static void setClientConfig(Router router, HttpClientConfiguration hcc) { + var client = getHttpClientInterceptor(router); + client.setHttpClientConfig(hcc); + client.init(); + } - router2.getRuleManager().addProxyAndOpenPortIfNew(proxy1); - router2.init(); + private static @NotNull ServiceProxy getServiceProxy(int port, String localhost, int targetPort) { + return new ServiceProxy(new ServiceProxyKey("localhost", "POST", ".*", port), localhost, targetPort); } - private static @NotNull HTTPClientInterceptor getHttpClientInterceptor(IRouter router) { - return (HTTPClientInterceptor) router.getTransport().getFlow().stream().filter(i -> i instanceof HTTPClientInterceptor).findFirst().get(); + private static @NotNull HTTPClientInterceptor getHttpClientInterceptor(Router router) { + return router.getTransport().getFirstInterceptorOfType(HTTPClientInterceptor.class).orElseThrow(); } @BeforeEach @@ -132,7 +138,7 @@ public void largeChunked() throws Exception { long len = Integer.MAX_VALUE + 1L; Exchange e = new Request.Builder().post("http://localhost:3046/foo").body(len, new LargeBodyTest.ConstantInputStream(len)).header(TRANSFER_ENCODING, CHUNKED).buildExchange(); - try(HttpClient hc = new HttpClient(hcc)) { + try (HttpClient hc = new HttpClient(hcc)) { hc.call(e); } assertTrue(e.getRequest().getBody().wasStreamed()); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java index 65d6be89f1..760011062f 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java @@ -21,6 +21,7 @@ import com.predic8.membrane.core.transport.http.*; import org.junit.jupiter.api.*; +import java.io.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; @@ -47,19 +48,17 @@ class MassivelyParallelTest { private static int CONCURRENT_THREADS = 500; static HttpClient client; - static HttpRouter server; + static TestRouter server; @BeforeAll - public static void init() { + public static void init() throws IOException { client = new HttpClient(); - - server = new HttpRouter(); + server = new TestRouter(); + server.add(createServiceProxy()); + server.start(); server.getTransport().setConcurrentConnectionLimitPerIp(CONCURRENT_THREADS); server.getTransport().setBacklog(CONCURRENT_THREADS); server.getTransport().setSocketTimeout(10000); - server.getConfig().setHotDeploy(false); - server.getRuleManager().addProxy(createServiceProxy(), MANUAL); - server.start(); } private static ServiceProxy createServiceProxy() { @@ -96,7 +95,7 @@ public void run() throws Exception { } private void runInParallel(Consumer job, int threadCount) { - try(ExecutorService es = Executors.newVirtualThreadPerTaskExecutor()) { + try (ExecutorService es = Executors.newVirtualThreadPerTaskExecutor()) { CountDownLatch cdl = new CountDownLatch(threadCount); try { for (int i = 0; i < threadCount; i++) { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java index 004f4fef70..0c5c296a60 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java @@ -14,39 +14,26 @@ package com.predic8.membrane.integration.withoutinternet; -import com.predic8.membrane.core.HttpRouter; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Response; -import com.predic8.membrane.core.interceptor.AbstractInterceptorWithSession; -import com.predic8.membrane.core.interceptor.Outcome; +import com.predic8.membrane.core.*; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; +import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.interceptor.session.*; import com.predic8.membrane.integration.*; import org.apache.http.Header; -import org.apache.http.client.config.CookieSpecs; -import org.apache.http.client.config.RequestConfig; -import org.apache.http.client.methods.CloseableHttpResponse; -import org.apache.http.client.methods.HttpGet; -import org.apache.http.client.methods.RequestBuilder; -import org.apache.http.client.protocol.HttpClientContext; -import org.apache.http.impl.client.BasicCookieStore; -import org.apache.http.impl.client.CloseableHttpClient; -import org.apache.http.impl.client.HttpClients; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.MethodSource; - -import java.time.Duration; -import java.time.Instant; -import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Collection; -import java.util.List; -import java.util.UUID; -import java.util.concurrent.CountDownLatch; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; -import java.util.function.Supplier; -import java.util.stream.Stream; +import org.apache.http.client.config.*; +import org.apache.http.client.methods.*; +import org.apache.http.client.protocol.*; +import org.apache.http.impl.client.*; +import org.junit.jupiter.params.*; +import org.junit.jupiter.params.provider.*; + +import java.time.*; +import java.time.format.*; +import java.util.*; +import java.util.concurrent.*; +import java.util.function.*; +import java.util.stream.*; import static org.junit.jupiter.api.Assertions.*; @@ -79,26 +66,26 @@ private static Object[] inMemory() { @MethodSource("data") public void remembersThings( String nameDummyField, - Supplier smSupplier) throws Exception{ - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); + Supplier smSupplier) throws Exception { + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); HttpClientContext ctx = getHttpClientContext(); String rememberThis = UUID.randomUUID().toString(); String rememberThisFromServer = ""; - try(CloseableHttpClient client = getHttpClient()){ + try (CloseableHttpClient client = getHttpClient()) { - try(CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(),ctx)){ + try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(), ctx)) { Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } - try(CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT),ctx)){ + try (CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT), ctx)) { rememberThisFromServer = resp.getFirstHeader(REMEMBER_HEADER).getValue(); Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } } - assertEquals(rememberThis,rememberThisFromServer); + assertEquals(rememberThis, rememberThisFromServer); httpRouter.stop(); httpRouter.shutdown(); @@ -108,26 +95,26 @@ public void remembersThings( @MethodSource("data") public void sessionExpires( String nameDummyField, - Supplier smSupplier) throws Exception{ - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier, Duration.ZERO))); + Supplier smSupplier) throws Exception { + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier, Duration.ZERO))); HttpClientContext ctx = getHttpClientContext(); String rememberThis = UUID.randomUUID().toString(); String rememberThisFromServer; - try(CloseableHttpClient client = getHttpClient()){ + try (CloseableHttpClient client = getHttpClient()) { - try(CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(),ctx)){ + try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(), ctx)) { Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } - try(CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT),ctx)){ + try (CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT), ctx)) { rememberThisFromServer = resp.getFirstHeader(REMEMBER_HEADER).getValue(); Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } } - assertNotEquals(rememberThis,rememberThisFromServer); + assertNotEquals(rememberThis, rememberThisFromServer); assertEquals("null", rememberThisFromServer); httpRouter.shutdown(); @@ -137,35 +124,35 @@ public void sessionExpires( @MethodSource("data") public void changeValueInSession( String nameDummyField, - Supplier smSupplier) throws Exception{ - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); + Supplier smSupplier) throws Exception { + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); HttpClientContext ctx = getHttpClientContext(); String rememberThis = UUID.randomUUID().toString(); String rememberThisFromServer; - try(CloseableHttpClient client = getHttpClient()){ + try (CloseableHttpClient client = getHttpClient()) { - try(CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(),ctx)){ + try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(), ctx)) { Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } - try(CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, "rememberThis").build(),ctx)){ - if(nameDummyField.equals("jwt")){ + try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, "rememberThis").build(), ctx)) { + if (nameDummyField.equals("jwt")) { List
collect = Arrays.stream(resp.getHeaders("Set-Cookie")).toList(); - assertEquals(2,collect.size()); + assertEquals(2, collect.size()); assertEquals(1, collect.stream().filter(v -> v.getValue().toLowerCase().contains(SessionManager.VALUE_TO_EXPIRE_SESSION_IN_BROWSER.toLowerCase())).count()); Arrays.stream(resp.getAllHeaders()).forEach(h -> System.out.println(h.toString())); } } - try(CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT),ctx)){ + try (CloseableHttpResponse resp = client.execute(new HttpGet("http://localhost:" + GATEWAY_PORT), ctx)) { rememberThisFromServer = resp.getFirstHeader(REMEMBER_HEADER).getValue(); } } - assertEquals("rememberThis",rememberThisFromServer); + assertEquals("rememberThis", rememberThisFromServer); httpRouter.shutdown(); } @@ -174,20 +161,20 @@ public void changeValueInSession( @MethodSource("data") public void sessionCookie( String nameDummyField, - Supplier smSupplier) throws Exception{ + Supplier smSupplier) throws Exception { AbstractInterceptorWithSession abstractInterceptorWithSession = testInterceptor(smSupplier); abstractInterceptorWithSession.getSessionManager().setSessionCookie(true); - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, abstractInterceptorWithSession)); + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, abstractInterceptorWithSession)); HttpClientContext ctx = getHttpClientContext(); String rememberThis = UUID.randomUUID().toString(); - try(CloseableHttpClient client = getHttpClient()){ + try (CloseableHttpClient client = getHttpClient()) { - for(int i = 0; i <= 100; i++) { + for (int i = 0; i <= 100; i++) { try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, rememberThis).build(), ctx)) { - if(resp.getFirstHeader("Set-Cookie") != null) { + if (resp.getFirstHeader("Set-Cookie") != null) { allSetCookieHeadersExceptFor1970Expire(resp).forEach(c -> { assertFalse(c.getValue().toLowerCase().contains("Expire".toLowerCase())); assertFalse(c.getValue().toLowerCase().contains("Max-Age".toLowerCase())); @@ -197,9 +184,9 @@ public void sessionCookie( } } - for(int i = 0; i <= 100; i++) { + for (int i = 0; i <= 100; i++) { try (CloseableHttpResponse resp = client.execute(RequestBuilder.get("http://localhost:" + GATEWAY_PORT).addHeader(REMEMBER_HEADER, UUID.randomUUID().toString()).build(), ctx)) { - if(resp.getFirstHeader("Set-Cookie") != null) { + if (resp.getFirstHeader("Set-Cookie") != null) { allSetCookieHeadersExceptFor1970Expire(resp).forEach(c -> { assertFalse(c.getValue().toLowerCase().contains("Expire".toLowerCase())); assertFalse(c.getValue().toLowerCase().contains("Max-Age".toLowerCase())); @@ -217,13 +204,13 @@ public void sessionCookie( @MethodSource("data") public void expiresPartIsRefreshedOnAccess( String nameDummyField, - Supplier smSupplier) throws Exception{ - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); + Supplier smSupplier) throws Exception { + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); HttpClientContext ctx = getHttpClientContext(); String rememberThis = UUID.randomUUID().toString(); - try(CloseableHttpClient client = getHttpClient()){ + try (CloseableHttpClient client = getHttpClient()) { String firstExpires; String secondExpires; @@ -251,7 +238,7 @@ public void expiresPartIsRefreshedOnAccess( } System.out.println(firstExpires); System.out.println(secondExpires); - assertNotEquals(firstExpires,secondExpires); + assertNotEquals(firstExpires, secondExpires); // throws if dates are not parsable - no assert available Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(firstExpires.split("=")[1])); @@ -266,7 +253,7 @@ public void expiresPartIsRefreshedOnAccess( public void parallelRequests( String nameDummyField, Supplier smSupplier) throws Exception { - HttpRouter httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); + var httpRouter = Util.basicRouter(Util.createServiceProxy(GATEWAY_PORT, testInterceptor(smSupplier))); HttpClientContext ctx = getHttpClientContext(); ExecutorService executor = Executors.newCachedThreadPool(); @@ -278,7 +265,7 @@ public void parallelRequests( CloseableHttpClient client = getHttpClient(); - for(int i = 0; i < limit; i++) { + for (int i = 0; i < limit; i++) { executor.execute(() -> { try { startAllInParallel.await(); @@ -292,7 +279,7 @@ public void parallelRequests( .filter(e -> e.contains(",")) .count(); - assertEquals(0,wrongCookies); + assertEquals(0, wrongCookies); } } catch (Exception e) { throw new RuntimeException(e); @@ -328,17 +315,17 @@ private HttpClientContext getHttpClientContext() { private AbstractInterceptorWithSession testInterceptor( Supplier smSupplier, Duration... ttl) { - if(ttl == null || ttl.length == 0) - ttl = new Duration[] {Duration.ofSeconds(300)}; + if (ttl == null || ttl.length == 0) + ttl = new Duration[]{Duration.ofSeconds(300)}; AbstractInterceptorWithSession result = new AbstractInterceptorWithSession() { @Override protected Outcome handleRequestInternal(Exchange exc) { String rememberThis = exc.getRequest().getHeader().getFirstValue(REMEMBER_HEADER); - if(rememberThis == null) - exc.setResponse(Response.ok().header(REMEMBER_HEADER,getSessionManager().getSession(exc).get(REMEMBER_HEADER)).build()); + if (rememberThis == null) + exc.setResponse(Response.ok().header(REMEMBER_HEADER, getSessionManager().getSession(exc).get(REMEMBER_HEADER)).build()); else { - getSessionManager().getSession(exc).put(REMEMBER_HEADER,rememberThis); + getSessionManager().getSession(exc).put(REMEMBER_HEADER, rememberThis); exc.setResponse(Response.ok().build()); } return Outcome.RETURN; diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java index e047013582..71486c6d3a 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/AcmeRenewTest.java @@ -67,8 +67,7 @@ public void all() throws Exception { acme.setContacts("mailto:jsmith@example.com"); acme.setAcmeSynchronizedStorage(new MemoryStorage()); - HttpRouter router = new HttpRouter(); - router.getConfig().setHotDeploy(false); + Router router = new TestRouter(); SSLParser sslParser = new SSLParser(); sslParser.setAcme(acme); ServiceProxy sp1 = new ServiceProxy(new ServiceProxyKey(3051), "localhost", 80); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java index 09aa5352dc..99f1cfba9f 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java @@ -29,13 +29,14 @@ public class OpenApiRewriteIntegrationTest { - private final IRouter r = new HttpRouter(); + private Router r; @BeforeEach public void setUp() throws Exception { - r.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy()); - r.getRuleManager().addProxyAndOpenPortIfNew(getTargetProxy()); - r.init(); + r = new TestRouter(); + r.add(getApiProxy()); + r.add(getTargetProxy()); + r.start(); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java index fd37c01487..8fe3835f68 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java @@ -29,14 +29,14 @@ public class REST2SOAPInterceptorIntegrationTest { - private static HttpRouter router; + private static Router router; @BeforeAll public static void setUp() throws Exception { ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3004), "", 0); - router = new HttpRouter(); - router.getRuleManager().addProxyAndOpenPortIfNew(proxy); + router = new TestRouter(); + router.add(proxy); var interceptors = proxy.getFlow(); REST2SOAPInterceptor rest2SoapInt = new REST2SOAPInterceptor(); @@ -45,7 +45,7 @@ public static void setUp() throws Exception { SampleSoapServiceInterceptor sampleSoapInt = new SampleSoapServiceInterceptor(); interceptors.add(sampleSoapInt); - router.init(); + router.start(); } @AfterAll @@ -60,7 +60,6 @@ public void testRest() throws Exception { GetMethod get = new GetMethod("http://localhost:3004/city/Bonn"); int status = client.executeMethod(get); - System.out.println(get.getResponseBodyAsString()); assertEquals(200, status); } diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index 21f78603bd..7bdf530b8b 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -25,17 +25,17 @@ public class SOAPProxyIntegrationTest { - private static IRouter router; - private static IRouter targetRouter; + private static Router router; + private static Router targetRouter; @BeforeAll public static void setup() throws Exception { ServiceProxy proxy = new ServiceProxy(new ServiceProxyKey(3000), null, 0); proxy.getFlow().add(new SampleSoapServiceInterceptor()); - targetRouter = new HttpRouter(); - targetRouter.getRuleManager().addProxyAndOpenPortIfNew(proxy); - targetRouter.init(); + targetRouter = new TestRouter(); + targetRouter.add(proxy); + targetRouter.start(); } @AfterAll @@ -44,17 +44,17 @@ public static void teardown() { } @BeforeEach - public void startRouter() { + void startRouter() { router = RouterBootstrap.initByXML("classpath:/soap-proxy.xml"); } @AfterEach - public void shutdownRouter() { + void shutdownRouter() { router.shutdown(); } @Test - public void targetProxyTest() { + void targetProxyTest() { when() .get("http://localhost:3000/foo?wsdl") .then() @@ -62,7 +62,7 @@ public void targetProxyTest() { } @Test - public void rewriteSimpleTest() { + void rewriteSimpleTest() { when() .get("http://localhost:2000/foo?wsdl") .then() diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index 87adea52b9..c7d0c13933 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -39,7 +39,7 @@ public abstract class OAuth2AuthorizationServerInterceptorBase { - static IRouter router; + static Router router; static Exchange exc; static OAuth2AuthorizationServerInterceptor oasi; static MembraneAuthorizationService mas; @@ -203,7 +203,7 @@ public static Runnable runUntilGoodAuthOpenidRequest() { @BeforeEach void setUp() throws Exception{ - router = new HttpRouter(); + router = new TestRouter(); router.start(); initOasi(); initMas(); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java index 2f25f9d350..38e2bf184c 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java @@ -39,8 +39,8 @@ class OAuth2Test { - static Router router; - static Router router2; + static DefaultRouter router; + static DefaultRouter router2; static ServiceProxy oAuth2ServerProxy; static OAuth2AuthorizationServerInterceptor oAuth2ASI; @@ -53,7 +53,7 @@ class OAuth2Test { @BeforeAll static void startup() throws Exception { - router = new Router(); + router = new DefaultRouter(); router.getConfig().setHotDeploy(false); router.setExchangeStore(new ForgetfulExchangeStore()); router.setTransport(new HttpTransport()); @@ -67,7 +67,7 @@ static void startup() throws Exception { router.init(); router.start(); - router2 = new Router(); + router2 = new DefaultRouter(); router2.getConfig().setHotDeploy(false); router2.setExchangeStore(new ForgetfulExchangeStore()); router2.setTransport(new HttpTransport()); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java index bb88404abe..ea9cdd9155 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java @@ -56,10 +56,10 @@ class LoadBalancingInterceptorFaultMonitoringStrategyTest { private static final Logger log = LoggerFactory.getLogger(LoadBalancingInterceptorFaultMonitoringStrategyTest.class.getName()); LoadBalancingInterceptor balancingInterceptor; - IRouter balancer; + Router balancer; // The simulation nodes - private final List nodes = new ArrayList<>(); + private final List nodes = new ArrayList<>(); private void setUp(TestingContext ctx) throws Exception { nodes.clear(); @@ -75,8 +75,8 @@ private void setUp(TestingContext ctx) throws Exception { } } - private IRouter createLoadBalancer() throws Exception { - IRouter r = new TestRouter(); + private Router createLoadBalancer() throws Exception { + Router r = new TestRouter(); ServiceProxy sp3 = new ServiceProxy(new ServiceProxyKey("localhost", "*", ".*", 3054), "thomas-bayer.com", 80); balancingInterceptor = new LoadBalancingInterceptor(); balancingInterceptor.setName("Default"); @@ -99,7 +99,7 @@ private IRouter createLoadBalancer() throws Exception { return config; } - private IRouter createRouterForNode(TestingContext ctx, int i) throws Exception { + private Router createRouterForNode(TestingContext ctx, int i) throws Exception { var r = new TestRouter(); r.add(createServiceProxy(ctx, i)); r.start(); @@ -121,7 +121,7 @@ public Outcome handleResponse(Exchange exc) { @AfterEach void tearDown() { - for (IRouter httpRouter : nodes) { + for (Router httpRouter : nodes) { try { httpRouter.shutdown(); } catch (Exception e) { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 9b2934b68b..5901eeff89 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -30,7 +30,6 @@ import static com.predic8.membrane.core.http.Header.*; import static com.predic8.membrane.core.http.MimeType.*; import static com.predic8.membrane.core.http.Response.*; -import static com.predic8.membrane.core.interceptor.InterceptorUtil.*; import static com.predic8.membrane.core.interceptor.Outcome.*; import static com.predic8.membrane.core.interceptor.balancer.BalancerUtil.*; import static java.lang.Thread.*; @@ -47,9 +46,9 @@ public abstract class LoadBalancingInterceptorTest { private DispatchingStrategy roundRobin; private DispatchingStrategy byThreadStrategy; private DispatchingStrategy priorityStrategy; - private IRouter service1; - private IRouter service2; - protected IRouter balancer; + private Router service1; + private Router service2; + protected Router balancer; @BeforeEach public void setUp() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index 78a68d8afa..87a084dfd2 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -37,10 +37,10 @@ public class MultipleLoadBalancersTest { protected static LoadBalancingInterceptor balancingInterceptor2; private static DispatchingStrategy roundRobinStrategy1; private static DispatchingStrategy roundRobinStrategy2; - protected static IRouter balancer; + protected static Router balancer; @AfterAll - static void tearDown() throws Exception { + static void tearDown() { service1.close(); service2.close(); service11.close(); @@ -50,7 +50,7 @@ static void tearDown() throws Exception { private static class MockService { final int port; - final IRouter router; + final Router router; final DummyWebServiceInterceptor mockInterceptor1; MockService(int port) throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java index 1b24293393..ab0134fa4c 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/ws_addressing/WsaEndpointRewriterInterceptorTest.java @@ -29,7 +29,7 @@ public class WsaEndpointRewriterInterceptorTest { @BeforeEach public void setUp() throws Exception { - IRouter router = new HttpRouter(); + Router router = new DummyTestRouter(); router.init(); rewriter = new WsaEndpointRewriterInterceptor(); rewriter.init(router); diff --git a/core/src/test/resources/proxy-rules-test-monitor-beans.xml b/core/src/test/resources/proxy-rules-test-monitor-beans.xml index 9e0107ca23..87ca7eb2e4 100644 --- a/core/src/test/resources/proxy-rules-test-monitor-beans.xml +++ b/core/src/test/resources/proxy-rules-test-monitor-beans.xml @@ -11,7 +11,7 @@ - + diff --git a/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java b/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java index 17f07af29c..4a36f09fc5 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/ConfigSerializationTest.java @@ -100,7 +100,7 @@ public void doit(String configFile) throws Exception { assertContainsNot("incomplete serialization", xml); - Router r2 = MCUtil.fromXML(Router.class, xml); + DefaultRouter r2 = MCUtil.fromXML(DefaultRouter.class, xml); String xml2 = MCUtil.toXML(r2); @@ -111,7 +111,7 @@ public void doit(String configFile) throws Exception { } private String readConfigFileAsXML(String configFile) throws IOException { - return MCUtil.toXML(MCUtil.fromXML(Router.class, readFileToString(new File(configFile), UTF_8))); + return MCUtil.toXML(MCUtil.fromXML(DefaultRouter.class, readFileToString(new File(configFile), UTF_8))); } public void prettyPrint(String xml) throws Exception { diff --git a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/env/HelpLinkExistenceTest.java b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/env/HelpLinkExistenceTest.java index ac087953cf..441a9d8a36 100644 --- a/distribution/src/test/java/com/predic8/membrane/examples/withinternet/env/HelpLinkExistenceTest.java +++ b/distribution/src/test/java/com/predic8/membrane/examples/withinternet/env/HelpLinkExistenceTest.java @@ -20,13 +20,12 @@ import java.lang.annotation.Annotation; import java.util.*; -import com.predic8.membrane.core.exchange.*; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import com.predic8.membrane.annot.MCElement; import com.predic8.membrane.core.Constants; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.http.Response; import com.predic8.membrane.core.interceptor.Interceptor; @@ -93,7 +92,7 @@ private Set> getElementClasses() { try { HashSet> currentSet = new HashSet<>(); - try (BufferedReader r = new BufferedReader(new InputStreamReader(requireNonNull(Router.class.getResourceAsStream("/META-INF/membrane.cache"))))) { + try (BufferedReader r = new BufferedReader(new InputStreamReader(requireNonNull(DefaultRouter.class.getResourceAsStream("/META-INF/membrane.cache"))))) { if (!CACHE_FILE_FORMAT_VERSION.equals(r.readLine())) throw new RuntimeException(); Class annotationClass; diff --git a/distribution/src/test/java/com/predic8/membrane/load/LoadTester.java b/distribution/src/test/java/com/predic8/membrane/load/LoadTester.java index 2d43b19078..e3b049a433 100644 --- a/distribution/src/test/java/com/predic8/membrane/load/LoadTester.java +++ b/distribution/src/test/java/com/predic8/membrane/load/LoadTester.java @@ -48,7 +48,7 @@ public class LoadTester { */ public static final int CONCURRENCY = 200; - Router r = new HttpRouter(); + Router r = new DefaultRouter(); public static void main(String[] args) throws Exception { var instance = new LoadTester(); diff --git a/war/src/main/java/com/predic8/membrane/servlet/MembraneServletContextListener.java b/war/src/main/java/com/predic8/membrane/servlet/MembraneServletContextListener.java index 155eaaac67..fc91c48750 100644 --- a/war/src/main/java/com/predic8/membrane/servlet/MembraneServletContextListener.java +++ b/war/src/main/java/com/predic8/membrane/servlet/MembraneServletContextListener.java @@ -15,7 +15,7 @@ package com.predic8.membrane.servlet; import com.predic8.membrane.core.Constants; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext; import jakarta.servlet.ServletContextEvent; import jakarta.servlet.ServletContextListener; @@ -36,7 +36,7 @@ public void contextInitialized(ServletContextEvent sce) { log.debug("loading proxies configuration from: " + getProxiesXmlLocation(sce)); appCtx = new BaseLocationXmlWebApplicationContext(); - Router router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, sce.getServletContext(), getProxiesXmlLocation(sce)); + DefaultRouter router = RouterUtil.initializeRoutersFromSpringWebContext(appCtx, sce.getServletContext(), getProxiesXmlLocation(sce)); if (router != null) throw new RuntimeException("A with a cannot be used with MembraneServletContextListener. Use MembraneServlet instead."); diff --git a/war/src/main/java/com/predic8/membrane/servlet/RouterUtil.java b/war/src/main/java/com/predic8/membrane/servlet/RouterUtil.java index 96daf4b5b5..ec45c58375 100644 --- a/war/src/main/java/com/predic8/membrane/servlet/RouterUtil.java +++ b/war/src/main/java/com/predic8/membrane/servlet/RouterUtil.java @@ -20,18 +20,18 @@ import org.springframework.web.context.support.XmlWebApplicationContext; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.servlet.embedded.ServletTransport; public class RouterUtil { - public static Router initializeRoutersFromSpringWebContext(XmlWebApplicationContext appCtx, final ServletContext ctx, String configLocation) { + public static DefaultRouter initializeRoutersFromSpringWebContext(XmlWebApplicationContext appCtx, final ServletContext ctx, String configLocation) { appCtx.setServletContext(ctx); appCtx.setConfigLocation(configLocation); appCtx.refresh(); - Collection routers = appCtx.getBeansOfType(Router.class).values(); - Router theOne = null; - for (Router r : routers) { + Collection routers = appCtx.getBeansOfType(DefaultRouter.class).values(); + DefaultRouter theOne = null; + for (DefaultRouter r : routers) { r.getResolverMap().addSchemaResolver(new FileSchemaWebAppResolver(ctx)); if (r.getTransport() instanceof ServletTransport) { if (theOne != null) diff --git a/war/src/main/java/com/predic8/membrane/servlet/embedded/MembraneServlet.java b/war/src/main/java/com/predic8/membrane/servlet/embedded/MembraneServlet.java index 9784f907cd..96724b4bb9 100644 --- a/war/src/main/java/com/predic8/membrane/servlet/embedded/MembraneServlet.java +++ b/war/src/main/java/com/predic8/membrane/servlet/embedded/MembraneServlet.java @@ -14,7 +14,7 @@ package com.predic8.membrane.servlet.embedded; -import com.predic8.membrane.core.Router; +import com.predic8.membrane.core.DefaultRouter; import com.predic8.membrane.servlet.RouterUtil; import com.predic8.membrane.servlet.config.spring.BaseLocationXmlWebApplicationContext; import jakarta.servlet.ServletConfig; @@ -36,7 +36,7 @@ public class MembraneServlet extends HttpServlet { private static final Logger log = LoggerFactory.getLogger(MembraneServlet.class); private XmlWebApplicationContext appCtx; - private Router router; + private DefaultRouter router; @Override public void init(ServletConfig config) throws ServletException { From 4b9b06f958acddd9972ad648c4d72dc8efc31673 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 19:57:34 +0100 Subject: [PATCH 34/40] refactor: replace `router.getConfig()` with `router.getConfiguration()` for improved naming consistency across core components and tests --- .../predic8/membrane/core/DefaultRouter.java | 24 +++++++------- .../membrane/core/DummyTestRouter.java | 33 ++----------------- .../com/predic8/membrane/core/Router.java | 15 +-------- .../membrane/core/RuleReinitializer.java | 2 +- .../AbstractInterceptorWithSession.java | 4 +-- .../AcmeHttpChallengeInterceptor.java | 5 +-- .../core/interceptor/ApisJsonInterceptor.java | 2 +- .../interceptor/DispatchingInterceptor.java | 2 +- .../core/interceptor/EchoInterceptor.java | 2 +- .../core/interceptor/FlowController.java | 2 +- .../interceptor/HTTPClientInterceptor.java | 12 +++---- .../InternalRoutingInterceptor.java | 4 +-- .../core/interceptor/LimitInterceptor.java | 2 +- .../MethodOverrideInterceptor.java | 2 +- .../interceptor/RegExReplaceInterceptor.java | 2 +- .../interceptor/RelocatingInterceptor.java | 2 +- .../interceptor/RuleMatchingInterceptor.java | 2 +- .../DynamicAdminPageInterceptor.java | 2 +- .../antivirus/ClamAntiVirusInterceptor.java | 2 +- .../BasicAuthenticationInterceptor.java | 2 +- .../session/LoginInterceptor.java | 2 +- .../ClusterNotificationInterceptor.java | 2 +- .../balancer/LoadBalancingInterceptor.java | 6 ++-- .../interceptor/flow/CallInterceptor.java | 2 +- .../core/interceptor/flow/ForInterceptor.java | 2 +- .../core/interceptor/flow/IfInterceptor.java | 2 +- .../interceptor/flow/ReturnInterceptor.java | 2 +- .../flow/choice/ChooseInterceptor.java | 2 +- .../flow/choice/InterceptorContainer.java | 2 +- .../FormValidationInterceptor.java | 2 +- .../GraalVMJavascriptLanguageAdapter.java | 2 +- .../RhinoJavascriptLanguageAdapter.java | 2 +- .../json/JsonProtectionInterceptor.java | 2 +- .../interceptor/jwt/JwtAuthInterceptor.java | 8 ++--- .../interceptor/jwt/JwtSignInterceptor.java | 2 +- .../KubernetesValidationInterceptor.java | 2 +- .../lang/AbstractSetterInterceptor.java | 2 +- .../interceptor/lang/SetBodyInterceptor.java | 2 +- .../interceptor/ntlm/NtlmInterceptor.java | 2 +- .../OAuth2TokenValidatorInterceptor.java | 2 +- .../oauth2client/FlowInitiator.java | 2 +- .../ratelimit/RateLimitInterceptor.java | 2 +- .../registration/RegistrationInterceptor.java | 2 +- .../interceptor/rest/HTTP2XMLInterceptor.java | 2 +- .../rest/REST2SOAPInterceptor.java | 4 +-- .../interceptor/rest/RESTInterceptor.java | 2 +- .../rest/SOAP2RESTInterceptor.java | 4 +-- .../rewrite/ReverseProxyingInterceptor.java | 2 +- .../ValidatorInterceptor.java | 4 +-- .../server/WSDLPublisherInterceptor.java | 2 +- .../server/WebServerInterceptor.java | 6 ++-- .../soap/SampleSoapServiceInterceptor.java | 2 +- .../statistics/StatisticsProvider.java | 2 +- .../core/interceptor/stomp/STOMPClient.java | 2 +- .../templating/TemplateInterceptor.java | 6 ++-- .../WsaEndpointRewriterInterceptor.java | 2 +- .../interceptor/xml/Json2XmlInterceptor.java | 2 +- .../interceptor/xml/Xml2JsonInterceptor.java | 4 +-- .../XMLContentFilterInterceptor.java | 2 +- .../XMLProtectionInterceptor.java | 6 ++-- .../interceptor/xslt/XSLTInterceptor.java | 4 +-- .../predic8/membrane/core/jmx/JmxRouter.java | 6 ++-- .../core/kubernetes/KubernetesWatcher.java | 2 +- .../core/lang/AbstractScriptInterceptor.java | 6 ++-- .../serviceproxy/ApiDocsInterceptor.java | 4 +-- .../serviceproxy/OpenAPIInterceptor.java | 12 +++---- .../OpenAPIPublisherInterceptor.java | 2 +- .../membrane/core/proxies/AbstractProxy.java | 2 +- .../membrane/core/proxies/SSLableProxy.java | 4 ++- .../transport/http/AbstractHttpHandler.java | 4 +-- .../transport/http2/Http2ExchangeHandler.java | 2 +- .../core/transport/ssl/AcmeSSLContext.java | 9 +++++ .../membrane/core/DefaultRouterTest.java | 4 +-- .../com/predic8/membrane/core/TestRouter.java | 1 + .../core/config/SpringReferencesTest.java | 2 +- ...InternalServiceRoutingInterceptorTest.java | 2 +- .../json/JsonProtectionInterceptorTest.java | 2 +- .../jwt/JwtAuthInterceptorTest.java | 13 ++++---- .../oauth2/client/AuthServerMock.java | 2 +- .../client/OAuth2ResourceRpIniLogoutTest.java | 4 +-- .../shadowing/ShadowingInterceptorTest.java | 4 +-- .../serviceproxy/OpenAPI31ReferencesTest.java | 2 +- .../OpenAPIPublisherInterceptorTest.java | 2 +- .../serviceproxy/OpenAPIRecordTest.java | 2 +- .../openapi/serviceproxy/RewriteTest.java | 2 +- .../membrane/core/proxies/ProxySSLTest.java | 4 +-- .../membrane/core/proxies/ProxyTest.java | 2 +- .../ServiceProxyWSDLInterceptorsTest.java | 2 +- .../proxies/UnavailableSoapProxyTest.java | 6 ++-- .../core/security/JWTSecuritySchemeTest.java | 18 ++++------ .../http/IllegalCharactersInURLTest.java | 6 ++-- .../client/HttpClientConfigurationTest.java | 2 +- .../http2/Http2ClientServerTest.java | 2 +- .../transport/ssl/HttpsKeepAliveTest.java | 2 +- .../transport/ssl/SessionResumptionTest.java | 2 +- .../core/ws/SoapProxyInvocationTest.java | 2 +- .../predic8/membrane/integration/Util.java | 2 +- .../interceptor/oauth2/OAuth2Test.java | 4 +-- 98 files changed, 177 insertions(+), 209 deletions(-) diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java index 9fa3dd7db7..d192f5b411 100644 --- a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java @@ -114,7 +114,7 @@ public class DefaultRouter extends AbstractRouter implements ApplicationContextA private String id; private String baseLocation; - private Configuration config = new Configuration(); + private Configuration configuration = new Configuration(); // // Components @@ -231,7 +231,7 @@ public void start() { hotDeployer.start(this); - if (config.getRetryInitInterval() > 0) + if (configuration.getRetryInitInterval() > 0) reinitializer.start(); } catch (DuplicatePathException e) { handleDuplicateOpenAPIPaths(e); @@ -380,7 +380,7 @@ private void startJmx() { try { JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); //exporter.removeBean(prefix + jmxRouterName); - exporter.addBean("io.membrane-api:00=routers, name=" + config.getJmx(), new JmxRouter(this, exporter)); + exporter.addBean("io.membrane-api:00=routers, name=" + configuration.getJmx(), new JmxRouter(this, exporter)); exporter.initAfterBeansAdded(); } catch (NoSuchBeanDefinitionException ignored) { // If bean is not available do not init jmx @@ -419,7 +419,7 @@ public ApplicationContext getBeanFactory() { } public boolean isProduction() { - return config.isProduction(); + return configuration.isProduction(); } public Statistics getStatistics() { @@ -476,7 +476,7 @@ public FlowController getFlowController() { public void handleAsynchronousInitializationResult(boolean success) { log.debug("Asynchronous initialization finished."); - if (!success && !config.isRetryInit()) + if (!success && !configuration.isRetryInit()) System.exit(1); ApiInfo.logInfosAboutStartedProxies(getRuleManager()); } @@ -543,26 +543,26 @@ public BeanRegistry getRegistry() { public void applyConfiguration(Configuration configuration) { hotDeployer = configuration.isHotDeploy() ? new DefaultHotDeployer() : new NullHotDeployer(); - this.config = configuration; + this.configuration = configuration; } public URIFactory getUriFactory() { - return config.getUriFactory(); + return configuration.getUriFactory(); } /** * Sets the configuration object for this router. * Only used for xml * - * @param config the configuration object + * @param configuration the configuration object */ @MCChildElement(order = -1) - public void setConfig(Configuration config) { - this.config = config; + public void setConfiguration(Configuration configuration) { + this.configuration = configuration; } - public Configuration getConfig() { - return config; + public Configuration getConfiguration() { + return configuration; } public RuleReinitializer getReinitializer() { diff --git a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java index a688768d04..ca19d984e5 100644 --- a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java @@ -84,7 +84,7 @@ public void add(Proxy proxy) throws IOException { } @Override - public Configuration getConfig() { + public Configuration getConfiguration() { return configuration; } @@ -128,11 +128,6 @@ public URIFactory getUriFactory() { return uriFactory; } - @Override - public boolean isProduction() { - return false; - } - @Override public ApplicationContext getBeanFactory() { return applicationContext; @@ -152,31 +147,7 @@ public TimerManager getTimerManager() { public Statistics getStatistics() { return statistics; } - - @Override - public KubernetesClientFactory getKubernetesClientFactory() { - return kubernetesClientFactory; - } - - @Override - public Collection getRules() { - throw new UnsupportedOperationException(); - } - - @Override - public RuleReinitializer getReinitializer() { - throw new UnsupportedOperationException(); - } - - /** - * TODO Only used for tests. It s brittle cause it is dependent on - * the list. In tests interceptors in the proxy can be used instead. - */ - public void addUserFeatureInterceptor(Interceptor i) { - List is = getTransport().getFlow(); - is.add(is.size() - 3, i); - } - + /** * Same as the default config from monitor-beans.xml */ diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index d877e91db6..631d22c86b 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -16,7 +16,6 @@ import com.predic8.membrane.core.exchangestore.*; import com.predic8.membrane.core.interceptor.*; -import com.predic8.membrane.core.kubernetes.client.*; import com.predic8.membrane.core.proxies.*; import com.predic8.membrane.core.resolver.*; import com.predic8.membrane.core.transport.*; @@ -25,7 +24,6 @@ import org.springframework.context.*; import java.io.*; -import java.util.*; public interface Router extends Lifecycle { @@ -40,7 +38,7 @@ public interface Router extends Lifecycle { void add(Proxy proxy) throws IOException; - Configuration getConfig(); + Configuration getConfiguration(); Transport getTransport(); @@ -60,9 +58,6 @@ public interface Router extends Lifecycle { URIFactory getUriFactory(); - // TODO move to configuration - boolean isProduction(); - ApplicationContext getBeanFactory(); HttpClientFactory getHttpClientFactory(); @@ -70,12 +65,4 @@ public interface Router extends Lifecycle { TimerManager getTimerManager(); Statistics getStatistics(); - - KubernetesClientFactory getKubernetesClientFactory(); - - // TODO: => to RuleManager? - Collection getRules(); - - RuleReinitializer getReinitializer(); - } diff --git a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java index 1293652367..4d69875149 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleReinitializer.java @@ -45,7 +45,7 @@ synchronized void start() { public void run() { retry(); } - }, router.getConfig().getRetryInitInterval(), router.getConfig().getRetryInitInterval()); + }, router.getConfiguration().getRetryInitInterval(), router.getConfiguration().getRetryInitInterval()); } public synchronized void stop() { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptorWithSession.java b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptorWithSession.java index aad4cb2ce8..7bb5f85816 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptorWithSession.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptorWithSession.java @@ -66,7 +66,7 @@ public Outcome handleRequest(Exchange exc) { outcome = handleRequestInternal(exc); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(REQUEST) .detail("Error handling request!") .exception(e) @@ -85,7 +85,7 @@ public Outcome handleResponse(Exchange exc) { return outcome; } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(RESPONSE) .detail("Error handling response!") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java index 7e171d20a7..2b2e661c5b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java @@ -25,6 +25,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; import static com.predic8.membrane.core.http.MimeType.APPLICATION_OCTET_STREAM; import static com.predic8.membrane.core.interceptor.Outcome.ABORT; import static java.util.Arrays.stream; @@ -53,7 +54,7 @@ public Outcome handleRequest(Exchange exc) { ? exc.getRequest().getHeader().getHost().replaceAll(":.*", "") : exc.getRequest().getHeader().getHost(); - for (Proxy proxy : router.getRules()) { + for (Proxy proxy : router.getRuleManager().getRules()) { if (!(proxy instanceof SSLableProxy sp)) continue; SSLContext sslInboundContext = sp.getSslInboundContext(); @@ -72,7 +73,7 @@ public Outcome handleRequest(Exchange exc) { try { keyAuth = token + "." + acmeClient.getThumbprint(); } catch (JoseException e) { - ProblemDetails.user(router.isProduction(),getDisplayName()) + ProblemDetails.user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not create thumbprint!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java index 8bdc3981de..87ec005cb0 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ApisJsonInterceptor.java @@ -59,7 +59,7 @@ public Outcome handleRequest(Exchange exc) { try { initJson(router, exc); } catch (JsonProcessingException e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not create APIs JSON!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/DispatchingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/DispatchingInterceptor.java index 1ced96ac4a..e0c559d110 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/DispatchingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/DispatchingInterceptor.java @@ -66,7 +66,7 @@ public Outcome handleRequest(Exchange exc) { pd.buildAndSetResponse(exc); return ABORT; } catch (Exception e) { - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .detail("Could not get forwarding destination to dispatch request") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/EchoInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/EchoInterceptor.java index 3d109cfdf2..650b008f2c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/EchoInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/EchoInterceptor.java @@ -43,7 +43,7 @@ public Outcome handleRequest(Exchange exc) { } } catch (Exception e) { log.error("Could not create echo.", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not create echo!") .exception(e) .stacktrace(false) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java index f0c6fc7b2c..36cefd6b8e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/FlowController.java @@ -94,7 +94,7 @@ public Outcome invokeRequestHandlers(Exchange exchange, List interc } catch (Exception e) { String msg = "Aborting! Exception caused in %s during %s %s flow.".formatted(interceptor.getDisplayName(), exchange.getRequest().getUri(), flow); log.warn(msg, e); - internal(router.isProduction(),interceptor.getDisplayName()) + internal(router.getConfiguration().isProduction(),interceptor.getDisplayName()) .detail(msg) .exception(e) .buildAndSetResponse(exchange); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptor.java index 4496d1d1bd..07d0c98f9d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/HTTPClientInterceptor.java @@ -87,7 +87,7 @@ public Outcome handleRequest(Exchange exc) { } catch (ConnectException e) { String msg = "Target %s is not reachable.".formatted(getDestination(exc)); log.warn(msg + PROXIES_HINT); - gateway(router.isProduction(), getDisplayName()) + gateway(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("connect") .status(502) .detail(msg) @@ -95,7 +95,7 @@ public Outcome handleRequest(Exchange exc) { return ABORT; } catch (SocketTimeoutException e) { // Details are logged further down in the HTTPClient - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("socket-timeout") .detail("Target %s is not reachable.".formatted(exc.getDestinations())) .buildAndSetResponse(exc); @@ -103,7 +103,7 @@ public Outcome handleRequest(Exchange exc) { } catch (UnknownHostException e) { String msg = "Target host %s of API %s is unknown. DNS was unable to resolve host name.".formatted(URLUtil.getHost(getDestination(exc)), exc.getProxy().getName()); log.warn(msg + PROXIES_HINT); - gateway(router.isProduction(), getDisplayName()) + gateway(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("unknown-host") .status(502) .detail(msg) @@ -112,7 +112,7 @@ public Outcome handleRequest(Exchange exc) { } catch (MalformedURLException e) { log.info("Malformed URL. Requested path is: {} {}",exc.getRequest().getUri() , e.getMessage()); log.debug("",e); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .title("Request path or 'Host' header is malformed") .addSubSee("malformed-url") .exception(e) @@ -123,7 +123,7 @@ public Outcome handleRequest(Exchange exc) { return ABORT; } catch (ProtocolUpgradeDeniedException e) { log.debug("Denied protocol upgrade request. uri={} protocol={}", exc.getRequest().getUri(), e.getProtocol()); - gateway(router.isProduction(), getDisplayName()) + gateway(router.getConfiguration().isProduction(), getDisplayName()) .status(401) .title("Protocol upgrade has been denied.") .addSubSee("denied-protocol-upgrade") @@ -134,7 +134,7 @@ public Outcome handleRequest(Exchange exc) { return ABORT; } catch (Exception e) { log.error("", e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .exception(e) .internal("proxy", exc.getProxy().getName()) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/InternalRoutingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/InternalRoutingInterceptor.java index ced4fe0d40..b926e5d40e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/InternalRoutingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/InternalRoutingInterceptor.java @@ -57,7 +57,7 @@ public Outcome handleRequest(Exchange exchange) { } catch (Exception e) { String detail = "Could not invoke request handler for internal route."; log.error(detail, e); // Most should be handled inside the interceptors - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(Flow.REQUEST) .detail(detail) .exception(e) @@ -81,7 +81,7 @@ public Outcome handleResponse(Exchange exc) { } catch (Exception e) { String detail = "Could not invoke response handler for internal route."; log.error(detail, e); // Most should be handled inside the interceptors - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(Flow.RESPONSE) .detail(detail) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/LimitInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/LimitInterceptor.java index b9c37acef3..8dbb75e35c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/LimitInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/LimitInterceptor.java @@ -82,7 +82,7 @@ private Outcome handleMessage(Exchange exc, Message msg) { long len = msg.getHeader().getContentLength(); if (len != -1 && len > maxBodyLength) { log.info("Message length of {} exceeded limit {}.",len,maxBodyLength); - security(router.isProduction(), getDisplayName()) + security(router.getConfiguration().isProduction(), getDisplayName()) .title("Message is too large.") .detail("Message bodies must be smaller than limit.") .internal("maxBodyLength", maxBodyLength) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/MethodOverrideInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/MethodOverrideInterceptor.java index 9a96509d78..258ad2cc80 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/MethodOverrideInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/MethodOverrideInterceptor.java @@ -42,7 +42,7 @@ public Outcome handleRequest(Exchange exc) { break; } } catch (IOException e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could overwrite method.") .internal("method", methodHeader) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptor.java index dfea02b061..203f9b8a31 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/RegExReplaceInterceptor.java @@ -69,7 +69,7 @@ private Outcome handleInternal(Exchange exc, Message message) { try { replaceBody(message); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not replace body!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/RelocatingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/RelocatingInterceptor.java index ae16b5c325..b33d826a3c 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/RelocatingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/RelocatingInterceptor.java @@ -62,7 +62,7 @@ public Outcome handleResponse(Exchange exc) { rewrite(exc); } catch (Exception e) { log.error("",e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error rewriting URI") .topLevel("URI", exc.getRequestURI()) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/RuleMatchingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/RuleMatchingInterceptor.java index ac6da7eb92..20d6dce417 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/RuleMatchingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/RuleMatchingInterceptor.java @@ -50,7 +50,7 @@ public Outcome handleRequest(Exchange exc) { if (proxy instanceof NullProxy) { // Do not log. 404 is too common - user(getRouter().isProduction(), "routing") + user(router.getConfiguration().isProduction(), "routing") .status(404) .title("Invalid path or method") .detail("The requested path or HTTP method is not supported.") diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/DynamicAdminPageInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/DynamicAdminPageInterceptor.java index 86a8461374..d86dbcfab8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/administration/DynamicAdminPageInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/administration/DynamicAdminPageInterceptor.java @@ -60,7 +60,7 @@ public Outcome handleRequest(Exchange exc) { o = dispatchRequest(exc); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error in dynamic administration request!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/antivirus/ClamAntiVirusInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/antivirus/ClamAntiVirusInterceptor.java index 2435a43ccd..2c60c064e4 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/antivirus/ClamAntiVirusInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/antivirus/ClamAntiVirusInterceptor.java @@ -72,7 +72,7 @@ private String getBody(Exchange exc) { private Outcome gatewayTimeout(Exchange exc) { log.error("Could not reach clamav daemon on {}:{}",host,port ); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .title("Virus scanner error!") .detail("Could not execute virus scan.") .internal("message","Could not reach clamav daemon.") diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java index 9ad9b99c1e..ea39c1c0ce 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/BasicAuthenticationInterceptor.java @@ -79,7 +79,7 @@ private String getPassword(Exchange exc) { } private Outcome deny(Exchange exc) { - security(router.isProduction(),getDisplayName()) + security(router.getConfiguration().isProduction(),getDisplayName()) .status(401) .title("Unauthorized") .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginInterceptor.java index 3e4f3d689e..cf0a6ac29a 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginInterceptor.java @@ -150,7 +150,7 @@ public Outcome handleRequest(Exchange exc) { loginDialog.handleLoginRequest(exc); } catch (Exception e) { log.error("",e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not handle login request.!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptor.java index f9dff798bf..0c0a1f835d 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptor.java @@ -74,7 +74,7 @@ public Outcome handleRequest(Exchange exc) { getParams(exc); } catch (Exception e) { log.error("",e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not decrypt parameters!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingInterceptor.java index 9ef5749275..6f4684fad5 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingInterceptor.java @@ -76,7 +76,7 @@ public Outcome handleRequest(Exchange exc) { //2) All destinations got disabled externally (through Membrane maintenance API). See class EmptyNodeListException. String msg = "No backend node found that is ready to handle this request. Check health of backends and balancer configuration."; log.error(msg); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .status(503) .title("Service unavailable") .addSubSee("node-dispatching") @@ -84,7 +84,7 @@ public Outcome handleRequest(Exchange exc) { .buildAndSetResponse(exc); return ABORT; } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .status(503) .title("Service unavailable") .addSubSee("node-dispatching") @@ -117,7 +117,7 @@ public Outcome handleResponse(Exchange exc) { try { sessionId = sessionIdExtractor.getSessionId(exc, RESPONSE); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("sessionid-extraction") .detail("Could not get session id!") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/CallInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/CallInterceptor.java index 36a6aac2b7..baa13a5a58 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/CallInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/CallInterceptor.java @@ -96,7 +96,7 @@ private Outcome handleInternal(Exchange exc) { return CONTINUE; } catch (Exception e) { log.error("Error processing response from {}: {}", dest, e.getMessage(), e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("internal-calling") .detail("Internal call") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ForInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ForInterceptor.java index cdafbeb686..6864e4d1ca 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ForInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ForInterceptor.java @@ -80,7 +80,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { try { o = exchangeExpression.evaluate(exc, flow, Object.class); } catch (ExchangeExpressionException e) { - ProblemDetails pd = ProblemDetails.internal(router.isProduction(), getDisplayName()); + ProblemDetails pd = ProblemDetails.internal(router.getConfiguration().isProduction(), getDisplayName()); e.provideDetails(pd) .detail("Error evaluating expression on exchange.") .component(getDisplayName()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/IfInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/IfInterceptor.java index f00c84e7f6..c119945918 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/IfInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/IfInterceptor.java @@ -73,7 +73,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { try { result = exchangeExpression.evaluate(exc, flow, Boolean.class); } catch (ExchangeExpressionException e) { - e.provideDetails(internal(router.isProduction(), getDisplayName())) + e.provideDetails(internal(router.getConfiguration().isProduction(), getDisplayName())) .detail("Error evaluating expression on exchange.") .buildAndSetResponse(exc); return ABORT; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ReturnInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ReturnInterceptor.java index 830dc5e77f..b0ef343f3f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ReturnInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/ReturnInterceptor.java @@ -61,7 +61,7 @@ public Outcome handleRequest(Exchange exc) { } catch (IOException e) { String detail = "Could not create response!"; log.error(detail, e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail(detail) .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/ChooseInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/ChooseInterceptor.java index f8446742c6..f012d9a598 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/ChooseInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/ChooseInterceptor.java @@ -80,7 +80,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { } private void handleExpressionProblemDetails(ExchangeExpressionException e, Exchange exc) { - e.provideDetails(internal(router.isProduction(),getDisplayName())) + e.provideDetails(internal(router.getConfiguration().isProduction(),getDisplayName())) .addSubSee("expression-evaluation") .detail("Error evaluating expression on exchange in if plugin.") .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java index d879bebbb3..c13ef720ee 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/flow/choice/InterceptorContainer.java @@ -42,7 +42,7 @@ Outcome invokeFlow(Exchange exc, Flow flow, Router router) { } private void handleInvocationProblemDetails(Exchange exc, Exception e, Router router) { - internal(router.isProduction(),"interceptor-container") + internal(router.getConfiguration().isProduction(),"interceptor-container") .detail("Error invoking plugin.") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptor.java index 3d5b013879..2cd1b8ac5f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/formvalidation/FormValidationInterceptor.java @@ -115,7 +115,7 @@ public Outcome handleRequest(Exchange exc) { try { propMap = URLParamUtil.getParams(router.getUriFactory(), exc, ERROR); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not parse query parameters!") .topLevel("uri", exc.getRequest().getUri()) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java index ecf9e8100d..a728fe0a5e 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/GraalVMJavascriptLanguageAdapter.java @@ -32,7 +32,7 @@ public GraalVMJavascriptLanguageAdapter(Router router) { @Override public ProblemDetails getProblemDetails(Exception e) { - ProblemDetails pd = internal(router.isProduction(),"javascript"); + ProblemDetails pd = internal(router.getConfiguration().isProduction(),"javascript"); if (e instanceof PolyglotException pe) { pd.internal("column", pe.getSourceLocation().getStartColumn()); pd.internal("line", pe.getSourceLocation().getStartLine() - preScriptLineLength ); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java index b638b14bb6..7b6449cd34 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/javascript/RhinoJavascriptLanguageAdapter.java @@ -31,7 +31,7 @@ public RhinoJavascriptLanguageAdapter(Router router) { @Override public ProblemDetails getProblemDetails(Exception e) { - ProblemDetails pd = ProblemDetails.internal(router.isProduction(),"javascript"); + ProblemDetails pd = ProblemDetails.internal(router.getConfiguration().isProduction(),"javascript"); if (e.getCause() instanceof ScriptException se) { pd.internal("column", se.getColumnNumber() + 1); pd.internal("line", se.getLineNumber() - preScriptLineLength + 1); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java index b4e20cf6cc..1edf284263 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptor.java @@ -75,7 +75,7 @@ private boolean shouldProvideDetails() { if (reportError != null) { return reportError; } - return !router.isProduction(); + return !router.getConfiguration().isProduction(); } private abstract static class Context { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptor.java index 9b5cd2e4a5..a4fc9de313 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptor.java @@ -92,14 +92,14 @@ public Outcome handleRequest(Exchange exc) { var jwt = jwtRetriever.get(exc); return handleJwt(exc, jwt); } catch (JWTException e) { - ProblemDetails.security(router.isProduction(), "jwt-auth") + ProblemDetails.security(router.getConfiguration().isProduction(), "jwt-auth") .detail(e.getMessage()) .stacktrace(true) .status(400) .buildAndSetResponse(exc); return RETURN; } catch (JsonProcessingException e) { - ProblemDetails.security(router.isProduction(), "jwt-auth") + ProblemDetails.security(router.getConfiguration().isProduction(), "jwt-auth") .detail(ERROR_DECODED_HEADER_NOT_JSON) .addSubSee(ERROR_DECODED_HEADER_NOT_JSON_ID) .stacktrace(true) @@ -107,7 +107,7 @@ public Outcome handleRequest(Exchange exc) { .buildAndSetResponse(exc); return RETURN; } catch (InvalidJwtException e) { - ProblemDetails.security(router.isProduction(), "jwt-auth") + ProblemDetails.security(router.getConfiguration().isProduction(), "jwt-auth") .detail(ERROR_VALIDATION_FAILED) .addSubSee(ERROR_VALIDATION_FAILED_ID) .stacktrace(false) @@ -115,7 +115,7 @@ public Outcome handleRequest(Exchange exc) { .buildAndSetResponse(exc); return RETURN; } catch (Exception e) { - ProblemDetails.security(router.isProduction(), "jwt-auth") + ProblemDetails.security(router.getConfiguration().isProduction(), "jwt-auth") .detail(ERROR_JWT_NOT_FOUND) .addSubSee(ERROR_JWT_NOT_FOUND_ID) .stacktrace(true) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtSignInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtSignInterceptor.java index 19fc37caed..046c11d9df 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtSignInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/jwt/JwtSignInterceptor.java @@ -89,7 +89,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { return CONTINUE; } catch (Exception e) { log.error("Error during attempt to sign JWT payload", e); - security(router.isProduction(),getDisplayName()) + security(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("crypto") .detail("Error during attempt to sign JWT payload.") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/kubernetes/KubernetesValidationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/kubernetes/KubernetesValidationInterceptor.java index 9349b95bf5..c86b410cae 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/kubernetes/KubernetesValidationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/kubernetes/KubernetesValidationInterceptor.java @@ -182,7 +182,7 @@ public Outcome handleRequest(Exchange exc) { return RETURN; } catch (Exception e) { log.error("", e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .component(getDisplayName()) .detail("Error handling request!") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/lang/AbstractSetterInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/lang/AbstractSetterInterceptor.java index 264fb54136..b5867ba1cd 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/lang/AbstractSetterInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/lang/AbstractSetterInterceptor.java @@ -73,7 +73,7 @@ private Outcome handleInternal(Exchange exchange, Flow flow) { } private ProblemDetails prepareProblemDetails(String msg) { - return internal(getRouter().isProduction(), getDisplayName()) + return internal(getRouter().getConfiguration().isProduction(), getDisplayName()) .title(msg) .internal("field", fieldName) .internal("expression", expression); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptor.java index 34d5349c23..a6cdffab37 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/lang/SetBodyInterceptor.java @@ -64,7 +64,7 @@ private Outcome handleInternal(Exchange exchange, Flow flow) { var message = "While evaluating expression %s: %s".formatted(expression, root.getMessage()); log.info(message); - internal(getRouter().isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .title("Error evaluating expression!") .internal("expression", expression) .exception(root) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ntlm/NtlmInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ntlm/NtlmInterceptor.java index 393dc618d7..6f69e9e050 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ntlm/NtlmInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ntlm/NtlmInterceptor.java @@ -92,7 +92,7 @@ public Outcome handleResponse(Exchange exc) { try { authenticationResult = authenticate(stableConnection, originalRequestUrl, user, pass, domain, workstation); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not authenticate!") .internal("domain", domain) .internal("workstation", workstation) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokenvalidation/OAuth2TokenValidatorInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokenvalidation/OAuth2TokenValidatorInterceptor.java index dee5ea92a1..708433f7d2 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokenvalidation/OAuth2TokenValidatorInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/tokenvalidation/OAuth2TokenValidatorInterceptor.java @@ -53,7 +53,7 @@ public Outcome handleRequest(Exchange exc) { if(callExchangeAndCheckFor200(buildAccessTokenValidationExchange(exc))) return CONTINUE; } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .exception(e) .buildAndSetResponse(exc); return ABORT; diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/FlowInitiator.java b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/FlowInitiator.java index 100a2e2bcb..31e27f2015 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/FlowInitiator.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/oauth2client/FlowInitiator.java @@ -83,7 +83,7 @@ public Outcome handleRequest(Exchange exc) { return handleRequestInternal(exc); } catch (Exception e) { log.error("", e); - ProblemDetails.internal(router.isProduction(),getDisplayName()) + ProblemDetails.internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error initiating OAuth2 flow!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ratelimit/RateLimitInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ratelimit/RateLimitInterceptor.java index 429dfbc8b0..427d4778b1 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ratelimit/RateLimitInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ratelimit/RateLimitInterceptor.java @@ -104,7 +104,7 @@ public Outcome handleRequest(Exchange exc) { return CONTINUE; } catch (SpelEvaluationException e) { log.info("Cannot evaluate keyExpression {} cause is {}", expression, e.getCause()); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubType("rate-limit") .detail("Cannot evaluate keyExpression '%s' cause is %s".formatted(expression, e.getMessage())) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/registration/RegistrationInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/registration/RegistrationInterceptor.java index 3193cad33c..5a20322d80 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/registration/RegistrationInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/registration/RegistrationInterceptor.java @@ -71,7 +71,7 @@ public Outcome handleRequest(Exchange exc) { connection.createStatement().executeUpdate(getInsertAccountIntoDatabaseSQL(user)); } catch (SQLException e) { log.error("",e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not access database") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/HTTP2XMLInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/HTTP2XMLInterceptor.java index 7ab0b96e9b..f653eb6136 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/HTTP2XMLInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/HTTP2XMLInterceptor.java @@ -40,7 +40,7 @@ public Outcome handleRequest(Exchange exc) { return handleRequestInternal(exc); } catch (Exception e) { log.error("",e); - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not generate XML from HTTP information!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/REST2SOAPInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/REST2SOAPInterceptor.java index 9c4c8445b6..eb92d7ca92 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/REST2SOAPInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/REST2SOAPInterceptor.java @@ -66,7 +66,7 @@ public Outcome handleRequest(Exchange exc) { getRequestXMLSource(exc), exc.getStringProperties()); } catch (Exception e) { log.error("", e); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .detail("Could not covert REST to SOAP!") .exception(e) .buildAndSetResponse(exc); @@ -84,7 +84,7 @@ public Outcome handleResponse(Exchange exc) { return handleResponseInternal(exc); } catch (Exception e) { log.error("", e); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .detail("Could not covert SOAP to REST!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/RESTInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/RESTInterceptor.java index 514cd75344..3810d646d5 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/RESTInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/RESTInterceptor.java @@ -49,7 +49,7 @@ public Outcome handleRequest(Exchange exc) { try { o = dispatchRequest(exc); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error dispatching request!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/SOAP2RESTInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/SOAP2RESTInterceptor.java index 7058d32905..ad2c93898b 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/rest/SOAP2RESTInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/rest/SOAP2RESTInterceptor.java @@ -56,7 +56,7 @@ public Outcome handleRequest(Exchange exc) { transformAndReplaceBody(exc.getRequest(), requestXSLT, new StreamSource(exc.getRequest().getBodyAsStreamDecoded()), exc.getStringProperties()); } catch (Exception e) { log.error("", e); - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not transform using XSLT!") .exception(e) .stacktrace(true) @@ -83,7 +83,7 @@ public Outcome handleResponse(Exchange exc) { transformAndReplaceBody(exc.getResponse(), responseXSLT, getExchangeXMLSource(exc), exc.getStringProperties()); } catch (Exception e) { log.error("", e); - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not transform using XSLT!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptor.java index 045151a23c..826546df79 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/rewrite/ReverseProxyingInterceptor.java @@ -72,7 +72,7 @@ public Outcome handleRequest(Exchange exc) { target = new URL(exc.getDestinations().getFirst()); } catch (MalformedURLException e) { log.error("Could not parse target URL: {}",destination); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not parse target URL") .internal("URL", exc.getDestinations().getFirst()) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptor.java index 198210a690..ce740bb09f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/schemavalidation/ValidatorInterceptor.java @@ -153,7 +153,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { return CONTINUE; } catch (IOException e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("io") .detail("Could not read message body") .exception(e) @@ -165,7 +165,7 @@ private Outcome handleInternal(Exchange exc, Flow flow) { return validator.validateMessage(exc, flow); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error validating message") .addSubSee("generic") .internal("validator", validator.getName()) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptor.java index 2b2ee61b91..5c1c00075f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptor.java @@ -170,7 +170,7 @@ public Outcome handleRequest(final Exchange exc) { return handleRequestInternal(exc); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not return WSDL document!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java index 17a7f4dcba..c9ede2d6e1 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/server/WebServerInterceptor.java @@ -99,7 +99,7 @@ public Outcome handleRequest(Exchange exc) { return handleRequestInternal(exc); } catch (IOException e) { log.error("", e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .flow(Flow.REQUEST) .detail("Error serving document") .exception(e) @@ -180,7 +180,7 @@ public Outcome handleRequest(Exchange exc) { try { return router.getUriFactory().create(exc.getDestinations().getFirst()); } catch (URISyntaxException e) { - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("uri-creation") .detail("Could not create uri") .exception(e) @@ -253,7 +253,7 @@ public Response createResponse(ResolverMap rr, String resPath) { .body(rr.resolve(resPath), true) .build(); } catch (Exception e) { - return internal(router.isProduction(), getDisplayName()) + return internal(router.getConfiguration().isProduction(), getDisplayName()) .title("Could not resolve file") .topLevel("path", resPath) .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/soap/SampleSoapServiceInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/soap/SampleSoapServiceInterceptor.java index 5825368d06..5967b9cbf6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/soap/SampleSoapServiceInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/soap/SampleSoapServiceInterceptor.java @@ -58,7 +58,7 @@ public Outcome handleRequest(Exchange exc) { try { return handleRequestInternal(exc); } catch (Exception e) { - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .detail("Could not process SOAP request!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/statistics/StatisticsProvider.java b/core/src/main/java/com/predic8/membrane/core/interceptor/statistics/StatisticsProvider.java index bd08e67fcd..5029207e5f 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/statistics/StatisticsProvider.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/statistics/StatisticsProvider.java @@ -67,7 +67,7 @@ public Outcome handleRequest(Exchange exc) { try { con = dataSource.getConnection(); } catch (SQLException e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not connect to database") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/stomp/STOMPClient.java b/core/src/main/java/com/predic8/membrane/core/interceptor/stomp/STOMPClient.java index 3452527e7f..b112e506c8 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/stomp/STOMPClient.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/stomp/STOMPClient.java @@ -109,7 +109,7 @@ public Outcome handleRequest(Exchange exc) { return handleRequestInternal(exc); } catch (IOException e) { log.error("", e); - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error in STOMP client!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptor.java index 8afe65d194..266b586ad3 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/templating/TemplateInterceptor.java @@ -69,7 +69,7 @@ protected Outcome handleInternal(Exchange exc, Flow flow) { process(exc, flow); } catch (GroovyRuntimeException e) { log.warn("Groovy error executing template: {}", e.getMessage()); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("groovy") .detail("Groovy error during template rendering.") .exception(e) @@ -77,7 +77,7 @@ protected Outcome handleInternal(Exchange exc, Flow flow) { .buildAndSetResponse(exc); return ABORT; } catch (TemplateExecutionException tee) { - ProblemDetails pd = internal(router.isProduction(), getDisplayName()) + ProblemDetails pd = internal(router.getConfiguration().isProduction(), getDisplayName()) .topLevel("line",tee.getLineNumber()) .topLevel("message", tee.getMessage()) .addSubSee("template"); @@ -104,7 +104,7 @@ protected Outcome handleInternal(Exchange exc, Flow flow) { } catch (Exception e) { log.warn("Error executing template.", e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("template") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/ws_addressing/WsaEndpointRewriterInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/ws_addressing/WsaEndpointRewriterInterceptor.java index 1b6dddd38d..0a37888fb6 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/ws_addressing/WsaEndpointRewriterInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/ws_addressing/WsaEndpointRewriterInterceptor.java @@ -56,7 +56,7 @@ public Outcome handleRequest(Exchange exc) { new WsaEndpointRewriter().rewriteEndpoint(message.getBodyAsStreamDecoded(), output, new Location( protocol, host, port)); } catch (Exception e) { log.error("",e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .detail("Could not rewrite endpoint!") .exception(e) .buildAndSetResponse(exchange); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptor.java index 5a0adadb33..9f633bfb28 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Json2XmlInterceptor.java @@ -74,7 +74,7 @@ private Outcome handleInternal(Exchange exchange, Flow flow) { try { msg.setBodyContent(json2Xml(msg)); } catch (Exception e) { - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .title("Error parsing JSON") .addSubType("validation/json") .exception(e) // Message contains a meaningful error message diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptor.java index 042b3aa1b4..2b424face2 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xml/Xml2JsonInterceptor.java @@ -58,7 +58,7 @@ public Outcome handleRequest(Exchange exc) { return handleInternal(exc.getRequest()); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(REQUEST) .detail("Could not transform XML to JSON!") .exception(e) @@ -72,7 +72,7 @@ public Outcome handleResponse(Exchange exc) { try { return handleInternal(exc.getResponse()); } catch (Exception e) { - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .flow(Flow.RESPONSE) .detail("Could not return WSDL document!") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xmlcontentfilter/XMLContentFilterInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xmlcontentfilter/XMLContentFilterInterceptor.java index e14716c6ef..9efccd1884 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xmlcontentfilter/XMLContentFilterInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xmlcontentfilter/XMLContentFilterInterceptor.java @@ -98,7 +98,7 @@ private Outcome handleMessage(Exchange exc, Message message) { return CONTINUE; } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .title("XML Error") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptor.java index ab40b42270..41a69d3f12 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xmlprotection/XMLProtectionInterceptor.java @@ -51,7 +51,7 @@ public Outcome handleRequest(Exchange exc) { return handleInternal(exc); } catch (Exception e) { log.error("", e); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .detail("Error inspecting body!") .exception(e) .buildAndSetResponse(exc); @@ -71,7 +71,7 @@ private Outcome handleInternal(Exchange exc) throws Exception { if (!exc.getRequest().isXML()) { String msg = "Content-Type %s is not XML.".formatted(exc.getRequest().getHeader().getContentType()); log.warn(msg); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .title("Request discarded by xmlProtection") .detail(msg) .buildAndSetResponse(exc); @@ -81,7 +81,7 @@ private Outcome handleInternal(Exchange exc) throws Exception { if (!protectXML(exc)) { String msg = "Request was rejected by XML protection. Please check XML."; log.warn(msg); - security(router.isProduction(), getDisplayName()) + security(router.getConfiguration().isProduction(), getDisplayName()) .title("Content violates XML security policy") .detail(msg) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java index 847e8266dc..1697b64c40 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/xslt/XSLTInterceptor.java @@ -53,7 +53,7 @@ public Outcome handleRequest(Exchange exc) { try { transformMsg(exc.getRequest(), xslt, exc.getStringProperties()); } catch (Exception e) { - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error transforming request!") .exception(e) .buildAndSetResponse(exc); @@ -68,7 +68,7 @@ public Outcome handleResponse(Exchange exc) { transformMsg(exc.getResponse(), xslt, exc.getStringProperties()); } catch (Exception e) { log.error("Error transforming response!", e); - user(router.isProduction(),getDisplayName()) + user(router.getConfiguration().isProduction(),getDisplayName()) .detail("Error transforming response!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java index 267e6e1567..34704d8522 100644 --- a/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/jmx/JmxRouter.java @@ -34,11 +34,11 @@ public JmxRouter(DefaultRouter router, JmxExporter exporter) { @ManagedAttribute public String getName(){ - return router.getConfig().getJmx(); + return router.getConfiguration().getJmx(); } private void exportServiceProxyList(){ - for(Proxy proxy : router.getRules()){ + for(Proxy proxy : router.getRuleManager().getRules()){ if(proxy instanceof ServiceProxy){ exportServiceProxy((ServiceProxy) proxy); } @@ -46,7 +46,7 @@ private void exportServiceProxyList(){ } private void exportServiceProxy(ServiceProxy rule) { - String prefix = "org.membrane-soa:00=serviceProxies, 01=%s, name=".formatted(router.getConfig().getJmx()); + String prefix = "org.membrane-soa:00=serviceProxies, 01=%s, name=".formatted(router.getConfiguration().getJmx()); exporter.addBean(prefix + rule.getName().replace(":",""), new JmxServiceProxy(rule, router)); } } diff --git a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java index 6b4d422c24..6f0d8dbfc1 100644 --- a/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java +++ b/core/src/main/java/com/predic8/membrane/core/kubernetes/KubernetesWatcher.java @@ -86,7 +86,7 @@ private KubernetesClient getClient() { } private Optional findK8sValidatingInterceptor() { - return router.getRules().stream() + return router.getRuleManager().getRules().stream() .map(Proxy::getFlow) .filter(Objects::nonNull) .flatMap(Collection::stream) diff --git a/core/src/main/java/com/predic8/membrane/core/lang/AbstractScriptInterceptor.java b/core/src/main/java/com/predic8/membrane/core/lang/AbstractScriptInterceptor.java index d1c87b8439..1791e1d7be 100644 --- a/core/src/main/java/com/predic8/membrane/core/lang/AbstractScriptInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/lang/AbstractScriptInterceptor.java @@ -105,7 +105,7 @@ protected Outcome runScript(Exchange exc, Flow flow) { msg.setBodyContent(om.writeValueAsBytes(m)); } catch (JsonProcessingException e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("json-processing-1") .detail("Error serializing Map to JSON") .exception(e) @@ -137,7 +137,7 @@ protected Outcome runScript(Exchange exc, Flow flow) { msg.setBodyContent(om.writeValueAsBytes(m)); } catch (JsonProcessingException e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("json-processing-2") .detail("Error serializing Map to JSON") .exception(e) @@ -174,7 +174,7 @@ protected void handleScriptExecutionException(Exchange exc, Exception e) { log.warn("Error executing {} script: {}", name, e.getMessage()); log.warn("Script: {}", src); - exc.setResponse(internal(router.isProduction(),getDisplayName()) + exc.setResponse(internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("script-execution") .title("Error executing script.") .addSubType("scripting") diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java index fbf972def9..dafd124cb5 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptor.java @@ -53,7 +53,7 @@ public Outcome handleRequest(Exchange exc) { publisher = new OpenAPIPublisher(ruleApiSpecs); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("publisher-creation") .detail("Error creating OpenAPI publisher!") .exception(e) @@ -69,7 +69,7 @@ public Outcome handleRequest(Exchange exc) { return publisher.handleOverviewOpenAPIDoc(exc, router, log); } catch (Exception e) { log.error("", e); - internal(router.isProduction(),getDisplayName()) + internal(router.getConfiguration().isProduction(),getDisplayName()) .addSubSee("publisher-handling") .detail("Error generating OpenAPI overview!") .exception(e) diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptor.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptor.java index 9ed2b64c78..ab5e899e9a 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptor.java @@ -108,7 +108,7 @@ public Outcome handleRequest(Exchange exc) { } catch (OpenAPIParsingException e) { String detail = "Could not parse OpenAPI with title %s. Check syntax and references.".formatted(rec.api.getInfo().getTitle()); log.warn(detail); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("openapi-parsing") .flow(REQUEST) .detail(detail) @@ -116,7 +116,7 @@ public Outcome handleRequest(Exchange exc) { .buildAndSetResponse(exc); return RETURN; } catch (ReadingBodyException e) { - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("reading-body") .flow(REQUEST) .detail("Connection problem: %s . Maybe the peer or the network closed the connection?".formatted(e.getMessage())) @@ -126,7 +126,7 @@ public Outcome handleRequest(Exchange exc) { } catch (Throwable t /* On purpose! Catch absolutely all */) { final String LOG_MESSAGE = "Message could not be validated against OpenAPI cause of an error during validation. Please check the OpenAPI with title %s."; log.error(LOG_MESSAGE.formatted(rec.api.getInfo().getTitle()), t); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("generic") .flow(REQUEST) .detail(LOG_MESSAGE.formatted(rec.api.getInfo().getTitle())) @@ -162,7 +162,7 @@ public Outcome handleResponse(Exchange exc) { } catch (OpenAPIParsingException e) { String detail = "Could not parse OpenAPI with title %s. Check syntax and references.".formatted(rec.api.getInfo().getTitle()); log.warn(detail, e); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .addSubType("openapi") .flow(RESPONSE) .detail(detail) @@ -171,7 +171,7 @@ public Outcome handleResponse(Exchange exc) { return RETURN; } catch (Throwable t /* On Purpose! Catch absolutely all */) { log.error("", t); - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .addSubSee("generic") .flow(RESPONSE) .detail("Message could not be validated against OpenAPI cause of an error during validation. Please check the OpenAPI with title %s.".formatted(rec.api.getInfo().getTitle())) @@ -350,7 +350,7 @@ private String buildValidationPropertiesDescription(Map props) { } private void createErrorResponse(Exchange exc, ValidationErrors errors, ValidationErrors.Direction direction, boolean validationDetails) { - user(router.isProduction(), getDisplayName()) + user(router.getConfiguration().isProduction(), getDisplayName()) .title("OpenAPI message validation failed") .addSubType("validation") .status(errors.get(0).getContext().getStatusCode()) diff --git a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptor.java b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptor.java index c26cf0617a..3255c31b71 100644 --- a/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptor.java @@ -119,7 +119,7 @@ public Outcome handleRequest(Exchange exc) { return handleOverviewOpenAPIDoc(exc); } catch (Exception e) { log.error("", e); - internal(router.isProduction(), getDisplayName()) + internal(router.getConfiguration().isProduction(), getDisplayName()) .detail("Error handling OpenAPI overview!") .exception(e) .buildAndSetResponse(exc); diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java index b35df337de..1c8eb2dc3d 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java @@ -101,7 +101,7 @@ public final void init(Router router) { } active = true; } catch (Exception e) { - if (!router.getConfig().isRetryInit()) + if (!router.getConfiguration().isRetryInit()) throw e; log.error("", e); active = false; diff --git a/core/src/main/java/com/predic8/membrane/core/proxies/SSLableProxy.java b/core/src/main/java/com/predic8/membrane/core/proxies/SSLableProxy.java index e57fff2ec2..890e5c22bc 100644 --- a/core/src/main/java/com/predic8/membrane/core/proxies/SSLableProxy.java +++ b/core/src/main/java/com/predic8/membrane/core/proxies/SSLableProxy.java @@ -15,7 +15,9 @@ package com.predic8.membrane.core.proxies; import com.predic8.membrane.annot.*; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.*; +import com.predic8.membrane.core.kubernetes.client.*; import com.predic8.membrane.core.transport.ssl.*; import org.jetbrains.annotations.*; @@ -46,7 +48,7 @@ public void init() { if (acmeCtx == null) acmeCtx = new AcmeSSLContext(sslInboundParser, host, router.getHttpClientFactory(), router.getTimerManager()); setSslInboundContext(acmeCtx); - acmeCtx.init(router.getKubernetesClientFactory(), router.getHttpClientFactory()); + acmeCtx.init(router); return; } sslInboundContext = generateSslInboundContext(); diff --git a/core/src/main/java/com/predic8/membrane/core/transport/http/AbstractHttpHandler.java b/core/src/main/java/com/predic8/membrane/core/transport/http/AbstractHttpHandler.java index 04b6d31f48..725bb671d0 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/http/AbstractHttpHandler.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/http/AbstractHttpHandler.java @@ -52,7 +52,7 @@ protected void invokeHandlers() throws AbortException, NoMoreRequestsException, getTransport().getRouter().getFlowController().invokeRequestHandlers(exchange, transport.getFlow()); if (exchange.getResponse() == null) { log.info("Interceptor chain returned no response"); - internal(transport.getRouter().isProduction(),"http-handler") + internal(transport.getRouter().getConfiguration().isProduction(),"http-handler") .addSubSee("no-response-produced") .detail("No response was generated by the interceptor chain.") .internal("interceptors", transport.getFlow()) @@ -77,7 +77,7 @@ protected void invokeHandlers() throws AbortException, NoMoreRequestsException, } private Response generateErrorResponse(Exception e) { - return internal(transport.getRouter().isProduction(),"http-handler") + return internal(transport.getRouter().getConfiguration().isProduction(),"http-handler") .addSubSee("error-during-request-phase") .exception(e) .build(); diff --git a/core/src/main/java/com/predic8/membrane/core/transport/http2/Http2ExchangeHandler.java b/core/src/main/java/com/predic8/membrane/core/transport/http2/Http2ExchangeHandler.java index b5778abcf6..ff6b8d3cbd 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/http2/Http2ExchangeHandler.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/http2/Http2ExchangeHandler.java @@ -163,7 +163,7 @@ private FlowController getFlowController() { } private Response generateErrorResponse(Exception e) { - return internal(transport.getRouter().isProduction(),"http2-exchange-handler") + return internal(transport.getRouter().getConfiguration().isProduction(),"http2-exchange-handler") .exception(e) .build(); } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/ssl/AcmeSSLContext.java b/core/src/main/java/com/predic8/membrane/core/transport/ssl/AcmeSSLContext.java index 4852c21ae4..6bc6ded6f8 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/ssl/AcmeSSLContext.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/ssl/AcmeSSLContext.java @@ -13,6 +13,7 @@ limitations under the License. */ package com.predic8.membrane.core.transport.ssl; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.config.security.*; import com.predic8.membrane.core.kubernetes.client.*; import com.predic8.membrane.core.transport.http.*; @@ -57,6 +58,14 @@ public AcmeSSLContext(SSLParser parser, this.timerManager = timerManager != null ? timerManager : new TimerManager(); } + public void init(Router router) { + KubernetesClientFactory kcf = null; + if (router instanceof DefaultRouter dr) { + kcf = dr.getRegistry().getBean(KubernetesClientFactory.class).orElse(null); + } + init(kcf,router.getHttpClientFactory()); + } + public void init(@Nullable KubernetesClientFactory kubernetesClientFactory, @Nullable HttpClientFactory httpClientFactory) { client.init(kubernetesClientFactory, httpClientFactory); initAndSchedule(); diff --git a/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java index 596eeebf2a..c889780fdb 100644 --- a/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java @@ -114,7 +114,7 @@ void devXML() { private static Router createRouter(int port, boolean production) throws IOException { Router r = new DefaultRouter(); - r.getConfig().setProduction(production); + r.getConfiguration().setProduction(production); APIProxy api = new APIProxy(); api.setKey(new APIProxyKey(port)); api.getFlow().add(new AbstractInterceptor() { @@ -128,7 +128,7 @@ public String getDisplayName() { return "interceptor"; } }); - r.getConfig().setHotDeploy(false); + r.getConfiguration().setHotDeploy(false); r.add(api); r.start(); return r; diff --git a/core/src/test/java/com/predic8/membrane/core/TestRouter.java b/core/src/test/java/com/predic8/membrane/core/TestRouter.java index 265fa104b1..8393824c2c 100644 --- a/core/src/test/java/com/predic8/membrane/core/TestRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/TestRouter.java @@ -25,6 +25,7 @@ public TestRouter() { public TestRouter(ProxyConfiguration proxyConfiguration) { if (proxyConfiguration != null) getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); + } @Override diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index 091cb14768..ef41926aeb 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -39,7 +39,7 @@ public static void after() { @Test public void doit() { - ServiceProxy p = (ServiceProxy) r.getRules().iterator().next(); + ServiceProxy p = (ServiceProxy) r.getRuleManager().getRules().getFirst(); List is = p.getFlow(); assertEquals(LogInterceptor.class, is.get(0).getClass()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index f38bfee9d0..4749d9bee0 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -40,7 +40,7 @@ abstract class AbstractInternalServiceRoutingInterceptorTest { @BeforeEach void setup() throws Exception { router = new TestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); configure(); router.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java index 5a5bc2479b..9036a0e292 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/json/JsonProtectionInterceptorTest.java @@ -33,7 +33,7 @@ public class JsonProtectionInterceptorTest { private static JsonProtectionInterceptor buildJPI(boolean prod) { DefaultRouter router = new DefaultRouter(); - router.getConfig().setProduction(prod); + router.getConfiguration().setProduction(prod); JsonProtectionInterceptor jpi = new JsonProtectionInterceptor(); jpi.setMaxTokens(4096); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java index 08806e6d8f..c6f13be199 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/jwt/JwtAuthInterceptorTest.java @@ -15,7 +15,7 @@ import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; -import com.predic8.membrane.core.DefaultRouter; +import com.predic8.membrane.core.*; import com.predic8.membrane.core.exchange.Exchange; import com.predic8.membrane.core.http.Request; import com.predic8.membrane.core.resolver.ResolverMap; @@ -240,7 +240,7 @@ private record TestData( @ParameterizedTest @MethodSource("data") - public void test(TestData data) throws Exception{ + void test(TestData data) throws Exception{ RsaJsonWebKey privateKey = RsaJwkGenerator.generateJwk(2048); privateKey.setKeyId(KID); @@ -261,10 +261,11 @@ private JwtAuthInterceptor prepareInterceptor(RsaJsonWebKey publicOnly) throws E } private JwtAuthInterceptor initInterceptor(JwtAuthInterceptor interceptor) throws Exception { - DefaultRouter routerMock = mock(DefaultRouter.class); - when(routerMock.getBaseLocation()).thenReturn(""); - when(routerMock.getResolverMap()).thenReturn(new ResolverMap()); - interceptor.init(routerMock); + DefaultRouter mock = mock(DefaultRouter.class); + when(mock.getBaseLocation()).thenReturn(""); + when(mock.getResolverMap()).thenReturn(new ResolverMap()); + when(mock.getConfiguration()).thenReturn(new Configuration()); + interceptor.init(mock); return interceptor; } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java index 8fece714e5..9b6b9103ba 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/AuthServerMock.java @@ -22,7 +22,7 @@ public abstract class AuthServerMock extends DummyTestRouter { public AuthServerMock() throws IOException { getTransport().setBacklog(10_000); getTransport().setSocketTimeout(10_000); - getConfig().setHotDeploy(false); + getConfiguration().setHotDeploy(false); getTransport().setConcurrentConnectionLimitPerIp(500); getRuleManager().addProxyAndOpenPortIfNew(mockServiceProxy()); diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java index 3fd59eddd3..5920bdb029 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/client/OAuth2ResourceRpIniLogoutTest.java @@ -82,12 +82,12 @@ public void init() throws IOException, JoseException { createKey(); mockAuthServer = new TestRouter(); - mockAuthServer.getConfig().setHotDeploy(false); + mockAuthServer.getConfiguration().setHotDeploy(false); mockAuthServer.add(getMockAuthServiceProxy()); mockAuthServer.start(); oauth2Resource = new TestRouter(); - oauth2Resource.getConfig().setHotDeploy(false); + oauth2Resource.getConfiguration().setHotDeploy(false); oauth2Resource.add(getConfiguredOAuth2Resource()); oauth2Resource.start(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java index c771e02d2f..4d9ef73f07 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/shadowing/ShadowingInterceptorTest.java @@ -68,7 +68,7 @@ void setUp() throws Exception { @BeforeAll static void startup() throws Exception { interceptorRouter = new DefaultRouter(); - interceptorRouter.getConfig().setHotDeploy(false); + interceptorRouter.getConfiguration().setHotDeploy(false); interceptorRouter.setExchangeStore(new ForgetfulExchangeStore()); interceptorRouter.setTransport(new HttpTransport()); @@ -91,7 +91,7 @@ static void startup() throws Exception { interceptorRouter.start(); shadowingRouter = new DefaultRouter(); - shadowingRouter.getConfig().setHotDeploy(false); + shadowingRouter.getConfiguration().setHotDeploy(false); shadowingRouter.setExchangeStore(new ForgetfulExchangeStore()); shadowingRouter.setTransport(new HttpTransport()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index 5f5bf4cb54..0fd0883c71 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -41,7 +41,7 @@ public class OpenAPI31ReferencesTest { @BeforeAll public static void setUp() throws Exception { router = new TestRouter(); - router.getConfig().setUriFactory(new URIFactory()); + router.getConfiguration().setUriFactory(new URIFactory()); OpenAPISpec spec = new OpenAPISpec(); spec.location = getPathFromResource( "openapi/specs/oas31/request-reference.yaml"); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java index 1902f14665..990bd508fc 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIPublisherInterceptorTest.java @@ -52,7 +52,7 @@ public class OpenAPIPublisherInterceptorTest { @BeforeEach void setUp() { DefaultRouter router = new DefaultRouter(); - router.getConfig().setUriFactory(new URIFactory()); + router.getConfiguration().setUriFactory(new URIFactory()); router.setBaseLocation(""); openAPIRecordFactory = new OpenAPIRecordFactory(router); OpenAPISpec spec = new OpenAPISpec(); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java index cda97c273e..5e25854db9 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIRecordTest.java @@ -30,7 +30,7 @@ class OpenAPIRecordTest { @BeforeEach void setUp() { DefaultRouter router = new DefaultRouter(); - router.getConfig().setUriFactory(new URIFactory()); + router.getConfiguration().setUriFactory(new URIFactory()); router.setBaseLocation(""); get.setRequest(new Request.Builder().method("GET").build()); diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java index faaca427d2..0bc0444ae1 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/RewriteTest.java @@ -50,7 +50,7 @@ void setUp() { rewriteAll.basePath = "/foo"; DefaultRouter router = new DefaultRouter(); - router.getConfig().setUriFactory(new URIFactory()); + router.getConfiguration().setUriFactory(new URIFactory()); router.setBaseLocation(""); OpenAPIRecordFactory openAPIRecordFactory = new OpenAPIRecordFactory(router); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index 44a5f9fc2e..7269290138 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -57,7 +57,7 @@ void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int pro private static @NotNull DefaultRouter createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) throws IOException { DefaultRouter proxy = new DefaultRouter(); - proxy.getConfig().setHotDeploy(false); + proxy.getConfiguration().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(proxyPort)); rule.getFlow().add(new AbstractInterceptor() { @Override @@ -112,7 +112,7 @@ private static void testClient(boolean backendUsesSSL, int backendPort, HttpClie private static @NotNull DefaultRouter createBackend(boolean backendUsesSSL, int backendPort) throws IOException { // Step 1: create the backend DefaultRouter backend = new DefaultRouter(); - backend.getConfig().setHotDeploy(false); + backend.getConfiguration().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(backendPort), null, 0); if (backendUsesSSL) { sp.setSslInboundParser(getSslParser("classpath:/ssl-rsa.keystore")); diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index e60a980f87..6ed7b292f6 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -44,7 +44,7 @@ public class ProxyTest { public static void init() throws IOException { router = new TestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); ProxyRule rule = new ProxyRule(new ProxyRuleKey(3055)); rule.getFlow().add(new AbstractInterceptor() { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java index ce64cd733c..fa2f65df8e 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyWSDLInterceptorsTest.java @@ -33,7 +33,7 @@ public class ServiceProxyWSDLInterceptorsTest { @BeforeEach void setUp() { router = new TestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); } @AfterEach diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 48ce41531e..71910167ae 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -54,8 +54,8 @@ void startRouter() throws IOException { HttpClientConfiguration httpClientConfig = new HttpClientConfiguration(); httpClientConfig.getRetryHandler().setRetries(1); r.setHttpClientConfig(httpClientConfig); - r.getConfig().setHotDeploy(false); - r.getConfig().setRetryInit(true); + r.getConfiguration().setHotDeploy(false); + r.getConfiguration().setRetryInit(true); sp = new SOAPProxy(); sp.setPort(2000); @@ -72,7 +72,7 @@ void startRouter() throws IOException { sp2.setPort(2001); sp2.setWsdl("http://localhost:4000?wsdl"); r2 = new DefaultRouter(); - r2.getConfig().setHotDeploy(false); + r2.getConfiguration().setHotDeploy(false); r2.add(sp2); } diff --git a/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java b/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java index f2f3824d4d..1a3a77670f 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/JWTSecuritySchemeTest.java @@ -26,6 +26,7 @@ import java.util.*; +import static com.predic8.membrane.core.http.Request.get; import static org.mockito.Mockito.mock; import static org.mockito.Mockito.when; @@ -45,14 +46,8 @@ public void test() throws Exception{ JwtAuthInterceptor interceptor = prepareInterceptor(publicOnly); - Exchange exc = new Request.Builder() - .get("") - .header("Authorization", "Bearer " + getSignedJwt(privateKey) + "1") - .buildExchange(); - + Exchange exc = get("").header("Authorization", "Bearer " + getSignedJwt(privateKey) + "1").buildExchange(); interceptor.handleRequest(exc); - - // } private JwtAuthInterceptor prepareInterceptor(RsaJsonWebKey publicOnly) throws Exception { @@ -60,10 +55,11 @@ private JwtAuthInterceptor prepareInterceptor(RsaJsonWebKey publicOnly) throws E } private JwtAuthInterceptor initInterceptor(JwtAuthInterceptor interceptor) throws Exception { - DefaultRouter routerMock = mock(DefaultRouter.class); - when(routerMock.getBaseLocation()).thenReturn(""); - when(routerMock.getResolverMap()).thenReturn(new ResolverMap()); - interceptor.init(routerMock); + DefaultRouter mock = mock(DefaultRouter.class); + when(mock.getBaseLocation()).thenReturn(""); + when(mock.getResolverMap()).thenReturn(new ResolverMap()); + when(mock.getConfiguration()).thenReturn(new Configuration()); + interceptor.init(mock); return interceptor; } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java index e9413acf6f..2de2147dae 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java @@ -36,7 +36,7 @@ class IllegalCharactersInURLTest { @BeforeEach void init() throws Exception { r = new TestRouter(); - r.getConfig().setHotDeploy(false); + r.getConfiguration().setHotDeploy(false); r.add(new ServiceProxy(new ServiceProxyKey(3027), "localhost", 3028)); ServiceProxy sp2 = new ServiceProxy(new ServiceProxyKey(3028), null, 80); sp2.getFlow().add(new AbstractInterceptor() { @@ -68,13 +68,13 @@ void apacheHttpClient() { @Test void illegal_with_router_tolerant_urifactory() throws Exception { - r.getConfig().setUriFactory(new URIFactory(true)); + r.getConfiguration().setUriFactory(new URIFactory(true)); makeCallWithIllegalCharacters(200); } @Test void illegal_with_router_intolerant_urifactory() throws Exception { - r.getConfig().setUriFactory(new URIFactory(false)); + r.getConfiguration().setUriFactory(new URIFactory(false)); makeCallWithIllegalCharacters(400); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java index c9786dc6b6..11dc67eb24 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java @@ -145,7 +145,7 @@ void outsideRouter() { } private @NotNull Proxy getApi1() { - Proxy api1 = router.getRules().stream().filter(proxy -> proxy.getName().equals("API1")).findFirst().orElseThrow(); + Proxy api1 = router.getRuleManager().getRuleByName("API1", Proxy.class); assertNotNull(api1); return api1; } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java index afc7c61e03..4e70f2d1b2 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http2/Http2ClientServerTest.java @@ -49,7 +49,7 @@ public void setup() throws IOException { SSLParser sslParser = getSslParser(); router = new TestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(new ServiceProxyKey(3049), "localhost", 80); sp.setSslInboundParser(sslParser); sp.getFlow().add(new AbstractInterceptor() { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java index 94df25af53..5abe016a4e 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/HttpsKeepAliveTest.java @@ -42,7 +42,7 @@ public class HttpsKeepAliveTest { @BeforeAll public static void startServer() throws IOException { server = new TestRouter(); - server.getConfig().setHotDeploy(false); + server.getConfiguration().setHotDeploy(false); ServiceProxy sp = new ServiceProxy(); sp.setPort(3063); SSLParser sslIB = new SSLParser(); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index 3303e682cc..bc357d290a 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -77,7 +77,7 @@ private static SSLContext createClientTLSContext() { private static Router createTLSServer(int port) { Router router = new DummyTestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); ServiceProxy rule = new ServiceProxy(new ServiceProxyKey(port), null, 0); SSLParser sslInboundParser = new SSLParser(); KeyStore keyStore = new KeyStore(); diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index 124b0f4a78..de4843b17a 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -66,7 +66,7 @@ public static void setup() throws Exception { private static void setupGateway() throws Exception { gw = new TestRouter(); - gw.getConfig().setHotDeploy(false); + gw.getConfiguration().setHotDeploy(false); gw.add(createCitiesSoapProxyGateway()); gw.add(createTwoServicesSOAPProxyGateway("ServiceA")); gw.start(); diff --git a/core/src/test/java/com/predic8/membrane/integration/Util.java b/core/src/test/java/com/predic8/membrane/integration/Util.java index c05c6e62f0..fce200a7ea 100644 --- a/core/src/test/java/com/predic8/membrane/integration/Util.java +++ b/core/src/test/java/com/predic8/membrane/integration/Util.java @@ -24,7 +24,7 @@ public class Util { public static Router basicRouter(Proxy... proxies){ var router = new TestRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); Arrays.stream(proxies).forEach(rule -> router.getRuleManager().addProxy(rule, RuleManager.RuleDefinitionSource.MANUAL)); router.start(); router.getTransport().setForceSocketCloseOnHotDeployAfter(1000); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java index 38e2bf184c..e2fd02daa0 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2Test.java @@ -54,7 +54,7 @@ class OAuth2Test { @BeforeAll static void startup() throws Exception { router = new DefaultRouter(); - router.getConfig().setHotDeploy(false); + router.getConfiguration().setHotDeploy(false); router.setExchangeStore(new ForgetfulExchangeStore()); router.setTransport(new HttpTransport()); @@ -68,7 +68,7 @@ static void startup() throws Exception { router.start(); router2 = new DefaultRouter(); - router2.getConfig().setHotDeploy(false); + router2.getConfiguration().setHotDeploy(false); router2.setExchangeStore(new ForgetfulExchangeStore()); router2.setTransport(new HttpTransport()); From df16814900d549c7cc68ec8e04a9a728add904e5 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Tue, 30 Dec 2025 21:13:10 +0100 Subject: [PATCH 35/40] refactor: replace `router.shutdown()` with `router.stop()` and introduce `DefaultMainComponents` to streamline router initialization and component management --- .../predic8/membrane/core/AbstractRouter.java | 2 +- .../membrane/core/DefaultMainComponents.java | 194 ++++++++++++++++++ .../predic8/membrane/core/DefaultRouter.java | 133 ++++-------- .../membrane/core/DummyTestRouter.java | 12 +- .../com/predic8/membrane/core/HttpRouter.java | 2 +- .../predic8/membrane/core/MainComponents.java | 50 +++++ .../com/predic8/membrane/core/Router.java | 35 +--- .../predic8/membrane/core/cli/RouterCLI.java | 4 +- .../AcmeHttpChallengeInterceptor.java | 21 +- .../membrane/AbstractTestWithRouter.java | 2 +- .../membrane/core/DefaultRouterTest.java | 4 +- .../membrane/core/RuleManagerTest.java | 2 +- .../com/predic8/membrane/core/SimpleTest.java | 2 +- .../com/predic8/membrane/core/TestRouter.java | 3 +- .../config/ReadRulesConfigurationTest.java | 2 +- ...ulesWithInterceptorsConfigurationTest.java | 2 +- .../core/config/SpringReferencesTest.java | 2 +- .../core/exchangestore/AbortExchangeTest.java | 2 +- .../membrane/core/http/Http10Test.java | 4 +- .../membrane/core/http/Http11Test.java | 4 +- .../membrane/core/http/MethodTest.java | 2 +- .../interceptor/AdjustContentLengthTest.java | 2 +- .../interceptor/InternalInvocationTest.java | 2 +- .../core/interceptor/UserFeatureTest.java | 2 +- .../balancer/ClusterBalancerTest.java | 2 +- .../ClusterNotificationInterceptorTest.java | 2 +- .../LoadBalancingWithClusterManagerTest.java | 8 +- .../flow/IfInterceptorSpELTest.java | 2 +- .../AbstractInterceptorFlowTest.java | 2 +- ...InternalServiceRoutingInterceptorTest.java | 2 +- .../oauth2/OAuth2RedirectTest.java | 6 +- .../OpenTelemetryInterceptorTest.java | 2 +- .../server/WSDLPublisherInterceptorTest.java | 2 +- .../session/SessionInterceptorTest.java | 2 +- .../soap/SoapAndInternalProxyTest.java | 2 +- .../lang/AbstractExchangeExpressionTest.java | 2 +- .../serviceproxy/ApiDocsInterceptorTest.java | 2 +- .../serviceproxy/OpenAPI31ReferencesTest.java | 2 +- .../serviceproxy/OpenAPIInterceptorTest.java | 2 +- .../openapi/serviceproxy/Swagger20Test.java | 2 +- ...WTInterceptorAndSecurityValidatorTest.java | 2 +- .../core/proxies/APIProxyKeyTest.java | 2 +- .../core/proxies/InternalProxyTest.java | 2 +- .../membrane/core/proxies/ProxyRuleTest.java | 2 +- .../membrane/core/proxies/ProxySSLTest.java | 4 +- .../membrane/core/proxies/ProxyTest.java | 2 +- .../membrane/core/proxies/SOAPProxyTest.java | 2 +- .../core/proxies/ServiceProxyTest.java | 2 +- .../core/proxies/TargetURLExpressionTest.java | 2 +- .../proxies/UnavailableSoapProxyTest.java | 10 +- .../membrane/core/resolver/ResolverTest.java | 2 +- .../core/security/KeyStoreUtilTest.java | 2 +- .../transport/http/BoundConnectionTest.java | 2 +- .../http/ConcurrentConnectionLimitTest.java | 2 +- .../core/transport/http/ConnectionTest.java | 2 +- .../transport/http/HttpKeepAliveTest.java | 2 +- .../http/IllegalCharactersInURLTest.java | 2 +- .../transport/http/ServiceInvocationTest.java | 2 +- .../transport/ssl/SessionResumptionTest.java | 4 +- .../core/ws/SoapProxyInvocationTest.java | 4 +- .../withinternet/LargeBodyTest.java | 4 +- .../ProxySSLConnectionMethodTest.java | 2 +- .../withinternet/ViaProxyTest.java | 4 +- .../RewriteInterceptorIntegrationTest.java | 2 +- ...tedMemoryExchangeStoreIntegrationTest.java | 4 +- .../MassivelyParallelTest.java | 2 +- .../withoutinternet/SessionManagerTest.java | 11 +- .../OpenApiRewriteIntegrationTest.java | 2 +- .../REST2SOAPInterceptorIntegrationTest.java | 2 +- .../interceptor/SOAPProxyIntegrationTest.java | 4 +- ...th2AuthorizationServerInterceptorBase.java | 2 +- ...nterceptorFaultMonitoringStrategyTest.java | 14 +- .../LoadBalancingInterceptorTest.java | 8 +- .../MultipleLoadBalancersTest.java | 4 +- 74 files changed, 400 insertions(+), 251 deletions(-) create mode 100644 core/src/main/java/com/predic8/membrane/core/DefaultMainComponents.java create mode 100644 core/src/main/java/com/predic8/membrane/core/MainComponents.java diff --git a/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java index 9966c60973..f408f7db89 100644 --- a/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/AbstractRouter.java @@ -17,7 +17,7 @@ import com.predic8.membrane.core.proxies.*; import org.slf4j.*; -public abstract class AbstractRouter implements Router { +public abstract class AbstractRouter implements Router, MainComponents { private static final Logger log = LoggerFactory.getLogger(DefaultRouter.class); diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultMainComponents.java b/core/src/main/java/com/predic8/membrane/core/DefaultMainComponents.java new file mode 100644 index 0000000000..5de49b9eb2 --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/DefaultMainComponents.java @@ -0,0 +1,194 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.annot.*; +import com.predic8.membrane.annot.beanregistry.*; +import com.predic8.membrane.core.config.spring.*; +import com.predic8.membrane.core.exchangestore.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.kubernetes.client.*; +import com.predic8.membrane.core.proxies.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.transport.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.transport.http.client.*; +import com.predic8.membrane.core.util.*; +import org.slf4j.*; +import org.springframework.beans.*; +import org.springframework.context.*; + +import java.util.*; + +public class DefaultMainComponents implements MainComponents { + + private static final Logger log = LoggerFactory.getLogger(DefaultRouter.class); + + private DefaultRouter router; + + private ApplicationContext beanFactory; + + protected BeanRegistry registry; + + protected Transport transport; + + private final TimerManager timerManager = new TimerManager(); + private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); + private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); + protected ResolverMap resolverMap; + + protected final Statistics statistics = new Statistics(); + + + public DefaultMainComponents(DefaultRouter router) { + log.debug("Creating new router."); + this.router = router; + resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); + resolverMap.addRuleResolver(router); + } + + public void init() { + log.debug("Initializing."); + + if (registry == null) { + registry = new BeanRegistryImplementation(null, router, null); + } + + registry.registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); + + registry.registerIfAbsent(ResolverMap.class, () -> { + ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); + rs.addRuleResolver(router); + return rs; + }); + + registry.registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); + registry.registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(router); + return rm; + }); + registry.registerIfAbsent(DNSCache.class, DNSCache::new); + + // Transport last + if (transport == null) { + transport = new HttpTransport(); + } + transport.init(router); + + } + + public void setRules(Collection proxies) { + getRuleManager().removeAllRules(); + for (Proxy proxy : proxies) + getRuleManager().addProxy(proxy, RuleManager.RuleDefinitionSource.SPRING); + } + + public RuleManager getRuleManager() { + return getRegistry().registerIfAbsent(RuleManager.class, () -> { + RuleManager rm = new RuleManager(); + rm.setRouter(router); + return rm; + }); + } + + public void setApplicationContext(ApplicationContext ctx) throws BeansException { + beanFactory = ctx; + if (ctx instanceof BaseLocationApplicationContext blac) + router.setBaseLocation(blac.getBaseLocation()); + } + + public void setRuleManager(RuleManager ruleManager) { + log.debug("Setting ruleManager."); + ruleManager.setRouter(router); + getRegistry().register("ruleManager", ruleManager); + } + + public ExchangeStore getExchangeStore() { + return getRegistry().getBean(ExchangeStore.class).orElseThrow(); + } + + public void setExchangeStore(ExchangeStore exchangeStore) { + getRegistry().register("exchangeStore", exchangeStore); + } + + @Override + public Transport getTransport() { + return transport; + } + + public void setTransport(Transport transport) { + this.transport = transport; + } + + public HttpClientConfiguration getHttpClientConfig() { + return getResolverMap().getHTTPSchemaResolver().getHttpClientConfig(); + } + + public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { + getResolverMap().getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); + } + + public DNSCache getDnsCache() { + return getRegistry().getBean(DNSCache.class).orElseThrow(); // TODO + } + + public ResolverMap getResolverMap() { + return resolverMap; + } + + public Statistics getStatistics() { + return statistics; + } + + public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { + getRegistry().register("globalInterceptor", globalInterceptor); + } + + public TimerManager getTimerManager() { + return timerManager; + } + + public KubernetesClientFactory getKubernetesClientFactory() { + return kubernetesClientFactory; + } + + public HttpClientFactory getHttpClientFactory() { + return httpClientFactory; + } + + public FlowController getFlowController() { + return getRegistry().registerIfAbsent(FlowController.class, () -> new FlowController(router)); + } + + public void setRegistry(BeanRegistry registry) { + this.registry = registry; + } + + public BeanRegistry getRegistry() { + if (registry == null) + registry = new BeanRegistryImplementation(null, router, null); + return registry; + } + + public URIFactory getUriFactory() { + throw new UnsupportedOperationException(); + } + + @Override + public ApplicationContext getBeanFactory() { + return beanFactory; + } +} diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java index d192f5b411..8bdfce175a 100644 --- a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java @@ -104,9 +104,7 @@ public class DefaultRouter extends AbstractRouter implements ApplicationContextA private static final Logger log = LoggerFactory.getLogger(DefaultRouter.class); - private ApplicationContext beanFactory; - - protected BeanRegistry registry; + protected DefaultMainComponents mainComponents; // // Configuration @@ -116,18 +114,6 @@ public class DefaultRouter extends AbstractRouter implements ApplicationContextA private Configuration configuration = new Configuration(); - // - // Components - // - protected Transport transport; - - private final TimerManager timerManager = new TimerManager(); - private final HttpClientFactory httpClientFactory = new HttpClientFactory(timerManager); - private final KubernetesClientFactory kubernetesClientFactory = new KubernetesClientFactory(httpClientFactory); - protected ResolverMap resolverMap; - - protected final Statistics statistics = new Statistics(); - private final Object lock = new Object(); @GuardedBy("lock") @@ -147,8 +133,7 @@ public class DefaultRouter extends AbstractRouter implements ApplicationContextA public DefaultRouter() { log.debug("Creating new router."); - resolverMap = new ResolverMap(httpClientFactory, kubernetesClientFactory); - resolverMap.addRuleResolver(this); + mainComponents = new DefaultMainComponents(this); } // @@ -174,27 +159,7 @@ public void init() { throw new IllegalStateException("Router already initialized."); } - getRegistry().registerIfAbsent(HttpClientConfiguration.class, () -> new HttpClientConfiguration()); - - getRegistry().registerIfAbsent(ResolverMap.class, () -> { - ResolverMap rs = new ResolverMap(httpClientFactory, kubernetesClientFactory); - rs.addRuleResolver(this); - return rs; - }); - - getRegistry().registerIfAbsent(ExchangeStore.class, LimitedMemoryExchangeStore::new); - getRegistry().registerIfAbsent(RuleManager.class, () -> { - RuleManager rm = new RuleManager(); - rm.setRouter(this); - return rm; - }); - getRegistry().registerIfAbsent(DNSCache.class, DNSCache::new); - - // Transport last - if (transport == null) { - transport = new HttpTransport(); - } - transport.init(this); + mainComponents.init(); initProxies(); @@ -249,16 +214,6 @@ public void start() { } } - /* - TODO: - - Why is the source hardcoded here. - - Why does it matter? - */ - public Collection getRules() { - log.debug("Getting rules."); - return getRuleManager().getRulesBySource(MANUAL); // TODO: Source? - } - @MCChildElement(order = 3) public void setRules(Collection proxies) { getRuleManager().removeAllRules(); @@ -266,30 +221,26 @@ public void setRules(Collection proxies) { getRuleManager().addProxy(proxy, RuleDefinitionSource.SPRING); } + public Collection getRules() { + return getRuleManager().getRules(); + } + @SuppressWarnings("NullableProblems") @Override public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - beanFactory = applicationContext; - if (applicationContext instanceof BaseLocationApplicationContext) - setBaseLocation(((BaseLocationApplicationContext) applicationContext).getBaseLocation()); + mainComponents.setApplicationContext(applicationContext); } public RuleManager getRuleManager() { - return getRegistry().registerIfAbsent(RuleManager.class, () -> { - RuleManager rm = new RuleManager(); - rm.setRouter(this); - return rm; - }); + return mainComponents.getRuleManager(); } public void setRuleManager(RuleManager ruleManager) { - log.debug("Setting ruleManager."); - ruleManager.setRouter(this); - getRegistry().register("ruleManager", ruleManager); + mainComponents.setRuleManager(ruleManager); } public ExchangeStore getExchangeStore() { - return getRegistry().getBean(ExchangeStore.class).orElseThrow(); + return mainComponents.getExchangeStore(); } /** @@ -300,12 +251,12 @@ public ExchangeStore getExchangeStore() { */ @MCAttribute public void setExchangeStore(ExchangeStore exchangeStore) { - getRegistry().register("exchangeStore", exchangeStore); + mainComponents.setExchangeStore(exchangeStore); } @Override public Transport getTransport() { - return transport; + return mainComponents.getTransport(); } /** @@ -316,11 +267,11 @@ public Transport getTransport() { */ @MCChildElement(order = 1, allowForeign = true) public void setTransport(Transport transport) { - this.transport = transport; + mainComponents.setTransport(transport); } public HttpClientConfiguration getHttpClientConfig() { - return getResolverMap().getHTTPSchemaResolver().getHttpClientConfig(); + return mainComponents.getHttpClientConfig(); } /** @@ -330,26 +281,15 @@ public HttpClientConfiguration getHttpClientConfig() { */ @MCChildElement() public void setHttpClientConfig(HttpClientConfiguration httpClientConfig) { - getResolverMap().getHTTPSchemaResolver().setHttpClientConfig(httpClientConfig); + mainComponents.setHttpClientConfig(httpClientConfig); } public DNSCache getDnsCache() { - return getRegistry().getBean(DNSCache.class).orElseThrow(); // TODO + return mainComponents.getDnsCache(); } public ResolverMap getResolverMap() { - return resolverMap; - } - - /** - * Closes all ports (if any were opened) and waits for running exchanges to complete. - *

- * When running as an embedded servlet, this has no effect. - */ - public void shutdown() { - if (transport != null) - transport.closeAll(); - timerManager.shutdown(); + return mainComponents.getResolverMap(); } /** @@ -374,11 +314,11 @@ public void add(Proxy proxy) throws IOException { } private void startJmx() { - if (beanFactory == null) + if (mainComponents.getBeanFactory() == null) return; try { - JmxExporter exporter = beanFactory.getBean(JMX_EXPORTER_NAME, JmxExporter.class); + JmxExporter exporter = mainComponents.getBeanFactory().getBean(JMX_EXPORTER_NAME, JmxExporter.class); //exporter.removeBean(prefix + jmxRouterName); exporter.addBean("io.membrane-api:00=routers, name=" + configuration.getJmx(), new JmxRouter(this, exporter)); exporter.initAfterBeansAdded(); @@ -399,6 +339,17 @@ public void stop() { } } + /** + * Closes all ports (if any were opened) and waits for running exchanges to complete. + *

+ * When running as an embedded servlet, this has no effect. + */ + private void shutdown() { + if (mainComponents.getTransport() != null) + mainComponents.getTransport().closeAll(); + mainComponents.getTimerManager().shutdown(); + } + @Override public boolean isRunning() { synchronized (lock) { @@ -415,7 +366,7 @@ public void setBaseLocation(String baseLocation) { } public ApplicationContext getBeanFactory() { - return beanFactory; + return mainComponents.getBeanFactory(); } public boolean isProduction() { @@ -423,7 +374,7 @@ public boolean isProduction() { } public Statistics getStatistics() { - return statistics; + return mainComponents.getStatistics(); } @SuppressWarnings("NullableProblems") @@ -437,7 +388,7 @@ public void setBeanName(String s) { */ @MCChildElement(order = 2) public void setGlobalInterceptor(GlobalInterceptor globalInterceptor) { - getRegistry().register("globalInterceptor", globalInterceptor); + mainComponents.setGlobalInterceptor(globalInterceptor); } public String getId() { @@ -459,19 +410,19 @@ public void waitFor() { } public TimerManager getTimerManager() { - return timerManager; + return mainComponents.getTimerManager(); } public KubernetesClientFactory getKubernetesClientFactory() { - return kubernetesClientFactory; + return mainComponents.getKubernetesClientFactory(); } public HttpClientFactory getHttpClientFactory() { - return httpClientFactory; + return mainComponents.getHttpClientFactory(); } public FlowController getFlowController() { - return getRegistry().registerIfAbsent(FlowController.class, () -> new FlowController(this)); + return mainComponents.getFlowController(); } public void handleAsynchronousInitializationResult(boolean success) { @@ -525,20 +476,18 @@ public boolean isActivatable(BeanDefinition bd) { } public AbstractRefreshableApplicationContext getRef() { - if (beanFactory instanceof AbstractRefreshableApplicationContext bf) + if (mainComponents.getBeanFactory() instanceof AbstractRefreshableApplicationContext bf) return bf; throw new RuntimeException("ApplicationContext is not a AbstractRefreshableApplicationContext. Please set ."); } @Override public void setRegistry(BeanRegistry registry) { - this.registry = registry; + mainComponents.setRegistry(registry); } public BeanRegistry getRegistry() { - if (registry == null) - registry = new BeanRegistryImplementation(null, this, null); - return registry; + return mainComponents.getRegistry(); } public void applyConfiguration(Configuration configuration) { diff --git a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java index ca19d984e5..85bbcb7d05 100644 --- a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java @@ -68,16 +68,6 @@ public void init() { initProxies(); } - @Override - public void shutdown() { - - } - - @Override - public void waitFor() { - - } - @Override public void add(Proxy proxy) throws IOException { ruleManager.addProxy(proxy, MANUAL); @@ -147,7 +137,7 @@ public TimerManager getTimerManager() { public Statistics getStatistics() { return statistics; } - + /** * Same as the default config from monitor-beans.xml */ diff --git a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java index 7096b67a14..d219639291 100644 --- a/core/src/main/java/com/predic8/membrane/core/HttpRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/HttpRouter.java @@ -20,6 +20,6 @@ public class HttpRouter extends DefaultRouter { @Override public HttpTransport getTransport() { - return (HttpTransport) transport; + return (HttpTransport) super.getTransport(); } } diff --git a/core/src/main/java/com/predic8/membrane/core/MainComponents.java b/core/src/main/java/com/predic8/membrane/core/MainComponents.java new file mode 100644 index 0000000000..003b3efa5b --- /dev/null +++ b/core/src/main/java/com/predic8/membrane/core/MainComponents.java @@ -0,0 +1,50 @@ +/* Copyright 2025 predic8 GmbH, www.predic8.com + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. */ + +package com.predic8.membrane.core; + +import com.predic8.membrane.core.exchangestore.*; +import com.predic8.membrane.core.interceptor.*; +import com.predic8.membrane.core.resolver.*; +import com.predic8.membrane.core.transport.*; +import com.predic8.membrane.core.transport.http.*; +import com.predic8.membrane.core.util.*; +import org.springframework.context.*; + +public interface MainComponents { + + Transport getTransport(); + + FlowController getFlowController(); + + ExchangeStore getExchangeStore(); + + void setExchangeStore(ExchangeStore exchangeStore); + + RuleManager getRuleManager(); + + ResolverMap getResolverMap(); + + DNSCache getDnsCache(); + + URIFactory getUriFactory(); + + ApplicationContext getBeanFactory(); + + HttpClientFactory getHttpClientFactory(); + + TimerManager getTimerManager(); + + Statistics getStatistics(); +} diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 631d22c86b..841aba0179 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -14,55 +14,24 @@ package com.predic8.membrane.core; -import com.predic8.membrane.core.exchangestore.*; -import com.predic8.membrane.core.interceptor.*; import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.resolver.*; -import com.predic8.membrane.core.transport.*; -import com.predic8.membrane.core.transport.http.*; -import com.predic8.membrane.core.util.*; import org.springframework.context.*; import java.io.*; -public interface Router extends Lifecycle { +public interface Router extends Lifecycle, MainComponents { void init(); /** * TODO: What is the difference between this and stop? */ - void shutdown(); - - void waitFor(); + // void shutdown(); void add(Proxy proxy) throws IOException; Configuration getConfiguration(); - Transport getTransport(); - - FlowController getFlowController(); - - ExchangeStore getExchangeStore(); - - void setExchangeStore(ExchangeStore exchangeStore); - - RuleManager getRuleManager(); - - ResolverMap getResolverMap(); - - DNSCache getDnsCache(); - String getBaseLocation(); - URIFactory getUriFactory(); - - ApplicationContext getBeanFactory(); - - HttpClientFactory getHttpClientFactory(); - - TimerManager getTimerManager(); - - Statistics getStatistics(); } diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index ebb195b34b..4e1114d61d 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -75,7 +75,9 @@ private static void start(String[] args) { if (commandLine.getCommand().getName().equals("private-jwk-to-public")) { privateJwkToPublic(commandLine); } - getRouter(commandLine).waitFor(); + var router = getRouter(commandLine); + if (router instanceof DefaultRouter dr) + dr.waitFor(); } private static void privateJwkToPublic(MembraneCommandLine commandLine) { diff --git a/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java b/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java index 2b2e661c5b..5bc4ba8155 100644 --- a/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java +++ b/core/src/main/java/com/predic8/membrane/core/interceptor/AcmeHttpChallengeInterceptor.java @@ -13,22 +13,19 @@ limitations under the License. */ package com.predic8.membrane.core.interceptor; -import com.predic8.membrane.annot.MCElement; +import com.predic8.membrane.annot.*; import com.predic8.membrane.core.exceptions.*; -import com.predic8.membrane.core.exchange.Exchange; -import com.predic8.membrane.core.http.Response; +import com.predic8.membrane.core.exchange.*; +import com.predic8.membrane.core.http.*; import com.predic8.membrane.core.proxies.*; -import com.predic8.membrane.core.transport.ssl.AcmeSSLContext; -import com.predic8.membrane.core.transport.ssl.SSLContext; -import com.predic8.membrane.core.transport.ssl.acme.AcmeClient; +import com.predic8.membrane.core.transport.ssl.*; +import com.predic8.membrane.core.transport.ssl.acme.*; import org.jose4j.lang.*; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; +import org.slf4j.*; -import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; -import static com.predic8.membrane.core.http.MimeType.APPLICATION_OCTET_STREAM; -import static com.predic8.membrane.core.interceptor.Outcome.ABORT; -import static java.util.Arrays.stream; +import static com.predic8.membrane.core.http.MimeType.*; +import static com.predic8.membrane.core.interceptor.Outcome.*; +import static java.util.Arrays.*; /** * @description diff --git a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java index dbb035ad76..5880cea797 100644 --- a/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java +++ b/core/src/test/java/com/predic8/membrane/AbstractTestWithRouter.java @@ -27,6 +27,6 @@ void setUp() { @AfterEach void shutDown() { - router.shutdown(); + router.stop(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java index c889780fdb..82631db90e 100644 --- a/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java +++ b/core/src/test/java/com/predic8/membrane/core/DefaultRouterTest.java @@ -39,8 +39,8 @@ static void setUp() throws IOException { @AfterAll static void tearDown() { - prod.shutdown(); - dev.shutdown(); + prod.stop(); + dev.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/RuleManagerTest.java b/core/src/test/java/com/predic8/membrane/core/RuleManagerTest.java index b5a48b5beb..99ee5f3dd0 100644 --- a/core/src/test/java/com/predic8/membrane/core/RuleManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/RuleManagerTest.java @@ -58,7 +58,7 @@ public void setUp() throws Exception{ @AfterEach public void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index 569bef6a47..f85462dbc8 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -33,7 +33,7 @@ public void test() { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/TestRouter.java b/core/src/test/java/com/predic8/membrane/core/TestRouter.java index 8393824c2c..6c6142275c 100644 --- a/core/src/test/java/com/predic8/membrane/core/TestRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/TestRouter.java @@ -25,12 +25,11 @@ public TestRouter() { public TestRouter(ProxyConfiguration proxyConfiguration) { if (proxyConfiguration != null) getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); - } @Override public HttpTransport getTransport() { - return (HttpTransport) transport; + return (HttpTransport) super.getTransport(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 61490b1066..5e36adfdd3 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -35,7 +35,7 @@ static void setUp() { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java index 2f067bdfa2..4f45a9c9c6 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java @@ -65,7 +65,7 @@ void ruleInterceptorDisplayNames() { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index ef41926aeb..f49533e547 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -34,7 +34,7 @@ public static void before() { @AfterAll public static void after() { - r.shutdown(); + r.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java index bd1f18b367..a528f26900 100644 --- a/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java +++ b/core/src/test/java/com/predic8/membrane/core/exchangestore/AbortExchangeTest.java @@ -117,6 +117,6 @@ private Response performRequest() throws Exception { @AfterEach public void done() { - router.shutdown(); + router.stop(); } } diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java index 9abe9bf657..fd1e4801bf 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http10Test.java @@ -49,8 +49,8 @@ public static void setUp() throws Exception { @AfterAll public static void tearDown() { - router2.shutdown(); - router.shutdown(); + router2.stop(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java index 92bfbae50b..bd4ceeca97 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java +++ b/core/src/test/java/com/predic8/membrane/core/http/Http11Test.java @@ -51,8 +51,8 @@ public static void setUp() throws Exception { @AfterAll public static void tearDown() { - router2.shutdown(); - router.shutdown(); + router2.stop(); + router.stop(); } /** diff --git a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java index 1c977cfdca..0346bd2d47 100644 --- a/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java +++ b/core/src/test/java/com/predic8/membrane/core/http/MethodTest.java @@ -50,7 +50,7 @@ public Outcome handleRequest(Exchange exc) { @AfterAll public static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java index 8289c7e639..1750688145 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/AdjustContentLengthTest.java @@ -38,7 +38,7 @@ public static void setUp() throws Exception { @AfterAll public static void tearDown() { - router.shutdown(); + router.stop(); } private static ServiceProxy createMonitorRule() { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java index d1f14884aa..7e7f7f4e7b 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java @@ -52,7 +52,7 @@ void returnedChain() throws Exception { @AfterEach public void tearDown() throws Exception { - router.shutdown(); + router.stop(); } private void callService(int port) throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index 104b59b94b..0cdd6ff436 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -50,7 +50,7 @@ void beforeEach() { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } private void callService(String s) { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java index b32e4a9274..bc3f919ec5 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterBalancerTest.java @@ -56,7 +56,7 @@ static void setUp() throws Exception { @AfterAll static void tearDown() { - r.shutdown(); + r.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java index 2fcf4c45fc..4a306b92cb 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/ClusterNotificationInterceptorTest.java @@ -61,7 +61,7 @@ public void setUp() throws Exception { @AfterEach public void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java index 5f5b200788..0c81fa871a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/balancer/LoadBalancingWithClusterManagerTest.java @@ -39,10 +39,10 @@ public class LoadBalancingWithClusterManagerTest { @AfterEach public void tearDown() { - lb.shutdown(); - node1.shutdown(); - node2.shutdown(); - node3.shutdown(); + lb.stop(); + node1.stop(); + node2.stop(); + node3.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java index f4693dc31d..e1e547832a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/IfInterceptorSpELTest.java @@ -40,7 +40,7 @@ static void setup() { @AfterAll static void teardown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java index a5e664600d..6ececd6032 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/AbstractInterceptorFlowTest.java @@ -39,7 +39,7 @@ void setUp() { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } protected void assertFlow(String expected,Interceptor... interceptors) throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java index 4749d9bee0..41e5ac4c0a 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/flow/invocation/internalservice/AbstractInternalServiceRoutingInterceptorTest.java @@ -47,7 +47,7 @@ void setup() throws Exception { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } public void api(Consumer c) throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java index f1aaf55155..afd5596cb6 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2RedirectTest.java @@ -61,9 +61,9 @@ void init() throws Exception { @AfterEach void shutdown() { - authorizationServerRouter.shutdown(); - oauth2ResourceRouter.shutdown(); - backendRouter.shutdown(); + authorizationServerRouter.stop(); + oauth2ResourceRouter.stop(); + backendRouter.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java index 92ada0392b..0f673dca18 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/opentelemetry/OpenTelemetryInterceptorTest.java @@ -35,6 +35,6 @@ void initTest() throws IOException { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } } \ No newline at end of file diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java index 6b1c57e465..6d77a1a5b1 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/server/WSDLPublisherInterceptorTest.java @@ -47,7 +47,7 @@ void before(String wsdlLocation, int port) throws Exception { } void after() { - router.shutdown(); + router.stop(); } @ParameterizedTest(name = "{0} {1}") diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java index a3f06c5ed7..84f71e763e 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/session/SessionInterceptorTest.java @@ -54,7 +54,7 @@ public void setUp() { @AfterEach void shutDown() throws IOException { - router.shutdown(); + router.stop(); httpClient.close(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java index 07164cd11c..f722d85f3d 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/soap/SoapAndInternalProxyTest.java @@ -43,7 +43,7 @@ void setup() { @AfterEach void teardown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java index 8c7a6db196..f73de88193 100644 --- a/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/lang/AbstractExchangeExpressionTest.java @@ -61,7 +61,7 @@ void setUp() throws URISyntaxException { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } protected abstract Request.Builder getRequestBuilder() throws URISyntaxException; diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java index b17966e927..c637fd6fd9 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/ApiDocsInterceptorTest.java @@ -67,7 +67,7 @@ void tearDown() { @AfterAll void tearDownAll() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java index 0fd0883c71..28cd672cca 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPI31ReferencesTest.java @@ -62,7 +62,7 @@ public static void setUp() throws Exception { @AfterAll public static void shutdown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java index f59d3d103f..38e2cd8b9a 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/OpenAPIInterceptorTest.java @@ -69,7 +69,7 @@ void setUp() { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java index a7af39a2bf..6cb0bc605f 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/serviceproxy/Swagger20Test.java @@ -66,7 +66,7 @@ public void setUp() throws Exception { @AfterEach public void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java index 5ffc928f0b..9f080e6685 100644 --- a/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java +++ b/core/src/test/java/com/predic8/membrane/core/openapi/validators/security/JWTInterceptorAndSecurityValidatorTest.java @@ -58,7 +58,7 @@ void setUp() throws Exception { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java index c4997f7494..3db31d67e8 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/APIProxyKeyTest.java @@ -37,7 +37,7 @@ public void setup() { @AfterEach public void shutdown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java index 1f1eb64085..8d1279dbc2 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/InternalProxyTest.java @@ -111,7 +111,7 @@ void setup() throws Exception { @AfterEach void teardown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java index 7b81fbb304..0b17105789 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java @@ -40,7 +40,7 @@ public static void setUp() { @AfterAll public static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java index 7269290138..0fcd8c41c1 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxySSLTest.java @@ -51,8 +51,8 @@ void test(boolean backendUsesSSL, boolean proxyUsesSSL, int backendPort, int pro testClient(backendUsesSSL, backendPort, createAndConfigureClient(proxyUsesSSL, proxyPort), proxyCounter); - proxy.shutdown(); - backend.shutdown(); + proxy.stop(); + backend.stop(); } private static @NotNull DefaultRouter createProxy(boolean proxyUsesSSL, int proxyPort, AtomicInteger proxyCounter) throws IOException { diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java index 6ed7b292f6..f9f75bc195 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyTest.java @@ -86,7 +86,7 @@ public Outcome handleRequest(Exchange exc) { @AfterAll public static void done() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java index d9bf6cb4db..7288ff0221 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/SOAPProxyTest.java @@ -51,7 +51,7 @@ void setUp() throws IOException { @AfterEach void shutDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java index cd0a04c59f..29b6329cf0 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ServiceProxyTest.java @@ -40,7 +40,7 @@ public static void setup() throws Exception { @AfterAll public static void shutdown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java index 0746cbf9d0..dbe6aa5e53 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/TargetURLExpressionTest.java @@ -38,7 +38,7 @@ void setUp() { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java index 71910167ae..263e881dfb 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/UnavailableSoapProxyTest.java @@ -43,9 +43,9 @@ static void setup() throws Exception { @AfterAll static void teardown() { - backendRouter.shutdown(); - r.shutdown(); - r2.shutdown(); + backendRouter.stop(); + r.stop(); + r2.stop(); } @BeforeEach @@ -78,8 +78,8 @@ void startRouter() throws IOException { @AfterEach void teardownEach() { - r.shutdown(); - r2.shutdown(); + r.stop(); + r2.stop(); } private void test() { diff --git a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java index 89e91588f1..189920ecef 100644 --- a/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java +++ b/core/src/test/java/com/predic8/membrane/core/resolver/ResolverTest.java @@ -100,7 +100,7 @@ public Outcome handleRequest(Exchange exc) { @AfterAll public static void teardown() { - router.shutdown(); + router.stop(); } // RelativeUrlType (SCHEMA, NAME, SAME_DIR, PARENT_DIR) is handled by the test methods as well as by the test resources diff --git a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java index 32d83f6569..ea402e0e46 100644 --- a/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java +++ b/core/src/test/java/com/predic8/membrane/core/security/KeyStoreUtilTest.java @@ -53,7 +53,7 @@ static void setUp() throws Exception { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java index 99706c3c76..df36d02b03 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/BoundConnectionTest.java @@ -59,7 +59,7 @@ public Outcome handleRequest(Exchange exc) { @AfterEach public void tearDown() { - router.shutdown(); + router.stop(); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java index 5d9a8ad8cb..0211a90b5a 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConcurrentConnectionLimitTest.java @@ -54,7 +54,7 @@ public void setup() throws Exception{ @AfterEach public void tearDown() throws Exception { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java index 09cb62b503..28fd97a0b4 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ConnectionTest.java @@ -47,7 +47,7 @@ void tearDown() throws Exception { assertTrue(conLocalhost.isClosed()); assertTrue(con127_0_0_1.isClosed()); - router.shutdown(); + router.stop(); } diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java index f43fb5a629..8972610d24 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/HttpKeepAliveTest.java @@ -69,7 +69,7 @@ public Outcome handleRequest(Exchange exc) { @AfterEach public void tearDown() { - service1.shutdown(); + service1.stop(); } private HttpClient createHttpClient(int defaultKeepAliveTimeout) { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java index 2de2147dae..12fc86b8a0 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/IllegalCharactersInURLTest.java @@ -53,7 +53,7 @@ public Outcome handleRequest(Exchange exc) { @AfterEach void unInit() { - r.shutdown(); + r.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java index fa7ead742b..4d5bbd91bc 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/ServiceInvocationTest.java @@ -50,7 +50,7 @@ void testInterceptorSequence() throws Exception { @AfterEach public void tearDown() { - router.shutdown(); + router.stop(); } private ServiceProxy createFirstRule() { diff --git a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java index bc357d290a..086e1083c3 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/ssl/SessionResumptionTest.java @@ -58,9 +58,9 @@ static void done() throws IOException { tcpForwarder.close(); } finally { try { - router1.shutdown(); + router1.stop(); } finally { - router2.shutdown(); + router2.stop(); } } } diff --git a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java index de4843b17a..28a8e267b3 100644 --- a/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/ws/SoapProxyInvocationTest.java @@ -132,8 +132,8 @@ private static void setupBackend() throws Exception { @AfterAll public static void teardown() { - gw.shutdown(); - backend.shutdown(); + gw.stop(); + backend.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java index 6a95bf550e..41060bbe2b 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/LargeBodyTest.java @@ -89,9 +89,9 @@ private static void setClientConfigHTTPClientOnInterceptor(TestRouter router2) { @AfterAll public static void shutdown() { if (router != null) - router.shutdown(); + router.stop(); if (router2 != null) - router2.shutdown(); + router2.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java index 757cc07a68..cf5c38e998 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/ProxySSLConnectionMethodTest.java @@ -40,7 +40,7 @@ void setUp() throws Exception { @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java index 5ffc800841..bd1ee88f2d 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/ViaProxyTest.java @@ -46,8 +46,8 @@ static void setUp() throws Exception { @AfterAll static void tearDown() { - router.shutdown(); - proxyRouter.shutdown(); + router.stop(); + proxyRouter.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java index 50467aa87a..f304997a61 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withinternet/interceptor/RewriteInterceptorIntegrationTest.java @@ -66,7 +66,7 @@ static void setUp() throws Exception { @AfterAll static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java index 9b455a694d..1f5100dfa8 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/LimitedMemoryExchangeStoreIntegrationTest.java @@ -99,9 +99,9 @@ public void init() { @AfterAll public static void shutdown() { if (router != null) - router.shutdown(); + router.stop(); if (router2 != null) - router2.shutdown(); + router2.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java index 760011062f..0ca063a4d2 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java @@ -87,7 +87,7 @@ public static void shutdown() { } @Test - @Timeout(30) // seconds + @Timeout(60) // seconds public void run() throws Exception { Set paths = newKeySet(); runInParallel((cdl) -> parallelTestWorker(cdl, paths), CONCURRENT_THREADS); diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java index 0c5c296a60..8d33e2f8ce 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/SessionManagerTest.java @@ -88,7 +88,6 @@ public void remembersThings( assertEquals(rememberThis, rememberThisFromServer); httpRouter.stop(); - httpRouter.shutdown(); } @ParameterizedTest(name = "{0}") @@ -117,7 +116,7 @@ public void sessionExpires( assertNotEquals(rememberThis, rememberThisFromServer); assertEquals("null", rememberThisFromServer); - httpRouter.shutdown(); + httpRouter.stop(); } @ParameterizedTest(name = "{0}") @@ -154,7 +153,7 @@ public void changeValueInSession( assertEquals("rememberThis", rememberThisFromServer); - httpRouter.shutdown(); + httpRouter.stop(); } @ParameterizedTest(name = "{0}") @@ -197,7 +196,7 @@ public void sessionCookie( } } - httpRouter.shutdown(); + httpRouter.stop(); } @ParameterizedTest(name = "{0}") @@ -245,7 +244,7 @@ public void expiresPartIsRefreshedOnAccess( Instant.from(DateTimeFormatter.RFC_1123_DATE_TIME.parse(secondExpires.split("=")[1])); } - httpRouter.shutdown(); + httpRouter.stop(); } @ParameterizedTest(name = "{0}") @@ -294,7 +293,7 @@ public void parallelRequests( executor.shutdown(); executor.awaitTermination(60, TimeUnit.SECONDS); client.close(); - httpRouter.shutdown(); + httpRouter.stop(); } private Stream

allSetCookieHeadersExceptFor1970Expire(CloseableHttpResponse resp) { diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java index 99f1cfba9f..2f28566aaf 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/OpenApiRewriteIntegrationTest.java @@ -41,7 +41,7 @@ public void setUp() throws Exception { @AfterEach public void tearDown() { - r.shutdown(); + r.stop(); } @NotNull diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java index 8fe3835f68..fade5fde68 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/REST2SOAPInterceptorIntegrationTest.java @@ -50,7 +50,7 @@ public static void setUp() throws Exception { @AfterAll public static void tearDown() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index 7bdf530b8b..15184a82c1 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -40,7 +40,7 @@ public static void setup() throws Exception { @AfterAll public static void teardown() { - targetRouter.shutdown(); + targetRouter.stop(); } @BeforeEach @@ -50,7 +50,7 @@ void startRouter() { @AfterEach void shutdownRouter() { - router.shutdown(); + router.stop(); } @Test diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java index c7d0c13933..56d96b954f 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/oauth2/OAuth2AuthorizationServerInterceptorBase.java @@ -212,7 +212,7 @@ void setUp() throws Exception{ @AfterEach void tearDown() { - router.shutdown(); + router.stop(); } public static Collection data() throws Exception { diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java index ea9cdd9155..5c1d6b28c8 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java @@ -123,13 +123,13 @@ public Outcome handleResponse(Exchange exc) { void tearDown() { for (Router httpRouter : nodes) { try { - httpRouter.shutdown(); + httpRouter.stop(); } catch (Exception e) { log.warn("Node shutdown failed.", e); } } try { - balancer.shutdown(); + balancer.stop(); } catch (Exception e) { log.warn("Balancer shutdown failed.", e); } @@ -206,7 +206,7 @@ public void test_5destinations_6threads_100calls_1shutdown() throws Exception { .successChance(1d) .preSubmitCallback(integer -> { if (integer == 20) { - nodes.getFirst().shutdown(); + nodes.getFirst().stop(); } return null; }) @@ -236,13 +236,13 @@ void test_5destinations_6threads_100calls_4shutdown() throws Exception { .successChance(1d) .preSubmitCallback(i -> { if (i == 10) { - nodes.getFirst().shutdown(); + nodes.getFirst().stop(); } else if (i == 20) { - nodes.get(1).shutdown(); + nodes.get(1).stop(); } else if (i == 30) { - nodes.get(2).shutdown(); + nodes.get(2).stop(); } else if (i == 40) { - nodes.get(3).shutdown(); + nodes.get(3).stop(); } return null; }) diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java index 5901eeff89..0f765282bd 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorTest.java @@ -110,9 +110,9 @@ private void enableFailOverOn5XX() { @AfterEach void tearDown() { - service1.shutdown(); - service2.shutdown(); - balancer.shutdown(); + service1.stop(); + service2.stop(); + balancer.stop(); } @Test @@ -222,7 +222,7 @@ void failOverOnConnectionRefused() throws Exception { assertEquals(1, mockInterceptor1.getCount()); assertEquals(1, mockInterceptor2.getCount()); - service1.shutdown(); + service1.stop(); sleep(1000); assertEquals(200, client.executeMethod(getPostMethod())); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java index 87a084dfd2..c00569b12d 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/MultipleLoadBalancersTest.java @@ -45,7 +45,7 @@ static void tearDown() { service2.close(); service11.close(); service12.close(); - balancer.shutdown(); + balancer.stop(); } private static class MockService { @@ -65,7 +65,7 @@ private static class MockService { } public void close() { - router.shutdown(); + router.stop(); } } From feea582b685a16d3b00af55f135e4b5701b53f29 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 31 Dec 2025 13:14:20 +0100 Subject: [PATCH 36/40] refactor: improve thread-safety and synchronization in `BeanRegistryImplementation`, enhance initialization/logging in routers, and remove unused/deprecated methods --- .../annot/beanregistry/BeanDefinition.java | 3 + .../BeanRegistryImplementation.java | 90 ++++++++++--------- .../predic8/membrane/core/DefaultRouter.java | 44 +++------ .../membrane/core/DummyTestRouter.java | 2 + .../com/predic8/membrane/core/Router.java | 5 -- .../predic8/membrane/core/RuleManager.java | 5 ++ .../core/transport/http/HttpTransport.java | 4 +- .../com/predic8/membrane/core/TestRouter.java | 7 ++ ...nterceptorFaultMonitoringStrategyTest.java | 36 ++++---- docs/ROADMAP.md | 1 + 10 files changed, 95 insertions(+), 102 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java index eaaea4951b..436e0d391a 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java @@ -16,6 +16,9 @@ import com.fasterxml.jackson.databind.*; import com.predic8.membrane.annot.yaml.*; +/** + * Immutable. + */ public class BeanDefinition { public static final String PROTOTYPE = "prototype"; diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 0c04d43612..72dd07c7d4 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -19,6 +19,7 @@ import org.jetbrains.annotations.*; import org.slf4j.*; +import javax.annotation.concurrent.*; import java.util.*; import java.util.concurrent.*; import java.util.function.*; @@ -27,8 +28,13 @@ * TODO: * - More Tests * - Document - * - Do we need uuid when then name is unique? * - For TB Unclear: Lifecycle activation/resolve + * - oldbean + * - a.) Revert to second list (singletonBeans) + * - b.) Give proxies an unique id + *

+ * For K8S UUID and name is needed cause name is only unique within a namespace. + * */ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { @@ -37,11 +43,14 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { private final BeanCacheObserver observer; private final Grammar grammar; + // uid -> bean + private final ConcurrentHashMap singletonBeans = new ConcurrentHashMap<>(); // Order is here not critical + // uid -> bean container private final Map bcs = new ConcurrentHashMap<>(); // Order is not critical. Order is determined by uidsToActivate - private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order - private final Object registrationLock = new Object(); + @GuardedBy("uidsToActivate") + private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order record UidAction(String uid, WatchAction action) { } @@ -91,47 +100,38 @@ public void handle(ChangeEvent changeEvent, boolean isLast) { } private void activationRun() { - // Iterate safely over clone - for (UidAction uidAction : cloneUidActions()) { + Set uidsToRemove = new HashSet<>(); + for (UidAction uidAction : uidsToActivate) { BeanContainer bc = bcs.get(uidAction.uid); - if (bc == null) { - log.warn("Skipping activation for missing uid {}", uidAction.uid); - continue; - } - - BeanDefinition def = bc.getDefinition(); - Object oldBean; - Object newBean = null; - try { - synchronized (bc) { - oldBean = (uidAction.action.isModified() || uidAction.action.isDeleted()) ? bc.getSingleton() : null; - if (!uidAction.action.isDeleted()) { - newBean = define(def); - bc.setSingleton(newBean); - } - } + Object bean = define(bc.getDefinition()); + bc.setSingleton(bean); + + // e.g. inform router about new proxy + observer.handleBeanEvent(new BeanDefinitionChanged(uidAction.action, bc.getDefinition()), bean, getOldBean(uidAction.action, bc.getDefinition())); - // Remove container after releasing the lock (avoid holding bc while mutating registry map) + if (uidAction.action.isAdded() || uidAction.action.isModified()) + singletonBeans.put(bc.getDefinition().getUid(), bean); if (uidAction.action.isDeleted()) { - bcs.remove(uidAction.uid); + singletonBeans.remove(bc.getDefinition().getUid()); + bcs.remove(bc.getDefinition().getUid()); } - - observer.handleBeanEvent(new BeanDefinitionChanged(uidAction.action, def), newBean, oldBean); + uidsToRemove.add(uidAction); } catch (Exception e) { - log.error("Could not handle {} {}/{}", uidAction.action, def.getNamespace(), def.getName(), e); + log.error("Could not handle {} {}/{}", uidAction.action, + bc.getDefinition().getNamespace(), bc.getDefinition().getName(), e); throw new RuntimeException(e); } } + for (UidAction uidAction : uidsToRemove) + uidsToActivate.remove(uidAction); } - private @NotNull List cloneUidActions() { - final List actions; - synchronized (uidsToActivate) { - actions = new ArrayList<>(uidsToActivate); - uidsToActivate.clear(); - } - return actions; + private @Nullable Object getOldBean(WatchAction action, BeanDefinition bd) { + Object oldBean = null; + if (action.isModified() || action.isDeleted()) + oldBean = singletonBeans.get(bd.getUid()); + return oldBean; } @Override @@ -204,7 +204,10 @@ public Optional getBean(Class clazz) { return beans.size() == 1 ? Optional.of(beans.getFirst()) : Optional.empty(); } - public void register(String beanName, Object bean) { + /** + * synchronized is a quick-fix for tests like LoadBalancingInterceptorFaultMonitoringStrategyTest. + */ + public synchronized void register(String beanName, Object bean) { if (bean == null) throw new IllegalArgumentException("bean must not be null"); @@ -214,16 +217,15 @@ public void register(String beanName, Object bean) { bcs.put(uuid, bc); } - public T registerIfAbsent(Class type, Supplier supplier) { - return getBean(type).orElseGet(() -> { - synchronized (registrationLock) { - return getBean(type).orElseGet(() -> { - T created = supplier.get(); - register(null, created); - return created; - }); - } - }); + /** + * synchronized is a quick-fix for tests like LoadBalancingInterceptorFaultMonitoringStrategyTest. + */ + public synchronized T registerIfAbsent(Class type, Supplier supplier) { + return getBean(type).orElseGet(() -> getBean(type).orElseGet(() -> { + T created = supplier.get(); + register(null, created); + return created; + })); } private static @NotNull String computeBeanName(String beanName, String uuid) { diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java index 8bdfce175a..fd8b9a3211 100644 --- a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java @@ -136,10 +136,6 @@ public DefaultRouter() { mainComponents = new DefaultMainComponents(this); } - // - // Initialization - // - /** * Initializes the {@code Router} * - by setting up its associated components. @@ -294,6 +290,7 @@ public ResolverMap getResolverMap() { /** * Adds a proxy to the router and initializes it. + * Can be called at any time before or after start(). * * TODO: Should we sync running cause a different Thread might call add? * @@ -306,7 +303,7 @@ public void add(Proxy proxy) throws IOException { if (running && proxy instanceof SSLableProxy sp) { sp.init(this); - ruleManager.addProxyAndOpenPortIfNew(sp, MANUAL); + ruleManager.addProxyAndOpenPortIfNew(sp); } else { ruleManager.addProxy(proxy, MANUAL); } @@ -314,9 +311,11 @@ public void add(Proxy proxy) throws IOException { } private void startJmx() { - if (mainComponents.getBeanFactory() == null) + if (mainComponents.getBeanFactory() == null) { + log.info("No bean factory available, not starting JMX."); return; - + } + log.debug("Starting JMX."); try { JmxExporter exporter = mainComponents.getBeanFactory().getBean(JMX_EXPORTER_NAME, JmxExporter.class); //exporter.removeBean(prefix + jmxRouterName); @@ -331,7 +330,10 @@ private void startJmx() { public void stop() { getRegistry().getBean(KubernetesWatcher.class).ifPresent(KubernetesWatcher::stop); hotDeployer.stop(); - shutdown(); + + if (mainComponents.getTransport() != null) + mainComponents.getTransport().closeAll(); + mainComponents.getTimerManager().shutdown(); synchronized (lock) { running = false; @@ -339,17 +341,6 @@ public void stop() { } } - /** - * Closes all ports (if any were opened) and waits for running exchanges to complete. - *

- * When running as an embedded servlet, this has no effect. - */ - private void shutdown() { - if (mainComponents.getTransport() != null) - mainComponents.getTransport().closeAll(); - mainComponents.getTimerManager().shutdown(); - } - @Override public boolean isRunning() { synchronized (lock) { @@ -446,21 +437,6 @@ public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBe if (newProxy.getName() == null) newProxy.setName(bdc.bd().getName()); - // TODO: Comment or code Should be deleted before merge - // Comment is kept for discussion only. - // - // init() in Proxies was called twice, here and in Router.initRemainingRules - // We should only keep one place. Which one is up to discussion - // - // try { - // newProxy.init(this); - // } catch (ConfigurationException e) { - // SpringConfigurationErrorHandler.handleRootCause(e, log); - // throw e; - // } catch (Exception e) { - // throw new RuntimeException("Could not init rule.", e); - // } - if (bdc.action().isAdded()) { add(newProxy); } else if (bdc.action().isDeleted()) diff --git a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java index 85bbcb7d05..2520df6c8c 100644 --- a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java @@ -140,6 +140,8 @@ public Statistics getStatistics() { /** * Same as the default config from monitor-beans.xml + * + * TODO: Sync somehow with standard transport order maybe TransportConfig class or in Transport? */ private static HttpTransport createTransport() { HttpTransport transport = new HttpTransport(); diff --git a/core/src/main/java/com/predic8/membrane/core/Router.java b/core/src/main/java/com/predic8/membrane/core/Router.java index 841aba0179..f078c94926 100644 --- a/core/src/main/java/com/predic8/membrane/core/Router.java +++ b/core/src/main/java/com/predic8/membrane/core/Router.java @@ -23,11 +23,6 @@ public interface Router extends Lifecycle, MainComponents { void init(); - /** - * TODO: What is the difference between this and stop? - */ - // void shutdown(); - void add(Proxy proxy) throws IOException; Configuration getConfiguration(); diff --git a/core/src/main/java/com/predic8/membrane/core/RuleManager.java b/core/src/main/java/com/predic8/membrane/core/RuleManager.java index 018b0c7ea3..4b975b8b1a 100644 --- a/core/src/main/java/com/predic8/membrane/core/RuleManager.java +++ b/core/src/main/java/com/predic8/membrane/core/RuleManager.java @@ -62,6 +62,11 @@ public boolean isAnyRuleWithPort(int port) { return false; } + /** + * Do not call directly. Router should call this method. Call Router.add() + Router.start() instead. + * @param proxy + * @throws IOException + */ public void addProxyAndOpenPortIfNew(SSLableProxy proxy) throws IOException { addProxyAndOpenPortIfNew(proxy, RuleDefinitionSource.MANUAL); } diff --git a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java index 3cdba24b14..46a191cc0a 100644 --- a/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java +++ b/core/src/main/java/com/predic8/membrane/core/transport/http/HttpTransport.java @@ -36,13 +36,15 @@ import static java.util.concurrent.TimeUnit.*; /** + * HttpTransport is responsible for opening and closing ports. Besides HttpTransport there is also a ServletTransport. + * * @description

* The transport receives messages from clients and invokes interceptors in the request and response flow. * The interceptors that are engaged with the transport are global and are invoked for each message flowing * through the router. *

* - * Besides HttpTransport there is also a ServletTransport. + * */ @MCElement(name="transport") public class HttpTransport extends Transport { diff --git a/core/src/test/java/com/predic8/membrane/core/TestRouter.java b/core/src/test/java/com/predic8/membrane/core/TestRouter.java index 6c6142275c..c5df8b9f64 100644 --- a/core/src/test/java/com/predic8/membrane/core/TestRouter.java +++ b/core/src/test/java/com/predic8/membrane/core/TestRouter.java @@ -17,11 +17,18 @@ import com.predic8.membrane.core.transport.http.*; import com.predic8.membrane.core.transport.http.client.*; +/** + * Opens ports but does not start hotdeployer, reinit, ... + */ public class TestRouter extends DefaultRouter { public TestRouter() { } + /* + TODO: overwrite init(), start() to do nothing + */ + public TestRouter(ProxyConfiguration proxyConfiguration) { if (proxyConfiguration != null) getResolverMap().getHTTPSchemaResolver().getHttpClientConfig().setProxy(proxyConfiguration); diff --git a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java index 5c1d6b28c8..392a355d22 100644 --- a/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java +++ b/core/src/test/java/com/predic8/membrane/interceptor/LoadBalancingInterceptorFaultMonitoringStrategyTest.java @@ -61,6 +61,22 @@ class LoadBalancingInterceptorFaultMonitoringStrategyTest { // The simulation nodes private final List nodes = new ArrayList<>(); + @AfterEach + void tearDown() { + for (Router httpRouter : nodes) { + try { + httpRouter.stop(); + } catch (Exception e) { + log.warn("Node shutdown failed.", e); + } + } + try { + balancer.stop(); + } catch (Exception e) { + log.warn("Balancer shutdown failed.", e); + } + } + private void setUp(TestingContext ctx) throws Exception { nodes.clear(); for (int i = 1; i <= ctx.numNodes; i++) { @@ -119,22 +135,6 @@ public Outcome handleResponse(Exchange exc) { return sp; } - @AfterEach - void tearDown() { - for (Router httpRouter : nodes) { - try { - httpRouter.stop(); - } catch (Exception e) { - log.warn("Node shutdown failed.", e); - } - } - try { - balancer.stop(); - } catch (Exception e) { - log.warn("Balancer shutdown failed.", e); - } - } - /** * Because we set the success chance to 0, none will pass. */ @@ -157,7 +157,7 @@ void test_2destinations_6threads_100calls_allFail() throws Exception { * Because we set the success chance to 1, all will pass. */ @Test - public void test_2destinations_6threads_100calls_allSucceed() throws Exception { + void test_2destinations_6threads_100calls_allSucceed() throws Exception { TestingContext ctx = new TestingContext.Builder() .numNodes(2) .numThreads(6) @@ -214,7 +214,7 @@ public void test_5destinations_6threads_100calls_1shutdown() throws Exception { run(ctx); - assertTrue(ctx.successCounter.get() > 95,"ctx.successCounter.get() > 95 was %s".formatted(ctx.successCounter.get())); + assertTrue(ctx.successCounter.get() > 95, "ctx.successCounter.get() > 95 was %s".formatted(ctx.successCounter.get())); for (int i = 0; i < 100; i++) { if (i < 10 || i >= 40) { assertTrue(ctx.runtimes[i] < 500, "For " + i + " value was: " + ctx.runtimes[i]); diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index d3e4028e6b..1481f420b6 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -18,6 +18,7 @@ - Tutorial - Documentation - See JmxExporter +- Synchronization of BeanRegistry # 7.1.0 From 1623f85c5c7b525520ad56476ae6906f835065d9 Mon Sep 17 00:00:00 2001 From: Thomas Bayer Date: Wed, 31 Dec 2025 13:50:28 +0100 Subject: [PATCH 37/40] refactor: extend timeout in `MassivelyParallelTest` to improve test stability under high load --- .../integration/withoutinternet/MassivelyParallelTest.java | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java index 0ca063a4d2..f4d38635ad 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/MassivelyParallelTest.java @@ -32,6 +32,7 @@ import static com.predic8.membrane.core.interceptor.Outcome.*; import static java.lang.Thread.*; import static java.util.concurrent.ConcurrentHashMap.*; +import static java.util.concurrent.TimeUnit.SECONDS; import static org.junit.jupiter.api.Assertions.*; /** @@ -102,7 +103,7 @@ private void runInParallel(Consumer job, int threadCount) { es.submit(() -> job.accept(cdl)); } es.shutdown(); - if (!es.awaitTermination(30, TimeUnit.SECONDS)) { + if (!es.awaitTermination(60, SECONDS)) { es.shutdownNow(); fail("Tasks did not complete within timeout"); } From 4166d5275c960d92d843cb5897d40a3e84ee4827 Mon Sep 17 00:00:00 2001 From: Tobias Polley Date: Thu, 1 Jan 2026 13:31:21 +0100 Subject: [PATCH 38/40] improved synchronization --- .../annot/beanregistry/BeanContainer.java | 77 +++++++++++++- .../annot/beanregistry/BeanDefinition.java | 2 + .../BeanRegistryImplementation.java | 100 ++++++------------ 3 files changed, 110 insertions(+), 69 deletions(-) diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java index 0493c45f0c..b022a63950 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanContainer.java @@ -14,24 +14,51 @@ package com.predic8.membrane.annot.beanregistry; +import com.predic8.membrane.annot.Grammar; +import com.predic8.membrane.annot.bean.BeanFactory; +import com.predic8.membrane.annot.yaml.GenericYamlParser; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + import java.util.concurrent.atomic.*; public class BeanContainer { + private static final Logger log = LoggerFactory.getLogger(BeanContainer.class); + private final BeanDefinition definition; /** * Constructed bean after initialization. */ private final AtomicReference singleton = new AtomicReference<>(); + /** + * Creates a BeanDefinition where the bean has not yet been instantiated and initialized. + */ public BeanContainer(BeanDefinition definition) { this.definition = definition; } - public Object getSingleton() { + /** + * Creates a BeanDefinition where the bean has already been instantiated and initialized. + */ + public BeanContainer(BeanDefinition definition, Object singleton) { + this.definition = definition; + this.singleton.set(singleton); + } + + /** + * Only to be used within this class. + * Use {@link #getOrCreate(BeanRegistryImplementation, Grammar)} instead. + */ + private Object getSingleton() { return singleton.get(); } - public void setSingleton(Object singleton) { + /** + * Only to be used within this class. + * Use {@link #getOrCreate(BeanRegistryImplementation, Grammar)} instead. + */ + private void setSingleton(Object singleton) { this.singleton.set(singleton); } @@ -43,4 +70,50 @@ public BeanDefinition getDefinition() { public String toString() { return "BeanContainer: %s of %s singleton: %s".formatted( definition.getName(),definition.getKind(),singleton.get()); } + + private synchronized Object define(BeanRegistryImplementation registry, Grammar grammar) { + log.debug("defining bean: {}", definition.getNode()); + try { + if ("bean".equals(definition.getKind())) { + return new BeanFactory(registry).create(definition.getNode().path("bean")); + } + return GenericYamlParser.readMembraneObject(definition.getKind(), + grammar, + definition.getNode(), + registry); + } catch (Exception e) { + throw new RuntimeException(e); + } + } + + public Object getOrCreate(BeanRegistryImplementation registry, Grammar grammar) { + boolean prototype = isPrototypeScope(getDefinition()); + + // Prototypes are created anew every time. + if (prototype) { + return define(registry, grammar); + } + + // Singleton: ensure define() runs at most once per BeanContainer. + synchronized (this) { + Object existing = getSingleton(); + if (existing != null) { + return existing; + } + + Object created = define(registry, grammar); + setSingleton(created); + return created; + } + } + + private static boolean isPrototypeScope(BeanDefinition bd) { + if (!bd.isBean()) + return bd.isPrototype(); + + return "PROTOTYPE".equalsIgnoreCase( + bd.getNode().path("bean").path("scope").asText("SINGLETON") + ); + } + } diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java index 436e0d391a..5afa1fda62 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanDefinition.java @@ -79,6 +79,8 @@ public String getKind() { } public String getScope() { + if (node == null) + return null; JsonNode meta = node.get("metadata"); if (meta == null) return null; diff --git a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java index 72dd07c7d4..8ea53231a7 100644 --- a/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java +++ b/annot/src/main/java/com/predic8/membrane/annot/beanregistry/BeanRegistryImplementation.java @@ -52,6 +52,11 @@ public class BeanRegistryImplementation implements BeanRegistry, BeanCollector { @GuardedBy("uidsToActivate") private final Set uidsToActivate = Collections.synchronizedSet(new LinkedHashSet<>()); // keeps order + /** + * Protects the initialization of beans, which are unique per class. + */ + private final Object uniqueClassInitialization = new Object(); + record UidAction(String uid, WatchAction action) { } @@ -61,21 +66,6 @@ public BeanRegistryImplementation(BeanCacheObserver observer, BeanRegistryAware registryAware.setRegistry(this); } - private Object define(BeanDefinition bd) { - log.debug("defining bean: {}", bd.getNode()); - try { - if ("bean".equals(bd.getKind())) { - return new BeanFactory(this).create(bd.getNode().path("bean")); - } - return GenericYamlParser.readMembraneObject(bd.getKind(), - grammar, - bd.getNode(), - this); - } catch (Exception e) { - throw new RuntimeException(e); - } - } - @Override public void start() { } @@ -104,10 +94,9 @@ private void activationRun() { for (UidAction uidAction : uidsToActivate) { BeanContainer bc = bcs.get(uidAction.uid); try { - Object bean = define(bc.getDefinition()); - bc.setSingleton(bean); + Object bean = bc.getOrCreate(this, grammar); - // e.g. inform router about new proxy + // e.g., inform router about a new ApiProxy or GlobalInterceptor observer.handleBeanEvent(new BeanDefinitionChanged(uidAction.action, bc.getDefinition()), bean, getOldBean(uidAction.action, bc.getDefinition())); if (uidAction.action.isAdded() || uidAction.action.isModified()) @@ -136,26 +125,7 @@ private void activationRun() { @Override public Object resolve(String url) { - BeanContainer bc = getFirstByName(url).orElseThrow(() -> new RuntimeException("Reference %s not found".formatted(url))); - - boolean prototype = isPrototypeScope(bc.getDefinition()); - - // Prototypes are created anew every time. - if (prototype) { - return define(bc.getDefinition()); - } - - // Singleton: ensure define() runs at most once per BeanContainer. - synchronized (bc) { - Object existing = bc.getSingleton(); - if (existing != null) { - return existing; - } - - Object created = define(bc.getDefinition()); - bc.setSingleton(created); - return created; - } + return getFirstByName(url).orElseThrow(() -> new RuntimeException("Reference %s not found".formatted(url))).getOrCreate(this, grammar); } private @NotNull Optional getFirstByName(String url) { @@ -165,7 +135,7 @@ public Object resolve(String url) { @Override public List getBeans() { return bcs.values().stream().filter(bd -> !bd.getDefinition().isComponent()) - .map(BeanContainer::getSingleton) + .map(bc -> bc.getOrCreate(this, grammar)) .filter(Objects::nonNull) .toList(); } @@ -175,19 +145,10 @@ public Grammar getGrammar() { return grammar; } - private static boolean isPrototypeScope(BeanDefinition bd) { - if (!bd.isBean()) - return bd.isPrototype(); - - return "PROTOTYPE".equalsIgnoreCase( - bd.getNode().path("bean").path("scope").asText("SINGLETON") - ); - } - @Override public List getBeans(Class clazz) { return bcs.values().stream() - .map(BeanContainer::getSingleton) + .map(bc -> bc.getOrCreate(this, grammar)) .filter(Objects::nonNull) .filter(clazz::isInstance) .map(clazz::cast) @@ -204,28 +165,33 @@ public Optional getBean(Class clazz) { return beans.size() == 1 ? Optional.of(beans.getFirst()) : Optional.empty(); } - /** - * synchronized is a quick-fix for tests like LoadBalancingInterceptorFaultMonitoringStrategyTest. - */ - public synchronized void register(String beanName, Object bean) { + public void register(String beanName, Object bean) { if (bean == null) throw new IllegalArgumentException("bean must not be null"); var uuid = UUID.randomUUID().toString(); - BeanContainer bc = new BeanContainer(new BeanDefinition("component", computeBeanName(beanName, uuid), null, uuid, null)); - bc.setSingleton(bean); - bcs.put(uuid, bc); - } - - /** - * synchronized is a quick-fix for tests like LoadBalancingInterceptorFaultMonitoringStrategyTest. - */ - public synchronized T registerIfAbsent(Class type, Supplier supplier) { - return getBean(type).orElseGet(() -> getBean(type).orElseGet(() -> { - T created = supplier.get(); - register(null, created); - return created; - })); + bcs.put(uuid, + new BeanContainer( + new BeanDefinition( + "component", + computeBeanName(beanName, uuid), + null, + uuid, + null), + bean)); + singletonBeans.put(uuid, bean); + // the return value of 'put' is ignored, since bean registration with + // random keys should not yield duplicates anyway. + } + + public T registerIfAbsent(Class type, Supplier supplier) { + synchronized (uniqueClassInitialization) { + return getBean(type).orElseGet(() -> getBean(type).orElseGet(() -> { + T created = supplier.get(); + register(null, created); + return created; + })); + } } private static @NotNull String computeBeanName(String beanName, String uuid) { From 8575853ca02a52c9b98eb62e55a348326cdc6b50 Mon Sep 17 00:00:00 2001 From: Tobias Polley Date: Thu, 1 Jan 2026 13:47:05 +0100 Subject: [PATCH 39/40] doc --- .../main/java/com/predic8/membrane/core/DummyTestRouter.java | 4 ++++ docs/ROADMAP.md | 1 + 2 files changed, 5 insertions(+) diff --git a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java index 2520df6c8c..fbca1b94e3 100644 --- a/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DummyTestRouter.java @@ -29,6 +29,10 @@ import static com.predic8.membrane.core.RuleManager.RuleDefinitionSource.MANUAL; +/** + * TODO rename this class: It is also being used in case the router is being started + * from the command line (=in a non-test environment). + */ public class DummyTestRouter extends AbstractRouter { private FlowController flowController = new FlowController(this); diff --git a/docs/ROADMAP.md b/docs/ROADMAP.md index 1481f420b6..70732f0b86 100644 --- a/docs/ROADMAP.md +++ b/docs/ROADMAP.md @@ -33,6 +33,7 @@ # 7.0.4 - Discuss renaming the WebSocketInterceptor.flow to something else to avoid confusion with flowParser +- do not pass a `Router` reference into all sorts of beans: Access to global functionality should happen only on a very limited basis. # 7.0.1 From c169acf956705d651eb88054be1d12e879f2b50c Mon Sep 17 00:00:00 2001 From: Tobias Polley Date: Thu, 1 Jan 2026 14:01:39 +0100 Subject: [PATCH 40/40] small improvements --- .../com/predic8/membrane/core/DefaultRouter.java | 16 +++++----------- ...terBootstrap.java => RouterXmlBootstrap.java} | 4 ++-- .../com/predic8/membrane/core/cli/RouterCLI.java | 2 +- .../com/predic8/membrane/core/SimpleTest.java | 2 +- .../core/config/ReadRulesConfigurationTest.java | 2 +- ...adRulesWithInterceptorsConfigurationTest.java | 2 +- .../core/config/SpringReferencesTest.java | 2 +- .../core/interceptor/InternalInvocationTest.java | 2 +- .../core/interceptor/UserFeatureTest.java | 2 +- .../membrane/core/proxies/ProxyRuleTest.java | 2 +- .../http/client/HttpClientConfigurationTest.java | 2 +- .../interceptor/SOAPProxyIntegrationTest.java | 2 +- 12 files changed, 17 insertions(+), 23 deletions(-) rename core/src/main/java/com/predic8/membrane/core/{RouterBootstrap.java => RouterXmlBootstrap.java} (97%) diff --git a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java index fd8b9a3211..f63f1f8d27 100644 --- a/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java +++ b/core/src/main/java/com/predic8/membrane/core/DefaultRouter.java @@ -125,7 +125,6 @@ public class DefaultRouter extends AbstractRouter implements ApplicationContextA /** * HotDeployer for changes on the XML configuration file. Does not cover YAML. * Not synchronized, since only modified during initialization - * Initialized with NullHotDeployer to avoid NPEs */ private HotDeployer hotDeployer = new DefaultHotDeployer(); @@ -153,16 +152,14 @@ public void init() { synchronized (lock) { if (initialized) throw new IllegalStateException("Router already initialized."); - } - mainComponents.init(); + mainComponents.init(); - initProxies(); + initProxies(); - synchronized (lock) { initialized = true; + reinitializer = new RuleReinitializer(this); // Bean } - reinitializer = new RuleReinitializer(this); // Bean } /** @@ -272,7 +269,7 @@ public HttpClientConfiguration getHttpClientConfig() { /** * @description A 'global' (per router) <httpClientConfig>. This instance is used everywhere - * a HTTP Client is used. Usually, in every specific place, you can still configure a local + * a HTTP Client is used. In every specific place, you should still be able to configure a local * <httpClientConfig> (with higher precedence compared to this global instance). */ @MCChildElement() @@ -426,11 +423,8 @@ public void handleAsynchronousInitializationResult(boolean success) { @Override public void handleBeanEvent(BeanDefinitionChanged bdc, Object bean, Object oldBean) throws IOException { log.debug("Bean changed: type={} instance={}", bean.getClass().getSimpleName(), bean); - if (bean instanceof GlobalInterceptor) { - return; - } - if (!(bean instanceof Proxy newProxy)) { + // should not happen, as handleBeanEvent() is only called for beans passing isActivatable(). throw new IllegalArgumentException("Bean must be a Proxy instance, but got: " + bean.getClass().getName()); } diff --git a/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java b/core/src/main/java/com/predic8/membrane/core/RouterXmlBootstrap.java similarity index 97% rename from core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java rename to core/src/main/java/com/predic8/membrane/core/RouterXmlBootstrap.java index 4234e49e73..d3ebf731bf 100644 --- a/core/src/main/java/com/predic8/membrane/core/RouterBootstrap.java +++ b/core/src/main/java/com/predic8/membrane/core/RouterXmlBootstrap.java @@ -25,9 +25,9 @@ /** * Bootstrapping a {@link DefaultRouter} instance using Spring XML-based configuration. */ -public class RouterBootstrap { +public class RouterXmlBootstrap { - private static final Logger log = LoggerFactory.getLogger(RouterBootstrap.class); + private static final Logger log = LoggerFactory.getLogger(RouterXmlBootstrap.class); /** * Initializes a {@link DefaultRouter} instance from the specified Spring XML configuration resource. diff --git a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java index 4e1114d61d..6eff721d93 100644 --- a/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java +++ b/core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java @@ -215,7 +215,7 @@ private static String getLocation(MembraneCommandLine commandLine) throws IOExce private static DefaultRouter initRouterByXml(String config) throws Exception { try { - return RouterBootstrap.initByXML(config); + return RouterXmlBootstrap.initByXML(config); } catch (XmlBeanDefinitionStoreException e) { handleXmlBeanDefinitionStoreException(e); } diff --git a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java index f85462dbc8..65500f6dc3 100644 --- a/core/src/test/java/com/predic8/membrane/core/SimpleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/SimpleTest.java @@ -23,7 +23,7 @@ public class SimpleTest { @BeforeAll static void setUp() { - router = RouterBootstrap.initByXML("classpath:/test-proxies.xml"); + router = RouterXmlBootstrap.initByXML("classpath:/test-proxies.xml"); } @Test diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java index 5e36adfdd3..7d1b53b52b 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesConfigurationTest.java @@ -29,7 +29,7 @@ public class ReadRulesConfigurationTest { @BeforeAll static void setUp() { - router = RouterBootstrap.initByXML("classpath:/proxies.xml"); + router = RouterXmlBootstrap.initByXML("classpath:/proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java index 4f45a9c9c6..f72c3d4189 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/ReadRulesWithInterceptorsConfigurationTest.java @@ -30,7 +30,7 @@ public class ReadRulesWithInterceptorsConfigurationTest { @BeforeAll static void setUp() { - router = RouterBootstrap.initByXML("src/test/resources/ref.proxies.xml"); + router = RouterXmlBootstrap.initByXML("src/test/resources/ref.proxies.xml"); proxies = router.getRuleManager().getRules(); } diff --git a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java index f49533e547..41e9e83225 100644 --- a/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java +++ b/core/src/test/java/com/predic8/membrane/core/config/SpringReferencesTest.java @@ -29,7 +29,7 @@ public class SpringReferencesTest { @BeforeAll public static void before() { - r = RouterBootstrap.initByXML("classpath:/proxies-using-spring-refs.xml"); + r = RouterXmlBootstrap.initByXML("classpath:/proxies-using-spring-refs.xml"); } @AfterAll diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java index 7e7f7f4e7b..cab1540c38 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/InternalInvocationTest.java @@ -26,7 +26,7 @@ public class InternalInvocationTest { @BeforeEach public void setUp() throws Exception { - router = RouterBootstrap.initByXML("classpath:/internal-invocation/proxies.xml"); + router = RouterXmlBootstrap.initByXML("classpath:/internal-invocation/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java index 0cdd6ff436..36bde9948f 100644 --- a/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java +++ b/core/src/test/java/com/predic8/membrane/core/interceptor/UserFeatureTest.java @@ -36,7 +36,7 @@ class UserFeatureTest { @BeforeAll static void setUp() { - router = RouterBootstrap.initByXML("classpath:/userFeature/proxies.xml"); + router = RouterXmlBootstrap.initByXML("classpath:/userFeature/proxies.xml"); MockInterceptor.clear(); } diff --git a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java index 0b17105789..c991f743f0 100644 --- a/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java +++ b/core/src/test/java/com/predic8/membrane/core/proxies/ProxyRuleTest.java @@ -30,7 +30,7 @@ public class ProxyRuleTest { @BeforeAll public static void setUp() { - router = RouterBootstrap.initByXML("src/test/resources/proxy-rules-test-monitor-beans.xml"); + router = RouterXmlBootstrap.initByXML("src/test/resources/proxy-rules-test-monitor-beans.xml"); proxy = new ProxyRule(new ProxyRuleKey(8888)); proxy.setName("Rule 1"); // TODO: this is not possible anymore rule.setInboundTLS(true); diff --git a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java index 11dc67eb24..08c6e83d05 100644 --- a/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java +++ b/core/src/test/java/com/predic8/membrane/core/transport/http/client/HttpClientConfigurationTest.java @@ -151,7 +151,7 @@ void outsideRouter() { } private void setupRouter(String globalHcc) { - router = RouterBootstrap.initFromXMLString(globalHcc); + router = RouterXmlBootstrap.initFromXMLString(globalHcc); assertNotNull(router.getHttpClientConfig()); assertNotNull(router.getResolverMap().getHTTPSchemaResolver().getHttpClientConfig()); } diff --git a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java index 15184a82c1..4e6ce0ad84 100644 --- a/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java +++ b/core/src/test/java/com/predic8/membrane/integration/withoutinternet/interceptor/SOAPProxyIntegrationTest.java @@ -45,7 +45,7 @@ public static void teardown() { @BeforeEach void startRouter() { - router = RouterBootstrap.initByXML("classpath:/soap-proxy.xml"); + router = RouterXmlBootstrap.initByXML("classpath:/soap-proxy.xml"); } @AfterEach