我正在使用Mule 4.1和Anypoint Studio 7.3。
我有一个工作流,该工作流使用数据库批量插入连接器将JSON记录数组插入SQL Server数据库。
当我部署Mule应用程序并调用API时,工作流成功完成,并且可以看到插入数据库表中的新记录。一切似乎都不错,但是当我单击连接器时,工作流中的数据库批量插入连接器旁边以及右侧的元数据输入面板上都出现错误(红色感叹号)。该错误显示为传播错误,并且以下错误详细信息如下。
我已经读到这是因为我在SQL中使用$(vars.dataName)表示法,但是我想使它动态化,因此在表名更改为查询的其余部分时,我不需要每次都复制SQL是相同的,我一直希望将表名作为使用数据库插入连接器调用流的流中的变量传递。
有没有办法做到这一点?我尝试使用属性,但是我需要能够更改属性名称以在需要时引用其他表。
数据库代码
<db:sql >#["INSERT INTO $(vars.dataName)
(
$(vars.dataName)ID,
Code,
Comments,
CreatedBy,
CreatedDate
)
VALUES
(
NEWID(),
:Code,
:Comments,
'SA',
GETDATE()
)"]</db:sql>
错误消息
org.mule.runtime.module.extension.internal.runtime.ValueResolvingException: Unable to resolve value for the parameter: sql
at org.mule.runtime.module.extension.internal.runtime.operation.OperationParameterValueResolver.getParameterValue(OperationParameterValueResolver.java:80)
at org.mule.runtime.module.extension.internal.metadata.MetadataMediator.getMetadataKeyObjectValue(MetadataMediator.java:309)
at org.mule.runtime.module.extension.internal.metadata.MetadataMediator.getMetadata(MetadataMediator.java:154)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.lambda$null$13(ExtensionComponent.java:298)
at org.mule.runtime.core.api.util.ExceptionUtils.tryExpecting(ExceptionUtils.java:227)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:849)
at org.mule.runtime.core.api.util.ClassUtils.withContextClassLoader(ClassUtils.java:813)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.lambda$getMetadata$14(ExtensionComponent.java:297)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.runWithMetadataContext(ExtensionComponent.java:354)
at org.mule.runtime.module.extension.internal.runtime.ExtensionComponent.getMetadata(ExtensionComponent.java:296)
at org.mule.runtime.core.internal.metadata.MuleMetadataService.lambda$getComponentMetadata$4(MuleMetadataService.java:185)
at org.mule.runtime.core.internal.metadata.MuleMetadataService.exceptionHandledMetadataFetch(MuleMetadataService.java:141)
at org.mule.runtime.core.internal.metadata.MuleMetadataService.getComponentMetadata(MuleMetadataService.java:184)
at org.mule.runtime.core.internal.metadata.MuleMetadataService.getOperationMetadata(MuleMetadataService.java:83)
at org.mule.runtime.config.internal.LazyMetadataService.lambda$getOperationMetadata$1(LazyMetadataService.java:69)
at java.util.Optional.orElseGet(Optional.java:267)
at org.mule.runtime.config.internal.LazyMetadataService.getOperationMetadata(LazyMetadataService.java:69)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.lambda$getOperationMetadata$2(MuleAgentMetadataService.java:74)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.withMetadataService(MuleAgentMetadataService.java:144)
at com.mulesoft.agent.services.metadata.MuleAgentMetadataService.getOperationMetadata(MuleAgentMetadataService.java:74)
at com.mulesoft.agent.external.handlers.metadata.MetadataRequestHandler.lambda$getOperationMetadata$3(MetadataRequestHandler.java:200)
at com.mulesoft.agent.util.ResponseHelper.response(ResponseHelper.java:88)
at com.mulesoft.agent.external.handlers.metadata.MetadataRequestHandler.getOperationMetadata(MetadataRequestHandler.java:198)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:387)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:331)
at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:103)
at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:297)
at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:254)
at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:372)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:865)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1655)
at com.mulesoft.agent.rest.RequestLoggingFilter.doFilter(RequestLoggingFilter.java:95)
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1642)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:533)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:146)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:257)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1595)
at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:255)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1340)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:203)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:473)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1564)
at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:201)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1242)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:144)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:132)
at org.eclipse.jetty.server.Server.handle(Server.java:503)
at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:364)
at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:260)
at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:305)
at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
at org.eclipse.jetty.io.ChannelEndPoint$2.run(ChannelEndPoint.java:118)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:333)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:310)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:168)
at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:126)
at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:366)
at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:765)
at org.eclipse.jetty.util.thread.QueuedThreadPool$2.run(QueuedThreadPool.java:683)
at java.lang.Thread.run(Thread.java:748)
Caused by: org.mule.runtime.core.api.expression.ExpressionRuntimeException: "You called the function 'AnonymousFunction' with these arguments:
1: Null (null)
2: String ("ID,\nCode,\nComments,\nCreatedBy,\nCreatedD...)
But it expects arguments of these types:
1: String
2: String
Trace:
at Anonymous function (Unknown)
at main (Unknown)" evaluating expression: ""INSERT INTO $(vars.dataName)
(
$(vars.dataName)ID,
Code,
Comments,
CreatedBy,
CreatedDate
)
VALUES
(
NEWID(),
:Code,
:Comments,
'SA',
GETDATE()
)"".
Caused by: org.mule.runtime.api.el.ExpressionExecutionException: You called the function 'AnonymousFunction' with these arguments:
1: Null (null)
2: String ("ID,\nCode,\nComments,\nCreatedBy,\nCreatedD...)
But it expects arguments of these types:
1: String
2: String
Trace:
at Anonymous function (Unknown)
at main (Unknown)
感谢您的帮助