2016-03-28 24 views
0

groovyのマップからキーを削除する必要があります。私は多くの記事を通して見えるとこれをやって試してみました:Mule - 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) 

答えて

2

マップは不変であるため、あなたはにUnsupportedOperationExceptionを取得しています;変更することはできません。回避策は、不要なエントリを除外する新しいマップを作成することです。

def mymap = message.getInboundProperty("http.query.params").findAll { 
    it.key != 'thatkey' 
} 
関連する問題