Skip to content

Commit e7eb3b5

Browse files
authored
Refactor remove proxy aware (#2884)
* Remove `ProxyAware` interface and clean up related logic - Eliminated `ProxyAware` interface, simplifying codebase and reducing unused complexity. - Updated `AbstractInterceptor`, `Interceptor`, and related implementations to directly manage proxy references via `getProxy()` and `init()`. - Refactored interceptors to remove unused `Proxy` fields and redundant `setProxy()` methods. - Adjusted roadmap to reflect removal of `ProxyAware` and associated refactoring tasks. * Remove unused fields, imports, and listeners in core classes - Simplified `AbstractFlowInterceptor`, `OAuth2AuthorizationServerInterceptor`, `WebServiceExplorerInterceptor`, and `RuleManager` by removing unused fields, imports, and redundant logic. - Cleaned up code to improve maintainability and readability across core interceptor and proxy-related classes. * Update proxy handling in interceptors and add tests for AbstractFlowInterceptor - Improved proxy initialization in `AbstractInterceptor` and `AbstractFlowInterceptor` to ensure consistent propagation. - Updated `init()` logic to handle `proxy` references appropriately across interceptors. - Added `AbstractFlowInterceptorTest` to validate proxy propagation and router integration. - Minor corrections in `ROADMAP.md` and cleanup of unused fields. * Update `AbstractFlowInterceptorTest` to validate propagation of proxy and router - Renamed test method for clarity and updated logic to use `setFlow` with `List.of`. - Verified proper initialization of nested interceptors with proxy and router.
1 parent eed215a commit e7eb3b5

12 files changed

Lines changed: 59 additions & 160 deletions

File tree

core/src/main/java/com/predic8/membrane/core/config/ProxyAware.java

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

core/src/main/java/com/predic8/membrane/core/interceptor/AbstractInterceptor.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,12 @@ public class AbstractInterceptor implements Interceptor {
3333

3434
protected Router router;
3535

36+
/**
37+
* The proxy where this interceptor is attached to, no matter how deep in
38+
* nested interceptors it is.
39+
*/
40+
protected Proxy proxy;
41+
3642
public AbstractInterceptor() {
3743
super();
3844
}
@@ -105,14 +111,19 @@ public final void init(Router router) {
105111
}
106112

107113
@Override
108-
public void init(Router router, Proxy ignored) {
114+
public void init(Router router, Proxy proxy) {
115+
this.proxy = proxy;
109116
init(router);
110117
}
111118

112119
public Router getRouter() { //wird von ReadRulesConfigurationTest aufgerufen.
113120
return router;
114121
}
115122

123+
public Proxy getProxy() {
124+
return proxy;
125+
}
126+
116127
public FlowController getFlowController() {
117128
return router.getFlowController();
118129
}

core/src/main/java/com/predic8/membrane/core/interceptor/Interceptor.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ public boolean isAbort() {
7575

7676
Router getRouter();
7777

78+
/**
79+
* The proxy where this interceptor is attached to, no matter how deep in
80+
* nested interceptors it is.
81+
*/
82+
Proxy getProxy();
83+
7884
void setAppliedFlow(EnumSet<Flow> flow);
7985
EnumSet<Flow> getAppliedFlow();
8086

core/src/main/java/com/predic8/membrane/core/interceptor/authentication/session/LoginInterceptor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,12 +14,10 @@
1414
package com.predic8.membrane.core.interceptor.authentication.session;
1515

1616
import com.predic8.membrane.annot.*;
17-
import com.predic8.membrane.core.config.ProxyAware;
1817
import com.predic8.membrane.core.exchange.*;
1918
import com.predic8.membrane.core.http.*;
2019
import com.predic8.membrane.core.interceptor.*;
2120
import com.predic8.membrane.core.interceptor.authentication.session.SessionManager.*;
22-
import com.predic8.membrane.core.proxies.Proxy;
2321
import com.predic8.membrane.core.util.*;
2422
import org.slf4j.*;
2523

@@ -94,7 +92,7 @@
9492
* @topic 3. Security and Validation
9593
*/
9694
@MCElement(name="login")
97-
public class LoginInterceptor extends AbstractInterceptor implements ProxyAware {
95+
public class LoginInterceptor extends AbstractInterceptor {
9896

9997
private static final Logger log = LoggerFactory.getLogger(LoginInterceptor.class.getName());
10098

@@ -106,7 +104,6 @@ public class LoginInterceptor extends AbstractInterceptor implements ProxyAware
106104
private SessionManager sessionManager;
107105
private AccountBlocker accountBlocker;
108106
private LoginDialog loginDialog;
109-
private Proxy proxy;
110107

111108
@Override
112109
public void init() {
@@ -298,9 +295,4 @@ public void setMessage(String message) {
298295
public String getDisplayName() {
299296
return "login";
300297
}
301-
302-
@Override
303-
public void setProxy(Proxy proxy) {
304-
this.proxy = proxy;
305-
}
306298
}

core/src/main/java/com/predic8/membrane/core/interceptor/flow/AbstractFlowInterceptor.java

Lines changed: 6 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,13 @@
1414

1515
package com.predic8.membrane.core.interceptor.flow;
1616

17-
import com.predic8.membrane.core.config.ProxyAware;
18-
import com.predic8.membrane.core.exchange.Exchange;
19-
import com.predic8.membrane.core.interceptor.AbstractInterceptor;
20-
import com.predic8.membrane.core.interceptor.Interceptor;
21-
import com.predic8.membrane.core.proxies.Proxy;
22-
import com.predic8.membrane.core.router.*;
23-
import org.slf4j.Logger;
24-
import org.slf4j.LoggerFactory;
17+
import com.predic8.membrane.core.exchange.*;
18+
import com.predic8.membrane.core.interceptor.*;
19+
import org.slf4j.*;
2520

26-
import java.util.ArrayList;
27-
import java.util.List;
21+
import java.util.*;
2822

29-
import static com.predic8.membrane.core.exceptions.ProblemDetails.internal;
23+
import static com.predic8.membrane.core.exceptions.ProblemDetails.*;
3024

3125
public abstract class AbstractFlowInterceptor extends AbstractInterceptor {
3226

@@ -46,7 +40,7 @@ public void setFlow(List<Interceptor> flow) {
4640
public void init() {
4741
super.init();
4842
for (Interceptor i : interceptors)
49-
i.init(router);
43+
i.init(router,proxy);
5044
}
5145

5246
protected static void createProblemDetails(String flow, Interceptor interceptor, Exchange exc, Exception e) {
@@ -58,14 +52,4 @@ protected static void createProblemDetails(String flow, Interceptor interceptor,
5852
.exception(e)
5953
.buildAndSetResponse(exc);
6054
}
61-
62-
@Override
63-
public void init(Router router, Proxy proxy) {
64-
for (Interceptor i : interceptors) {
65-
if(i instanceof ProxyAware pa) {
66-
pa.setProxy(proxy);
67-
}
68-
}
69-
init(router);
70-
}
7155
}

core/src/main/java/com/predic8/membrane/core/interceptor/groovy/GroovyInterceptor.java

Lines changed: 2 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -15,10 +15,8 @@
1515
package com.predic8.membrane.core.interceptor.groovy;
1616

1717
import com.predic8.membrane.annot.*;
18-
import com.predic8.membrane.core.config.ProxyAware;
1918
import com.predic8.membrane.core.lang.*;
2019
import com.predic8.membrane.core.lang.groovy.*;
21-
import com.predic8.membrane.core.proxies.Proxy;
2220
import com.predic8.membrane.core.util.ConfigurationException;
2321
import org.codehaus.groovy.control.*;
2422
import org.codehaus.groovy.control.messages.*;
@@ -38,16 +36,14 @@
3836
* @topic 2. Enterprise Integration Patterns
3937
*/
4038
@MCElement(name = "groovy", mixed = true)
41-
public class GroovyInterceptor extends AbstractScriptInterceptor implements ProxyAware {
39+
public class GroovyInterceptor extends AbstractScriptInterceptor {
4240

4341
private static final Logger log = LoggerFactory.getLogger(GroovyInterceptor.class);
4442

4543
public GroovyInterceptor() {
4644
name = "groovy";
4745
}
4846

49-
private Proxy proxy;
50-
5147
@Override
5248
public EnumSet<Flow> getAppliedFlow() {
5349
return REQUEST_RESPONSE_ABORT_FLOW;
@@ -64,7 +60,7 @@ protected void initInternal() {
6460
}
6561

6662
private void logGroovyError(MultipleCompilationErrorsException e) {
67-
log.error("Error in Groovy script in API '{}' with source: {}", proxy.getName(), src);
63+
log.error("Error in Groovy script: {}", src);
6864
for(Message error : e.getErrorCollector().getErrors()) {
6965
ByteArrayOutputStream bais = new ByteArrayOutputStream();
7066
PrintWriter pw = new PrintWriter(bais);
@@ -83,10 +79,4 @@ public String getShortDescription() {
8379
public String getLongDescription() {
8480
return "%s:<br/><pre style=\"overflow-x:auto\">%s</pre>".formatted(removeFinalChar(getShortDescription()), escapeHtml4(src.stripIndent()));
8581
}
86-
87-
@Override
88-
public void setProxy(Proxy proxy) {
89-
this.proxy = proxy;
90-
}
91-
9282
}

core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/OAuth2AuthorizationServerInterceptor.java

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package com.predic8.membrane.core.interceptor.oauth2;
1515

1616
import com.predic8.membrane.annot.*;
17-
import com.predic8.membrane.core.config.ProxyAware;
1817
import com.predic8.membrane.core.exchange.*;
1918
import com.predic8.membrane.core.interceptor.*;
2019
import com.predic8.membrane.core.interceptor.authentication.session.*;
@@ -44,7 +43,7 @@
4443
*/
4544
@SuppressWarnings("LoggingSimilarMessage")
4645
@MCElement(name = "oauth2authserver")
47-
public class OAuth2AuthorizationServerInterceptor extends AbstractInterceptor implements ProxyAware {
46+
public class OAuth2AuthorizationServerInterceptor extends AbstractInterceptor {
4847
private static final Logger log = LoggerFactory.getLogger(OAuth2AuthorizationServerInterceptor.class.getName());
4948
public static final Set<@NotNull String> SUPPORTED_AUTHORIZATION_GRANTS = Set.of("code", "token", "id_token token");
5049

@@ -77,8 +76,6 @@ public class OAuth2AuthorizationServerInterceptor extends AbstractInterceptor im
7776
private WellknownFile wellknownFile = new WellknownFile();
7877
private ConsentPageFile consentPageFile = new ConsentPageFile();
7978

80-
private Proxy proxy;
81-
8279
@Override
8380
public void init() {
8481
super.init();
@@ -440,9 +437,4 @@ public String computeBasePath() {
440437
public String getBasePath() {
441438
return basePath;
442439
}
443-
444-
@Override
445-
public void setProxy(Proxy proxy) {
446-
this.proxy = proxy;
447-
}
448440
}

core/src/main/java/com/predic8/membrane/core/interceptor/soap/WebServiceExplorerInterceptor.java

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,11 @@
1515

1616
import com.googlecode.jatl.*;
1717
import com.predic8.membrane.annot.*;
18-
import com.predic8.membrane.core.config.*;
1918
import com.predic8.membrane.core.exchange.*;
2019
import com.predic8.membrane.core.http.*;
2120
import com.predic8.membrane.core.interceptor.*;
2221
import com.predic8.membrane.core.interceptor.administration.*;
2322
import com.predic8.membrane.core.interceptor.rest.*;
24-
import com.predic8.membrane.core.proxies.Proxy;
2523
import com.predic8.membrane.core.util.wsdl.parser.*;
2624
import org.slf4j.*;
2725

@@ -39,7 +37,7 @@
3937
* @description Serves an HTML “web service explorer”.
4038
*/
4139
@MCElement(name="webServiceExplorer")
42-
public class WebServiceExplorerInterceptor extends RESTInterceptor implements ProxyAware {
40+
public class WebServiceExplorerInterceptor extends RESTInterceptor {
4341

4442
private static final Logger log = LoggerFactory.getLogger(WebServiceExplorerInterceptor.class);
4543

@@ -48,11 +46,6 @@ public class WebServiceExplorerInterceptor extends RESTInterceptor implements Pr
4846
private String wsdl;
4947
private String portName;
5048

51-
/**
52-
* Field is accessed by reflection
53-
*/
54-
private Proxy proxy;
55-
5649
public WebServiceExplorerInterceptor() {
5750
name = "web service explorer";
5851
}
@@ -247,9 +240,4 @@ public StandardPage(Writer writer, String title) {
247240
public String getShortDescription() {
248241
return "Displays a graphical UI describing the web service when accessed using GET requests.";
249242
}
250-
251-
@Override
252-
public void setProxy(Proxy proxy) {
253-
this.proxy = proxy;
254-
}
255243
}

core/src/main/java/com/predic8/membrane/core/proxies/AbstractProxy.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
package com.predic8.membrane.core.proxies;
1515

1616
import com.predic8.membrane.annot.*;
17-
import com.predic8.membrane.core.config.ProxyAware;
1817
import com.predic8.membrane.core.interceptor.*;
1918
import com.predic8.membrane.core.router.*;
2019
import com.predic8.membrane.core.stats.*;
@@ -90,10 +89,7 @@ public final void init(Router router) {
9089
this.router = router;
9190
try {
9291
init(); // Extension point for subclasses
93-
for (Interceptor i : interceptors) {
94-
if(i instanceof ProxyAware pa) {
95-
pa.setProxy(this);
96-
}
92+
for (var i : interceptors) {
9793
i.init(router, this);
9894
}
9995
active = true;

0 commit comments

Comments
 (0)