gpt4 book ai didi

java - Mule ESB 的 DataMapper 自定义脚本?

转载 作者:行者123 更新时间:2023-11-30 08:54:52 28 4
gpt4 key购买 nike

我正在尝试使用数据映射器。我正在尝试根据自己的喜好修改脚本,但我一直收到错误,即使在图形可视化中它似乎工作正常我可以看到字符串分开。

这是我的脚本

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;

基本上问题是 split 。当我像 output.blabla= "Hello"; 这样直接影响一个 String 时这行得通。但是 split 和做作是行不通的。知道如何修复它吗?一开始是否有可能做到这一点?

这是我的错误。

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

最佳答案

我将其改为 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

关于java - Mule ESB 的 DataMapper 自定义脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29280332/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com