【问题标题】:Mule - Removing a given key from a map in Groovy componentMule - 从 Groovy 组件中的地图中删除给定的键
【发布时间】:2016-03-28 23:42:04
【问题描述】:

我需要从 groovy 中的地图中删除一个键。我看过很多帖子并尝试过这样做:

   def mymap = message.getInboundProperty("http.query.params");

   mymap.remove('thatKey');

上面的代码对我不起作用并抛出错误:

    Message               : Failed to invoke ScriptComponent{GlobalProductDataStoreIntegrationMainFlow.component.1929599908}. Component     that caused exception is: ScriptComponent{GlobalProductDataStoreIntegrationMainFlow.component.1929599908}. Message payload is of     type: NullPayload
Type                  : org.mule.component.ComponentException
Code                  : MULE_ERROR--2
Payload               : {NullPayload}
JavaDoc               : http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html
********************************************************************************
Exception stack is:
1. null (java.lang.UnsupportedOperationException)
  java.util.Collections$UnmodifiableMap:1345 (null)
2. java.lang.UnsupportedOperationException (javax.script.ScriptException)
  org.codehaus.groovy.jsr223.GroovyScriptEngineImpl:348 (http://java.sun.com/j2ee/sdk_1.3/techdocs/api/javax/script/ScriptException.html)
 3. Failed to invoke    ScriptComponent{GlobalProductDataStoreIntegrationMainFlow.component.1929599908}.      Component that caused     exception is:    ScriptComponent{GlobalProductDataStoreIntegrationMainFlow.component.1929599908}.        Message payload is of type: NullPayload (org.mule.component.ComponentException)
  org.mule.component.AbstractComponent:142 (http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/component/ComponentException.html)
********************************************************************************
Root Exception stack trace:
java.lang.UnsupportedOperationException
at java.util.Collections$UnmodifiableMap.remove(Collections.java:1345)
at org.mule.module.http.internal.ParameterMap.remove(ParameterMap.java:112)

【问题讨论】:

    标签: groovy mule mule-component


    【解决方案1】:

    你得到 UnsupportedOperationException 因为地图是不可变的;它不能被修改。解决方法是创建一个排除您不想要的条目的新地图:

    def mymap = message.getInboundProperty("http.query.params").findAll { 
        it.key != 'thatkey' 
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2019-09-05
      • 1970-01-01
      • 2010-12-16
      • 2018-07-11
      • 2017-12-27
      • 2021-09-27
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多