Mule 3.9.0 - Mule Throw异常,不执行异常流程(异常策略)

时间:2017-12-25 08:13:05

标签: mule mule-esb

如何处理此异常? 如果我在Content-Type中发送了错误的编码值(UTF-88),则Mule抛出异常而不执行异常流。

警告2017-12-22 10:19:55,733 [[2017-mule_api_registry-uni_auth_app] .HttpConnectoConfig.worker.02] org.mule.module.http.internal.listener.DefaultHttpListener:解析请求发生异常: java.nio.charset.UnsupportedCharsetException:UTF-88     在java.nio.charset.Charset.forName(Charset.java:531)〜[?:1.8.0_111]     at org.mule.transformer.types.SimpleDataType.setEncoding(SimpleDataType.java:89)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage.updateDataTypeWithProperty(DefaultMuleMessage.java:551)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage.setProperty(DefaultMuleMessage.java:502)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage.setProperty(DefaultMuleMessage.java:494)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage.addProperties(DefaultMuleMessage.java:1398)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage。(DefaultMuleMessage.java:198)~ [mule-core-3.9.0.jar:3.9.0]     在org.mule.DefaultMuleMessage。(DefaultMuleMessage.java:175)〜[mule-core-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.HttpRequestToMuleEvent.transform(HttpRequestToMuleEvent.java:128)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.DefaultHttpListener.createEvent(DefaultHttpListener.java:187)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.DefaultHttpListener.access $ 000(DefaultHttpListener.java:48)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.DefaultHttpListener $ 1.handleRequest(DefaultHttpListener.java:133)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.grizzly.GrizzlyRequestDispatcherFilter.handleRead(GrizzlyRequestDispatcherFilter.java:100)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.glassfish.grizzly.filterchain.ExecutorResolver $ 9.execute(ExecutorResolver.java:119)〜[grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284)〜[grizzly-framework-2.3.33.jar:2.3.33]     at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201)~ [grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133)〜[grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112)~ [grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)〜[grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:539)〜[grizzly-framework-2.3.33.jar:2.3.33]     在org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112)〜[grizzly-framework-2.3.33.jar:2.3.33]     在org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.run0(ExecutorPerServerAddressIOStrategy.java:119)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy.access $ 100(ExecutorPerServerAddressIOStrategy.java:31)〜[mule-module-http-3.9.0.jar:3.9.0]     在org.mule.module.http.internal.listener.grizzly.ExecutorPerServerAddressIOStrategy $ WorkerThreadRunnable.run(ExecutorPerServerAddressIOStrategy.java:142)〜[mule-module-http-3.9.0.jar:3.9.0]     在java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)[?:1.8.0_111]     at java.util.concurrent.ThreadPoolExecutor $ Worker.run(ThreadPoolExecutor.java:617)[?:1.8.0_111]     在java.lang.Thread.run(Thread.java:745)[?:1.8.0_111]

2 个答案:

答案 0 :(得分:0)

1.在每个元素中使用MEL表达式来测试Content-Type标题:

  

#[message.inboundProperties [' Content-Type']。包含(' UTF-8')]

2.使用元素作为开关的默认语句:从那里抛出异常。

例如:

results['Survived'].eq(labels_test).sum()

答案 1 :(得分:0)

在mule核心中,有一个类 org.mule.transformer.types.SimpleDataType.java ,它负责此异常。 setEncoding 方法会检查字符集的有效性,对于无效的字符集, Charset.forname 方法会抛出 UnsupportedCharsetException 。为避免这种情况,您可以像这样修改代码块 -

public void setEncoding(String encoding)
{
    if (!StringUtils.isEmpty(encoding))
    {
        try {
            // Checks that the encoding is valid and supported
            Charset.forName(encoding);
        }catch(UnsupportedCharsetException e) {
            encoding = "UTF-8";
        }
    }

    this.encoding = encoding;
}

您必须设置默认字符集,否则您无法从MuleMessage实例获取有效负载,例如 -

message.getPayloadAsString();

在我的情况下,我将其设置为'UTF-8'。您可以根据需要进行设置。