Java 类org.eclipse.jetty.server.handler.ContextHandler.Context 实例源码
项目:nexus-public
文件:JettyServer.java
private static void logStartupBanner(Server server) {
Object banner = null;
ContextHandler contextHandler = server.getChildHandlerByClass(ContextHandler.class);
if (contextHandler != null) {
Context context = contextHandler.getServletContext();
if (context != null) {
banner = context.getAttribute("nexus-banner");
}
}
StringBuilder buf = new StringBuilder();
buf.append("\n-------------------------------------------------\n\n");
buf.append("Started ").append(banner instanceof String ? banner : "Nexus Repository Manager");
buf.append("\n\n-------------------------------------------------");
log.info(buf.toString());
}
项目:jetty-runtime
文件:RequestContextScope.java
@Override
public void enterScope(Context context, Request request, Object reason) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("enterScope " + context);
}
if (request != null) {
Integer depth = contextDepth.get();
if (depth == null || depth.intValue() == 0) {
depth = 1;
String traceId = (String) request.getAttribute(X_CLOUD_TRACE);
if (traceId == null) {
traceId = request.getHeader(X_CLOUD_TRACE);
if (traceId != null) {
int slash = traceId.indexOf('/');
if (slash >= 0) {
traceId = traceId.substring(0, slash);
}
request.setAttribute(X_CLOUD_TRACE, traceId);
TraceLoggingEnhancer.setCurrentTraceId(traceId);
}
} else {
depth = depth + 1;
}
contextDepth.set(depth);
}
}
}
项目:jetty-runtime
文件:RequestContextScope.java
@Override
public void exitScope(Context context, Request request) {
if (logger.isLoggable(Level.FINE)) {
logger.fine("exitScope " + context);
}
Integer depth = contextDepth.get();
if (depth != null) {
if (depth > 1) {
contextDepth.set(depth - 1);
} else {
contextDepth.remove();
TraceLoggingEnhancer.setCurrentTraceId(null);
}
}
}
项目:FinanceAnalytics
文件:WebPushTestUtils.java
/**
* Creates and starts a Jetty server using {@code web-push/WEB-INF/web.xml} and configured using Spring
* @return The server and the Spring context
* @param springXml The location of the Spring XML config file
*/
public Pair<Server, WebApplicationContext> createJettyServer(final String springXml) throws Exception {
final WebAppContext context = new WebAppContext();
context.setContextPath("/");
context.setResourceBase("build/classes");
context.setDescriptor("web-push/WEB-INF/web.xml");
context.setInitParameter("contextConfigLocation", springXml);
context.addEventListener(new ContextLoaderListener());
final Server server = new Server();
server.setHandler(context);
final SelectChannelConnector connector = new SelectChannelConnector();
connector.setPort(_port);
server.addConnector(connector);
server.start();
if (_port == 0) {
setPort(connector.getLocalPort());
}
final Context servletContext = context.getServletContext();
final WebApplicationContext springContext = WebApplicationContextUtils.getRequiredWebApplicationContext(servletContext);
final Map<String, ConnectionManager> cmMap = springContext.getBeansOfType(ConnectionManager.class);
if (cmMap.size() == 1) {
WebPushServletContextUtils.setConnectionManager(servletContext, cmMap.values().iterator().next());
}
final Map<String, LongPollingConnectionManager> lpcmMap = springContext.getBeansOfType(LongPollingConnectionManager.class);
if (lpcmMap.size() == 1) {
WebPushServletContextUtils.setLongPollingConnectionManager(servletContext, lpcmMap.values().iterator().next());
}
return Pairs.of(server, springContext);
}
项目:jlubricant
文件:EmbeddableJetty.java
public ServletContext createWebApp(
String webappContextPath2, String webAppResourcePath2,
String[] virtualHosts2, String[] welcomeFiles2) {
Preconditions.condition("Please provide a context. A context specifies the path of the web app.", webappContextPath2 != null);
// check whether the resource path to the web application really exists.
URI uri;
try {
uri = new ClassPathResource(webAppResourcePath2).getURI();
File webAppBaseDir = new File(uri);
Preconditions.condition( format("Resource %s should be a directory, but it is not", uri) , webAppBaseDir.exists() && webAppBaseDir.isDirectory());
log.info("Installing web app found at resource path '{}' resolved to URI '{}'.", webAppResourcePath2, uri);
} catch (IOException e) {
throw new RuntimeException("Unable to find web app files at resource path '" + webAppResourcePath2 + "'.", e);
}
WebAppContext webapp = new WebAppContext();
if(virtualHosts2!=null){
webapp.setVirtualHosts(virtualHosts2);
}
webapp.setContextPath(webappContextPath2);
webapp.setWar(uri.toString());
// Disable directory listings if no index.html is found.
webapp.setInitParameter("org.eclipse.jetty.servlet.Default.dirAllowed",
String.valueOf(dirAllowed));
if(welcomeFiles2!=null){
webapp.setWelcomeFiles(welcomeFiles2);
}
setHandler(webapp);
Context servletContext = webapp.getServletContext();
return servletContext;
}