Skip to content

Commit

Permalink
fix(EMA): EMA: Fix #26111 proxyEditModeURL Query Param for Edit Mode …
Browse files Browse the repository at this point in the history
…Anywhere
  • Loading branch information
jcastro-dotcms committed Sep 19, 2023
1 parent aaa87a8 commit c36ebff
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions dotCMS/src/main/java/com/dotcms/ema/EMAWebInterceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@ public String[] getFilters() {

@Override
public Result intercept(final HttpServletRequest request, final HttpServletResponse response) {

final Host currentHost = WebAPILocator.getHostWebAPI().getCurrentHostNoThrow(request);

if (!this.existsConfiguration(currentHost.getIdentifier())) {
Expand All @@ -89,7 +88,8 @@ public boolean afterIntercept(final HttpServletRequest request, final HttpServle
if (response instanceof MockHttpCaptureResponse) {
final Optional<EMAConfigurationEntry> emaConfig = this.getEmaConfigByURL(currentSite, request.getRequestURI());
final Optional<String> proxyUrlOpt = emaConfig.map(EMAConfigurationEntry::getUrlEndpoint);
final String proxyUrl = proxyUrlOpt.orElse("[ EMPTY ]");
final String proxyUrl = getProxyURL(request).isPresent() ?
getProxyURL(request).get() : proxyUrlOpt.orElse("[ EMPTY ]");
final MockHttpCaptureResponse mockResponse = (MockHttpCaptureResponse)response;
final String postJson = new String(mockResponse.getBytes());
final String authToken =
Expand All @@ -107,7 +107,7 @@ public boolean afterIntercept(final HttpServletRequest request, final HttpServle
this.sendHttpResponse(this.generateErrorPage("Unable to connect with the rendering engine",
proxyUrl, pResponse), postJson, response);
} else {
this.sendHttpResponse(new String(pResponse.getResponse(), StandardCharsets.UTF_8.name()), postJson, response);
this.sendHttpResponse(new String(pResponse.getResponse(), StandardCharsets.UTF_8), postJson, response);
}
}
} catch (final Exception e) {
Expand Down Expand Up @@ -164,10 +164,8 @@ private boolean existsConfiguration(final String hostId) {
* @return An Optional with the overridden Proxy URL, if present.
*/
protected Optional<String> getProxyURL (final HttpServletRequest request) {

Optional<String> proxyURL = Optional.empty();
if (null != request.getParameter(PROXY_EDIT_MODE_URL_VAR)) {

final String proxyURLParamValue = request.getParameter(PROXY_EDIT_MODE_URL_VAR);
proxyURL = UtilMethods.isSet(proxyURLParamValue)?Optional.of(proxyURLParamValue):Optional.empty();
if (null != request.getSession(false)) {
Expand All @@ -179,10 +177,8 @@ protected Optional<String> getProxyURL (final HttpServletRequest request) {
}
} else if (null != request.getSession(false) &&
UtilMethods.isSet(request.getSession(false).getAttribute(PROXY_EDIT_MODE_URL_VAR))) {

proxyURL = Optional.ofNullable(request.getSession(false).getAttribute(PROXY_EDIT_MODE_URL_VAR).toString());
}

return proxyURL;
}

Expand Down

0 comments on commit c36ebff

Please sign in to comment.