Example usage for javax.servlet AsyncEvent getThrowable

List of usage examples for javax.servlet AsyncEvent getThrowable

Introduction

In this page you can find the example usage for javax.servlet AsyncEvent getThrowable.

Prototype

public Throwable getThrowable() 

Source Link

Document

Gets the Throwable from this AsyncEvent.

Usage

From source file:com.cisco.oss.foundation.http.server.MonitoringFilter.java

@Override
public void doFilterImpl(final ServletRequest request, final ServletResponse response, final FilterChain chain)
        throws IOException, ServletException {

    regiterMonitoring();/*from   w ww .  ja v  a 2 s. co  m*/

    final long startTime = System.currentTimeMillis();
    HttpServletRequest httpServletRequest = (HttpServletRequest) request;
    HttpServletResponse httpServletResponse = (HttpServletResponse) response;
    String tempMethodName = httpServletRequest.getMethod();
    if (uniqueUriMonitoringEnabled) {
        tempMethodName += ":" + httpServletRequest.getRequestURI();
    }

    boolean reportToMonitoring = true;

    try {
        LOGGER.trace("Monitoring filter: Request processing started at: {}", startTime);

        //         methodName = httpServletRequest.getMethod() + ":" + httpServletRequest.getRequestURI().toString();
        tempMethodName = updateMethodName(httpServletRequest, tempMethodName);

        LOGGER.trace("transaction method name is: {}", tempMethodName);

        CommunicationInfo.getCommunicationInfo().transactionStarted(serviceDetails, tempMethodName,
                threadPool != null ? threadPool.getThreads() : -1);

    } catch (Exception e) {
        LOGGER.error("can't report monitoring data as it has failed on:" + e);
        reportToMonitoring = false;
    }
    final String methodName = tempMethodName;

    try {
        chain.doFilter(httpServletRequest, httpServletResponse);

        if (request.isAsyncStarted()) {

            AsyncContext async = request.getAsyncContext();
            async.addListener(new AsyncListener() {
                @Override
                public void onComplete(AsyncEvent event) throws IOException {
                    final long endTime = System.currentTimeMillis();
                    final int processingTime = (int) (endTime - startTime);
                    LOGGER.debug("Processing time: {} milliseconds", processingTime);
                }

                @Override
                public void onTimeout(AsyncEvent event) throws IOException {

                }

                @Override
                public void onError(AsyncEvent event) throws IOException {
                    Throwable throwable = event.getThrowable();
                    if (throwable != null) {
                        CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName,
                                true, throwable.toString());
                    }
                }

                @Override
                public void onStartAsync(AsyncEvent event) throws IOException {

                }
            });

        } else {
            final long endTime = System.currentTimeMillis();
            final int processingTime = (int) (endTime - startTime);
            LOGGER.debug("Processing time: {} milliseconds", processingTime);
        }

    } catch (Exception e) {
        CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, true,
                e.toString());
        throw e;
    }

    if (reportToMonitoring) {
        try {

            int status = httpServletResponse.getStatus();

            if (status >= 400) {
                CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, true,
                        httpServletResponse.getStatus() + "");

            } else {

                CommunicationInfo.getCommunicationInfo().transactionFinished(serviceDetails, methodName, false,
                        "");
            }
        } catch (Exception e) {
            LOGGER.error("can't report monitoring data as it has failed on:" + e);
        }
    }

}

From source file:org.apache.vysper.xmpp.extension.xep0124.BoshBackedSessionContext.java

protected void handleAsyncEventError(AsyncEvent event) {
    final ServletRequest suppliedRequest = event.getSuppliedRequest();
    final ServletResponse suppliedResponse = event.getSuppliedResponse();
    BoshRequest boshRequest = (BoshRequest) suppliedRequest.getAttribute(BOSH_REQUEST_ATTRIBUTE);
    BoshResponse boshResponse = (BoshResponse) suppliedRequest.getAttribute(BOSH_RESPONSE_ATTRIBUTE);

    // works at least for jetty:
    final Exception exceptionObject = (Exception) suppliedRequest.getAttribute("javax.servlet.error.exception");
    final Throwable throwable = event.getThrowable() != null ? event.getThrowable() : exceptionObject;

    final Long rid = boshRequest == null ? null : boshRequest.getRid();
    LOGGER.warn("SID = " + getSessionId() + " - JID = " + getInitiatingEntity() + " - RID = " + rid
            + " - async error on event ", event.getClass(), throwable);
}