use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class AntWebAppContext method doStart.
/**
*
*/
public void doStart() {
try {
TaskLog.logWithTimestamp("Starting web application " + this.getDescriptor());
if (jettyEnvXml != null && jettyEnvXml.exists())
envConfiguration.setJettyEnvXml(Resource.toURL(jettyEnvXml));
ClassLoader parentLoader = this.getClass().getClassLoader();
if (parentLoader instanceof AntClassLoader)
parentLoader = new AntURLClassLoader((AntClassLoader) parentLoader);
setClassLoader(new WebAppClassLoader(parentLoader, this));
if (attributes != null && attributes.getAttributes() != null) {
for (Attribute a : attributes.getAttributes()) setAttribute(a.getName(), a.getValue());
}
//apply a context xml file if one was supplied
if (contextXml != null) {
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(contextXml));
TaskLog.log("Applying context xml file " + contextXml);
xmlConfiguration.configure(this);
}
super.doStart();
} catch (Exception e) {
TaskLog.log(e.toString());
}
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class QuickStartTest method testStandardTestWar.
@Test
public void testStandardTestWar() throws Exception {
PreconfigureStandardTestWar.main(new String[] {});
WebDescriptor descriptor = new WebDescriptor(Resource.newResource("./target/test-standard-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-standard-preconfigured";
//optional jetty context xml file to configure the webapp
Resource contextXml = Resource.newResource("src/test/resources/test.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() + "/test/dump/info");
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
assertEquals(200, connection.getResponseCode());
assertThat(IO.toString((InputStream) connection.getContent()), Matchers.containsString("Dump Servlet"));
server.stop();
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class Quickstart method main.
public static void main(String... args) throws Exception {
if (args.length < 1)
error("No WAR file or directory given");
//war file or dir to start
String war = args[0];
//optional jetty context xml file to configure the webapp
Resource contextXml = null;
if (args.length > 1)
contextXml = Resource.newResource(args[1]);
Server server = new Server(8080);
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();
server.join();
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class ServerSupport method applyXmlConfigurations.
/**
* Apply xml files to server startup, passing in ourselves as the
* "Server" instance.
*
* @param server the server to apply the xml to
* @param files the list of xml files
* @return the Server implementation, after the xml is applied
* @throws Exception if unable to apply the xml configuration
*/
public static Server applyXmlConfigurations(Server server, List<File> files) throws Exception {
if (files == null || files.isEmpty())
return server;
Map<String, Object> lastMap = new HashMap<String, Object>();
if (server != null)
lastMap.put("Server", server);
for (File xmlFile : files) {
if (PluginLog.getLog() != null)
PluginLog.getLog().info("Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath());
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(xmlFile));
//chain ids from one config file to another
if (lastMap != null)
xmlConfiguration.getIdMap().putAll(lastMap);
//Set the system properties each time in case the config file set a new one
Enumeration<?> ensysprop = System.getProperties().propertyNames();
while (ensysprop.hasMoreElements()) {
String name = (String) ensysprop.nextElement();
xmlConfiguration.getProperties().put(name, System.getProperty(name));
}
xmlConfiguration.configure();
lastMap = xmlConfiguration.getIdMap();
}
return (Server) lastMap.get("Server");
}
use of org.eclipse.jetty.xml.XmlConfiguration in project jetty.project by eclipse.
the class AbstractJettyMojo method configureWebApplication.
/**
* Subclasses should invoke this to setup basic info
* on the webapp
*
* @throws Exception if unable to configure web application
*/
public void configureWebApplication() throws Exception {
//As of jetty-7, you must use a <webApp> element
if (webApp == null)
webApp = new JettyWebAppContext();
//context xml file can OVERRIDE those settings
if (contextXml != null) {
File file = FileUtils.getFile(contextXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(Resource.toURL(file));
getLog().info("Applying context xml file " + contextXml);
xmlConfiguration.configure(webApp);
}
//If no contextPath was specified, go with default of project artifactid
String cp = webApp.getContextPath();
if (cp == null || "".equals(cp)) {
cp = "/" + project.getArtifactId();
webApp.setContextPath(cp);
}
//If no tmp directory was specified, and we have one, use it
if (webApp.getTempDirectory() == null) {
File target = new File(project.getBuild().getDirectory());
File tmp = new File(target, "tmp");
if (!tmp.exists())
tmp.mkdirs();
webApp.setTempDirectory(tmp);
}
getLog().info("Context path = " + webApp.getContextPath());
getLog().info("Tmp directory = " + (webApp.getTempDirectory() == null ? " determined at runtime" : webApp.getTempDirectory()));
getLog().info("Web defaults = " + (webApp.getDefaultsDescriptor() == null ? " jetty default" : webApp.getDefaultsDescriptor()));
getLog().info("Web overrides = " + (webApp.getOverrideDescriptor() == null ? " none" : webApp.getOverrideDescriptor()));
}
Aggregations