我正在 Mule Flow 中执行 groovy脚本。
使用版本 Mule Server 3.5.1.EE ..
我已经在classpath
Groovy脚本内容很简单
return "demo payload"
执行时,我得到异常堆栈跟踪
java.lang.NullPointerException
at org.mule.component.AbstractComponent.invokeInternal(AbstractComponent.java:108)
at org.mule.component.AbstractComponent.process(AbstractComponent.java:152)
at org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor.execute(ExceptionToMessagingExceptionExecutionInterceptor.java:24)
at org.mule.execution.MessageProcessorNotificationExecutionInterceptor.execute(MessageProcessorNotificationExecutionInterceptor.java:58)
如果我需要发布更多细节,请告诉我 任何帮助将不胜感激。
答案 0 :(得分:1)
我不确定你是否做得对,但在Mule流程中正确使用Groovy看起来像:
<?xml version="1.0" encoding="UTF-8"?>
<mule ...>
<flow name="lab1Flow1" doc:name="lab1Flow1">
<http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="HTTP"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA["demo payload"]]></scripting:script>
</scripting:component>
</flow>
</mule>
如果您使用curl尝试上面的流程,它应该响应(按预期):
$ curl -i http://localhost:8081
HTTP/1.1 200 OK
Date: Sun, 07 Dec 2014 16:52:48 +0000
Server: Mule EE Core Extensions/3.5.2
X-MULE_SESSION: ...
X-MULE_ENCODING: UTF-8
Content-Type: text/plain
Content-Length: 12
Connection: close
demo payload
答案 1 :(得分:0)
<?xml version="1.0" encoding="UTF-8"?>
<mule xmlns:scripting="http://www.mulesoft.org/schema/mule/scripting" xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns="http://www.mulesoft.org/schema/mule/core" xmlns:doc="http://www.mulesoft.org/schema/mule/documentation"
xmlns:spring="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-current.xsd
http://www.mulesoft.org/schema/mule/core http://www.mulesoft.org/schema/mule/core/current/mule.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.mulesoft.org/schema/mule/scripting http://www.mulesoft.org/schema/mule/scripting/current/mule-scripting.xsd">
<http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="8081" doc:name="HTTP Listener Configuration"/>
<flow name="groovydemoFlow">
<http:listener config-ref="HTTP_Listener_Configuration" path="/" doc:name="HTTP"/>
<scripting:component doc:name="Groovy">
<scripting:script engine="Groovy"><![CDATA[println('demo payload');]]></scripting:script>
</scripting:component>
</flow>
</mule>
Please try this