Java Code Examples for org.eclipse.jetty.server.Request#getAttribute()
The following examples show how to use
org.eclipse.jetty.server.Request#getAttribute() .
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: TimedHandler.java From micrometer with Apache License 2.0 | 6 votes |
void onAsyncComplete(AsyncEvent event) { HttpChannelState state = ((AsyncContextEvent) event).getHttpChannelState(); Request request = state.getBaseRequest(); Timer.Sample sample = (Timer.Sample) request.getAttribute(SAMPLE_REQUEST_TIMER_ATTRIBUTE); LongTaskTimer.Sample lttSample = (LongTaskTimer.Sample) request.getAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE); if (sample != null) { sample.stop(Timer.builder("jetty.server.requests") .description("HTTP requests to the Jetty server") .tags(tagsProvider.getTags(request, request.getResponse())) .tags(tags) .register(registry)); lttSample.stop(); } asyncWaits.decrementAndGet(); // If we have no more dispatches, should we signal shutdown? FutureCallback shutdownCallback = shutdown.get(); if (shutdownCallback != null && openRequests.activeTasks() == 0) { shutdownCallback.succeeded(); } }
Example 2
Source File: TimedHandler.java From micrometer with Apache License 2.0 | 5 votes |
void onAsyncTimeout(AsyncEvent event) { asyncExpires.increment(); HttpChannelState state = ((AsyncContextEvent) event).getHttpChannelState(); Request request = state.getBaseRequest(); LongTaskTimer.Sample lttSample = (LongTaskTimer.Sample) request.getAttribute(SAMPLE_REQUEST_LONG_TASK_TIMER_ATTRIBUTE); lttSample.stop(); }
Example 3
Source File: RequestContextScope.java From jetty-runtime with Apache License 2.0 | 5 votes |
@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 4
Source File: AthenzRequestLog.java From athenz with Apache License 2.0 | 5 votes |
private void logRequestUri(StringBuilder buf, Request request) { final Object skipQuery = request.getAttribute(REQUEST_URI_SKIP_QUERY); append(buf, (skipQuery == Boolean.TRUE) ? request.getRequestURI() : request.getOriginalURI()); final Object addlQuery = request.getAttribute(REQUEST_URI_ADDL_QUERY); if (addlQuery != null) { buf.append('?'); buf.append(addlQuery.toString()); } }
Example 5
Source File: AbstractKeycloakJettyAuthenticator.java From keycloak with Apache License 2.0 | 5 votes |
public AdapterTokenStore getTokenStore(Request request, HttpFacade facade, KeycloakDeployment resolvedDeployment) { AdapterTokenStore store = (AdapterTokenStore) request.getAttribute(TOKEN_STORE_NOTE); if (store != null) { return store; } if (resolvedDeployment.getTokenStore() == TokenStore.SESSION) { store = createSessionTokenStore(request, resolvedDeployment); } else { store = new JettyCookieTokenStore(request, facade, resolvedDeployment); } request.setAttribute(TOKEN_STORE_NOTE, store); return store; }
Example 6
Source File: AbstractKeycloakJettyAuthenticator.java From keycloak with Apache License 2.0 | 5 votes |
public void logoutCurrent(Request request) { AdapterDeploymentContext deploymentContext = (AdapterDeploymentContext) request.getAttribute(AdapterDeploymentContext.class.getName()); KeycloakSecurityContext ksc = (KeycloakSecurityContext) request.getAttribute(KeycloakSecurityContext.class.getName()); if (ksc != null) { JettyHttpFacade facade = new OIDCJettyHttpFacade(request, null); KeycloakDeployment deployment = deploymentContext.resolveDeployment(facade); if (ksc instanceof RefreshableKeycloakSecurityContext) { ((RefreshableKeycloakSecurityContext) ksc).logout(deployment); } AdapterTokenStore tokenStore = getTokenStore(request, facade, deployment); tokenStore.logout(); request.removeAttribute(KeycloakSecurityContext.class.getName()); } }
Example 7
Source File: AbstractSamlAuthenticator.java From keycloak with Apache License 2.0 | 5 votes |
public JettySamlSessionStore getTokenStore(Request request, HttpFacade facade, SamlDeployment resolvedDeployment) { JettySamlSessionStore store = (JettySamlSessionStore) request.getAttribute(TOKEN_STORE_NOTE); if (store != null) { return store; } store = createJettySamlSessionStore(request, facade, resolvedDeployment); request.setAttribute(TOKEN_STORE_NOTE, store); return store; }
Example 8
Source File: AccessLogRequestLog.java From vespa with Apache License 2.0 | 4 votes |
@Override public void log(final Request request, final Response response) { try { AccessLogEntry accessLogEntry = Optional.ofNullable(request.getAttribute(JDiscHttpServlet.ATTRIBUTE_NAME_ACCESS_LOG_ENTRY)) .map(AccessLogEntry.class::cast) .orElseGet(AccessLogEntry::new); accessLogEntry.setRawPath(request.getRequestURI()); String queryString = request.getQueryString(); if (queryString != null) { accessLogEntry.setRawQuery(queryString); } accessLogEntry.setUserAgent(request.getHeader("User-Agent")); accessLogEntry.setHttpMethod(request.getMethod()); accessLogEntry.setHostString(request.getHeader("Host")); accessLogEntry.setReferer(request.getHeader("Referer")); String peerAddress = request.getRemoteAddr(); accessLogEntry.setIpV4Address(peerAddress); accessLogEntry.setPeerAddress(peerAddress); String remoteAddress = getRemoteAddress(request); if (!Objects.equal(remoteAddress, peerAddress)) { accessLogEntry.setRemoteAddress(remoteAddress); } int peerPort = request.getRemotePort(); accessLogEntry.setPeerPort(peerPort); int remotePort = getRemotePort(request); if (remotePort != peerPort) { accessLogEntry.setRemotePort(remotePort); } accessLogEntry.setHttpVersion(request.getProtocol()); accessLogEntry.setScheme(request.getScheme()); accessLogEntry.setLocalPort(getConnectorLocalPort(request)); Principal principal = (Principal) request.getAttribute(ServletRequest.JDISC_REQUEST_PRINCIPAL); if (principal != null) { accessLogEntry.setUserPrincipal(principal); } X509Certificate[] clientCert = (X509Certificate[]) request.getAttribute(ServletRequest.SERVLET_REQUEST_X509CERT); if (clientCert != null && clientCert.length > 0) { accessLogEntry.setSslPrincipal(clientCert[0].getSubjectX500Principal()); } String sslSessionId = (String) request.getAttribute(ServletRequest.SERVLET_REQUEST_SSL_SESSION_ID); if (sslSessionId != null) { accessLogEntry.addKeyValue("ssl-session-id", sslSessionId); } String cipherSuite = (String) request.getAttribute(ServletRequest.SERVLET_REQUEST_CIPHER_SUITE); if (cipherSuite != null) { accessLogEntry.addKeyValue("cipher-suite", cipherSuite); } final long startTime = request.getTimeStamp(); final long endTime = System.currentTimeMillis(); accessLogEntry.setTimeStamp(startTime); accessLogEntry.setDurationBetweenRequestResponse(endTime - startTime); accessLogEntry.setReturnedContentSize(response.getHttpChannel().getBytesWritten()); accessLogEntry.setStatusCode(response.getCommittedMetaData().getStatus()); LOGGED_REQUEST_HEADERS.forEach(header -> { String value = request.getHeader(header); if (value != null) { accessLogEntry.addKeyValue(header, value); } }); accessLog.log(accessLogEntry); } catch (Exception e) { // Catching any exceptions here as it is unclear how Jetty handles exceptions from a RequestLog. logger.log(Level.SEVERE, "Failed to log access log entry: " + e.getMessage(), e); } }
Example 9
Source File: AthenzRequestLog.java From athenz with Apache License 2.0 | 4 votes |
private void logPrincipal(StringBuilder buf, Request request) { final Object principal = request.getAttribute(REQUEST_PRINCIPAL); append(buf, (principal == null) ? null : principal.toString()); }