use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class JettyWebXmlConfiguration method configure.
/**
* Configure
* Apply web-jetty.xml configuration
* @see Configuration#configure(WebAppContext)
*/
@Override
public void configure(WebAppContext context) throws Exception {
//cannot configure if the _context is already started
if (context.isStarted()) {
LOG.debug("Cannot configure webapp after it is started");
return;
}
LOG.debug("Configuring web-jetty.xml");
Resource web_inf = context.getWebInf();
// handle any WEB-INF descriptors
if (web_inf != null && web_inf.isDirectory()) {
// do jetty.xml file
Resource jetty = web_inf.addPath("jetty8-web.xml");
if (!jetty.exists())
jetty = web_inf.addPath(JETTY_WEB_XML);
if (!jetty.exists())
jetty = web_inf.addPath("web-jetty.xml");
if (jetty.exists()) {
if (LOG.isDebugEnabled())
LOG.debug("Configure: " + jetty);
Object xml_attr = context.getAttribute(XML_CONFIGURATION);
context.removeAttribute(XML_CONFIGURATION);
final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration ? (XmlConfiguration) xml_attr : new XmlConfiguration(jetty.getURI().toURL());
setupXmlConfiguration(jetty_config, web_inf);
try {
WebAppClassLoader.runWithServerClassAccess(() -> {
jetty_config.configure(context);
return null;
});
} catch (Exception e) {
LOG.warn("Error applying {}", jetty);
throw e;
}
}
}
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class Starter method configureJetty.
public void configureJetty() throws Exception {
LOG.debug("Starting Jetty Server ...");
Resource.setDefaultUseCaches(false);
//apply any configs from jetty.xml files first
applyJettyXml();
//ensure there's a connector
ServerSupport.configureConnectors(server, null);
//check if contexts already configured, create if not
ServerSupport.configureHandlers(server, null);
//Set up list of default Configurations to apply to a webapp
ServerSupport.configureDefaultConfigurationClasses(server);
webApp = new JettyWebAppContext();
//configure webapp from properties file describing unassembled webapp
configureWebApp();
//make it a quickstart if the quickstart-web.xml file exists
if (webApp.getTempDirectory() != null) {
File qs = new File(webApp.getTempDirectory(), "quickstart-web.xml");
if (qs.exists() && qs.isFile())
webApp.setQuickStartWebDescriptor(Resource.newResource(qs));
}
//already configured by the time the context xml file is applied.
if (contextXml != null) {
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(contextXml));
xmlConfiguration.getIdMap().put("Server", server);
xmlConfiguration.configure(webApp);
}
ServerSupport.addWebApplication(server, webApp);
if (stopPort > 0 && stopKey != null) {
ShutdownMonitor monitor = ShutdownMonitor.getInstance();
monitor.setPort(stopPort);
monitor.setKey(stopKey);
monitor.setExitVm(true);
}
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class QuickStartTest method testSpecWar.
@Test
public void testSpecWar() throws Exception {
PreconfigureSpecWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-spec-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-spec-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test-spec.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Test Specification WebApp"));
server.stop();
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class QuickStartTest method testJNDIWar.
@Test
public void testJNDIWar() throws Exception {
PreconfigureJNDIWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-jndi-preconfigured/WEB-INF/quickstart-web.xml"));
descriptor.setValidating(true);
descriptor.parse();
Node node = descriptor.getRoot();
assertThat(node, Matchers.notNullValue());
System.setProperty("jetty.home", "target");
//war file or dir to start
String war = "target/test-jndi-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test-jndi.xml");
Server server = new Server(0);
QuickStartWebApp webapp = new QuickStartWebApp();
webapp.setAutoPreconfigure(true);
webapp.setWar(war);
webapp.setContextPath("/");
//apply context xml file
if (contextXml != null) {
// System.err.println("Applying "+contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(contextXml.getURI().toURL());
xmlConfiguration.configure(webapp);
}
server.setHandler(webapp);
server.start();
URL url = new URL("http://127.0.0.1:" + server.getBean(NetworkConnector.class).getLocalPort() + "/");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
String content = IO.toString((InputStream) connection.getContent());
assertThat(content, Matchers.containsString("JNDI Test WebApp"));
server.stop();
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class TestableJettyServer method load.
public void load() throws Exception {
XmlConfiguration last = null;
Object[] obj = new Object[this._xmlConfigurations.size()];
// Configure everything
for (int i = 0; i < this._xmlConfigurations.size(); i++) {
URL configURL = this._xmlConfigurations.get(i);
System.err.println("configuring: " + configURL);
XmlConfiguration configuration = new XmlConfiguration(configURL);
if (last != null) {
configuration.getIdMap().putAll(last.getIdMap());
}
configuration.getProperties().putAll(_properties);
obj[i] = configuration.configure();
last = configuration;
}
// Test for Server Instance.
Server foundServer = null;
int serverCount = 0;
for (int i = 0; i < this._xmlConfigurations.size(); i++) {
if (obj[i] instanceof Server) {
if (obj[i].equals(foundServer)) {
// Identical server instance found
break;
}
foundServer = (Server) obj[i];
serverCount++;
}
}
if (serverCount <= 0) {
throw new Exception("Load failed to configure a " + Server.class.getName());
}
Assert.assertEquals("Server load count", 1, serverCount);
this._server = foundServer;
this._server.setStopTimeout(1000);
}
Aggregations