Mule ESB 的 DataMapper 自定义脚本?
Mule ESB's DataMapper custom script?
我正在尝试使用数据映射器。我正在尝试根据自己的喜好修改脚本,但即使在图形可视化中它似乎可以正常工作,我仍然会收到错误消息我可以看到字符串分开了。
这是我的脚本
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;
基本上问题是分裂。当我像 output.blabla= "Hello" 这样直接影响字符串时;这行得通。但是分裂和做作是行不通的。知道如何解决这个问题吗?一开始是否有可能解决这个问题?
这是我的错误。
Exception while trying to execute your data mapping.
Check:
• All the required libraries are declared on the classpath.
• No errors are shown on the mapping.
• If using groovy script, check your script is valid.
Cause By:
Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
org.jetel.exception.JetelRuntimeException: Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
at org.jetel.graph.Node.createNodeException(Node.java:543)
at org.jetel.graph.Node.run(Node.java:522)
at org.jetel.graph.runtime.SingleThreadWatchDog.executePhase(SingleThreadWatchDog.java:88)
at org.jetel.graph.runtime.WatchDog.call(WatchDog.java:266)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:92)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:151)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:37)
at com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor.execute(DefaultGraphExecutor.java:85)
at com.mulesoft.mule.module.datamapper.api.DataMapperHelper.execute(DataMapperHelper.java:38)
at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mulesoft.mule.datamapper.ui.graph.service.impl.SingleGraphLauncher.launch(SingleGraphLauncher.java:82)
at com.mulesoft.mule.datamapper.ui.utils.RunGraphJob.run(RunGraphJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.jetel.exception.TransformException: Message: Transform failed!
at org.jetel.component.DataRecordTransform.transformOnError(DataRecordTransform.java:132)
at org.jetel.component.Reformat.execute(Reformat.java:273)
at org.jetel.graph.Node.run(Node.java:493)
... 13 more
Caused by: org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "//MEL
//START -> DO NOT REMOVE
output.__id = str2long(input.__id);
//END -> DO NOT REMOVE
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;" failed.
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:71)
at com.mulesoft.datamapper.transform.MelRecordTransform.transform(MelRecordTransform.java:53)
at org.jetel.component.Reformat.execute(Reformat.java:271)
... 14 more
Caused by: java.lang.RuntimeException: cannot invoke method: split
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
at org.mule.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
at org.mule.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
at org.mule.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
at org.mule.mvel2.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:70)
at org.mule.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at org.mule.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mule.mvel2.MVEL.executeExpression(MVEL.java:943)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:72)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:35)
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:67)
... 16 more
Caused by: java.lang.NullPointerException
at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
... 27 more
可以拆分字符串并将值分配给数据映射器中的输出值,就像您尝试做的那样。
您收到空指针异常,这意味着您的 "input.streetAddress" 可能为空。
你能检查一下你输入的街道地址数据是否存在。
-维奈
我将其改为 Groovy 脚本:
String acronymeministere = "YOOOO;"
String pays = "CA;"
String finalString = ""
payload.each { p ->
String telephoneinternet = ";";
String telephone = ";";
String telecopieur = ";"
String nomdefamille = ";";
String prenom = ";";
String initale =";"
String qualificateurdegen = ";"
String email = ";";
String immeubleetsuffixe = ";"
String odonyme = ";"
String ville = ";";
String province = ";";
String codepostal = ";";
String casepostale = ";"
String bureau = ";"
String etage = ";"
String localisation = ";"
String edifice = ";"
String autres =";"
if(p.streetAddress != null){
String streetnumaddress = p.streetAddress;
String[] parts = streetnumaddress.split(",");
immeubleetsuffixe = parts[0].trim() + immeubleetsuffixe
odonyme = parts[1].trim() + odonyme
}
telephoneinternet = p.telephoneNumber.toString().trim() + telephoneinternet
telephone = p.telephoneNumber.toString().trim() + telephone
nomdefamille = p.sn.toString().trim() + nomdefamille
prenom = p.givenName.toString().trim() + prenom
email = p.mail.toString().trim() + email
ville = p.l.toString().trim() + ville
province = p.st.toString().trim() + province
codepostal = p.postalCode.toString().trim() + codepostal
finalString += ('"' + acronymeministere+telephoneinternet+telephone+telecopieur+nomdefamille
+prenom+initale+qualificateurdegen+email+immeubleetsuffixe
+odonyme+ville+province+codepostal+casepostale+pays+bureau+
etage+localisation+edifice+autres+ '"'+'\n')
}
return finalString
我正在尝试使用数据映射器。我正在尝试根据自己的喜好修改脚本,但即使在图形可视化中它似乎可以正常工作,我仍然会收到错误消息我可以看到字符串分开了。
这是我的脚本
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;
基本上问题是分裂。当我像 output.blabla= "Hello" 这样直接影响字符串时;这行得通。但是分裂和做作是行不通的。知道如何解决这个问题吗?一开始是否有可能解决这个问题?
这是我的错误。
Exception while trying to execute your data mapping.
Check:
• All the required libraries are declared on the classpath.
• No errors are shown on the mapping.
• If using groovy script, check your script is valid.
Cause By:
Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
org.jetel.exception.JetelRuntimeException: Component [Foreach 'array' -> 'array':FOREACH_ARRAY_ARRAY] finished with status ERROR.
at org.jetel.graph.Node.createNodeException(Node.java:543)
at org.jetel.graph.Node.run(Node.java:522)
at org.jetel.graph.runtime.SingleThreadWatchDog.executePhase(SingleThreadWatchDog.java:88)
at org.jetel.graph.runtime.WatchDog.call(WatchDog.java:266)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:92)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:151)
at com.mulesoft.mule.module.datamapper.clover.impl.CloverEngineImpl.execute(CloverEngineImpl.java:37)
at com.mulesoft.mule.module.datamapper.impl.DefaultGraphExecutor.execute(DefaultGraphExecutor.java:85)
at com.mulesoft.mule.module.datamapper.api.DataMapperHelper.execute(DataMapperHelper.java:38)
at sun.reflect.GeneratedMethodAccessor48.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at com.mulesoft.mule.datamapper.ui.graph.service.impl.SingleGraphLauncher.launch(SingleGraphLauncher.java:82)
at com.mulesoft.mule.datamapper.ui.utils.RunGraphJob.run(RunGraphJob.java:59)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)
Caused by: org.jetel.exception.TransformException: Message: Transform failed!
at org.jetel.component.DataRecordTransform.transformOnError(DataRecordTransform.java:132)
at org.jetel.component.Reformat.execute(Reformat.java:273)
at org.jetel.graph.Node.run(Node.java:493)
... 13 more
Caused by: org.mule.api.expression.ExpressionRuntimeException: Execution of the expression "//MEL
//START -> DO NOT REMOVE
output.__id = str2long(input.__id);
//END -> DO NOT REMOVE
String streetnumaddress = input.streetAddress;
String[] parts = streetnumaddress.split(",");
String streetnumber = parts[0];
String streetaddress = parts[1];
output.blabla= "Hello";
output.telephone = input.telephoneNumber;
output.lastname= input.sn;
output.firstname= input.givenName;
output.email = input.mail;
output.city= input.l;
output.province = input.st;
output.codepostal = input.postalCode;
output.country= "CA";
output.telephoneinternet = input.telephoneNumber;
output.immeubleetsuffixe = streetnumber;
output.odonyme = streetaddress;" failed.
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:71)
at com.mulesoft.datamapper.transform.MelRecordTransform.transform(MelRecordTransform.java:53)
at org.jetel.component.Reformat.execute(Reformat.java:271)
... 14 more
Caused by: java.lang.RuntimeException: cannot invoke method: split
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:63)
at org.mule.mvel2.optimizers.impl.refl.nodes.VariableAccessor.getValue(VariableAccessor.java:37)
at org.mule.mvel2.ast.ASTNode.getReducedValueAccelerated(ASTNode.java:108)
at org.mule.mvel2.compiler.ExecutableAccessor.getValue(ExecutableAccessor.java:38)
at org.mule.mvel2.ast.TypedVarNode.getReducedValueAccelerated(TypedVarNode.java:70)
at org.mule.mvel2.MVELRuntime.execute(MVELRuntime.java:86)
at org.mule.mvel2.compiler.CompiledExpression.getDirectValue(CompiledExpression.java:123)
at org.mule.mvel2.compiler.CompiledExpression.getValue(CompiledExpression.java:119)
at org.mule.mvel2.MVEL.executeExpression(MVEL.java:943)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:72)
at org.mule.el.mvel.MVELExpressionExecutor.execute(MVELExpressionExecutor.java:35)
at org.mule.el.mvel.DataMapperExpressionLanguage.evaluate(DataMapperExpressionLanguage.java:67)
... 16 more
Caused by: java.lang.NullPointerException
at sun.reflect.GeneratedMethodAccessor59.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)
at java.lang.reflect.Method.invoke(Unknown Source)
at org.mule.mvel2.optimizers.impl.refl.nodes.MethodAccessor.getValue(MethodAccessor.java:48)
... 27 more
可以拆分字符串并将值分配给数据映射器中的输出值,就像您尝试做的那样。
您收到空指针异常,这意味着您的 "input.streetAddress" 可能为空。 你能检查一下你输入的街道地址数据是否存在。
-维奈
我将其改为 Groovy 脚本:
String acronymeministere = "YOOOO;"
String pays = "CA;"
String finalString = ""
payload.each { p ->
String telephoneinternet = ";";
String telephone = ";";
String telecopieur = ";"
String nomdefamille = ";";
String prenom = ";";
String initale =";"
String qualificateurdegen = ";"
String email = ";";
String immeubleetsuffixe = ";"
String odonyme = ";"
String ville = ";";
String province = ";";
String codepostal = ";";
String casepostale = ";"
String bureau = ";"
String etage = ";"
String localisation = ";"
String edifice = ";"
String autres =";"
if(p.streetAddress != null){
String streetnumaddress = p.streetAddress;
String[] parts = streetnumaddress.split(",");
immeubleetsuffixe = parts[0].trim() + immeubleetsuffixe
odonyme = parts[1].trim() + odonyme
}
telephoneinternet = p.telephoneNumber.toString().trim() + telephoneinternet
telephone = p.telephoneNumber.toString().trim() + telephone
nomdefamille = p.sn.toString().trim() + nomdefamille
prenom = p.givenName.toString().trim() + prenom
email = p.mail.toString().trim() + email
ville = p.l.toString().trim() + ville
province = p.st.toString().trim() + province
codepostal = p.postalCode.toString().trim() + codepostal
finalString += ('"' + acronymeministere+telephoneinternet+telephone+telecopieur+nomdefamille
+prenom+initale+qualificateurdegen+email+immeubleetsuffixe
+odonyme+ville+province+codepostal+casepostale+pays+bureau+
etage+localisation+edifice+autres+ '"'+'\n')
}
return finalString