Skip to content

Package: EmbeddedJetty

EmbeddedJetty

nameinstructionbranchcomplexitylinemethod
EmbeddedJetty()
M: 3 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 1 C: 0
0%
M: 1 C: 0
0%
start(String, int)
M: 86 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 22 C: 0
0%
M: 1 C: 0
0%
static {...}
M: 7 C: 0
0%
M: 0 C: 0
100%
M: 1 C: 0
0%
M: 2 C: 0
0%
M: 1 C: 0
0%
stop()
M: 21 C: 0
0%
M: 2 C: 0
0%
M: 2 C: 0
0%
M: 6 C: 0
0%
M: 1 C: 0
0%

Coverage

1: /*******************************************************************************
2: * Copyright (c) 2018, 2022 Eurotech and/or its affiliates and others
3: *
4: * This program and the accompanying materials are made
5: * available under the terms of the Eclipse Public License 2.0
6: * which is available at https://www.eclipse.org/legal/epl-2.0/
7: *
8: * SPDX-License-Identifier: EPL-2.0
9: *
10: * Contributors:
11: * Eurotech
12: *******************************************************************************/
13: package org.eclipse.kapua.qa.common.utils;
14:
15: import cucumber.api.java.en.Given;
16: import org.eclipse.jetty.jmx.MBeanContainer;
17: import org.eclipse.jetty.server.Server;
18: import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
19: import org.eclipse.jetty.webapp.Configuration;
20: import org.eclipse.jetty.webapp.WebAppContext;
21: import org.eclipse.kapua.commons.setting.system.SystemSettingKey;
22: import org.slf4j.Logger;
23: import org.slf4j.LoggerFactory;
24:
25: import java.io.File;
26: import java.lang.management.ManagementFactory;
27: import java.net.InetSocketAddress;
28:
29: public class EmbeddedJetty {
30:
31: private static final Logger logger = LoggerFactory.getLogger(EmbeddedJetty.class);
32:
33: private static final boolean NO_EMBEDDED_SERVERS = Boolean.getBoolean("org.eclipse.kapua.qa.noEmbeddedServers");
34:
35: private static Server jetty;
36:
37: @Given("^Start Jetty Server on host \"(.*)\" at port \"(.+)\"$")
38: public void start(String host, int port) throws Exception {
39:
40:• if (NO_EMBEDDED_SERVERS) {
41: return;
42: }
43: // Switch back to default DB connection resolver
44: // as Jetty has its own class loader and has to access in memory DB over TCP
45: System.setProperty(SystemSettingKey.DB_JDBC_CONNECTION_URL_RESOLVER.key(), "DEFAULT");
46:
47: InetSocketAddress address = new InetSocketAddress(host, port);
48: jetty = new Server(address);
49: logger.info("Starting Jetty " + jetty);
50:
51: // Setup JMX
52: MBeanContainer mbContainer = new MBeanContainer(
53: ManagementFactory.getPlatformMBeanServer());
54: jetty.addBean(mbContainer);
55:
56: WebAppContext webapp = new WebAppContext();
57: webapp.setContextPath("/");
58: //File warFile = new File("../rest-api/web/target/api.war");
59: String warFileName = System.getProperty("jetty.war.file");
60: File warFile = new File(warFileName);
61: webapp.setWar(warFile.getAbsolutePath());
62: webapp.addAliasCheck(new AllowSymLinkAliasChecker());
63:
64: Configuration.ClassList classlist = Configuration.ClassList.setServerDefault(jetty);
65: classlist.addBefore(
66: "org.eclipse.jetty.webapp.JettyWebXmlConfiguration",
67: "org.eclipse.jetty.annotations.AnnotationConfiguration" );
68:
69: webapp.setAttribute(
70: "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
71: ".*/[^/]*servlet-api-[^/]*\\.jar$|.*/javax.servlet.jsp.jstl-.*\\.jar$|.*/[^/]*taglibs.*\\.jar$" );
72:
73: jetty.setHandler(webapp);
74:
75: jetty.start();
76: jetty.dumpStdErr();
77: // Blocks
78: //jetty.join();
79: }
80:
81: @Given("^Stop Jetty Server$")
82: public void stop() throws Exception {
83:
84:• if (NO_EMBEDDED_SERVERS) {
85: return;
86: }
87: logger.info("Stopping Jetty " + jetty);
88:
89: jetty.stop();
90: System.setProperty(SystemSettingKey.DB_JDBC_CONNECTION_URL_RESOLVER.key(), "H2");
91: }
92:
93: }