2

我有一个非常具体的问题,我真的到处搜索答案......这是一种情况:我有一个带有自定义聚合策略的 Scatter-Gather 组件。
http://clip2net.com/s/j66jK8 - 这个过程的子流
语义相当简单。请求带有Basic Authentication Header,上层只调用空的java处理器,返回原始payload,下层通过LDAP认证用户,并返回此认证过程的布尔结果。自定义聚合类检查结果,如果身份验证成功,则返回原始有效负载,该有效负载来自道路#1。如果不OK,则抛出异常。这里没有错,它有效。

有一点棘手的事情。如果用户传递了错误的身份验证数据,则会在 ldap:bind 模块中发生异常。根据文档,异常被传播到 Scatter-Gather 所以我试图用这个来捕捉它:

@Override
public MuleEvent aggregate(AggregationContext context) throws MuleException {
    for (MuleEvent event: context.collectEventsWithExceptions()) {
        event.getMessage().getExceptionPayload().getException().printStackTrace();
        throw new RuntimeException(event.getMessage().getExceptionPayload().getException());
    }

    MuleEvent result = DefaultMuleEvent.copy(context.getEvents().get(0));       
    if (!(Boolean) context.getEvents().get(1).getMessage().getPayload()) {
        throw new SecurityException();
    }       

    return result;
}

但!结果,我看到了堆栈跟踪没有的异常,该异常javax.naming.AuthenticationException由 ldap:bind 组件引发,并自动打印到日志中(见下文)。

所以,我的问题是:如何从自定义聚合类中获取并重新抛出这个 javax.naming.AuthenticationException 异常?

感谢您的所有想法和帮助。先感谢您。

WARN  2014-10-15 20:51:18,552 [[minkult].ScatterGatherWorkManager.02] org.mule.module.ldap.api.jndi.LDAPJNDIConnection: Bind failed.
ERROR 2014-10-15 20:51:18,559 [[minkult].ScatterGatherWorkManager.02] org.mule.retry.notifiers.ConnectNotifier: Failed to connect/reconnect: Work Descriptor. Root Exception was: javax.naming.AuthenticationException: [LDAP: error code 49 - INVALID_CREDENTIALS: Bind failed: Attempt to lookup non-existant entry: cn=sim,ou=people,dc=example,dc=com]; resolved object com.sun.jndi.ldap.LdapCtx@5de37d66. Type: class javax.naming.AuthenticationException
COUNT: 1
org.mule.api.transport.DispatchException: route number 1 failed to be executed. Failed to route event via endpoint: InterceptingChainLifecycleWrapper 'wrapper for processor chain 'null'' 
[ 
  ScriptComponent{CheckAuth.component.553657235}, 
  org.mule.module.ldap.processors.BindMessageProcessor@647af13d, 
  org.mule.module.ldap.processors.SearchMessageProcessor@2aac6fa7, 
  InvokerMessageProcessor [name=ldapUtils, object=com.at.mkrf.aggregate.LDAPUtils@5714c7da, methodName=findGroupByName, argExpressions=[#[payload], #[systemName]], argTypes=[Ljava.lang.Class;@5af349a6]
]. Message payload is of type: NullPayload
4

1 回答 1

0

在 a 上CompositeRoutingException,您可以调用:

exception.getExceptions().values()

从 scatter-gather 中抛出一个Arrayof s。Throwable然后只需重新抛出适当的异常。

于 2015-01-09T15:28:27.770 回答