简体   繁体   中英

Invalid mime type with DataWeave

I'm trying to create a flow in Mule ESB (Enterprise Edition) that receives a message from a queue in WMQ 7.5 (xml payload), transforms it with DataWeave (for my purposes here, to a new xml file that is the same as the old one), and then puts it back on another queue. My flow is as follows:

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

<mule xmlns:mulexml="http://www.mulesoft.org/schema/mule/xml" xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" xmlns:wmq="http://www.mulesoft.org/schema/mule/ee/wmq" 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/ee/wmq http://www.mulesoft.org/schema/mule/ee/wmq/current/mule-wmq-ee.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/xml http://www.mulesoft.org/schema/mule/xml/current/mule-xml.xsd">
    <wmq:connector (MQ configuration is here, it is not the problem) />
    <flow name="dataweaveFlow">
        <wmq:inbound-endpoint queue="I0" connector-ref="WMQ" doc:name="WMQ">
            <wmq:transaction action="ALWAYS_BEGIN"/>
        </wmq:inbound-endpoint>
        <set-variable variableName="MULE_REPLYTO_STOP" value="true" doc:name="Variable"/>
        <dw:transform-message doc:name="Transform Message">
            <dw:input-payload doc:sample="empty_1.xml"/>
            <dw:set-payload><![CDATA[%dw 1.0
%input payload application/xml
%output application/xml
---
payload]]></dw:set-payload>
        </dw:transform-message>

        <wmq:outbound-endpoint queue="O0" connector-ref="WMQ" doc:name="WMQ">
            <wmq:transaction action="ALWAYS_JOIN"/>
        </wmq:outbound-endpoint>
    </flow>
</mule>

And my DataWeave configuration looks like this: Input:

<?xml version='1.0' encoding='windows-1252'?>
<empty/>

Transformation:

  %dw 1.0
%input payload application/xml
%output application/xml
---
payload

Now, when I run this flow, and I put a message on the queue, Mule can't process the message and continually throws exceptions, saying: "Invalid mime type application/xml", and the exception stack is 1. Invalid mime type application/xml (com.mulesoft.weave.mule.exception.InvalidMimeTypeException) com.mulesoft.weave.mule.WeaveMessageProcessor:165 (null) 2. Invalid mime type application/xml (com.mulesoft.weave.mule.exception.InvalidMimeTypeException). Message payload is of type: String (org.mule.api.MessagingException) org.mule.execution.ExceptionToMessagingExceptionExecutionInterceptor:32 ( http://www.mulesoft.org/docs/site/current3/apidocs/org/mule/api/MessagingException.html )

Anyway, I'm fairly new to Mule (and certainly DataWeave), and help would be appreciated! Let me know if any more details are needed.

After a long conversation between Mule support and myself, this was uncovered as a bug. As of my ticket, is currently being worked on by the engineering team. This happens when your main flow processing strategy is set to synchronous rather than queued asynchronous .

Try testing this by clicking on your main flow, and setting the processing strategy to queued asynchronous specifically.

Note that you will not be able to use WMQ transactionality with a queued asynchronous processing strategy, hence my frustration with this bug.

After the bug being reported it was uncovered that a combination of WMQ , DataWeave and synchronous processing strategy was throwing this weird exception. Patch is already available, it will be fixed on future versions of the ESB but for now you may contact support and ask about SE-3167 . Good luck!

在Dataweave之前向XML添加一个Transformer对象,这会将您的Message转换为正确的格式。

First thing if you are getting XML from Input source suppose say WMQ connector go and set MIME type to application/xml . To set MIME type to application/xml right click on WMQ connector and then click on Advanced and set MIME Type : application/xml .

You are returning %output application/xml so i will suggest you to use DOM to XML Transformer after data weave component . I think it will work then.

This issue is rather vague and the solution I found for it was even more weird. I simply added a "Object to String" transformer after my Data Weaver /Transform Message, and before my WMQ outbound-endpoint, and it worked. The problem is that the Data Weaver gives an output of "com.mulesoft.weave.mule.WeaveMessageProcessor$WeaveOutputHandler" at all times .

Do try this fix...I'm pretty sure it'll work.

As you mentioned before the %input directive is not being used. It will be removed from Studio autocompletion.

The way to enforce DataWeave to use a reader is with the mimeType property or as you mentioned with a set-property as this will enforce the Mule Message to have a MimeType

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