DFDL
Since Camel 4.11
Only producer is supported
The DFDL component allows you to transform the fixed format data such as EDI message from/to XML using Data Format Description Language, also known as DFDL. DFDL schema is an XML schema annotated with DFDL elements and attributes.
While DFDL schema defines the XML representation of the data structure, it also defines how the conversion between the fixed format and XML is processed using DFDL annotations.
This component uses Apache Daffodil as an underlying DFDL implementation.
URI format
dfdl:schemaUri[?options]
The URI format contains schemaUri, which can be the classpath-local URI of the DFDL schema file.
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
At the component level, you set general and shared configurations that are, then, inherited by the endpoints. It is the highest configuration level.
For example, a component may have security settings, credentials for authentication, urls for network connection and so forth.
Some components only have a few options, and others may have many. Because components typically have pre-configured defaults that are commonly used, then you may often only need to configure a few options on a component; or none at all.
You can configure components using:
-
the Component DSL.
-
in a configuration file (
application.properties,*.yamlfiles, etc). -
directly in the Java code.
Configuring Endpoint Options
You usually spend more time setting up endpoints because they have many options. These options help you customize what you want the endpoint to do. The options are also categorized into whether the endpoint is used as a consumer (from), as a producer (to), or both.
Configuring endpoints is most often done directly in the endpoint URI as path and query parameters. You can also use the Endpoint DSL and DataFormat DSL as a type safe way of configuring endpoints and data formats in Java.
A good practice when configuring options is to use Property Placeholders.
Property placeholders provide a few benefits:
-
They help prevent using hardcoded urls, port numbers, sensitive information, and other settings.
-
They allow externalizing the configuration from the code.
-
They help the code to become more flexible and reusable.
The following two sections list all the options, firstly for the component followed by the endpoint.
Component Options
The DFDL component supports the following options which are listed below.
| Name | Description | Default | Type |
|---|---|---|---|
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc. | true | boolean |
Endpoint Options
The DFDL endpoint is configured using URI syntax:
dfdl:schemaUri
With the following path and query parameters:
Path Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Required The location of the DFDL schema (an XML Schema with DFDL annotations), loaded from the classpath by default (with the file system as fallback), or from the file system with the file: prefix. Apache Daffodil compiles the schema once, when the endpoint starts, and a schema error fails the start. | String |
Query Parameters
| Name | Description | Default | Type |
|---|---|---|---|
Whether to parse or unparse the message body. PARSE reads the body as bytes of the data the DFDL schema describes and sets the body to the XML infoset as a DOM Document. UNPARSE reads the body as the XML infoset, converted to a DOM Document, and sets the body to the data as a ByteArrayOutputStream. A diagnostic error fails the exchange with a DfdlParseException or DfdlUnparseException that holds the Daffodil diagnostics. Enum values:
| PARSE | ParseDirection | |
Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing. | false | boolean | |
The name of the global element of the DFDL schema to use as the root of the infoset. It takes effect only when rootNamespace is set as well; otherwise Apache Daffodil uses the first global element declaration of the schema. | String | ||
The namespace of the root element set by rootElement. It takes effect only when rootElement is set as well, so a root element in no namespace cannot be selected. | String |
Message Body
The message body at each side of the DFDL component: Consumer is the body of the messages the consumer creates, Consumer reply the bodies a consumer that answers its caller can reply with, Producer input the bodies the producer can send or write, and Producer output the body after the producer.
| Side | Body | Description |
|---|---|---|
Producer input |
| Data in the format the DFDL schema describes, such as an EDI message, to parse. UNPARSE takes the XML infoset as text, bytes, a stream, a file or a DOM Document. A Map or no body fails.
|
Producer output |
| The XML infoset as a DOM Document. UNPARSE gives the data in the format the DFDL schema describes as bytes, in a ByteArrayOutputStream.
|
The bodies are the ones with the default options. A side that is not listed is not known, and tooling does not guess it. The carriers, the sides and the tools that use them are described in Message Body Types.
DFDL Schemas
Many DFDL schemas are freely available at DFDLSchemas on GitHub including:
-
UN/EDIFACT — models UN/EDIFACT interchanges (ISO 9735) including Supply Chain messages (ORDERS, INVOIC, DESADV, etc.)
-
NACHA — ACH payment transactions
-
HL7 — healthcare messaging
-
PCAP — network packet capture
Using DFDL endpoints
The following format is an example of using DFDL to convert an EDI message to an XML using X12-837P-dfdl.xsd DFDL schema file.
-
Java
-
XML
-
YAML
from("direct:parse")
.to("dfdl:X12-837P.dfdl.xsd"); <route>
<from uri="direct:parse"/>
<to uri="dfdl:X12-837P.dfdl.xsd"/>
</route> - route:
from:
uri: direct:parse
steps:
- to:
uri: dfdl:X12-837P.dfdl.xsd The following format is an example of using DFDL to convert an XML to an EDI message using X12-837P-dfdl.xsd DFDL schema file. Note that UNPARSE is specified for the parseDirection parameter.
-
Java
-
XML
-
YAML
from("direct:unparse")
.to("dfdl:X12-837P.dfdl.xsd?parseDirection=UNPARSE"); <route>
<from uri="direct:unparse"/>
<to uri="dfdl:X12-837P.dfdl.xsd?parseDirection=UNPARSE"/>
</route> - route:
from:
uri: direct:unparse
steps:
- to:
uri: dfdl:X12-837P.dfdl.xsd
parameters:
parseDirection: UNPARSE