Java Code Examples for javax.servlet.AsyncEvent#getSuppliedResponse()
The following examples show how to use
javax.servlet.AsyncEvent#getSuppliedResponse() .
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: ServletRuntime.java From brave with Apache License 2.0 | 6 votes |
@Override public void onComplete(AsyncEvent e) { HttpServletRequest req = (HttpServletRequest) e.getSuppliedRequest(); // Use package-private attribute to check if this hook was called redundantly Object sendHandled = req.getAttribute("brave.servlet.TracingFilter$SendHandled"); if (sendHandled instanceof AtomicBoolean && ((AtomicBoolean) sendHandled).compareAndSet(false, true)) { HttpServletResponse res = (HttpServletResponse) e.getSuppliedResponse(); HttpServerResponse response = brave.servlet.HttpServletResponseWrapper.create(req, res, e.getThrowable()); handler.handleSend(response, span); } else { // TODO: None of our tests reach this condition. Make a concrete case that re-enters the // onComplete hook or remove the special case } }
Example 2
Source File: SimpleAsyncListener.java From quarkus-http with Apache License 2.0 | 5 votes |
@Override public void onError(AsyncEvent event) throws IOException { ServletResponse response = event.getSuppliedResponse(); HttpServletResponse httpResponse = (HttpServletResponse) response; httpResponse.setContentType("text/plain"); httpResponse.setStatus(StatusCodes.OK); PrintWriter writer = httpResponse.getWriter(); writer.write(MESSAGE); writer.flush(); if (this.ctx != null) { ctx.complete(); } else { event.getAsyncContext().complete(); } }
Example 3
Source File: ApmAsyncListener.java From apm-agent-java with Apache License 2.0 | 5 votes |
private void endTransaction(AsyncEvent event) { // To ensure transaction is ended only by a single event if (completed.getAndSet(true) || transaction == null) { return; } try { HttpServletRequest request = (HttpServletRequest) event.getSuppliedRequest(); request.removeAttribute(TRANSACTION_ATTRIBUTE); HttpServletResponse response = (HttpServletResponse) event.getSuppliedResponse(); final Response resp = transaction.getContext().getResponse(); if (transaction.isSampled() && servletTransactionHelper.isCaptureHeaders()) { for (String headerName : response.getHeaderNames()) { resp.addHeader(headerName, response.getHeaders(headerName)); } } // request.getParameterMap() may allocate a new map, depending on the servlet container implementation // so only call this method if necessary final String contentTypeHeader = request.getHeader("Content-Type"); final Map<String, String[]> parameterMap; if (transaction.isSampled() && servletTransactionHelper.captureParameters(request.getMethod(), contentTypeHeader)) { parameterMap = request.getParameterMap(); } else { parameterMap = null; } Throwable throwableToSend = event.getThrowable(); if (throwableToSend == null) { throwableToSend = throwable; } servletTransactionHelper.onAfter(transaction, throwableToSend, response.isCommitted(), response.getStatus(), true, request.getMethod(), parameterMap, request.getServletPath(), request.getPathInfo(), contentTypeHeader, false ); } finally { asyncContextAdviceHelperImpl.recycle(this); } }
Example 4
Source File: TracingAsyncListener.java From java-specialagent with Apache License 2.0 | 5 votes |
@Override public void onComplete(AsyncEvent event) throws IOException { HttpServletRequest httpRequest = (HttpServletRequest) event.getSuppliedRequest(); HttpServletResponse httpResponse = (HttpServletResponse) event.getSuppliedResponse(); for (ServletFilterSpanDecorator spanDecorator: spanDecorators) { spanDecorator.onResponse(httpRequest, httpResponse, span); } span.finish(); }
Example 5
Source File: TracingAsyncListener.java From java-specialagent with Apache License 2.0 | 5 votes |
@Override public void onTimeout(AsyncEvent event) throws IOException { HttpServletRequest httpRequest = (HttpServletRequest) event.getSuppliedRequest(); HttpServletResponse httpResponse = (HttpServletResponse) event.getSuppliedResponse(); for (ServletFilterSpanDecorator spanDecorator : spanDecorators) { spanDecorator.onTimeout(httpRequest, httpResponse, event.getAsyncContext().getTimeout(), span); } }
Example 6
Source File: TracingAsyncListener.java From java-specialagent with Apache License 2.0 | 5 votes |
@Override public void onError(AsyncEvent event) throws IOException { HttpServletRequest httpRequest = (HttpServletRequest) event.getSuppliedRequest(); HttpServletResponse httpResponse = (HttpServletResponse) event.getSuppliedResponse(); for (ServletFilterSpanDecorator spanDecorator: spanDecorators) { spanDecorator.onError(httpRequest, httpResponse, event.getThrowable(), span); } }
Example 7
Source File: ServerAsyncListener.java From aceql-http with GNU Lesser General Public License v2.1 | 5 votes |
@Override public void onTimeout(AsyncEvent event) throws IOException { HttpServletRequest request = (HttpServletRequest)event.getSuppliedRequest(); LoggerUtil.log(request, event.getThrowable()); HttpServletResponse response = (HttpServletResponse)event.getSuppliedResponse(); AsyncDebug.debug("Set reponse status to SC_GATEWAY_TIMEOUT"); response.setStatus(HttpServletResponse.SC_GATEWAY_TIMEOUT); }
Example 8
Source File: OcHttpServletListener.java From opencensus-java with Apache License 2.0 | 5 votes |
@Override public void onComplete(AsyncEvent event) { ServletResponse response = event.getSuppliedResponse(); if (response instanceof HttpServletResponse) { OcHttpServletUtil.recordMessageSentEvent(handler, context, (HttpServletResponse) response); } handler.handleEnd( context, (HttpServletRequest) event.getSuppliedRequest(), (HttpServletResponse) event.getSuppliedResponse(), null); this.close(); }
Example 9
Source File: SpanFinishingFilter.java From java-jaxrs with Apache License 2.0 | 5 votes |
@Override public void onComplete(AsyncEvent event) throws IOException { HttpServletResponse httpResponse = (HttpServletResponse)event.getSuppliedResponse(); if (httpResponse.getStatus() >= 500) { addExceptionLogs(spanWrapper.get(), event.getThrowable()); } Tags.HTTP_STATUS.set(spanWrapper.get(), httpResponse.getStatus()); spanWrapper.finish(); }
Example 10
Source File: UndertowAsyncListener.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(final AsyncEvent asyncEvent) { try { if (asyncEvent.getSuppliedResponse() instanceof HttpServletResponse) { return ((HttpServletResponse) asyncEvent.getSuppliedResponse()).getStatus(); } } catch (Exception ignored) { } return 0; }
Example 11
Source File: TomcatAsyncListener.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(final AsyncEvent asyncEvent) { try { if (asyncEvent.getSuppliedResponse() instanceof HttpServletResponse) { return ((HttpServletResponse) asyncEvent.getSuppliedResponse()).getStatus(); } } catch (Exception ignored) { } return 0; }
Example 12
Source File: JettyAsyncListener.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(AsyncEvent asyncEvent) { try { if (asyncEvent.getSuppliedResponse() instanceof HttpServletResponse) { return ((HttpServletResponse) asyncEvent.getSuppliedResponse()).getStatus(); } } catch (Exception ignored) { } return 0; }
Example 13
Source File: ResinAsyncListener.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(final AsyncEvent asyncEvent) { try { if (asyncEvent.getSuppliedResponse() instanceof HttpServletResponse) { return ((HttpServletResponse) asyncEvent.getSuppliedResponse()).getStatus(); } } catch (Exception ignored) { } return 0; }
Example 14
Source File: JbossAsyncListener.java From pinpoint with Apache License 2.0 | 5 votes |
private int getStatusCode(final AsyncEvent asyncEvent) { try { if (asyncEvent.getSuppliedResponse() instanceof HttpServletResponse) { return ((HttpServletResponse) asyncEvent.getSuppliedResponse()).getStatus(); } } catch (Exception ignored) { } return 0; }
Example 15
Source File: SimpleAsyncListener.java From quarkus-http with Apache License 2.0 | 4 votes |
@Override public void onTimeout(AsyncEvent event) throws IOException { HttpServletResponse response = (HttpServletResponse) event.getSuppliedResponse(); response.setStatus(StatusCodes.OK); event.getAsyncContext().complete(); }
Example 16
Source File: WingtipsRequestSpanCompletionAsyncListener.java From wingtips with Apache License 2.0 | 4 votes |
/** * Does the work of doing the final span tagging and naming, and completes the span for {@link * #originalRequestTracingState}. The request, response, and any error needed for the tagging/naming are pulled * from the given {@link AsyncEvent}. This method is configured to only ever execute once (via the * {@link #alreadyCompleted} atomic boolean) - subsequent calls will return immediately without doing anything. * * @param event The {@link AsyncEvent} that triggered finalizing the request span. */ @SuppressWarnings("deprecation") protected void completeRequestSpan(AsyncEvent event) { // Async servlet stuff can trigger multiple completion methods depending on how the request is processed, // but we only care about the first. if (alreadyCompleted.getAndSet(true)) { return; } ServletRequest request = event.getSuppliedRequest(); ServletResponse response = event.getSuppliedResponse(); final HttpServletRequest httpRequest = (request instanceof HttpServletRequest) ? (HttpServletRequest) request : null; final HttpServletResponse httpResponse = (response instanceof HttpServletResponse) ? (HttpServletResponse) response : null; final Throwable error = event.getThrowable(); // Reattach the original tracing state and handle span finalization/completion. //noinspection deprecation runnableWithTracing( new Runnable() { @Override public void run() { Span span = Tracer.getInstance().getCurrentSpan(); try { // Handle response/error tagging and final span name. tagAndNamingStrategy.handleResponseTaggingAndFinalSpanName( span, httpRequest, httpResponse, error, tagAndNamingAdapter ); } finally { // Complete the overall request span. Tracer.getInstance().completeRequestSpan(); } } }, originalRequestTracingState ).run(); }