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


Java ErrorController类代码示例

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


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

示例1: afterCompletion

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
		throws Exception {
	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	if (CompensableCoordinatorController.class.equals(clazz)) {
		return;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return;
	}

	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return;
	}

	Compensable annotation = clazz.getAnnotation(Compensable.class);
	if (annotation == null) {
		return;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	CompensableManager compensableManager = beanFactory.getCompensableManager();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	CompensableTransaction compensable = compensableManager.getCompensableTransactionQuietly();
	TransactionContext transactionContext = compensable.getTransactionContext();

	byte[] byteArray = CommonUtils.serializeObject(transactionContext);
	String compensableStr = ByteUtils.byteArrayToString(byteArray);
	response.addHeader(HEADER_TRANCACTION_KEY, compensableStr);
	response.addHeader(HEADER_PROPAGATION_KEY, this.identifier);

	TransactionResponseImpl resp = new TransactionResponseImpl();
	resp.setTransactionContext(transactionContext);
	resp.setSourceTransactionCoordinator(beanRegistry.getConsumeCoordinator(null));

	transactionInterceptor.beforeSendResponse(resp);

}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:41,代码来源:CompensableHandlerInterceptor.java

示例2: preHandle

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	if (TransactionCoordinatorController.class.equals(clazz)) {
		return true;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return true;
	}

	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return true;
	}

	String propagationStr = request.getHeader(HEADER_PROPAGATION_KEY);

	String transactionText = StringUtils.trimToNull(transactionStr);
	String propagationText = StringUtils.trimToNull(propagationStr);

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	byte[] byteArray = transactionText == null ? new byte[0] : ByteUtils.stringToByteArray(transactionText);

	TransactionContext transactionContext = null;
	if (byteArray != null && byteArray.length > 0) {
		transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);
	}

	TransactionRequestImpl req = new TransactionRequestImpl();
	req.setTransactionContext(transactionContext);
	req.setTargetTransactionCoordinator(beanRegistry.getConsumeCoordinator(propagationText));

	transactionInterceptor.afterReceiveRequest(req);

	return true;
}
 
开发者ID:liuyangming,项目名称:ByteJTA,代码行数:39,代码来源:TransactionHandlerInterceptor.java

示例3: afterCompletion

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler, Exception ex)
		throws Exception {
	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	if (TransactionCoordinatorController.class.equals(clazz)) {
		return;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return;
	}

	String transactionText = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionText)) {
		return;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	TransactionBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionManager transactionManager = beanFactory.getTransactionManager();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	Transaction transaction = transactionManager.getTransactionQuietly();
	TransactionContext transactionContext = transaction.getTransactionContext();

	byte[] byteArray = CommonUtils.serializeObject(transactionContext);
	String transactionStr = ByteUtils.byteArrayToString(byteArray);
	response.addHeader(HEADER_TRANCACTION_KEY, transactionStr);
	response.addHeader(HEADER_PROPAGATION_KEY, this.identifier);

	TransactionResponseImpl resp = new TransactionResponseImpl();
	resp.setTransactionContext(transactionContext);
	resp.setSourceTransactionCoordinator(beanRegistry.getConsumeCoordinator(null));

	transactionInterceptor.beforeSendResponse(resp);

}
 
开发者ID:liuyangming,项目名称:ByteJTA,代码行数:36,代码来源:TransactionHandlerInterceptor.java

示例4: jsonapiErrorController

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(value = ErrorController.class, search = SearchStrategy.CURRENT)
public BasicErrorController jsonapiErrorController(ErrorAttributes errorAttributes) {
	return new CrnkErrorController(errorAttributes, this.serverProperties.getError(), this.errorViewResolvers);
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:6,代码来源:CrnkErrorControllerAutoConfiguration.java

示例5: preHandle

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {
	HandlerMethod hm = (HandlerMethod) handler;
	Class<?> clazz = hm.getBeanType();
	if (CompensableCoordinatorController.class.equals(clazz)) {
		return true;
	} else if (ErrorController.class.isInstance(hm.getBean())) {
		return true;
	}

	String transactionStr = request.getHeader(HEADER_TRANCACTION_KEY);
	if (StringUtils.isBlank(transactionStr)) {
		return true;
	}

	String propagationStr = request.getHeader(HEADER_PROPAGATION_KEY);

	String transactionText = StringUtils.trimToNull(transactionStr);
	String propagationText = StringUtils.trimToNull(propagationStr);

	Compensable annotation = clazz.getAnnotation(Compensable.class);
	if (annotation == null) {
		return true;
	}

	SpringCloudBeanRegistry beanRegistry = SpringCloudBeanRegistry.getInstance();
	CompensableBeanFactory beanFactory = beanRegistry.getBeanFactory();
	TransactionInterceptor transactionInterceptor = beanFactory.getTransactionInterceptor();

	byte[] byteArray = transactionText == null ? new byte[0] : ByteUtils.stringToByteArray(transactionText);

	TransactionContext transactionContext = null;
	if (byteArray != null && byteArray.length > 0) {
		transactionContext = (TransactionContext) CommonUtils.deserializeObject(byteArray);
	}

	TransactionRequestImpl req = new TransactionRequestImpl();
	req.setTransactionContext(transactionContext);
	req.setTargetTransactionCoordinator(beanRegistry.getConsumeCoordinator(propagationText));

	transactionInterceptor.afterReceiveRequest(req);

	return true;
}
 
开发者ID:liuyangming,项目名称:ByteTCC,代码行数:44,代码来源:CompensableHandlerInterceptor.java

示例6: dataResultErrorController

import org.springframework.boot.autoconfigure.web.ErrorController; //导入依赖的package包/类
@Bean
@ConditionalOnMissingBean(DataResultErrorController.class)
public ErrorController dataResultErrorController(ErrorAttributes errorAttributes){
	return new DataResultErrorController(errorAttributes, this.serverProperties.getError(),
			this.errorViewResolvers);
}
 
开发者ID:wayshall,项目名称:onetwo,代码行数:7,代码来源:ErrorHandleConfiguration.java


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