Issue #11709 fix jetty-with-custom-class.xml file and use it (#11716)

* Issue #11709 fix jetty-with-custom-class.xml file and use it
This commit is contained in:
Jan Bartel 2024-05-03 04:14:46 +02:00 committed by GitHub
parent c5b2533fde
commit b11d1cb27f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 143 additions and 46 deletions

View File

@ -22,6 +22,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Objects; import java.util.Objects;
import java.util.Optional;
import java.util.StringTokenizer; import java.util.StringTokenizer;
import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.AppLifeCycle;
@ -195,13 +196,14 @@ public class JettyServerFactory
private static DeploymentManager ensureDeploymentManager(Server server) private static DeploymentManager ensureDeploymentManager(Server server)
{ {
Collection<DeploymentManager> deployers = server.getBeans(DeploymentManager.class); Collection<DeploymentManager> deployers = server.getBeans(DeploymentManager.class);
DeploymentManager deploymentManager; DeploymentManager deploymentManager = null;
if (deployers != null) if (deployers != null)
{ {
deploymentManager = deployers.stream().findFirst().get(); deploymentManager = deployers.stream().findFirst().orElse(null);
} }
else
if (deploymentManager == null)
{ {
deploymentManager = new DeploymentManager(); deploymentManager = new DeploymentManager();
deploymentManager.setContexts(getContextHandlerCollection(server)); deploymentManager.setContexts(getContextHandlerCollection(server));

View File

@ -42,6 +42,10 @@
</exclusion> </exclusion>
</exclusions> </exclusions>
</dependency> </dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId> <groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>jetty-ee10-demo-mock-resources</artifactId> <artifactId>jetty-ee10-demo-mock-resources</artifactId>
@ -263,18 +267,6 @@
<artifactId>jetty-alpn-server</artifactId> <artifactId>jetty-alpn-server</artifactId>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<!--
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<scope>test</scope>
</dependency>
-->
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>org.eclipse.jetty.ee10.demos</groupId> <groupId>org.eclipse.jetty.ee10.demos</groupId>
<artifactId>jetty-ee10-demo-container-initializer</artifactId> <artifactId>jetty-ee10-demo-container-initializer</artifactId>
@ -539,6 +531,8 @@
<systemPropertyVariables> <systemPropertyVariables>
<mavenRepoPath>${session.repositorySession.localRepository.basedir.absolutePath}</mavenRepoPath> <mavenRepoPath>${session.repositorySession.localRepository.basedir.absolutePath}</mavenRepoPath>
<settingsFilePath>${env.GLOBAL_MVN_SETTINGS}</settingsFilePath> <settingsFilePath>${env.GLOBAL_MVN_SETTINGS}</settingsFilePath>
<!-- uncomment to be able to use jetty logging -->
<!-- pax.exam.system>default</pax.exam.system -->
</systemPropertyVariables> </systemPropertyVariables>
<argLine>-Dconscrypt-version=${conscrypt.version}</argLine> <argLine>-Dconscrypt-version=${conscrypt.version}</argLine>
<!-- TODO --> <!-- TODO -->

View File

@ -67,10 +67,9 @@
<Item>org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration</Item> <Item>org.eclipse.jetty.ee10.plus.webapp.PlusConfiguration</Item>
<Item>org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration</Item> <Item>org.eclipse.jetty.ee10.plus.webapp.EnvConfiguration</Item>
<Item>org.eclipse.jetty.ee10.webapp.JmxConfiguration</Item> <Item>org.eclipse.jetty.ee10.webapp.JmxConfiguration</Item>
<Item>config.org.eclipse.jetty.ee10.websocket.server.JettyWebSocketConfiguration</Item> <Item>org.eclipse.jetty.ee10.websocket.server.config.JettyWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketConfiguration</Item> <Item>org.eclipse.jetty.ee10.websocket.jakarta.server.config.JakartaWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.ee10.osgi.annotations.AnnotationConfiguration</Item> <Item>org.eclipse.jetty.ee10.osgi.annotations.AnnotationConfiguration</Item>
<Item>org.eclipse.jetty.ee10.osgi.boot.OSGiWebInfConfiguration</Item>
<Item>org.eclipse.jetty.ee10.osgi.boot.OSGiMetaInfConfiguration</Item> <Item>org.eclipse.jetty.ee10.osgi.boot.OSGiMetaInfConfiguration</Item>
</Array> </Array>
</Arg> </Arg>

View File

@ -0,0 +1,123 @@
//
// ========================================================================
// Copyright (c) 1995 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under the
// terms of the Eclipse Public License v. 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0, or the Apache License, Version 2.0
// which is available at https://www.apache.org/licenses/LICENSE-2.0.
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty.ee10.osgi.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import javax.inject.Inject;
import org.eclipse.jetty.client.ContentResponse;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.osgi.OSGiServerConstants;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.ops4j.pax.exam.Configuration;
import org.ops4j.pax.exam.CoreOptions;
import org.ops4j.pax.exam.Option;
import org.ops4j.pax.exam.junit.PaxExam;
import org.ops4j.pax.tinybundles.core.TinyBundle;
import org.ops4j.pax.tinybundles.core.TinyBundles;
import org.osgi.framework.BundleContext;
import org.osgi.framework.Constants;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.ops4j.pax.exam.CoreOptions.mavenBundle;
import static org.ops4j.pax.exam.CoreOptions.systemProperty;
/**
* TestJettyOSGiBootWithBundle
*
* Tests reading config from a bundle and loading classes from it
*
* Tests the ServiceContextProvider.
*/
@RunWith(PaxExam.class)
public class TestJettyOSGiBootWithBundle
{
private static final String TEST_JETTY_HOME_BUNDLE = "test-jetty-xml-bundle";
@Inject
BundleContext bundleContext = null;
@Configuration
public static Option[] configure() throws IOException
{
ArrayList<Option> options = new ArrayList<>();
options.addAll(TestOSGiUtil.configurePaxExamLogging());
options.add(TestOSGiUtil.optionalRemoteDebug());
options.add(CoreOptions.junitBundles());
options.addAll(configureJettyHomeAndPort());
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res", "com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects"));
TestOSGiUtil.coreJettyDependencies(options);
TestOSGiUtil.coreJspDependencies(options);
options.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-alpn-java-client").versionAsInProject().start());
options.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-alpn-client").versionAsInProject().start());
//back down version of bnd used here because tinybundles expects only this version
options.add(mavenBundle().groupId("biz.aQute.bnd").artifactId("biz.aQute.bndlib").version("3.5.0").start());
options.add(mavenBundle().groupId("org.ops4j.pax.tinybundles").artifactId("tinybundles").versionAsInProject().start());
TinyBundle bundle = TinyBundles.bundle();
bundle.add(SomeCustomBean.class);
bundle.set(Constants.BUNDLE_SYMBOLICNAME, TEST_JETTY_HOME_BUNDLE);
File etcFolder = new File("src/test/config/etc");
bundle.add("jettyhome/etc/jetty-http-boot-with-bundle.xml", new FileInputStream(new File(etcFolder, "jetty-http-boot-with-bundle.xml")));
bundle.add("jettyhome/etc/jetty-with-custom-class.xml", new FileInputStream(new File(etcFolder, "jetty-with-custom-class.xml")));
options.add(CoreOptions.streamBundle(bundle.build()).startLevel(1));
options.add(CoreOptions.cleanCaches(true));
return options.toArray(new Option[0]);
}
public static List<Option> configureJettyHomeAndPort()
{
List<Option> options = new ArrayList<>();
options.add(systemProperty(OSGiServerConstants.MANAGED_JETTY_XML_CONFIG_URLS).value("etc/jetty-with-custom-class.xml,etc/jetty-http-boot-with-bundle.xml"));
options.add(systemProperty("jetty.http.port").value("0"));
// TODO: FIXME: options.add(systemProperty("jetty.ssl.port").value(String.valueOf(TestOSGiUtil.DEFAULT_SSL_PORT)));
options.add(systemProperty("jetty.home.bundle").value(TEST_JETTY_HOME_BUNDLE));
return options;
}
@Test
public void testContextHandler() throws Exception
{
if (Boolean.getBoolean(TestOSGiUtil.BUNDLE_DEBUG))
TestOSGiUtil.diagnoseBundles(bundleContext);
// now test the context
HttpClient client = new HttpClient();
try
{
client.start();
String tmp = System.getProperty("boot.bundle.port");
assertNotNull(tmp);
int port = Integer.valueOf(tmp.trim());
ContentResponse response = client.GET("http://127.0.0.1:" + port);
assertEquals(HttpStatus.NOT_FOUND_404, response.getStatus());
String content = new String(response.getContent());
assertNotNull(content);
}
finally
{
client.stop();
}
}
}

View File

@ -153,41 +153,20 @@ public class TestOSGiUtil
res.add(systemProperty("org.ops4j.pax.url.mvn.settings").value(System.getProperty("settingsFilePath"))); res.add(systemProperty("org.ops4j.pax.url.mvn.settings").value(System.getProperty("settingsFilePath")));
} }
res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject().noStart()); //configure jetty slf4j logging, and provide a jetty-logging properties file
//note 1: you will need to change the surefire plugin config in pom.xml to set the system property "pax.exam.system=false"
/* //to make paxexam use this slf4j
* Jetty 11 uses slf4j 2.0.0 by default, however we want to test with slf4j 1.7.30 for backwards compatibility. //note 2: if you do set the above system property, more than likely the test will not finish, no idea why
* To do that, we need to use slf4j-simple as the logging implementation. We make a simplelogger.properties res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-slf4j-impl").versionAsInProject().start());
* file available so that jetty logging can be configured res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-api").versionAsInProject());
*/
// BEGIN - slf4j 1.7.x
/* slf4j-simple conflicts with both slf4j 1.7.x, and jetty-slf4j-impl. (but in different ways)
TinyBundle simpleLoggingPropertiesBundle = TinyBundles.bundle();
simpleLoggingPropertiesBundle.add("simplelogger.properties", ClassLoader.getSystemResource("simplelogger.properties"));
simpleLoggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "simple-logger-properties");
simpleLoggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "slf4j-simple");
simpleLoggingPropertiesBundle.add(FragmentActivator.class);
res.add(CoreOptions.streamBundle(simpleLoggingPropertiesBundle.build()).noStart());
res.add(mavenBundle().groupId("org.slf4j").artifactId("slf4j-simple").versionAsInProject().noStart());
*/
// END - slf4j 1.7.x
/*
* When running with slf4j >= 2.0.0, remove the slf4j simple logger above and uncomment the following lines
*/
// BEGIN - slf4j 2.x
TinyBundle loggingPropertiesBundle = TinyBundles.bundle(); TinyBundle loggingPropertiesBundle = TinyBundles.bundle();
loggingPropertiesBundle.add("jetty-logging.properties", ClassLoader.getSystemResource("jetty-logging.properties")); loggingPropertiesBundle.add("jetty-logging.properties", ClassLoader.getSystemResource("jetty-logging.properties"));
loggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "jetty-logging-properties"); loggingPropertiesBundle.set(Constants.BUNDLE_SYMBOLICNAME, "jetty-logging-properties");
loggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "org.eclipse.jetty.logging"); loggingPropertiesBundle.set(Constants.FRAGMENT_HOST, "org.eclipse.jetty.logging");
loggingPropertiesBundle.add(FragmentActivator.class); loggingPropertiesBundle.add(FragmentActivator.class);
res.add(CoreOptions.streamBundle(loggingPropertiesBundle.build()).noStart()); res.add(CoreOptions.streamBundle(loggingPropertiesBundle.build()).noStart());
res.add(mavenBundle().groupId("org.eclipse.jetty").artifactId("jetty-slf4j-impl").versionAsInProject().start());
// END - slf4j 2.x
res.add(mavenBundle().groupId("jakarta.el").artifactId("jakarta.el-api").versionAsInProject().start()); res.add(mavenBundle().groupId("jakarta.el").artifactId("jakarta.el-api").versionAsInProject().start());
res.add(mavenBundle().groupId("jakarta.servlet").artifactId("jakarta.servlet-api").versionAsInProject().start()); res.add(mavenBundle().groupId("jakarta.servlet").artifactId("jakarta.servlet-api").versionAsInProject().start());
res.add(mavenBundle().groupId("org.eclipse.platform").artifactId("org.eclipse.osgi.util").versionAsInProject()); res.add(mavenBundle().groupId("org.eclipse.platform").artifactId("org.eclipse.osgi.util").versionAsInProject());
res.add(mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject()); res.add(mavenBundle().groupId("org.osgi").artifactId("org.osgi.service.cm").versionAsInProject());

View File

@ -67,7 +67,7 @@
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item> <Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item> <Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
<Item>org.eclipse.jetty.ee9.webapp.JmxConfiguration</Item> <Item>org.eclipse.jetty.ee9.webapp.JmxConfiguration</Item>
<Item>config.org.eclipse.jetty.ee10.websocket.server.JettyWebSocketConfiguration</Item> <Item>org.eclipse.jetty.ee9.websocket.server.config.JettyWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketConfiguration</Item> <Item>org.eclipse.jetty.websocket.jakarta.server.config.JakartaWebSocketConfiguration</Item>
<Item>org.eclipse.jetty.ee9.osgi.annotations.AnnotationConfiguration</Item> <Item>org.eclipse.jetty.ee9.osgi.annotations.AnnotationConfiguration</Item>
<Item>org.eclipse.jetty.ee9.osgi.boot.OSGiWebInfConfiguration</Item> <Item>org.eclipse.jetty.ee9.osgi.boot.OSGiWebInfConfiguration</Item>