org.eclipse.jetty.server.handler.ContextHandler.Context Java Examples

The following examples show how to use org.eclipse.jetty.server.handler.ContextHandler.Context. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JettyServer.java    From nexus-public with Eclipse Public License 1.0 6 votes vote down vote up
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());
}
 
Example #2
Source File: RequestContextScope.java    From jetty-runtime with Apache License 2.0 5 votes vote down vote up
@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) {
      contextDepth.set(1);
      String currentTraceId = (String) request.getAttribute(X_CLOUD_TRACE);
      if (currentTraceId == null) {
        // extract xCloud Trace in format: TRACE_ID/SPAN_ID;o=TRACE_TRUE
        String cloudTrace = request.getHeader(X_CLOUD_TRACE);
        if (cloudTrace != null) {
          int split = cloudTrace.indexOf('/');
          if (split < 0) {
            split = cloudTrace.indexOf(';');
          }
          String traceId = split >= 0 ? cloudTrace.substring(0, split) : cloudTrace;
          if (traceId != null) {
            currentTraceId = String.format("projects/%s/traces/%s", projectId, traceId);
            request.setAttribute(X_CLOUD_TRACE, currentTraceId);
            TraceLoggingEnhancer.setCurrentTraceId(currentTraceId);
          }
        }
      }
    } else {
      contextDepth.set(depth + 1);
    }
  }
}
 
Example #3
Source File: RequestContextScope.java    From jetty-runtime with Apache License 2.0 5 votes vote down vote up
@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);
    }
  }
}