当前位置: 首页>>代码示例>>Java>>正文


Java WebAsyncUtils类代码示例

本文整理汇总了Java中org.springframework.web.context.request.async.WebAsyncUtils的典型用法代码示例。如果您正苦于以下问题:Java WebAsyncUtils类的具体用法?Java WebAsyncUtils怎么用?Java WebAsyncUtils使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


WebAsyncUtils类属于org.springframework.web.context.request.async包,在下文中一共展示了WebAsyncUtils类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

    if (returnValue == null) {
        mavContainer.setRequestHandled(true);
        return;
    }

    final AsyncResponseEntity<?> asyncResponseEntity = AsyncResponseEntity.class.cast(returnValue);
    
    Observable<?> observable = asyncResponseEntity.getObservable();
    Single<?> single = asyncResponseEntity.getSingle();
    MultiValueMap<String, String> headers =  asyncResponseEntity.getHeaders();
    HttpStatus status = asyncResponseEntity.getStatus();
    
    if(observable != null)
    	WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new ObservableDeferredResult<>(observable, headers, status), mavContainer);
    else if(single != null)
    	WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(new SingleDeferredResult<>(single, headers, status), mavContainer);
    
}
 
开发者ID:quebic-source,项目名称:microservices-sample-project,代码行数:22,代码来源:AsyncResponseEntityReturnHandler.java

示例2: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	final DeferredResult<Object> deferredResult = new DeferredResult<Object>();
	WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult, mavContainer);

	ListenableFuture<?> future = (ListenableFuture<?>) returnValue;
	future.addCallback(new ListenableFutureCallback<Object>() {
		@Override
		public void onSuccess(Object result) {
			deferredResult.setResult(result);
		}
		@Override
		public void onFailure(Throwable ex) {
			deferredResult.setErrorResult(ex);
		}
	});
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:25,代码来源:ListenableFutureReturnValueHandler.java

示例3: setUp

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Before
public void setUp() throws Exception {

	List<HttpMessageConverter<?>> converters = Arrays.asList(
			new StringHttpMessageConverter(), new MappingJackson2HttpMessageConverter());

	this.handler = new ResponseBodyEmitterReturnValueHandler(converters);
	this.mavContainer = new ModelAndViewContainer();

	this.request = new MockHttpServletRequest();
	this.response = new MockHttpServletResponse();
	this.webRequest = new ServletWebRequest(this.request, this.response);

	AsyncWebRequest asyncWebRequest = new StandardServletAsyncWebRequest(this.request, this.response);
	WebAsyncUtils.getAsyncManager(this.webRequest).setAsyncWebRequest(asyncWebRequest);
	this.request.setAsyncSupported(true);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:18,代码来源:ResponseBodyEmitterReturnValueHandlerTests.java

示例4: timeoutValueAndCallback

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Test
public void timeoutValueAndCallback() throws Exception {

	AsyncWebRequest asyncWebRequest = mock(AsyncWebRequest.class);
	WebAsyncUtils.getAsyncManager(this.request).setAsyncWebRequest(asyncWebRequest);

	ResponseBodyEmitter emitter = new ResponseBodyEmitter(19000L);
	emitter.onTimeout(mock(Runnable.class));
	emitter.onCompletion(mock(Runnable.class));

	MethodParameter returnType = returnType(TestController.class, "handle");
	this.handler.handleReturnValue(emitter, returnType, this.mavContainer, this.webRequest);

	verify(asyncWebRequest).setTimeout(19000L);
	verify(asyncWebRequest).addTimeoutHandler(any(Runnable.class));
	verify(asyncWebRequest, times(2)).addCompletionHandler(any(Runnable.class));
	verify(asyncWebRequest).startAsync();
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:19,代码来源:ResponseBodyEmitterReturnValueHandlerTests.java

示例5: doFilterInternal

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
protected void doFilterInternal(HttpServletRequest httpServletRequest, HttpServletResponse httpServletResponse,
        FilterChain filterChain) throws ServletException, IOException {
    setMdc();

    WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(httpServletRequest);

    UserIdLoggingFilter tenancyProcessingInterceptor = (UserIdLoggingFilter) asyncManager
            .getCallableInterceptor(CALLABLE_INTERCEPTOR_KEY);
    if (tenancyProcessingInterceptor == null) {
        asyncManager.registerCallableInterceptor(CALLABLE_INTERCEPTOR_KEY, new UserIdCallableProcessingInterceptorAdapter());
    }
    try {
        filterChain.doFilter(httpServletRequest, httpServletResponse);
    } finally {
        removeMdc();
    }

}
 
开发者ID:Talend,项目名称:daikon,代码行数:20,代码来源:UserIdLoggingFilter.java

示例6: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {
    if (returnValue == null) {
        mavContainer.setRequestHandled(true);
        return;
    }
    final DeferredResult<Object> deferredResult = new DeferredResult<>();
    Futures.addCallback((ListenableFuture<?>) returnValue, new FutureCallback<Object>() {
        @Override
        public void onSuccess(@Nullable Object result) {
            deferredResult.setResult(result);
        }

        @Override
        public void onFailure(Throwable t) {
            deferredResult.setErrorResult(t);
        }
    });
    WebAsyncUtils.getAsyncManager(webRequest).startDeferredResultProcessing(deferredResult,mavContainer);
}
 
开发者ID:Kixeye,项目名称:chassis,代码行数:21,代码来源:ListenableFutureReturnValueHandler.java

示例7: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue,
                              MethodParameter returnType,
                              ModelAndViewContainer mavContainer,
                              NativeWebRequest webRequest) throws Exception {
    final DeferredResult<Object> deferredResult = new DeferredResult<>();
    final CompletableFuture<?> future = (CompletableFuture<?>) returnValue;
    final CompletableFuture<Object> completedFuture = future.handle((ret, err) -> {
        if (ret != null) {
            deferredResult.setResult(ret);
            return ret;
        }
        else {
            deferredResult.setErrorResult(err);
            return null;
        }
    });

    WebAsyncUtils
            .getAsyncManager(webRequest)
            .startDeferredResultProcessing(deferredResult, mavContainer);
}
 
开发者ID:CarloMicieli,项目名称:trenako-v2,代码行数:23,代码来源:CompletableFutureReturnValueHandler.java

示例8: preHandle

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void preHandle(WebRequest request) throws DataAccessException {

	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applyCallableInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// do not modify the EntityManager: just mark the request accordingly
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:35,代码来源:OpenEntityManagerInViewInterceptor.java

示例9: preHandle

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according and bind it to the thread via the
 * {@link org.springframework.transaction.support.TransactionSynchronizationManager}.
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening Hibernate Session in OpenSessionInViewInterceptor");
		Session session = openSession();
		SessionHolder sessionHolder = new SessionHolder(session);
		TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

		AsyncRequestInterceptor asyncRequestInterceptor =
				new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
		asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
		asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:34,代码来源:OpenSessionInViewInterceptor.java

示例10: preHandle

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
/**
 * Open a new Hibernate {@code Session} according to the settings of this
 * {@code HibernateAccessor} and bind it to the thread via the
 * {@link TransactionSynchronizationManager}.
 * @see org.springframework.orm.hibernate3.SessionFactoryUtils#getSession
 */
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applySessionBindingInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if ((isSingleSession() && TransactionSynchronizationManager.hasResource(getSessionFactory())) ||
		SessionFactoryUtils.isDeferredCloseActive(getSessionFactory())) {
		// Do not modify the Session: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		if (isSingleSession()) {
			// single session mode
			logger.debug("Opening single Hibernate Session in OpenSessionInViewInterceptor");
			Session session = SessionFactoryUtils.getSession(
					getSessionFactory(), getEntityInterceptor(), getJdbcExceptionTranslator());
			applyFlushMode(session, false);
			SessionHolder sessionHolder = new SessionHolder(session);
			TransactionSynchronizationManager.bindResource(getSessionFactory(), sessionHolder);

			AsyncRequestInterceptor asyncRequestInterceptor =
					new AsyncRequestInterceptor(getSessionFactory(), sessionHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, asyncRequestInterceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, asyncRequestInterceptor);
		}
		else {
			// deferred close mode
			SessionFactoryUtils.initDeferredClose(getSessionFactory());
		}
	}
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:46,代码来源:OpenSessionInViewInterceptor.java

示例11: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType, ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

    if (returnValue == null) {
        mavContainer.setRequestHandled(true);
        return;
    }

    final Observable<?> observable = Observable.class.cast(returnValue);
    log.debug("handleReturnValue begin to process");
    WebAsyncUtils.getAsyncManager(webRequest)
            .startDeferredResultProcessing(new ObservableAdapter<>(observable), mavContainer);
    log.debug("handleReturnValue stop to process");
}
 
开发者ID:bobxwang,项目名称:springboot-scala-withswagger,代码行数:15,代码来源:ObservableReturnValueHandler.java

示例12: preHandle

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void preHandle(WebRequest request) throws DataAccessException {
	String participateAttributeName = getParticipateAttributeName();

	WebAsyncManager asyncManager = WebAsyncUtils.getAsyncManager(request);
	if (asyncManager.hasConcurrentResult()) {
		if (applyCallableInterceptor(asyncManager, participateAttributeName)) {
			return;
		}
	}

	if (TransactionSynchronizationManager.hasResource(getEntityManagerFactory())) {
		// Do not modify the EntityManager: just mark the request accordingly.
		Integer count = (Integer) request.getAttribute(participateAttributeName, WebRequest.SCOPE_REQUEST);
		int newCount = (count != null ? count + 1 : 1);
		request.setAttribute(getParticipateAttributeName(), newCount, WebRequest.SCOPE_REQUEST);
	}
	else {
		logger.debug("Opening JPA EntityManager in OpenEntityManagerInViewInterceptor");
		try {
			EntityManager em = createEntityManager();
			EntityManagerHolder emHolder = new EntityManagerHolder(em);
			TransactionSynchronizationManager.bindResource(getEntityManagerFactory(), emHolder);

			AsyncRequestInterceptor interceptor = new AsyncRequestInterceptor(getEntityManagerFactory(), emHolder);
			asyncManager.registerCallableInterceptor(participateAttributeName, interceptor);
			asyncManager.registerDeferredResultInterceptor(participateAttributeName, interceptor);
		}
		catch (PersistenceException ex) {
			throw new DataAccessResourceFailureException("Could not create JPA EntityManager", ex);
		}
	}
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:OpenEntityManagerInViewInterceptor.java

示例13: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	HttpServletResponse response = webRequest.getNativeResponse(HttpServletResponse.class);
	ServerHttpResponse outputMessage = new ServletServerHttpResponse(response);

	if (ResponseEntity.class.isAssignableFrom(returnValue.getClass())) {
		ResponseEntity<?> responseEntity = (ResponseEntity<?>) returnValue;
		outputMessage.setStatusCode(responseEntity.getStatusCode());
		outputMessage.getHeaders().putAll(responseEntity.getHeaders());

		returnValue = responseEntity.getBody();
		if (returnValue == null) {
			mavContainer.setRequestHandled(true);
			return;
		}
	}

	ServletRequest request = webRequest.getNativeRequest(ServletRequest.class);
	ShallowEtagHeaderFilter.disableContentCaching(request);

	Assert.isInstanceOf(StreamingResponseBody.class, returnValue);
	StreamingResponseBody streamingBody = (StreamingResponseBody) returnValue;

	Callable<Void> callable = new StreamingResponseBodyTask(outputMessage.getBody(), streamingBody);
	WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(callable, mavContainer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:34,代码来源:StreamingResponseBodyReturnValueHandler.java

示例14: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	Callable<?> callable = (Callable<?>) returnValue;
	WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(callable, mavContainer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:13,代码来源:CallableMethodReturnValueHandler.java

示例15: handleReturnValue

import org.springframework.web.context.request.async.WebAsyncUtils; //导入依赖的package包/类
@Override
public void handleReturnValue(Object returnValue, MethodParameter returnType,
		ModelAndViewContainer mavContainer, NativeWebRequest webRequest) throws Exception {

	if (returnValue == null) {
		mavContainer.setRequestHandled(true);
		return;
	}

	WebAsyncTask<?> webAsyncTask = (WebAsyncTask<?>) returnValue;
	webAsyncTask.setBeanFactory(this.beanFactory);
	WebAsyncUtils.getAsyncManager(webRequest).startCallableProcessing(webAsyncTask, mavContainer);
}
 
开发者ID:langtianya,项目名称:spring4-understanding,代码行数:14,代码来源:AsyncTaskMethodReturnValueHandler.java


注:本文中的org.springframework.web.context.request.async.WebAsyncUtils类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。