本文整理汇总了Java中org.eclipse.jetty.xml.XmlConfiguration.configure方法的典型用法代码示例。如果您正苦于以下问题:Java XmlConfiguration.configure方法的具体用法?Java XmlConfiguration.configure怎么用?Java XmlConfiguration.configure使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jetty.xml.XmlConfiguration
的用法示例。
在下文中一共展示了XmlConfiguration.configure方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: start
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
public void start() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
// Integer port = getPort();
// if (port != null && port > 0) {
// Connector[] connectors = server.getConnectors();
// for (Connector connector : connectors) {
// connector.setPort(port);
// }
// }
Handler handler = server.getHandler();
if (handler != null && handler instanceof WebAppContext) {
WebAppContext webAppContext = (WebAppContext) handler;
webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例2: afterPropertiesSet
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
public void afterPropertiesSet() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
Integer port = getPort();
if (port != null && port > 0) {
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", htdocsDir);
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例3: main
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
public static void main(String args[]) throws Exception {
Resource jetty_xml = Resource.newSystemResource("jetty/jetty.xml");
XmlConfiguration configuration = new XmlConfiguration(jetty_xml.getInputStream());
Server server = (Server) configuration.configure();
int port = 8081;
Connector[] connectors = server.getConnectors();
for (Connector connector : connectors) {
connector.setPort(port);
}
Handler handler = server.getHandler();
if (handler != null && handler instanceof ServletContextHandler) {
ServletContextHandler servletHandler = (ServletContextHandler) handler;
servletHandler.getInitParams().put("org.eclipse.jetty.servlet.Default.resourceBase", "/tmp/");
}
server.start();
server.join();
}
示例4: start
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
public void start() throws Exception {
Resource configXml = Resource.newSystemResource(config);
XmlConfiguration configuration = new XmlConfiguration(configXml.getInputStream());
server = (Server) configuration.configure();
// Integer port = getPort();
// if (port != null && port > 0) {
// Connector[] connectors = server.getConnectors();
// for (Connector connector : connectors) {
// connector.setPort(port);
// }
// }
Handler handler = server.getHandler();
if (handler != null && handler instanceof WebAppContext) {
WebAppContext webAppContext = (WebAppContext) handler;
webAppContext.setResourceBase(JettyEmbedServer.class.getResource("/webapp").toString());
}
server.start();
if (logger.isInfoEnabled()) {
logger.info("##Jetty Embed Server is startup!");
}
}
示例5: init
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
/**
* Inits the system by creating a new server and handler
*/
private void init() {
try {
if (useConfigFile) {
Resource resource = Resource.newSystemResource(_configFile);
XmlConfiguration config = new XmlConfiguration(resource.getInputStream());
_server = (Server) config.configure();
_handler = new HttpHandler();
_server.setHandler(_handler);
} else {
_server = new Server();
_handler = new HttpHandler();
_server.setHandler(_handler);
}
} catch(Exception e){
throw new RuntimeException("Server unable to start: " + e.getMessage());
}
}
示例6: parseArgs
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
/**
* Modified from XmlConfiguration.main()
*/
public void parseArgs(String[] args) throws Exception {
Properties properties=new Properties();
XmlConfiguration last=null;
InputStream in = null;
for (int i = 0; i < args.length; i++) {
if (args[i].toLowerCase().endsWith(".properties")) {
in = Resource.newResource(args[i]).getInputStream();
properties.load(in);
in.close();
} else {
XmlConfiguration configuration = new XmlConfiguration(Resource.newResource(args[i]).getURL());
if (last!=null)
configuration.getIdMap().putAll(last.getIdMap());
if (properties.size()>0) {
// to avoid compiler errror
Map foo = configuration.getProperties();
foo.putAll(properties);
}
Object o = configuration.configure();
if (o instanceof LifeCycle)
_jettys.add((LifeCycle)o);
last=configuration;
}
}
}
示例7: onInit
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
/** {@inheritDoc} */
@Override
protected void onInit() {
final File jettyXml = new File(System.getProperty("opennms.home") + File.separator + "etc" + File.separator + "jetty.xml");
InputStream jettyXmlStream = null;
try {
m_server = new Server();
if (jettyXml.exists()) {
jettyXmlStream = jettyXml.toURI().toURL().openStream();
} else {
jettyXmlStream = getClass().getResourceAsStream("jetty.xml");
}
if (jettyXmlStream == null) {
throw new RuntimeException("Unable to locate jetty.xml in the classpath!");
}
final XmlConfiguration xmlConfiguration = new XmlConfiguration(jettyXmlStream);
xmlConfiguration.configure(m_server);
} catch (final Exception ioe) {
throw new RuntimeException(ioe);
}
m_server.setStopAtShutdown(true);
}
示例8: main
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
/**
* Main function, starts the jetty server. The first parameter can be the jetty.xml configuration file.
*
* @param args
* Alternative location of jetty configuration file
*/
public static void main(String[] args) {
Server server = null;
try {
URL configUrl;
// Jetty configuration file is the only param allowed
if (args != null && args.length != 1) {
System.err.println("Usage java " + Main.class.getName() + " [URL path to jetty xml conf]");
System.exit(1);
}
String jettyXmlUrl = args[0];
configUrl = getConfigUrl(jettyXmlUrl);
XmlConfiguration xmlConfiguration = new XmlConfiguration(configUrl);
server = new Server();
xmlConfiguration.configure(server);
// Start Jetty
server.start();
server.join();
} catch (Exception e) {
System.err.println("Could not start the Jetty server: " + e);
e.printStackTrace();
if (server != null) {
try {
server.stop();
} catch (Exception e1) {
System.err.println("Unable to stop the jetty server: " + e1);
}
}
}
}
示例9: readXmlConfig
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
private void readXmlConfig(final String configPath) {
try {
final XmlConfiguration configuration = new XmlConfiguration(new FileInputStream(configPath));
configuration.configure(this);
} catch (final Throwable e) {
throw new ReadXMLException(e.getMessage(), e);
}
}
示例10: doStart
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
@Override
protected void doStart() throws Exception {
Resource resource = Resource.newResource(webapp);
File file = resource.getFile();
if (!resource.exists())
throw new IllegalStateException("WebApp resouce does not exist "+resource);
String lcName=file.getName().toLowerCase(Locale.ENGLISH);
if (lcName.endsWith(".xml")) {
XmlConfiguration xmlc = new XmlConfiguration(resource.getURI().toURL());
xmlc.getIdMap().put("Server", contexts.getServer());
xmlc.getProperties().put("jetty.home",System.getProperty("jetty.home","."));
xmlc.getProperties().put("jetty.base",System.getProperty("jetty.base","."));
xmlc.getProperties().put("jetty.webapp",file.getCanonicalPath());
xmlc.getProperties().put("jetty.webapps",file.getParentFile().getCanonicalPath());
xmlc.getProperties().putAll(properties);
handler = (ContextHandler)xmlc.configure();
} else {
WebAppContext wac=new WebAppContext();
wac.setWar(webapp);
wac.setContextPath("/");
}
contexts.addHandler(handler);
if (contexts.isRunning())
handler.start();
}
示例11: performCustomConfiguration
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
private void performCustomConfiguration() throws Exception {
File jettyConfig = systemEnvironment.getJettyConfigFile();
if (jettyConfig.exists()) {
replaceJettyXmlIfItBelongsToADifferentVersion(jettyConfig);
LOG.info("Configuring Jetty using {}", jettyConfig.getAbsolutePath());
FileInputStream serverConfiguration = new FileInputStream(jettyConfig);
XmlConfiguration configuration = new XmlConfiguration(serverConfiguration);
configuration.configure(server);
} else {
String message = String.format(
"No custom jetty configuration (%s) found, using defaults.",
jettyConfig.getAbsolutePath());
LOG.info(message);
}
}
示例12: configureWebApplication
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
/**
* Subclasses should invoke this to setup basic info
* on the webapp
*
* @throws MojoExecutionException
*/
public void configureWebApplication () throws Exception
{
//As of jetty-7, you must use a <webAppConfig> element
if (webAppConfig == null)
webAppConfig = new JettyWebAppContext();
//Apply any context xml file to set up the webapp
//CAUTION: if you've defined a <webAppConfig> element then the
//context xml file can OVERRIDE those settings
if (webAppXml != null)
{
File file = FileUtils.getFile(webAppXml);
XmlConfiguration xmlConfiguration = new XmlConfiguration(file.toURL());
getLog().info("Applying context xml file "+webAppXml);
xmlConfiguration.configure(webAppConfig);
}
//If no contextPath was specified, go with our default
String cp = webAppConfig.getContextPath();
if (cp == null || "".equals(cp))
{
webAppConfig.setContextPath((contextPath.startsWith("/") ? contextPath : "/"+ contextPath));
}
//If no tmp directory was specified, and we have one, use it
if (webAppConfig.getTempDirectory() == null && tmpDirectory != null)
{
if (!tmpDirectory.exists())
tmpDirectory.mkdirs();
webAppConfig.setTempDirectory(tmpDirectory);
}
getLog().info("Context path = " + webAppConfig.getContextPath());
getLog().info("Tmp directory = "+ (webAppConfig.getTempDirectory()== null? " determined at runtime": webAppConfig.getTempDirectory()));
getLog().info("Web defaults = "+(webAppConfig.getDefaultsDescriptor()==null?" jetty default":webAppConfig.getDefaultsDescriptor()));
getLog().info("Web overrides = "+(webAppConfig.getOverrideDescriptor()==null?" none":webAppConfig.getOverrideDescriptor()));
}
示例13: applyJettyXml
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
public void applyJettyXml() throws Exception
{
if (getJettyXmlFiles() == null)
return;
for ( File xmlFile : getJettyXmlFiles() )
{
getLog().info( "Configuring Jetty from xml configuration file = " + xmlFile.getCanonicalPath() );
XmlConfiguration xmlConfiguration = new XmlConfiguration(xmlFile.toURI().toURL());
xmlConfiguration.configure(this.server);
}
}
示例14: createServer
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
protected Server createServer() throws Exception {
ClassLoader serverClassLoader = Thread.currentThread().getContextClassLoader();
ClassLoader sharedClassLoader = new URLClassLoader(pathsToURLs(serverClassLoader, SHARED_CLASS_PATH_IN_JAR), serverClassLoader);
Server server;
if (jettyConfUrl != null) {
XmlConfiguration xmlConfiguration = new XmlConfiguration(jettyConfUrl);
server = (Server) xmlConfiguration.configure();
} else {
server = new Server(port);
}
server.setStopAtShutdown(true);
List<Handler> handlers = new ArrayList<>();
if (CubaJettyUtils.hasCoreApp(serverClassLoader)) {
String coreContextPath = contextPath;
if (isSingleJar(serverClassLoader)) {
if (PATH_DELIMITER.equals(contextPath)) {
coreContextPath = PATH_DELIMITER + "app-core";
} else {
coreContextPath = contextPath + "-core";
}
}
handlers.add(createAppContext(serverClassLoader, sharedClassLoader, CORE_PATH_IN_JAR, coreContextPath));
}
if (hasWebApp(serverClassLoader)) {
handlers.add(createAppContext(serverClassLoader, sharedClassLoader, WEB_PATH_IN_JAR, contextPath));
}
if (hasPortalApp(serverClassLoader)) {
String portalContextPath = contextPath;
if (isSingleJar(serverClassLoader)) {
portalContextPath = this.portalContextPath;
}
handlers.add(createAppContext(serverClassLoader, sharedClassLoader, PORTAL_PATH_IN_JAR, portalContextPath));
}
if (hasFrontApp(serverClassLoader)) {
handlers.add(createFrontAppContext(serverClassLoader, sharedClassLoader));
}
HandlerCollection handlerCollection = new HandlerCollection();
handlerCollection.setHandlers(handlers.toArray(new Handler[handlers.size()]));
server.setHandler(handlerCollection);
return server;
}
示例15: doStart
import org.eclipse.jetty.xml.XmlConfiguration; //导入方法依赖的package包/类
private void doStart(boolean waitForServer, @Nullable final Runnable callback) throws Exception {
if (thread != null) {
throw new IllegalStateException("Already started");
}
log.info("Starting");
List<LifeCycle> components = new ArrayList<>();
PropertyMap props = new PropertyMap();
props.putAll(JettyServer.this.properties);
// For all arguments, load properties or parse XMLs
XmlConfiguration last = null;
for (String arg : args) {
URL url = Resource.newResource(arg).getURL();
if (url.getFile().toLowerCase(Locale.ENGLISH).endsWith(".properties")) {
log.info("Loading properties: {}", url);
props.load(url);
}
else {
log.info("Applying configuration: {}", url);
XmlConfiguration configuration = new XmlConfiguration(url);
if (last != null) {
configuration.getIdMap().putAll(last.getIdMap());
}
if (!props.isEmpty()) {
configuration.getProperties().putAll(props);
}
Object component = configuration.configure();
if (component instanceof LifeCycle) {
components.add((LifeCycle) component);
}
last = configuration;
}
}
// complain if no components configured
if (components.isEmpty()) {
throw new Exception("Failed to configure any components");
}
Server server = null;
for (Object object : components) {
if (object instanceof Server) {
server = (Server) object;
break;
}
}
connectorManager = new ConnectorManager(server, last.getIdMap());
thread = new JettyMainThread(components, callback);
thread.setContextClassLoader(classLoader);
thread.startComponents(waitForServer);
}