本文整理汇总了Java中org.mortbay.jetty.webapp.WebAppContext.setClassLoader方法的典型用法代码示例。如果您正苦于以下问题:Java WebAppContext.setClassLoader方法的具体用法?Java WebAppContext.setClassLoader怎么用?Java WebAppContext.setClassLoader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mortbay.jetty.webapp.WebAppContext
的用法示例。
在下文中一共展示了WebAppContext.setClassLoader方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: main
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void main( String[] args )
throws Exception
{
Server server = new Server( 8081 );
WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/reporting" );
ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );
server.setHandler( handlers );
server.start();
server.join();
}
示例2: main
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void main( String[] args )
throws Exception
{
Server server = new Server( 8080 );
WebAppContext webappcontext = new WebAppContext( "src/main/webapp", "/xdocreport-webapp" );
ContextHandlerCollection servlet_contexts = new ContextHandlerCollection();
webappcontext.setClassLoader( Thread.currentThread().getContextClassLoader() );
HandlerCollection handlers = new HandlerCollection();
handlers.setHandlers( new Handler[] { servlet_contexts, webappcontext, new DefaultHandler() } );
server.setHandler( handlers );
// JSP Servlet + Context
Context jsp_ctx = new Context( servlet_contexts, "/jsp", Context.SESSIONS );
jsp_ctx.addServlet( new ServletHolder( new org.apache.jasper.servlet.JspServlet() ), "*.jsp" );
server.start();
server.join();
}
示例3: setupSolr
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
private void setupSolr() throws Exception {
FileUtils.deleteQuietly(SOLR_WORK_DIR);
FileUtils.copyDirectory(new File("src/test/resources/solr/"), SOLR_WORK_DIR);
String configSolrXml = "<solr>" + " <solrcloud>" + " <str name=\"host\">${host:}</str>"
+ " <int name=\"hostPort\">" + solrPort + "</int>"
+ " <str name=\"hostContext\">${hostContext:solr}</str>"
+ " <int name=\"zkClientTimeout\">${zkClientTimeout:300000}</int>"
+ " <bool name=\"genericCoreNodeNames\">${genericCoreNodeNames:true}</bool>" + " </solrcloud>"
+ " <shardHandlerFactory name=\"shardHandlerFactory\"" + " class=\"HttpShardHandlerFactory\">"
+ " <int name=\"socketTimeout\">${socketTimeout:0}</int>"
+ " <int name=\"connTimeout\">${connTimeout:0}</int>" + " </shardHandlerFactory>" + "</solr>";
File solrConfig = new File(SOLR_WORK_DIR, "solr.xml");
OutputStream out = new FileOutputStream(solrConfig);
out.write(configSolrXml.getBytes("UTF-8"));
out.close();
server = new Server(solrPort);
final WebAppContext context = new WebAppContext();
context.setResourceBase(SOLR_WORK_DIR.getPath());
context.setContextPath("/");
context.setClassLoader(Thread.currentThread().getContextClassLoader());
System.setProperty("solr.solr.home", SOLR_WORK_DIR.getPath());
server.setHandler(context);
server.start();
jenkinsSearchBackend.setSolrBackend(false, solrPort);
}
示例4: doStart
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
public static void doStart() throws Exception {
Server server = new Server();
SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(JETTY_SERVER_PORT);
String webDefault = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "**/webdefault.xml";
Resource web = resolver.getResources(webDefault)[0];
String descriptor = web.getFile().getAbsolutePath();
String pattern = ResourcePatternResolver.CLASSPATH_ALL_URL_PREFIX + "**/" + SpiderJetty.class.getName() + ".class";
Resource resource = resolver.getResources(pattern)[0];
String resourcePath = resource.getFile().getAbsolutePath().replaceAll("target.*$", "") + "webapp";
WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setDefaultsDescriptor(descriptor);
context.setResourceBase("file:" + resourcePath);
context.setClassLoader(Thread.currentThread().getContextClassLoader());
server.setConnectors(new Connector[]{connector});
server.setHandler(context);
server.setStopAtShutdown(true);
server.setSendServerVersion(false);
server.setSendDateHeader(false);
server.setGracefulShutdown(1000);
try {
server.start();
server.join();
} catch (Exception e) {
e.printStackTrace();
}
}
示例5: setUp
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
tmpdir = new File(System.getProperty("java.io.tmpdir") + "/oiosaml-" + Math.random());
if (tmpdir.exists()) {
FileUtils.cleanDirectory(tmpdir);
}
tmpdir.mkdir();
// Reinitialize SAMLConfiguration
Map<String,String> params=new HashMap<String, String>();
params.put(Constants.INIT_OIOSAML_HOME, tmpdir.getAbsolutePath());
SAMLConfigurationFactory.getConfiguration().setInitConfiguration(params);
//FileConfiguration.setSystemConfiguration(null);
IdpMetadata.setMetadata(null);
SPMetadata.setMetadata(null);
System.setProperty(SAMLUtil.OIOSAML_HOME, tmpdir.getAbsolutePath());
server = new Server(8808);
WebAppContext wac = new WebAppContext();
wac.setClassLoader(Thread.currentThread().getContextClassLoader());
wac.setContextPath("/saml");
wac.setWar("webapp/");
server.setHandler(wac);
server.start();
client = new WebClient();
page = (HtmlPage) client.getPage(BASE + "/saml/configure");
}
示例6: setUpServer
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Before
public final void setUpServer() throws Exception {
tmpdir = new File(System.getProperty("java.io.tmpdir") + "/oiosaml-" + Math.random());
tmpdir.mkdir();
// Reinitialize SAMLConfiguration
Map<String,String> params=new HashMap<String, String>();
params.put(Constants.INIT_OIOSAML_HOME, tmpdir.getAbsolutePath());
SAMLConfigurationFactory.getConfiguration().setInitConfiguration(params);
FileUtils.forceMkdir(new File(tmpdir, "metadata/IdP"));
FileUtils.forceMkdir(new File(tmpdir, "metadata/SP"));
credential = TestHelper.getCredential();
EntityDescriptor idpDescriptor = TestHelper.buildEntityDescriptor(credential);
FileOutputStream fos = new FileOutputStream(new File(tmpdir, "metadata/IdP/gen.xml"));
IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(idpDescriptor)).getBytes(), fos);
fos.close();
EntityDescriptor spDescriptor = (EntityDescriptor) SAMLUtil.unmarshallElement(getClass().getResourceAsStream("/dk/itst/oiosaml/sp/SPMetadata.xml"));
fos = new FileOutputStream(new File(tmpdir, "metadata/SP/SPMetadata.xml"));
IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(spDescriptor)).getBytes(), fos);
fos.close();
spMetadata = new SPMetadata(spDescriptor, SAMLConstants.SAML20P_NS);
idpMetadata = new IdpMetadata(SAMLConstants.SAML20P_NS, idpDescriptor);
fos = new FileOutputStream(new File(tmpdir, "oiosaml-sp.log4j.xml"));
IOUtils.write("<!DOCTYPE log4j:configuration SYSTEM \"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd\"><log4j:configuration xmlns:log4j=\"http://jakarta.apache.org/log4j/\" debug=\"false\"></log4j:configuration>", fos);
fos.close();
final File crlFile = generateCRL(null);
Properties props = new Properties();
props.setProperty(Constants.PROP_SHOW_ERROR, "true");
props.setProperty(Constants.PROP_CERTIFICATE_LOCATION, "keystore");
props.setProperty(Constants.PROP_CERTIFICATE_PASSWORD, "password");
props.setProperty(Constants.PROP_LOG_FILE_NAME, "oiosaml-sp.log4j.xml");
props.setProperty(Constants.PROP_SESSION_HANDLER_FACTORY, SingleVMSessionHandlerFactory.class.getName());
props.setProperty(Constants.PROP_CRL + idpMetadata.getFirstMetadata().getEntityID(), crlFile.toURI().toString());
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setKeyEntry("oiosaml", credential.getPrivateKey(), "password".toCharArray(), new Certificate[] {
TestHelper.getCertificate(credential) });
OutputStream bos = new FileOutputStream(new File(tmpdir, "keystore"));
ks.store(bos, "password".toCharArray());
bos.close();
props.setProperty(Constants.PROP_ASSURANCE_LEVEL, "2");
props.setProperty(Constants.PROP_IGNORE_CERTPATH, "true");
fos = new FileOutputStream(new File(tmpdir, SAMLUtil.OIOSAML_DEFAULT_CONFIGURATION_FILE));
props.store(fos, "Generated");
fos.close();
IdpMetadata.setMetadata(null);
SPMetadata.setMetadata(null);
server = new Server(8808);
WebAppContext wac = new WebAppContext();
wac.setClassLoader(Thread.currentThread().getContextClassLoader());
wac.setContextPath("/saml");
wac.setWar("webapp/");
server.setHandler(wac);
server.start();
Thread.sleep(1000); // This sleep is necessary to ensure that CRLChecker finishes before the first request. Otherwise, no certificates will be valid.
client = new WebClient();
client.setRedirectEnabled(false);
client.setThrowExceptionOnFailingStatusCode(false);
handler = new RedirectRefreshHandler();
client.setRefreshHandler(handler);
}
示例7: setUpServer
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
@Before
public final void setUpServer() throws Exception {
tmpdir = new File(System.getProperty("java.io.tmpdir") + "/oiosaml-" + Math.random());
tmpdir.mkdir();
// Reinitialize SAMLConfiguration
Map<String,String> params=new HashMap<String, String>();
params.put(Constants.INIT_OIOSAML_HOME, tmpdir.getAbsolutePath());
SAMLConfigurationFactory.getConfiguration().setInitConfiguration(params);
FileUtils.forceMkdir(new File(tmpdir, "metadata/IdP"));
FileUtils.forceMkdir(new File(tmpdir, "metadata/SP"));
credential = TestHelper.getCredential();
EntityDescriptor idpDescriptor = TestHelper.buildEntityDescriptor(credential);
FileOutputStream fos = new FileOutputStream(new File(tmpdir, "metadata/IdP/gen.xml"));
IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(idpDescriptor)).getBytes(), fos);
fos.close();
EntityDescriptor spDescriptor = (EntityDescriptor) SAMLUtil.unmarshallElement(getClass().getResourceAsStream("/dk/itst/oiosaml/sp/SPMetadata.xml"));
fos = new FileOutputStream(new File(tmpdir, "metadata/SP/SPMetadata.xml"));
IOUtils.write(XMLHelper.nodeToString(SAMLUtil.marshallObject(spDescriptor)).getBytes(), fos);
fos.close();
spMetadata = new SPMetadata(spDescriptor, SAMLConstants.SAML20P_NS);
idpMetadata = new IdpMetadata(SAMLConstants.SAML20P_NS, idpDescriptor);
fos = new FileOutputStream(new File(tmpdir, "oiosaml-sp.log4j.xml"));
IOUtils.write("<!DOCTYPE log4j:configuration SYSTEM \"http://logging.apache.org/log4j/docs/api/org/apache/log4j/xml/log4j.dtd\"><log4j:configuration xmlns:log4j=\"http://jakarta.apache.org/log4j/\" debug=\"false\"></log4j:configuration>", fos);
fos.close();
Properties props = new Properties();
props.setProperty(Constants.PROP_SHOW_ERROR, "true");
props.setProperty(Constants.PROP_CERTIFICATE_LOCATION, "keystore");
props.setProperty(Constants.PROP_CERTIFICATE_PASSWORD, "password");
props.setProperty(Constants.PROP_LOG_FILE_NAME, "oiosaml-sp.log4j.xml");
props.setProperty(Constants.PROP_SESSION_HANDLER_FACTORY, SingleVMSessionHandlerFactory.class.getName());
KeyStore ks = KeyStore.getInstance("JKS");
ks.load(null, null);
ks.setKeyEntry("oiosaml", credential.getPrivateKey(), "password".toCharArray(), new Certificate[] {
TestHelper.getCertificate(credential) });
OutputStream bos = new FileOutputStream(new File(tmpdir, "keystore"));
ks.store(bos, "password".toCharArray());
bos.close();
props.setProperty(Constants.PROP_ASSURANCE_LEVEL, "2");
props.setProperty(Constants.PROP_IGNORE_CERTPATH, "true");
fos = new FileOutputStream(new File(tmpdir, SAMLUtil.OIOSAML_DEFAULT_CONFIGURATION_FILE));
props.store(fos, "Generated");
fos.close();
IdpMetadata.setMetadata(null);
SPMetadata.setMetadata(null);
server = new Server(8808);
WebAppContext wac = new WebAppContext();
wac.setClassLoader(Thread.currentThread().getContextClassLoader());
wac.setContextPath("/saml");
wac.setWar("webapp/");
server.setHandler(wac);
server.start();
client = new WebClient();
client.setRedirectEnabled(false);
client.setThrowExceptionOnFailingStatusCode(false);
handler = new RedirectRefreshHandler();
client.setRefreshHandler(handler);
}
示例8: createJettyWebContext
import org.mortbay.jetty.webapp.WebAppContext; //导入方法依赖的package包/类
/**
* Creates the Jetty specific web context for the given OSGi bundle.
*
* @param bundle
* @return
* @throws Exception
*/
private WebAppContext createJettyWebContext(Bundle bundle, String contextPath) throws Exception {
WebAppContext wac = new WebAppContext();
// create a jetty web app context
// the server is being used to generate the temp folder (so we have to set it)
wac.setServer(serverService);
// set the war string since it's used to generate the temp path
wac.setWar(OsgiStringUtils.nullSafeName(bundle));
// same goes for the context path (add leading "/" -> w/o the context will not work)
wac.setContextPath(contextPath);
// no hot deployment (at least not through directly Jetty)
wac.setCopyWebDir(false);
wac.setExtractWAR(true);
//
// 1. resource settings
//
// start with the slow, IO activity
Resource rootResource = getRootResource(bundle, wac);
// wac needs access to the WAR root
// we have to make sure we don't trigger any direct file lookup
// so instead of calling .setWar()
// we set the base resource directly
wac.setBaseResource(rootResource);
// reset the war setting (so that the base resource is used)
wac.setWar(null);
//
// 2. class-loading behaviour
//
// obey the servlet spec class-loading contract
wac.setSystemClasses(systemClasses);
wac.setServerClasses(serverClasses);
// no java 2 loading compliance
wac.setParentLoaderPriority(false);
// create special classloader
wac.setClassLoader(Utils.createWebAppClassLoader(bundle, Server.class));
return wac;
}