Skip to content

Commit db0d8f8

Browse files
Rename getRequestURI() to getOriginalRelativeURI() (#2625)
* test infra (wip) * wip * finish xml test * simplify tests * add XmlProtectionTutorialTest * add Json TutorialTests * feat(xml-protection): set HTTP status codes for error responses - Added explicit status codes (500, 415, 400) for error responses in `XMLProtectionInterceptor` to improve clarity and alignment with HTTP standards. * refactor(core): remove `URLNormalizerInterceptor` and replace `getRequestURI` with `getUri` for improved URI handling - Completely removed the unused `URLNormalizerInterceptor`. - Updated multiple classes to replace deprecated `getRequestURI` with `getUri` or `getOriginalRelativeURI` for improved readability and consistency in URI handling. - Added `getOriginalRelativeURI` method in `Exchange` class to encapsulate original relative URI logic. * refactor(core): rename `getRequestURI` to `getOriginalRelativeURI` and remove redundant method - Updated `Exchange` class to replace `getRequestURI` with `getOriginalRelativeURI` for improved naming consistency. - Removed redundant `getOriginalRelativeURI` implementation that relied on `getRequestURI`. * update to use `getOriginalRelativeURI()` instead of `getRequestURI()` across core and test classes * test(core): simplify `getOpenapiValidatorRequestFromExchange` test setup - Refactored test to use utility methods for cleaner and more concise setup. - Replaced manual request creation with `post` method and static constants for improved readability. * test(core): clean up imports and fix formatting in `UtilsTest` - Removed unused imports for better readability. - Standardized formatting to improve code consistency across `UtilsTest`. * test(core): add suppression for empty try block warning in `UtilsTest` - Added `//noinspection EmptyTryBlock` to silence warnings for intentionally empty try block in `getResourceAsStreamInvalidResource` test. --------- Co-authored-by: Thomas Bayer <bayer@predic8.de>
1 parent 9be1b74 commit db0d8f8

35 files changed

Lines changed: 96 additions & 150 deletions

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

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,19 +14,17 @@
1414

1515
package com.predic8.membrane.core.exchange;
1616

17-
import com.predic8.membrane.core.*;
1817
import com.predic8.membrane.core.http.*;
19-
import com.predic8.membrane.core.proxies.Proxy;
2018
import com.predic8.membrane.core.proxies.*;
19+
import com.predic8.membrane.core.proxies.Proxy;
2120
import com.predic8.membrane.core.transport.http.*;
2221
import com.predic8.membrane.core.util.*;
2322
import org.slf4j.*;
2423

2524
import java.net.*;
2625
import java.util.*;
2726

28-
import static java.lang.Boolean.TRUE;
29-
import static java.util.stream.Collectors.toMap;
27+
import static java.util.stream.Collectors.*;
3028

3129
public class Exchange extends AbstractExchange {
3230

@@ -125,7 +123,7 @@ public void collectStatistics() {
125123
* <p>
126124
* To be used, for example, when generating self-referring web pages.
127125
*/
128-
public String getRequestURI() {
126+
public String getOriginalRelativeURI() {
129127
if (HttpUtil.isAbsoluteURI(getOriginalRequestUri())) {
130128
try {
131129
return new URL(getOriginalRequestUri()).getFile();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ public Outcome handleRequest(Exchange exc) {
8080
}
8181

8282
private static @NotNull String getMessageForURISyntaxException(Exchange exc, URISyntaxException e) {
83-
var uri = exc.getRequestURI();
83+
var uri = exc.getOriginalRelativeURI();
8484
if (e.getIndex() >= 0 && e.getIndex() < uri.length()) {
8585
return "The request path contains an invalid character '%s' at pos %d".formatted(uri.charAt(e.getIndex()), e.getIndex());
8686
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public Outcome handleResponse(Exchange exc) {
5959
log.error("",e);
6060
internal(router.getConfiguration().isProduction(),getDisplayName())
6161
.detail("Error rewriting URI")
62-
.topLevel("URI", exc.getRequestURI())
62+
.topLevel("URI", exc.getOriginalRelativeURI())
6363
.exception(e)
6464
.buildAndSetResponse(exc);
6565
return ABORT;

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

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

core/src/main/java/com/predic8/membrane/core/interceptor/acl/AccessControlInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public Outcome handleRequest(Exchange exc) {
6767
String remoteIp = exc.getRemoteAddrIp();
6868
if (!accessControl.isPermitted(remoteIp)) {
6969
setResponseToAccessDenied(exc);
70-
log.debug("Access denied. remoteIp={} method={} uri={}", remoteIp, exc.getRequest().getMethod(), exc.getRequestURI());
70+
log.debug("Access denied. remoteIp={} method={} uri={}", remoteIp, exc.getRequest().getMethod(), exc.getOriginalRelativeURI());
7171
return ABORT;
7272
}
7373
return CONTINUE;

core/src/main/java/com/predic8/membrane/core/interceptor/adminapi/AdminApiInterceptor.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public void init() {
7777
@Override
7878
public Outcome handleRequest(Exchange exc) {
7979
try {
80-
String uri = exc.getRequestURI();
80+
String uri = exc.getRequest().getUri();
8181
if (uri.matches(".*/health.*")) {
8282
return handleHealth(exc);
8383
} else if (uri.matches(".*/apis.*")) {
@@ -242,7 +242,7 @@ private void writePluginRow(List<Interceptor> plugins, Flow limitedFlow, JsonGen
242242
private Outcome handleCalls(Exchange exc) {
243243
ExchangeQueryResult res;
244244
try {
245-
QueryParameter qp = new QueryParameter(queryToParameters(new URI(exc.getRequestURI()).getQuery()), null);
245+
QueryParameter qp = new QueryParameter(queryToParameters(new URI(exc.getRequest().getUri()).getQuery()), null);
246246
res = getRouter().getExchangeStore().getFilteredSortedPaged(qp, false);
247247

248248
StringWriter writer = new StringWriter();

core/src/main/java/com/predic8/membrane/core/interceptor/apikey/ApiKeysInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ public void init() {
108108
public Outcome handleRequest(Exchange exc) {
109109
var key = getKey(exc);
110110
if (required && key.isEmpty()) {
111-
log.warn("Tried access apiKey protected resource without key. Uri: {}", exc.getRequestURI());
111+
log.warn("Tried access apiKey protected resource without key. Uri: {}", exc.getOriginalRelativeURI());
112112
security(false, getDisplayName())
113113
.title(TITLE_4XX)
114114
.status(401)

core/src/main/java/com/predic8/membrane/core/interceptor/ntlm/NtlmInterceptor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ private String getT2Payload(Exchange resT1) {
137137
}
138138

139139
private String buildRequestUrl(Exchange exc) {
140-
return (exc.getTargetConnection().getSslProvider() != null ? "https" : "http") + "://" + exc.getRequest().getHeader().getHost() + exc.getRequestURI();
140+
return (exc.getTargetConnection().getSslProvider() != null ? "https" : "http") + "://" + exc.getRequest().getHeader().getHost() + exc.getOriginalRelativeURI();
141141
}
142142

143143
private void prepareStreamByEmptyingIt(Exchange exc) {

core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/flows/CodeFlow.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ protected Outcome respondWithAuthorizationCodeAndRedirect(Exchange exc, String c
4747
String state = null;
4848
String redirectUrl;
4949

50-
String rawQuery = URLUtil.getPathQuery(authServer.getRouter().getConfiguration().getUriFactory(),exc.getRequestURI());
50+
String rawQuery = URLUtil.getPathQuery(authServer.getRouter().getConfiguration().getUriFactory(),exc.getOriginalRelativeURI());
5151
if(rawQuery.startsWith(authServer.getBasePath() + "/"))
5252
rawQuery = rawQuery.substring(authServer.getBasePath().length() + 1);
5353
if(rawQuery.startsWith("?"))

core/src/main/java/com/predic8/membrane/core/interceptor/oauth2/processors/AuthEndpointProcessor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ public AuthEndpointProcessor(OAuth2AuthorizationServerInterceptor authServer) {
3434

3535
@Override
3636
public boolean isResponsible(Exchange exc) {
37-
return exc.getRequestURI().startsWith(authServer.getBasePath() + "/oauth2/auth") && !authServer.isLoginViewDisabled();
37+
return exc.getOriginalRelativeURI().startsWith(authServer.getBasePath() + "/oauth2/auth") && !authServer.isLoginViewDisabled();
3838
}
3939

4040
@Override

0 commit comments

Comments
 (0)