【问题标题】:Mule / Maven Error: Invalid content was found starting with element 'dw:transform-message'Mule / Maven 错误:发现以元素 'dw:transform-message' 开头的无效内容
【发布时间】:2017-07-25 18:24:13
【问题描述】:

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

测试集:com.mycompany.myproject.testApiResponseNotNullTestCase

测试运行:1,失败:0,错误:1,跳过:0,经过的时间:4.423 秒 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"之一:响应,“http://www.mulesoft.org/schema/mule/core”:legacy-abstract-exception-strategy,“http://www.mulesoft.org/schema/mule/core”:abstract-message-info-mapping}'是预期的。 (org.mule.api.lifecycle.InitialisationException) 引起:org.mule.api.lifecycle.InitialisationException:来自 URL [file:/C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test 的 XML 文档中的第 34 行-classes/myproject.xml] 无效;嵌套异常是 org.xml.sax.SAXParseException;行号:34;列号:111; cvc-complex-type.2.4.a:发现以元素“dw:transform-message”开头的无效内容。

我已经尝试通过将以下内容添加到我的 pom.xml 来解决此问题

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

看起来很奇怪(或者可能完全符合预期!?)在“预期”之后提到的所有其他项目都出现在架构中,而dw:transform-message 没有......但这是由 Anypoint Studio AFAIK 生成的 XML。

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

【问题讨论】:

  • 你能分享C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test-classes/myproject.xmlmyProject.xml吗?

标签: mule mule-studio munit


【解决方案1】:

org/xml/sax/SAXParseException.html基本上是说你项目的一个XML文档中缺少信息。

此异常可能包含用于在 原始 XML 文档,就好像它来自一个 Locator 对象。 请注意 尽管应用程序将收到 SAXParseException 作为 ErrorHandler 接口中处理程序的参数, 应用程序实际上不需要抛出异常;反而, 它可以简单地读取其中的信息并采取不同的行动

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

引起:org.xml.sax.SAXParseException:cvc-complex-type.2.4.a: 发现以元素“dw:transform-message”开头的无效内容

需要修复的地方

来自 URL 的 XML 文档中的第 34 行 [file:/C:/Users/myuser/Documents/.../dev/Mule%20Workspaces/myproject/myproject/target/test-classes/myproject.xml]

【讨论】:

【解决方案2】:

在你的 pom 中添加这个依赖

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

【讨论】:

  • 您的示例中的“_2.11”不只是我上面发布的旧版本吗?
  • 尝试在您的项目中更新 Maven 依赖项(右键单击项目并从上下文菜单中选择)。您也可以从命令行运行mvn clean package,这将更新项目依赖项
【解决方案3】:

您必须添加与您的 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 这样做,它会导致未定义和不受支持的行为。

【讨论】:

    猜你喜欢
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-22
    • 2015-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多