I have a spring-boot 2.1.2.RELEASE application that uses embedded tomcat webserver and uses OpenKM via it's SDK.
Now, I have some integration tests that use restassured
lib to make REST calls and verify response structure. My idea is to integrate OpenKM.war
into this wmbedded tomcat and be able to run this tests without need to have openkm application running on some different server.
this is how I make embedded tomcat to read and deploy openkm.war:
@Configuration
public class TomcatConfig {
@Bean
public ServletWebServerFactory servletContainer() {
TomcatServletWebServerFactory tomcat = new TomcatServletWebServerFactory() {
@Override
protected void postProcessContext(Context context) {
SecurityConstraint securityConstraint = new SecurityConstraint();
securityConstraint.setUserConstraint("CONFIDENTIAL");
SecurityCollection collection = new SecurityCollection();
collection.addPattern("/*");
securityConstraint.addCollection(collection);
context.addConstraint(securityConstraint);
}
@Override
protected TomcatWebServer getTomcatWebServer(Tomcat tomcat) {
new File(tomcat.getServer().getCatalinaBase(), "webapp").mkdirs();
try {
tomcat.addWebapp("/okm", new ClassPathResource("webapp/openkm.war").getFile().toString());
} catch (Exception ex) {
throw new IllegalStateException("Failed to add okm", ex);
}
return super.getTomcatWebServer(tomcat);
}
};
tomcat.addAdditionalTomcatConnectors(redirectConnector());
return tomcat;
}
private Connector redirectConnector() {
Connector connector = new Connector("org.apache.coyote.http11.Http11NioProtocol");
connector.setScheme("http");
connector.setPort(8080);
connector.setSecure(false);
connector.setRedirectPort(8443);
return connector;
}
}
deploy takes way to longer than on the standalone tomcat webserver that is shipped with openkm, but it deploys.
However deployment process fails with:
IOException parsing XML document from URL [file:/tmp/tomcat.2352216859213135410.8080/openkm.xml]; nested exception is java.io.FileNotFoundException: /tmp/tomcat.2352216859213135410.8080/openkm.xml (No such file or directory)
I have this file (plus server.xml, context.xml) alongside openkm.war file, but it seems like embedded tomcat doesn't know about it.
All these files are located in src/main/resources/webapp
.
So, I would like to know what configuration piece am I missing or whether there is whole other better to achieve what I want?
tmp
dir and running your server? – Livengood