Skip to content

Commit

Permalink
fix for redirect URL when hostname contains context path (MID-6091)
Browse files Browse the repository at this point in the history
  • Loading branch information
skublik committed Mar 2, 2020
1 parent 333cc2c commit 0a3f79e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 13 deletions.
Expand Up @@ -59,14 +59,14 @@ public static class EmbeddedTomcat {
private int port;

@Value("${server.servlet.context-path}")
private String servletPath;
private String contextPath;

@Autowired
private SystemObjectCache systemObjectCache;

@Bean
public TomcatServletWebServerFactory tomcatEmbeddedServletContainerFactory() {
MidPointTomcatServletWebServerFactory tomcat = new MidPointTomcatServletWebServerFactory(servletPath, systemObjectCache);
MidPointTomcatServletWebServerFactory tomcat = new MidPointTomcatServletWebServerFactory(contextPath, systemObjectCache);

if(enableAjp) {
Connector ajpConnector = new Connector("AJP/1.3");
Expand Down
Expand Up @@ -41,12 +41,12 @@ public class MidPointTomcatServletWebServerFactory extends TomcatServletWebServe

private int backgroundProcessorDelay;

private String servletPath;
private String contextPath;

private SystemObjectCache systemObjectCache;

public MidPointTomcatServletWebServerFactory(String servletPath, SystemObjectCache systemObjectCache){
this.servletPath = servletPath;
public MidPointTomcatServletWebServerFactory(String contextPath, SystemObjectCache systemObjectCache){
this.contextPath = contextPath;
this.systemObjectCache = systemObjectCache;
}

Expand Down Expand Up @@ -94,9 +94,9 @@ public Response createResponse() {
if (protocolHandler instanceof AbstractAjpProtocol<?>) {
int packetSize = ((AbstractAjpProtocol<?>) protocolHandler).getPacketSize();
return new MidpointResponse(packetSize - org.apache.coyote.ajp.Constants.SEND_HEAD_LEN,
servletPath, systemObjectCache);
contextPath, systemObjectCache);
} else {
return new MidpointResponse(servletPath, systemObjectCache);
return new MidpointResponse(contextPath, systemObjectCache);
}
}
};
Expand Down
Expand Up @@ -28,17 +28,17 @@ public class MidpointResponse extends Response {

private static final Trace LOGGER = TraceManager.getTrace(MidpointResponse.class);

private String servletPath;
private String contextPath;
private SystemObjectCache systemObjectCache;

public MidpointResponse(String servletPath, SystemObjectCache systemObjectCache) {
this(OutputBuffer.DEFAULT_BUFFER_SIZE, servletPath, systemObjectCache);
}

public MidpointResponse(int outputBufferSize, String servletPath, SystemObjectCache systemObjectCache) {
public MidpointResponse(int outputBufferSize, String contextPath, SystemObjectCache systemObjectCache) {
super(outputBufferSize);

this.servletPath = servletPath;
this.contextPath = contextPath;
this.systemObjectCache = systemObjectCache;
}

Expand All @@ -49,15 +49,17 @@ public void setHeader(String name, String value) {
if (publicUrlPrefix != null && StringUtils.isNotBlank(value)) {
if (value.startsWith(".")) {
value = publicUrlPrefix + value.substring(1);
} else if (StringUtils.isBlank(servletPath)) {
} else if (StringUtils.isBlank(contextPath)) {
if (value.startsWith("/")) {
value = publicUrlPrefix + value;
} else {
String partAfterSchema = value.substring(value.indexOf("://") + 3);
value = publicUrlPrefix + partAfterSchema.substring(partAfterSchema.indexOf("/"));
}
} else if (value.contains(servletPath + "/")) {
value = publicUrlPrefix + value.substring(value.indexOf(servletPath) + servletPath.length());
} else if (value.contains(contextPath + "/")) {
String partAfterHostname = value.substring(value.indexOf("://") + 3);
partAfterHostname = partAfterHostname.substring(partAfterHostname.indexOf("/"));
value = publicUrlPrefix + partAfterHostname.substring(partAfterHostname.indexOf(contextPath) + contextPath.length());
}
}
}
Expand Down

0 comments on commit 0a3f79e

Please sign in to comment.