Java Code Examples for javax.servlet.AsyncEvent#getThrowable()
The following examples show how to use
javax.servlet.AsyncEvent#getThrowable() .
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: JettyAsyncListener.java From pinpoint with Apache License 2.0 | 6 votes |
private Throwable getThrowable(AsyncEvent asyncEvent) { try { if (asyncEvent.getThrowable() != null) { return asyncEvent.getThrowable(); } // Jetty 8.x final ServletRequest request = asyncEvent.getSuppliedRequest(); if (request != null) { final Object errorException = request.getAttribute(RequestDispatcher.ERROR_EXCEPTION); if (errorException instanceof Throwable) { return (Throwable) errorException; } } } catch (Exception ignored) { } return null; }
Example 2
Source File: AsyncReqProcWithHttpClientCallback.java From uavstack with Apache License 2.0 | 6 votes |
@Override public void onTimeout(AsyncEvent arg0) throws IOException { // 超时,也要返回合理的错误信息 try { OutputStream os = ac.getResponse().getOutputStream(); HttpClientCallbackResult result = new HttpClientCallbackResult(null, os); HttpAsyncException exp = new HttpAsyncException(HttpAsyncException.ExceptionEvent.REQASYNC_TIMEOUT, arg0.getThrowable()); result.setRetCode(getStatusCode()); result.setException(exp); callback.failed(result); } catch (RuntimeException e) { // ignore } }
Example 3
Source File: AsyncReqProcWithHttpClientCallback.java From uavstack with Apache License 2.0 | 6 votes |
@Override public void onError(AsyncEvent arg0) throws IOException { // 也要返回合理的错误信息 try { OutputStream os = ac.getResponse().getOutputStream(); HttpClientCallbackResult result = new HttpClientCallbackResult(null, os); HttpAsyncException exp = new HttpAsyncException(HttpAsyncException.ExceptionEvent.REQASYNC_ERROR, arg0.getThrowable()); result.setRetCode(getStatusCode()); result.setException(exp); callback.failed(result); } catch (RuntimeException e) { // ignore } }
Example 4
Source File: ApmAsyncListener.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Override public void onTimeout(AsyncEvent event) { throwable = event.getThrowable(); if (isJBossEap6(event)) { endTransaction(event); } /* NOTE: HTTP status code may not have been set yet, so we do not call endTransaction() from here. According to the Servlet 3 specification (http://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf, section 2.3.3.3), onComplete() should always be called by the container even in the case of timeout or error, and the final HTTP status code should be set by then. So we'll just defer to onComplete() for finalizing the span and do nothing here. But JBoss EAP 6 is a special one... */ }
Example 5
Source File: ApmAsyncListener.java From apm-agent-java with Apache License 2.0 | 6 votes |
@Override public void onError(AsyncEvent event) { throwable = event.getThrowable(); if (isJBossEap6(event)) { endTransaction(event); } /* NOTE: HTTP status code may not have been set yet, so we only hold a reference to the related error that may not be otherwise available, but not calling endTransaction() from here. According to the Servlet 3 specification (http://download.oracle.com/otn-pub/jcp/servlet-3.0-fr-eval-oth-JSpec/servlet-3_0-final-spec.pdf, section 2.3.3.3), onComplete() should always be called by the container even in the case of timeout or error, and the final HTTP status code should be set by then. So we'll just defer to onComplete() for finalizing the span and do nothing here. But JBoss EAP 6 is a special one... */ }
Example 6
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 7
Source File: AsyncListenerWrapper.java From tomcatsrc with Apache License 2.0 | 5 votes |
private AsyncEvent customizeEvent(AsyncEvent event) { if (servletRequest != null && servletResponse != null) { return new AsyncEvent(event.getAsyncContext(), servletRequest, servletResponse, event.getThrowable()); } else { return event; } }
Example 8
Source File: AWSXRayServletAsyncListener.java From aws-xray-sdk-java with Apache License 2.0 | 5 votes |
private void processEvent(AsyncEvent event) throws IOException { AWSXRayRecorder recorder = getRecorder(); Entity prior = recorder.getTraceEntity(); try { Entity entity = (Entity) event.getSuppliedRequest().getAttribute(ENTITY_ATTRIBUTE_KEY); recorder.setTraceEntity(entity); if (null != event.getThrowable()) { entity.addException(event.getThrowable()); } filter.postFilter(event.getSuppliedRequest(), event.getSuppliedResponse()); } finally { recorder.setTraceEntity(prior); } }
Example 9
Source File: AsyncListenerWrapper.java From Tomcat8-Source-Read with MIT License | 5 votes |
private AsyncEvent customizeEvent(AsyncEvent event) { if (servletRequest != null && servletResponse != null) { return new AsyncEvent(event.getAsyncContext(), servletRequest, servletResponse, event.getThrowable()); } else { return event; } }
Example 10
Source File: ServletHttpHandlerAdapter.java From java-technology-stack with MIT License | 5 votes |
@Override public void onError(AsyncEvent event) { Throwable ex = event.getThrowable(); logger.debug(this.logPrefix + "Error notification: " + (ex != null ? ex : "<no Throwable>")); AsyncContext context = event.getAsyncContext(); runIfAsyncNotComplete(context, this.isCompleted, context::complete); }
Example 11
Source File: ServletHttpHandlerAdapter.java From spring-analysis-note with MIT License | 5 votes |
@Override public void onError(AsyncEvent event) { Throwable ex = event.getThrowable(); logger.debug(this.logPrefix + "Error notification: " + (ex != null ? ex : "<no Throwable>")); AsyncContext context = event.getAsyncContext(); runIfAsyncNotComplete(context, this.isCompleted, context::complete); }
Example 12
Source File: ServletServerHttpRequest.java From java-technology-stack with MIT License | 4 votes |
@Override public void onTimeout(AsyncEvent event) { Throwable ex = event.getThrowable(); ex = ex != null ? ex : new IllegalStateException("Async operation timeout."); bodyPublisher.onError(ex); }
Example 13
Source File: ServletServerHttpResponse.java From java-technology-stack with MIT License | 4 votes |
@Override public void onTimeout(AsyncEvent event) { Throwable ex = event.getThrowable(); ex = (ex != null ? ex : new IllegalStateException("Async operation timeout.")); handleError(ex); }
Example 14
Source File: AsyncContextImpl.java From component-runtime with Apache License 2.0 | 4 votes |
private AsyncEvent wrap(final AsyncEvent event) { if (request != null && response != null) { return new AsyncEvent(event.getAsyncContext(), request, response, event.getThrowable()); } return event; }
Example 15
Source File: ServletServerHttpRequest.java From spring-analysis-note with MIT License | 4 votes |
@Override public void onTimeout(AsyncEvent event) { Throwable ex = event.getThrowable(); ex = ex != null ? ex : new IllegalStateException("Async operation timeout."); bodyPublisher.onError(ex); }
Example 16
Source File: AsyncDispatcherServlet.java From Spring-Security-Third-Edition with MIT License | 4 votes |
@Override public void onError(AsyncEvent event) throws IOException { String error = (event.getThrowable() == null ? "UNKNOWN ERROR" : event.getThrowable().getMessage()); logger.error("Error in async request " + error); handleTimeoutOrError(event, "Error processing " + error); }
Example 17
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(); }
Example 18
Source File: ServletServerHttpResponse.java From spring-analysis-note with MIT License | 4 votes |
@Override public void onTimeout(AsyncEvent event) { Throwable ex = event.getThrowable(); ex = (ex != null ? ex : new IllegalStateException("Async operation timeout.")); handleError(ex); }