當前位置: 首頁>>代碼示例>>Java>>正文


Java AsyncEvent類代碼示例

本文整理匯總了Java中javax.servlet.AsyncEvent的典型用法代碼示例。如果您正苦於以下問題:Java AsyncEvent類的具體用法?Java AsyncEvent怎麽用?Java AsyncEvent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


AsyncEvent類屬於javax.servlet包,在下文中一共展示了AsyncEvent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: onComplete

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@Override
public void onComplete(AsyncEvent arg0) throws IOException {

    // 返回信息

    OutputStream os = ac.getResponse().getOutputStream();
    InputStream is = response.getEntity().getContent();

    // 調用微信平台的Callback
    HttpClientCallbackResult result = new HttpClientCallbackResult(is, os);
    result.setRetCode(getStatusCode());
    try {
        callback.completed(result);
    }
    catch (RuntimeException e) {
        // ignore
    }
    finally {
        os.flush();
        os.close();
        is.close();
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:24,代碼來源:AsyncReqProcWithHttpClientCallback.java

示例2: onTimeout

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@Override
public void onTimeout(AsyncEvent event) throws IOException {
  // in this time, maybe:
  // 1.invocation in executor's queue
  // 2.already executing in executor
  // 3.already send response
  // to avoid concurrent, must lock request
  ServletRequest request = event.getSuppliedRequest();
  HttpServletRequestEx requestEx = (HttpServletRequestEx) request.getAttribute(RestConst.REST_REQUEST);

  synchronized (requestEx) {
    ServletResponse response = event.getAsyncContext().getResponse();
    if (!response.isCommitted()) {
      LOGGER.error("Rest request timeout, method {}, path {}.", requestEx.getMethod(), requestEx.getRequestURI());
      // invocation in executor's queue
      response.setContentType(MediaType.APPLICATION_JSON);

      // we don't know if developers declared one statusCode in contract
      // so we use cse inner statusCode here
      ((HttpServletResponse) response).setStatus(ExceptionFactory.PRODUCER_INNER_STATUS_CODE);
      PrintWriter out = response.getWriter();
      out.write(TIMEOUT_MESSAGE);
      response.flushBuffer();
    }

    request.removeAttribute(RestConst.REST_REQUEST);
  }
}
 
開發者ID:apache,項目名稱:incubator-servicecomb-java-chassis,代碼行數:29,代碼來源:RestAsyncListener.java

示例3: processEvent

import javax.servlet.AsyncEvent; //導入依賴的package包/類
private void processEvent(AsyncEvent event) throws IOException {
    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);
    }
}
 
開發者ID:aws,項目名稱:aws-xray-sdk-java,代碼行數:14,代碼來源:AWSXRayServletFilter.java

示例4: onAsyncStart

import javax.servlet.AsyncEvent; //導入依賴的package包/類
private void onAsyncStart(AsyncContext newAsyncContext) {
    final boolean setupRequired = SecurityActions.currentServletRequestContext() == null;
    ThreadSetupAction.Handle handle = null;
    if (setupRequired) {
        handle = servletRequestContext.getDeployment().getThreadSetupAction().setup(exchange);
    }
    try {
        //now run request listeners
        setupRequestContext(setupRequired);
        try {
            for (final BoundAsyncListener listener : asyncListeners) {
                //make sure we use the new async context
                AsyncEvent event = new AsyncEvent(newAsyncContext, listener.servletRequest, listener.servletResponse);
                try {
                    listener.asyncListener.onStartAsync(event);
                } catch (IOException e) {
                    UndertowServletLogger.REQUEST_LOGGER.ioExceptionDispatchingAsyncEvent(e);
                }
            }
        } finally {
            tearDownRequestContext(setupRequired);
        }
    } finally {
        if (setupRequired) {
            handle.tearDown();
        }
    }
}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:29,代碼來源:AsyncContextImpl.java

示例5: onError

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@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
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:18,代碼來源:AsyncReqProcWithHttpClientCallback.java

示例6: onTimeout

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@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
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:18,代碼來源:AsyncReqProcWithHttpClientCallback.java

示例7: handleTimeoutOrError

import javax.servlet.AsyncEvent; //導入依賴的package包/類
private void handleTimeoutOrError(AsyncEvent event, String message) {
            PrintWriter writer = null;
            try {
                future.cancel(true);
                HttpServletResponse response = (HttpServletResponse) event.getAsyncContext().getResponse();
                //HttpServletRequest request = (HttpServletRequest) event.getAsyncContext().getRequest();
                //request.getRequestDispatcher("/app/error.htm").forward(request, response);
                writer = response.getWriter();
                writer.print(message);
                writer.flush();
            } catch (Exception ex) {
// FIXME:               logger.error(ex);
            } finally {
                event.getAsyncContext().complete();
                if (writer != null) {
                    writer.close();
                }
            }
        }
 
開發者ID:PacktPublishing,項目名稱:Spring-Security-Third-Edition,代碼行數:20,代碼來源:AsyncDispatcherServlet.java

示例8: setStarted

import javax.servlet.AsyncEvent; //導入依賴的package包/類
public void setStarted(Context context, ServletRequest request, ServletResponse response,
		boolean originalRequestResponse) {

	synchronized (asyncContextLock) {
		this.request.getCoyoteRequest().action(ActionCode.ASYNC_START, this);

		this.context = context;
		this.servletRequest = request;
		this.servletResponse = response;
		this.hasOriginalRequestAndResponse = originalRequestResponse;
		this.event = new AsyncEvent(this, request, response);

		List<AsyncListenerWrapper> listenersCopy = new ArrayList<AsyncListenerWrapper>();
		listenersCopy.addAll(listeners);
		listeners.clear();
		for (AsyncListenerWrapper listener : listenersCopy) {
			try {
				listener.fireOnStartAsync(event);
			} catch (Throwable t) {
				ExceptionUtils.handleThrowable(t);
				log.warn("onStartAsync() failed for listener of type [" + listener.getClass().getName() + "]", t);
			}
		}
	}
}
 
開發者ID:how2j,項目名稱:lazycat,代碼行數:26,代碼來源:AsyncContextImpl.java

示例9: startDeferredResultProcessingTimeoutAndResumeThroughCallback

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughCallback() throws Exception {

	final DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
	deferredResult.onTimeout(new Runnable() {
		@Override
		public void run() {
			deferredResult.setResult(23);
		}
	});

	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:21,代碼來源:WebAsyncManagerTimeoutTests.java

示例10: startDeferredResultProcessingTimeoutAndResumeThroughInterceptor

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@Test
public void startDeferredResultProcessingTimeoutAndResumeThroughInterceptor() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptorAdapter() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			result.setErrorResult(23);
			return true;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(23, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:WebAsyncManagerTimeoutTests.java

示例11: startDeferredResultProcessingAfterTimeoutException

import javax.servlet.AsyncEvent; //導入依賴的package包/類
@Test
public void startDeferredResultProcessingAfterTimeoutException() throws Exception {

	DeferredResult<Integer> deferredResult = new DeferredResult<Integer>();
	final Exception exception = new Exception();

	DeferredResultProcessingInterceptor interceptor = new DeferredResultProcessingInterceptorAdapter() {
		@Override
		public <T> boolean handleTimeout(NativeWebRequest request, DeferredResult<T> result) throws Exception {
			throw exception;
		}
	};

	this.asyncManager.registerDeferredResultInterceptor("interceptor", interceptor);
	this.asyncManager.startDeferredResultProcessing(deferredResult);

	AsyncEvent event = null;
	this.asyncWebRequest.onTimeout(event);

	assertTrue(this.asyncManager.hasConcurrentResult());
	assertEquals(exception, this.asyncManager.getConcurrentResult());
	assertEquals("/test", ((MockAsyncContext) this.servletRequest.getAsyncContext()).getDispatchedPath());
}
 
開發者ID:langtianya,項目名稱:spring4-understanding,代碼行數:24,代碼來源:WebAsyncManagerTimeoutTests.java

示例12: onTimeout

import javax.servlet.AsyncEvent; //導入依賴的package包/類
/**
 * Async operation timeout (AsyncListener interface)
 *
 * @param   event               Async event
 */
@Override
public void onTimeout(AsyncEvent event) {
    AsyncContext context = event.getAsyncContext();
    lock.lock();
    try {
        pendingWaits.remove(context);
        JSONObject response = new JSONObject();
        response.put("events", new JSONArray());
        response.put("requestProcessingTime", System.currentTimeMillis()-timestamp);
        try (Writer writer = context.getResponse().getWriter()) {
            response.writeJSONString(writer);
        } catch (IOException exc) {
            Logger.logDebugMessage(String.format("Unable to return API response to %s: %s",
                                                 address, exc.toString()));
        }
        context.complete();
        timestamp = System.currentTimeMillis();
    } finally {
        lock.unlock();
    }
}
 
開發者ID:BitcoinFullnode,項目名稱:ROKOS-OK-Bitcoin-Fullnode,代碼行數:27,代碼來源:EventListener.java

示例13: setStarted

import javax.servlet.AsyncEvent; //導入依賴的package包/類
public void setStarted(Context context, ServletRequest request,
        ServletResponse response, boolean originalRequestResponse) {

    this.request.getCoyoteRequest().action(
            ActionCode.ASYNC_START, this);

    this.context = context;
    this.servletRequest = request;
    this.servletResponse = response;
    this.hasOriginalRequestAndResponse = originalRequestResponse;
    this.event = new AsyncEvent(this, request, response);

    List<AsyncListenerWrapper> listenersCopy =
        new ArrayList<AsyncListenerWrapper>();
    listenersCopy.addAll(listeners);
    for (AsyncListenerWrapper listener : listenersCopy) {
        try {
            listener.fireOnStartAsync(event);
        } catch (Throwable t) {
            ExceptionUtils.handleThrowable(t);
            log.warn("onStartAsync() failed for listener of type [" +
                    listener.getClass().getName() + "]", t);
        }
    }
    listeners.clear();
}
 
開發者ID:deathspeeder,項目名稱:class-guard,代碼行數:27,代碼來源:AsyncContextImpl.java

示例14: setStarted

import javax.servlet.AsyncEvent; //導入依賴的package包/類
public void setStarted(Context context, ServletRequest request,
        ServletResponse response, boolean originalRequestResponse) {
    
    this.request.getCoyoteRequest().action(
            ActionCode.ASYNC_START, this);

    this.context = context;
    this.servletRequest = request;
    this.servletResponse = response;
    this.hasOriginalRequestAndResponse = originalRequestResponse;
    this.event = new AsyncEvent(this, request, response);
    
    List<AsyncListenerWrapper> listenersCopy =
        new ArrayList<AsyncListenerWrapper>();
    listenersCopy.addAll(listeners);
    for (AsyncListenerWrapper listener : listenersCopy) {
        try {
            listener.fireOnStartAsync(event);
        } catch (IOException ioe) {
            log.warn("onStartAsync() failed for listener of type [" +
                    listener.getClass().getName() + "]", ioe);
        }
    }
    listeners.clear();
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:26,代碼來源:AsyncContextImpl.java

示例15: setErrorState

import javax.servlet.AsyncEvent; //導入依賴的package包/類
public void setErrorState(Throwable t) {
    if (t!=null) request.setAttribute(RequestDispatcher.ERROR_EXCEPTION, t);
    request.getCoyoteRequest().action(ActionCode.ASYNC_ERROR, null);
    AsyncEvent errorEvent = new AsyncEvent(event.getAsyncContext(),
            event.getSuppliedRequest(), event.getSuppliedResponse(), t);
    List<AsyncListenerWrapper> listenersCopy =
        new ArrayList<AsyncListenerWrapper>();
    listenersCopy.addAll(listeners);
    for (AsyncListenerWrapper listener : listenersCopy) {
        try {
            listener.fireOnError(errorEvent);
        } catch (IOException ioe) {
            log.warn("onStartAsync() failed for listener of type [" +
                    listener.getClass().getName() + "]", ioe);
        }
    }
}
 
開發者ID:WhiteBearSolutions,項目名稱:WBSAirback,代碼行數:18,代碼來源:AsyncContextImpl.java


注:本文中的javax.servlet.AsyncEvent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。