Example usage for javax.servlet AsyncEvent getSuppliedResponse

List of usage examples for javax.servlet AsyncEvent getSuppliedResponse

Introduction

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

Prototype

public ServletResponse getSuppliedResponse() 

Source Link

Document

Gets the ServletResponse from this AsyncEvent.

Usage

From source file:byps.http.HActiveMessages.java

/**
 * This function is called when a new message arrives in onPost
 * @param header//  ww  w  . j  a  v  a  2 s . c o m
 * @param rctxt
 * @param workerThread 
 * @throws BException
 */
public void addMessage(final BMessageHeader header, final HRequestContext rctxt, final Thread workerThread)
        throws BException {
    if (log.isDebugEnabled())
        log.debug("addMessage(" + header + ", rctxt=" + rctxt);

    HActiveMessage msg = getOrCreateActiveMessage(header.messageId);
    msg.setSessionid(header.sessionId);

    HAsyncErrorListener alsn = new HAsyncErrorListener() {

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

            HRequestContext rctxt = getAndRemoveRequestContext(header.messageId);
            if (rctxt == null)
                return;

            HttpServletResponse resp = (HttpServletResponse) arg0.getSuppliedResponse();

            boolean isLongPoll = (header.flags & BMessageHeader.FLAG_LONGPOLL) != 0;
            int status = isLongPoll ? HttpServletResponse.SC_NO_CONTENT
                    : HttpServletResponse.SC_REQUEST_TIMEOUT;
            resp.setStatus(status);

            resp.getOutputStream().close();

            if (log.isDebugEnabled())
                log.debug("AsyncErrorListener.onTimeout(" + arg0 + ") status=" + status);
        }

        @Override
        public void onError(AsyncEvent arg0) throws IOException {
            if (log.isDebugEnabled())
                log.debug("AsyncErrorListener.onError(" + arg0 + ")");
            getAndRemoveRequestContext(header.messageId);
        }
    };
    rctxt.addListener(alsn);

    msg.setRequestContext(rctxt, workerThread);
    if (log.isDebugEnabled())
        log.debug(")addMessage");
}

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);
}