use of jp.ossc.nimbus.service.aop.InterceptorChain in project nimbus by nimbus-org.
the class ExceptionWrapInterceptorServiceTest method test1.
public void test1() throws Throwable {
ServiceManagerFactory.registerManager("Test");
ExceptionWrapInterceptorService interceptor1 = new ExceptionWrapInterceptorService();
ServiceManagerFactory.registerService("Test", "ExceptionWrapInterceptor", interceptor1);
Interceptor interceptor2 = new Interceptor() {
public Object invoke(InvocationContext context, InterceptorChain chain) throws Throwable {
throw new IllegalArgumentException();
}
};
try {
ServiceManagerFactory.findManager("Test").createAllService();
Properties mapping = new Properties();
mapping.setProperty("java.lang.IllegalArgumentException", "java.lang.UnsupportedOperationException");
interceptor1.setWrapExceptionMapping(mapping);
ServiceManagerFactory.findManager("Test").startAllService();
try {
new DefaultInterceptorChain(new DefaultInterceptorChainList(new Interceptor[] { interceptor1, interceptor2 }), new Invoker() {
public Object invoke(InvocationContext context) throws Throwable {
return "test";
}
}).invokeNext(new DefaultMethodInvocationContext());
fail();
} catch (UnsupportedOperationException e) {
assertTrue(e.getMessage() == null || "java.lang.IllegalArgumentException".equals(e.getMessage()));
}
} finally {
ServiceManagerFactory.findManager("Test").stopAllService();
ServiceManagerFactory.findManager("Test").destroyAllService();
ServiceManagerFactory.unregisterManager("Test");
}
}
use of jp.ossc.nimbus.service.aop.InterceptorChain in project nimbus by nimbus-org.
the class EJBDriveDispatcher method invokeInterceptor.
/**
* インターセプタを通してUnitOfWorkを実行する。
* インターセプタが指定されていなければ直接UnitOfWorkを実行する。
* @param input
* @return 出力オブジェクト
* @throws InterceptorException
* @throws TargetCheckedException
* @throws TargetUncheckedException
*/
public Object invokeInterceptor(Object input) throws InterceptorException, TargetCheckedException, TargetUncheckedException {
Object ret = null;
if (mFactory == null && chainFactory == null) {
try {
ret = (UnitOfWork) invokeUnitOfWorkBase((UnitOfWork) input);
} catch (IOCException e) {
throw new TargetUncheckedException(e.getCause());
} catch (Throwable e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00018", e);
}
throw new TargetUncheckedException(e);
}
} else {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00004", this.getInterceptorKey());
}
if (mFactory != null) {
InterceptorChainInvoker ici = this.mFactory.createInterceptorInvoker(this.getInterceptorKey());
ret = ici.invokeChain(this, input);
} else if (chainFactory != null) {
try {
InterceptorChain chain = chainFactory.getInterceptorChain(getInterceptorKey());
ret = chain.invokeNext(createInvocationContext(input));
} catch (TargetUncheckedException e) {
throw e;
} catch (TargetCheckedException e) {
throw e;
} catch (InterceptorException e) {
throw e;
} catch (RuntimeException e) {
throw e;
} catch (Exception e) {
throw new IOCException(e);
} catch (Throwable th) {
if (th instanceof Error) {
throw (Error) th;
}
}
}
}
return ret;
}
use of jp.ossc.nimbus.service.aop.InterceptorChain in project nimbus by nimbus-org.
the class SLSBCommandBean method invokeCommand.
/**
* コマンドを実行する。
* @param cmd コマンド
* @return 実行後のコマンド
*/
public Command invokeCommand(Command cmd) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00006");
}
// インターセプタで実行した際にも同じフローキーで実行させるため保持しておく。
String key = cmd.getFlowKey();
InterceptorChainInvoker ici = null;
InterceptorChain ic = null;
if (this.getIciFactory() != null) {
ici = this.getIciFactory().createInterceptorInvoker(key);
} else if (this.getIcFactory() != null) {
ic = this.getIcFactory().getInterceptorChain(key);
}
Object ret = null;
if (ici == null && ic == null) {
// 直接実行
if (this.getLogger() != null) {
this.getLogger().write("IOC__00007");
}
try {
ret = invokeBeanFlow(cmd);
} catch (Exception e) {
if (e instanceof RuntimeException) {
throw (RuntimeException) e;
} else {
cmd.setException(e);
}
} catch (Throwable e) {
throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
}
} else if (ici != null) {
// インターセプタを通して実行
try {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00008");
}
ret = ici.invokeChain(this, cmd);
if (this.getLogger() != null) {
this.getLogger().write("IOC__00012");
}
} catch (InterceptorException e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00009", e);
}
throw new IOCException("SLSBCommandBean invokeCommand InterceptorException", e);
} catch (TargetCheckedException e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00010", e);
}
cmd.setException(e.getCause());
return cmd;
} catch (TargetUncheckedException e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00011", e.getCause());
}
if (e.getCause() instanceof RuntimeException) {
throw (RuntimeException) e.getCause();
} else {
throw new IOCException("SLSBCommandBean invokeCommand TargetUncheckedException", e.getCause());
}
} catch (Throwable e) {
throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
}
} else {
// インターセプタを通して実行
try {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00008");
}
ret = ic.invokeNext(createInvocationContext(cmd));
if (this.getLogger() != null) {
this.getLogger().write("IOC__00012");
}
} catch (RuntimeException e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00011", e);
}
throw e;
} catch (Exception e) {
if (this.getLogger() != null) {
this.getLogger().write("IOC__00010", e);
}
cmd.setException(e);
return cmd;
} catch (Throwable e) {
throw new IOCException("SLSBCommandBean invokeCommand Unrecognize Exception", e);
}
}
cmd.setOutObject(ret);
return cmd;
}
Aggregations