當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。