Skip to content

Commit 9d23eca

Browse files
authored
Refactor: Move Router, ... (#2523)
* refactor: remove unused classes and methods, streamline imports, and improve package structure in `core` module * refactor: move `RuleManager` to `proxies` package, clean up imports, and remove unused methods * refactor: replace `DefaultRouter` with `Router` for improved abstraction across components, remove unused classes/methods, and streamline imports * refactor: update `LargeBodyTest` to replace `TestRouter` with `Router`, streamline initialization and lifecycle management * refactor: simplify imports, remove unused methods, and improve lifecycle handling across routers and tests * refactor: simplify `AzureDnsApiSimulator` by replacing `Outcome.RETURN` with static import and minor cleanup in methods
1 parent a3e8f85 commit 9d23eca

317 files changed

Lines changed: 879 additions & 1029 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

core/src/main/java/com/predic8/membrane/core/FixedStreamReader.java

Lines changed: 0 additions & 43 deletions
This file was deleted.

core/src/main/java/com/predic8/membrane/core/HttpRouter.java

Lines changed: 0 additions & 25 deletions
This file was deleted.

core/src/main/java/com/predic8/membrane/core/RoutingException.java

Lines changed: 0 additions & 26 deletions
This file was deleted.

core/src/main/java/com/predic8/membrane/core/TerminateException.java

Lines changed: 0 additions & 57 deletions
This file was deleted.

core/src/main/java/com/predic8/membrane/core/azure/api/AzureApiClient.java

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -13,16 +13,16 @@
1313
limitations under the License. */
1414
package com.predic8.membrane.core.azure.api;
1515

16-
import com.predic8.membrane.core.azure.AzureDns;
17-
import com.predic8.membrane.core.azure.AzureIdentity;
18-
import com.predic8.membrane.core.azure.AzureTableStorage;
19-
import com.predic8.membrane.core.azure.api.auth.AuthenticationApi;
20-
import com.predic8.membrane.core.azure.api.dns.DnsRecordApi;
21-
import com.predic8.membrane.core.azure.api.tablestorage.TableStorageApi;
22-
import com.predic8.membrane.core.transport.http.HttpClient;
23-
import com.predic8.membrane.core.transport.http.HttpClientFactory;
24-
import com.predic8.membrane.core.util.TimerManager;
16+
import com.predic8.membrane.core.azure.*;
17+
import com.predic8.membrane.core.azure.api.auth.*;
18+
import com.predic8.membrane.core.azure.api.dns.*;
19+
import com.predic8.membrane.core.azure.api.tablestorage.*;
20+
import com.predic8.membrane.core.router.*;
21+
import com.predic8.membrane.core.transport.http.*;
22+
import com.predic8.membrane.core.util.*;
23+
import org.jetbrains.annotations.*;
2524

25+
import javax.annotation.*;
2626
import javax.annotation.Nullable;
2727

2828
public class AzureApiClient implements AutoCloseable {
@@ -31,16 +31,12 @@ public class AzureApiClient implements AutoCloseable {
3131
private final AuthenticationApi authApi;
3232
private final TableStorageApi tableStorageApi;
3333

34-
3534
public AzureApiClient(
3635
@Nullable AzureIdentity identityConfig,
3736
AzureTableStorage tableStorage,
38-
HttpClientFactory httpClientFactory
39-
) {
40-
if (httpClientFactory == null) {
41-
httpClientFactory = new HttpClientFactory(new TimerManager());
42-
}
43-
this.httpClient = httpClientFactory.createClient(tableStorage.getHttpClientConfiguration());
37+
@NotNull Router router
38+
) {
39+
this.httpClient = router.getHttpClientFactory().createClient(tableStorage.getHttpClientConfiguration());
4440

4541
authApi = new AuthenticationApi(httpClient, identityConfig);
4642
tableStorageApi = new TableStorageApi(this, tableStorage);

core/src/main/java/com/predic8/membrane/core/ExitException.java renamed to core/src/main/java/com/predic8/membrane/core/cli/ExitException.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
See the License for the specific language governing permissions and
1313
limitations under the License. */
1414

15-
package com.predic8.membrane.core;
15+
package com.predic8.membrane.core.cli;
1616

1717
/**
1818
* Exception that signals that the startup failed and that Membrane should exit.

core/src/main/java/com/predic8/membrane/core/cli/RouterCLI.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,11 @@
1515
package com.predic8.membrane.core.cli;
1616

1717
import com.predic8.membrane.annot.beanregistry.*;
18-
import com.predic8.membrane.core.*;
1918
import com.predic8.membrane.core.config.spring.*;
2019
import com.predic8.membrane.core.exceptions.*;
2120
import com.predic8.membrane.core.openapi.serviceproxy.*;
2221
import com.predic8.membrane.core.resolver.*;
22+
import com.predic8.membrane.core.router.*;
2323
import org.apache.commons.cli.*;
2424
import org.jetbrains.annotations.*;
2525
import org.slf4j.*;
@@ -135,7 +135,7 @@ public static String getExceptionMessageWithCauses(Throwable throwable) {
135135
return null;
136136
}
137137

138-
private static DefaultRouter initRouterByConfig(MembraneCommandLine commandLine) throws Exception {
138+
private static Router initRouterByConfig(MembraneCommandLine commandLine) throws Exception {
139139
String config = getRulesFile(commandLine);
140140
if (config.endsWith(".xml")) {
141141
var router = initRouterByXml(config);
@@ -149,17 +149,17 @@ private static DefaultRouter initRouterByConfig(MembraneCommandLine commandLine)
149149
}
150150

151151
private static Router initRouterByOpenApiSpec(MembraneCommandLine commandLine) throws Exception {
152-
Router router = new DummyTestRouter();
152+
Router router = new DefaultRouter();
153153
router.getRuleManager().addProxyAndOpenPortIfNew(getApiProxy(commandLine));
154154
router.init();
155155
return router;
156156
}
157157

158-
private static DefaultRouter initRouterByYAML(MembraneCommandLine commandLine, String option) throws Exception {
158+
private static Router initRouterByYAML(MembraneCommandLine commandLine, String option) throws Exception {
159159
return initRouterByYAML(commandLine.getCommand().getOptionValue(option));
160160
}
161161

162-
private static DefaultRouter initRouterByYAML(String location) throws Exception {
162+
private static Router initRouterByYAML(String location) throws Exception {
163163
var router = new DefaultRouter();
164164
router.setBaseLocation(location);
165165

@@ -213,7 +213,7 @@ private static String getLocation(MembraneCommandLine commandLine) throws IOExce
213213
return new File(getUserDir(), location).getCanonicalPath();
214214
}
215215

216-
private static DefaultRouter initRouterByXml(String config) throws Exception {
216+
private static Router initRouterByXml(String config) throws Exception {
217217
try {
218218
return RouterXmlBootstrap.initByXML(config);
219219
} catch (XmlBeanDefinitionStoreException e) {

core/src/main/java/com/predic8/membrane/core/exchange/Exchange.java

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -85,18 +85,6 @@ public String getOriginalHostHeaderHost() {
8585
return originalHostHeader.replaceFirst(":.*", "");
8686
}
8787

88-
public void block(Message msg) throws TerminateException {
89-
try {
90-
log.debug("Message thread waits");
91-
msg.wait();
92-
log.debug("Message thread received notify");
93-
if (isForcedToStop())
94-
throw new TerminateException("Force the exchange to stop.");
95-
} catch (InterruptedException e1) {
96-
Thread.currentThread().interrupt();
97-
}
98-
}
99-
10088
public String getOriginalHostHeaderPort() {
10189
int pos = originalHostHeader.indexOf(':');
10290
if (pos == -1) {

core/src/main/java/com/predic8/membrane/core/exchangestore/AbstractPersistentExchangeStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,12 +16,12 @@
1616

1717
import com.google.common.cache.*;
1818
import com.predic8.membrane.annot.*;
19-
import com.predic8.membrane.core.*;
2019
import com.predic8.membrane.core.exchange.*;
2120
import com.predic8.membrane.core.exchange.snapshots.*;
2221
import com.predic8.membrane.core.http.*;
2322
import com.predic8.membrane.core.interceptor.*;
2423
import com.predic8.membrane.core.proxies.*;
24+
import com.predic8.membrane.core.router.*;
2525

2626
import java.util.*;
2727
import java.util.concurrent.*;

core/src/main/java/com/predic8/membrane/core/exchangestore/ElasticSearchExchangeStore.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@
1717
import com.fasterxml.jackson.databind.*;
1818
import com.google.common.collect.*;
1919
import com.predic8.membrane.annot.*;
20-
import com.predic8.membrane.core.*;
2120
import com.predic8.membrane.core.exchange.*;
2221
import com.predic8.membrane.core.exchange.snapshots.*;
2322
import com.predic8.membrane.core.http.*;
2423
import com.predic8.membrane.core.interceptor.administration.*;
2524
import com.predic8.membrane.core.interceptor.rest.*;
2625
import com.predic8.membrane.core.proxies.Proxy;
2726
import com.predic8.membrane.core.proxies.*;
27+
import com.predic8.membrane.core.router.*;
2828
import com.predic8.membrane.core.transport.http.*;
2929
import org.apache.commons.io.*;
3030
import org.json.*;

0 commit comments

Comments
 (0)