3

I have a very simple hashmap payload being converted to application/json. I have done this in other flows by just dragging the dataweave component in, and writing the mapping expression.

now for some reason, I am getting the following error:

The prefix "metadata" for attribute "metadata:id" associated with an element type "dw:transform-message" is not bound.

when I look at the xml, I see that my new dataweave component does not have a metadata:id attribute, but the other dataweave component i used does have a metadata:id attribute.

  1. why are these acting differently?
  2. why is a metadata:id not getting auto generated like it was for the other flow?
  3. why do I need a metadata:id attribute in the first place? in both cases I use a JSON to Object component prior to calling the mapper.
Nathan Tregillus
  • 6,006
  • 3
  • 52
  • 91

2 Answers2

5

When you use DataWeave component, you need to declare xml namespaces. If you are using Studio designer, then Studio adds related namespaces as soon as you drag and drop components to your configuration.

So when you drag and drop dataweave component, studio would add below namespaces and schema location to config -

xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw"

http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd

In Mule, you can define MetaData for every component which would help to see data structure at design time. All these metadata definitions are stored under {project_home}\catalog folder with file names that looks like UUID. These file names are then added to your component definitions with metadata:id attribute. You need metadata namespace even if one component (doesnt have to DW as metadata is feature common to all components).

<dw:transform-message metadata:id="262e6569-8f38-4e0b-a61d-15550870101e" doc:name="Transform Message">

If you add metadata from Studio designer then Studio should automatically add below namespace and schema location. If you add it manually or copy-paste from one xml to another which doesn't have it then you would need to add it your self -

xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata"

Example config with Dataweave and metadata can look like below -

<mule xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 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/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd">
Manik Magar
  • 1,403
  • 2
  • 10
  • 20
  • I finally figured out that the system was failing due to a different component up stream in the flow. I had a Database command that was getting passed a variable parameter, and I missed the VARCHAR datatype. – Nathan Tregillus Apr 11 '16 at 22:53
  • 1
    the craziest thing was that I had to remove all of the dataweave components before the error messages for the up stream components errors started appearing – Nathan Tregillus Apr 11 '16 at 22:53
  • We no longer need to add metadata in Mule 4. It is supported by anypoint studio out of the box. – cammando Feb 26 '20 at 18:15
1

I believe the inclusion of the metadata attribute is to point to a resource where you've defined some metadata for your DataWeave input and/or output structure off the back of a sample file. The error you've detailed above looks like schema validation, please check you have the following in your opening mule tag in the XML config:

xmlns:dw="http://www.mulesoft.org/schema/mule/ee/dw" 
xmlns:metadata="http://www.mulesoft.org/schema/mule/metadata" 
http://www.mulesoft.org/schema/mule/ee/dw http://www.mulesoft.org/schema/mule/ee/dw/current/dw.xsd

Hope that helps!

danw
  • 1,608
  • 4
  • 29
  • 48