Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Spring boot redirect / -> /midpoint/ (MID-4486)
- Loading branch information
Showing
5 changed files
with
194 additions
and
0 deletions.
There are no files selected for viewing
61 changes: 61 additions & 0 deletions
61
...min-gui/src/main/java/com/evolveum/midpoint/web/boot/EmbeddedTomcatAutoConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
/** | ||
* Copyright (c) 2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.web.boot; | ||
|
||
import javax.servlet.Servlet; | ||
|
||
import org.apache.catalina.startup.Tomcat; | ||
import org.springframework.boot.autoconfigure.AutoConfigureOrder; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean; | ||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication; | ||
import org.springframework.boot.autoconfigure.condition.SearchStrategy; | ||
import org.springframework.boot.autoconfigure.web.EmbeddedServletContainerAutoConfiguration.BeanPostProcessorsRegistrar; | ||
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory; | ||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.context.annotation.Import; | ||
import org.springframework.core.Ordered; | ||
|
||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
/** | ||
* @author semancik | ||
* | ||
*/ | ||
@AutoConfigureOrder(Ordered.HIGHEST_PRECEDENCE) | ||
@Configuration | ||
@ConditionalOnWebApplication | ||
@Import(BeanPostProcessorsRegistrar.class) | ||
public class EmbeddedTomcatAutoConfiguration { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(EmbeddedTomcatAutoConfiguration.class); | ||
|
||
@Configuration | ||
@ConditionalOnClass({ Servlet.class, Tomcat.class }) | ||
@ConditionalOnMissingBean(value = EmbeddedServletContainerFactory.class, search = SearchStrategy.CURRENT) | ||
public static class EmbeddedTomcat { | ||
|
||
@Bean | ||
public TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory() { | ||
return new MidPointTomcatEmbeddedServletContainerFactory(); | ||
} | ||
|
||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
...in/java/com/evolveum/midpoint/web/boot/MidPointTomcatEmbeddedServletContainerFactory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
/** | ||
11 * Copyright (c) 2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.web.boot; | ||
|
||
import org.apache.catalina.startup.Tomcat; | ||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainer; | ||
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory; | ||
|
||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
/** | ||
* @author semancik | ||
* | ||
*/ | ||
public class MidPointTomcatEmbeddedServletContainerFactory extends TomcatEmbeddedServletContainerFactory { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(MidPointTomcatEmbeddedServletContainerFactory.class); | ||
|
||
@Override | ||
protected TomcatEmbeddedServletContainer getTomcatEmbeddedServletContainer(Tomcat tomcat) { | ||
|
||
// TODO: doc | ||
|
||
RootRootContext rootRootContext = new RootRootContext(); | ||
tomcat.getHost().addChild(rootRootContext); | ||
|
||
return super.getTomcatEmbeddedServletContainer(tomcat); | ||
} | ||
|
||
|
||
|
||
} |
40 changes: 40 additions & 0 deletions
40
gui/admin-gui/src/main/java/com/evolveum/midpoint/web/boot/RootRootContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Copyright (c) 2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.web.boot; | ||
|
||
import org.apache.catalina.LifecycleException; | ||
import org.apache.catalina.core.StandardContext; | ||
|
||
/** | ||
* Fake root context | ||
* @author semancik | ||
*/ | ||
public class RootRootContext extends StandardContext { | ||
|
||
public RootRootContext() { | ||
super(); | ||
setPath(""); | ||
setDisplayName("RootRoot"); | ||
} | ||
|
||
// HAck | ||
@Override | ||
public void resourcesStart() throws LifecycleException { | ||
super.resourcesStart(); | ||
setConfigured(true); | ||
} | ||
|
||
} |
47 changes: 47 additions & 0 deletions
47
gui/admin-gui/src/main/java/com/evolveum/midpoint/web/boot/TomcatRootValve.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
/* | ||
* Copyright (c) 2018 Evolveum | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
package com.evolveum.midpoint.web.boot; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.servlet.ServletException; | ||
|
||
import org.apache.catalina.Context; | ||
import org.apache.catalina.connector.Request; | ||
import org.apache.catalina.connector.Response; | ||
import org.apache.catalina.valves.ValveBase; | ||
|
||
import com.evolveum.midpoint.util.logging.Trace; | ||
import com.evolveum.midpoint.util.logging.TraceManager; | ||
|
||
public class TomcatRootValve extends ValveBase { | ||
|
||
private static final Trace LOGGER = TraceManager.getTrace(TomcatRootValve.class); | ||
|
||
@Override | ||
public void invoke(Request request, Response response) throws IOException, ServletException { | ||
|
||
Context context = request.getContext(); | ||
if (context instanceof RootRootContext) { | ||
LOGGER.trace("Redirecting {} to real application root", request.getContextPath()); | ||
response.sendRedirect("/midpoint"); | ||
return; | ||
} | ||
|
||
getNext().invoke(request, response); | ||
} | ||
|
||
} |
Binary file not shown.