【发布时间】:2016-04-01 15:27:15
【问题描述】:
使用 catch 异常策略捕获并处理异常后,我无法将控制权带回 mule 中的主流。有什么方法可以像我们在 java 中一样在 mule 中继续正常执行。 详情请参考代码。
简单的网络服务类:
public class HorrorScopeService {
public String getHorrorScopeByMonth(String month) throws Exception {
/*CustomLogger.info(CustomLogger.requestLogger, this.getClass(), "getHorrorScopeByMonth()", "PROCESSING REQUEST");
CustomLogger.info(CustomLogger.requestLogger, this.getClass(), "getHorrorScopeByMonth()", String.format("MONTH FOR WHICH REQUEST IS PROCESSING IS %s", month));*/
//CustomException customException=null;
CustomLogger.infoRequest(CustomLogger.requestLogger, "RID_9051844007", "REQUEST", "TESTING", "9051844007", "ha ha ha");
String status="SUCCESS";
System.out.println("1111111111111111111111");
String data=null;;
try{
switch(month) {
case "JAN":
data="Not a good month to be born";
break;
case "FEB":
data="People born in this month are ok ok";
break;
case "MAR":
data="People born in this month are good";
break;
case "APR":
data="People born in this month are brilliant";
break;
default:
status="FAIL";
data="you should not be born";
int number=2;
int result=number/0;
}
}catch(Exception e) {
System.out.println("2222222222222222222222222222");
throw new CustomException(e, "RID_905184", "9051844",
this.getClass(), "getHorrorScopeByMonth()");
} finally {
CustomLogger.infoResponse(CustomLogger.requestLogger, "RID_9051844007", "RESPONSE", "TESTING", "9051844007", "90SEC", status, status,(String) data);
CustomLogger.infoFunctionalKeyValueLog(CustomLogger.functionalLogger, "RID_9051844007", "ERROR", "TESTING", "9051844007", this.getClass(), "getHorrorScopeByMonth()",(String) data);
System.out.println("55555555555555555555555555555");
}
return data;
}
}
Handler类:这是处理异常的类
import org.mule.api.transformer.TransformerException;
import org.mule.transformer.AbstractTransformer;
import com.comviva.custom.exception.CustomException;
import com.comviva.custom.logger.CustomLogger;
public class CustomExceptionHandler extends AbstractTransformer{
@Override
protected Object doTransform(Object src, String enc)
throws TransformerException {
System.out.println("33333333333333333333333333 "+src.toString()+ " enc="+enc);
CustomException exceptionClass=(CustomException)src;
//System.out.println("print stack trace=");
//exceptionClass.getEx().printStackTrace();
System.out.println("4444444444444444444444get stack trace="+exceptionClass.getEx().getCause() );
CustomLogger.error(CustomLogger.errorLogger, exceptionClass.getRequestId(), "ERROR", "TESTING", exceptionClass.getUserIdentifier(), exceptionClass.getClassName(),
exceptionClass.getMethodName(),String.valueOf(exceptionClass.getEx().getStackTrace()[0].getLineNumber()), exceptionClass.getEx().getMessage(), exceptionClass.getEx());
return src;
}
}
在处理完异常后,我希望 finally 块执行,但它没有被执行。处理异常后有什么方法可以让控制器返回到 thrower 类。
【问题讨论】:
标签: mule mule-component