简体   繁体   中英

Groovy Script in Mule flow not working

I am trying to execute groovy script in Mule Flow .
Using version Mule Server 3.5.1.EE.. I have already included groovy-all.jar in classpath

Groovy script content is simple

return "demo payload"

On execution i get below exception stack trace

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)

Let me know if i need to post more details.
Any help would be appreciated.

I'm not sure if you got this right but a proper usage of Groovy in a Mule flow looks like:

<?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>

If you try the flow above with curl it should respond (as expected):

$ 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
<?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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM