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

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

我正在尝试 运行 使用 Maven 的项目,使用简单的测试 class,但是测试出错(没有失败!)并显示消息:

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'.

我已经尝试通过将以下内容添加到我的pom.xml

来解决这个问题
<dependency>
   <groupId>com.mulesoft.weave</groupId>
   <artifactId>mule-plugin-weave</artifactId>
   <version>4.0.0-M4</version>
</dependency>

"expected" 之后提到的所有其他项目都出现在模式中,而 dw:transform-message 没有出现,这似乎很奇怪(或者可能完全符合预期!?)...但这是 XML 由 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>

org/xml/sax/SAXParseException.html 基本上意味着您项目的 XML 文档中缺少信息。

This exception may include information for locating the error in the original XML document, as if it came from a Locator object. Note that although the application will receive a SAXParseException as the argument to the handlers in the ErrorHandler interface, the application is not actually required to throw the exception; instead, it can simply read the information in it and take a different action

并且错误堆栈跟踪清楚地表明在你的情况下它

Caused by: org.xml.sax.SAXParseException: cvc-complex-type.2.4.a: Invalid content was found starting with element 'dw:transform-message'

需要固定在

Line 34 in XML document from URL [file:/C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test-classes/myproject.xml]

在您的 pom 中添加此依赖项

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

您必须添加与您的 Mule Runtime 版本匹配的确切版本。如果你的版本在 3.7.0 和 3.8.1 之间你需要添加:

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

如果大于3.8.1小于4:

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

对于 4.0.0+ 你不应该添加任何东西。

您不得添加与运行时版本不同的版本。您不是这样做来升级 DataWeave,它会导致未定义和不受支持的行为。