Skip to content

Commit

Permalink
[Misc] Make the XWiki 14.x functional docker tests work on Jetty 9.4.x
Browse files Browse the repository at this point in the history
  • Loading branch information
vmassol committed May 16, 2022
1 parent 1fde58b commit 00cf4eb
Show file tree
Hide file tree
Showing 2 changed files with 105 additions and 0 deletions.
Expand Up @@ -22,10 +22,14 @@
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.apache.commons.io.IOUtils;
import org.apache.maven.RepositoryUtils;
import org.apache.maven.model.Model;
import org.apache.maven.plugin.MojoExecutionException;
Expand Down Expand Up @@ -60,6 +64,8 @@ public class WARBuilder

private static final String JAR = "jar";

private static final Pattern MAJOR_VERSION = Pattern.compile("\\d+");

private ExtensionMojoHelper extensionHelper;

private ConfigurationFilesGenerator configurationFilesGenerator;
Expand Down Expand Up @@ -177,6 +183,10 @@ public void build() throws Exception
// Step: Unzip the Flamingo skin
unzipSkin(testConfiguration, skinDependencies, targetWARDirectory);

// In order to make XWiki work OOB in Jetty 9, we need to replace jetty-web.xml with an overridden
// version. TODO: Remove once we drop support for Jetty 9.
handleJetty9(webInfDirectory);

// Mark it as having been built successfully
touchMarkerFile();
}
Expand Down Expand Up @@ -341,4 +351,42 @@ private File getMarkerFile()
{
return new File(this.targetWARDirectory, "build.marker");
}

private void handleJetty9(File webInfDirectory) throws Exception
{
ServletEngine engine = this.testConfiguration.getServletEngine();
String tag = this.testConfiguration.getServletEngineTag();
if (engine == ServletEngine.JETTY && extractJettyVersionFromDockerTag(tag) < 10) {
// Override the jetty-web.xml
copyJettyWebFile(webInfDirectory);
}
}

private void copyJettyWebFile(File webInfDirectory) throws Exception
{
File outputFile = new File(webInfDirectory, "jetty-web.xml");
if (this.testConfiguration.isVerbose()) {
LOGGER.info("... Override jetty-web.xml since Jetty version is < 10");
}
try (FileOutputStream fos = new FileOutputStream(outputFile)) {
InputStream is = getClass().getClassLoader().getResourceAsStream("jetty9-web.xml");
IOUtils.copy(is, fos);
}
}

private int extractJettyVersionFromDockerTag(String tag)
{
int result = 10;
if (tag != null) {
Matcher matcher = MAJOR_VERSION.matcher(tag);
if (matcher.find()) {
try {
result = Integer.valueOf(matcher.group());
} catch (NumberFormatException e) {
// On error consider we're on Jetty 10
}
}
}
return result;
}
}
@@ -0,0 +1,57 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "https://www.eclipse.org/jetty/configure_9_0.dtd">

<!--
* See the NOTICE file distributed with this work for additional
* information regarding copyright ownership.
*
* This is free software; you can redistribute it and/or modify it
* under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation; either version 2.1 of
* the License, or (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this software; if not, write to the Free
* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
-->

<Configure class="org.eclipse.jetty.webapp.WebAppContext">
<!-- In order to avoid getting a "java.lang.IllegalStateException: Form too large" error when editing large page in
XWiki we need to tell Jetty to allow for large content since by default it only allows for 20K. We do this by
passing the "org.eclipse.jetty.server.Request.maxFormContentSize" attribute.
Note 1: Setting this value too high can leave your server vulnerable to denial of service attacks.
Note 2: We're setting it here instead of in Jetty's XML configuration files so that the XWiki WAR can be used
in any Jetty config and work out of the box.
-->
<Set name="maxFormContentSize">1000000</Set>
<!-- Increasing the maxFormKeys in order to be able to import correctly a full wiki (more than 1000 pages in 11.10).
The import should be fixed at a point to allow importing everything without creating a form with a field by page.
Once done this configuration can be removed. See https://jira.xwiki.org/browse/XWIKI-11597 for a follow up. -->
<Set name="maxFormKeys">2000</Set>

<!-- Tell jetty that javax.mail should be something that is invisible to the user, but if it's provided inside the
webapp use that instead (this is the case for XWiki). This is needed for work around issue
https://github.com/appropriate/docker-jetty/issues/108. Note that we don't have this problem in the XWiki
Standalone packaging since we create a custom distribution of Jetty and we don't include the Jetty "mail"
module. However we have the problem in our functional Docker-based tests where we use the official Jetty
image. -->
<!-- Note: In Jetty 10+ it's no longer necessary to have this hack. Once all the Jetty version we use are >= 10.0
then we'll be able to remove this file. -->
<Call name="getSystemClasspathPattern">
<Call name="add">
<Arg>-javax.mail.</Arg>
</Call>
</Call>
<Call name="getServerClasspathPattern">
<Call name="add">
<Arg>javax.mail.</Arg>
</Call>
</Call>

</Configure>

0 comments on commit 00cf4eb

Please sign in to comment.