当前位置: 首页>>代码示例>>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;未经允许,请勿转载。