mulemule-studiomunit

Mule / Maven Error: Invalid content was found starting with element 'dw:transform-message'


I'm trying to run a project with Maven, using a simple test class, however the test is erroring out (not failing!) with the message:

Test set: com.mycompany.myproject.testApiResponseNotNullTestCase

Tests run: 1, Failures: 0, Errors: 1, Skipped: 0, Time elapsed: 4.423 sec <<< FAILURE! - in com.mycompany.myproject.testApiResponseNotNullTestCase clientTestCase(com.mycompany.myproject.testApiResponseNotNullTestCase) Time elapsed: 3.084 sec <<< ERROR! org.mule.api.config.ConfigurationException: Line 34 in XML document from URL [file:/C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test-classes/myproject.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 111; cvc-complex-type.2.4.a: Invalid content was found starting with element 'dw:transform-message'. One of '{"http://www.mulesoft.org/schema/mule/core":abstract-message-processor, "http://www.mulesoft.org/schema/mule/core":abstract-outbound-endpoint, "http://www.mulesoft.org/schema/mule/core":abstract-mixed-content-message-processor, "http://www.mulesoft.org/schema/mule/core":response, "http://www.mulesoft.org/schema/mule/core":legacy-abstract-exception-strategy, "http://www.mulesoft.org/schema/mule/core":abstract-message-info-mapping}' is expected. (org.mule.api.lifecycle.InitialisationException) Caused by: org.mule.api.lifecycle.InitialisationException: Line 34 in XML document from URL [file:/C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test-classes/myproject.xml] is invalid; nested exception is org.xml.sax.SAXParseException; lineNumber: 34; columnNumber: 111; cvc-complex-type.2.4.a: Invalid content was found starting with element 'dw:transform-message'.

I have already tried to fix this by adding the following to my pom.xml

<dependency>
   <groupId>com.mulesoft.weave</groupId>
   <artifactId>mule-plugin-weave</artifactId>
   <version>4.0.0-M4</version>
</dependency>

It seems odd (or maybe exactly as expected!?) that all the other items mentioned after "expected" appear in the schema and dw:transform-message doesn't... but this is the XML generated by Anypoint Studio AFAIK.

<?xml version="1.0" encoding="UTF-8"?>

<mule xmlns:json="http://www.mulesoft.org/schema/mule/json" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 
	xmlns:http="http://www.mulesoft.org/schema/mule/http" xmlns:context="http://www.springframework.org/schema/context" 
	xmlns:file="http://www.mulesoft.org/schema/mule/file" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 
	xmlns:db="http://www.mulesoft.org/schema/mule/db" 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/db http://www.mulesoft.org/schema/mule/db/current/mule-db.xsd
http://www.mulesoft.org/schema/mule/file http://www.mulesoft.org/schema/mule/file/current/mule-file.xsd
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd
http://www.mulesoft.org/schema/mule/http http://www.mulesoft.org/schema/mule/http/current/mule-http.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-current.xsd
http://www.mulesoft.org/schema/mule/json http://www.mulesoft.org/schema/mule/json/current/mule-json.xsd">
    <db:generic-config name="LocalDev_SqlServerConfig" url="jdbc:sqlserver://${mssql.server}:${mssql.port};databaseName=${mssql.database};user=${mssql.user};password=${mssql.password}" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" doc:name="Generic Database Configuration"/>

    <http:listener-config name="HTTP_Listener_Configuration" host="0.0.0.0" port="${http.port}" basePath="/api" doc:name="HTTP Listener Configuration"/>
    <db:generic-config name="GenericMsSqlDbConnection" url="jdbc:sqlserver://${db.server}:${db.port};databaseName=${db.database};user=${db.user};password=${db.password}" driverClassName="com.microsoft.sqlserver.jdbc.SQLServerDriver" doc:name="Generic Database Configuration"/>
    <context:property-placeholder location="main-${env}.properties"/>
    <flow name="mainFlow">
        <http:listener config-ref="HTTP_Listener_Configuration" path="/test" allowedMethods="GET" doc:name="HTTP">
            <http:response-builder statusCode="200" reasonPhrase="OK"/>
            <http:error-response-builder statusCode="500" reasonPhrase="Internal server error"/>
        </http:listener>
        <set-property propertyName="currentDate" value="#[server.dateTime.getDayOfMonth() +&quot;/&quot;+ server.dateTime.getMonth() +&quot;/&quot; +server.dateTime.getYear()]" doc:name="Set Date Property"/>
        <set-property propertyName="hostname" value="#[server.host]" doc:name="Set Server Property"/>
        <logger message="Set property &quot;currentDate&quot; to #[message.outboundProperties.currentDate]" level="INFO" doc:name="Logger"/>
        <db:select config-ref="GenericMsSqlDbConnection" doc:name="Database">
            <db:parameterized-query><![CDATA[SELECT COUNT(*) AS OpportunityCount FROM vwOppsAnon1]]></db:parameterized-query>
        </db:select>
        <dw:transform-message metadata:id="480debf4-819f-4927-90ae-382a17489221" doc:name="Transform Message">
            <dw:set-payload><![CDATA[%dw 1.0
%output application/json
---
payload map ((payload01 , indexOfPayload01) -> {
	opportunityCount: payload01.OpportunityCount,
	date: outboundProperties.currentDate as :string,
	server: outboundProperties.hostname
})]]></dw:set-payload>
        </dw:transform-message>
    </flow>
</mule>


Solution

  • You have to add the exact version that matches your Mule Runtime version. If you version is between 3.7.0 and 3.8.1 you need to add:

    <dependency>
            <groupId>com.mulesoft.weave</groupId>
            <artifactId>mule-plugin-weave_2.11</artifactId>
            <version>${mule-version}</version>
            <scope>provided</scope>
    </dependency>
    

    If it is greater than 3.8.1 and less than 4:

    <dependency>
            <groupId>com.mulesoft.weave</groupId>
            <artifactId>mule-plugin-weave</artifactId>
            <version>${mule-version}</version>
            <scope>provided</scope>
    </dependency>
    

    For 4.0.0+ you should not add anything.

    You must not add different versions than your runtime version. You are not upgrading DataWeave doing that, it will cause undefined and unsupported behavior.