AS2
Since Camel 2.22
Both producer and consumer are supported
The AS2 component provides transport of EDI messages using the HTTP transfer protocol as specified in RFC4130.
Maven users will need to add the following dependency to their pom.xml for this component:
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-as2</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
Configuring Options
Camel components are configured on two separate levels:
-
component level
-
endpoint level
Configuring Component Options
The component level is the highest level which holds general and common configurations that are inherited by the endpoints. 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.
Configuring components can be done with the Component DSL, in a configuration file (application.properties|yaml), or directly with Java code.
Configuring Endpoint Options
Where you find yourself configuring the most is on endpoints, as endpoints often have many options, which allows you to configure what you need the endpoint to do. The options are also categorized into whether the endpoint is used as consumer (from) or as a producer (to), or used for 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, which allows to not hardcode urls, port numbers, sensitive information, and other settings. In other words placeholders allows to externalize the configuration from your code, and gives more flexibility and reuse.
The following two sections lists all the options, firstly for the component followed by the endpoint.
Component Options
The AS2 component supports 4 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. |
false |
boolean |
|
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 |
|
Component configuration. |
AS2Configuration |
Endpoint Options
The AS2 endpoint is configured using URI syntax:
as2:apiName/methodName
with the following path and query parameters:
Query Parameters (31 parameters)
Name | Description | Default | Type |
---|---|---|---|
The value of the AS2From header of AS2 message. |
String |
||
The structure of AS2 Message. One of: PLAIN - No encryption, no signature, SIGNED - No encryption, signature, ENCRYPTED - Encryption, no signature, ENCRYPTED_SIGNED - Encryption, signature. Enum values:
|
AS2MessageStructure |
||
The value of the AS2To header of AS2 message. |
String |
||
The version of the AS2 protocol. Enum values:
|
1.1 |
String |
|
The name of the attached file. |
String |
||
The Client Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. |
camel.apache.org |
String |
|
The algorithm used to compress EDI message. Enum values:
|
AS2CompressionAlgorithm |
||
The key used to encrypt the EDI message. |
PrivateKey |
||
The value of the Disposition-Notification-To header. Assigning a value to this parameter requests a message disposition notification (MDN) for the AS2 message. |
String |
||
The transfer encoding of EDI message. |
String |
||
The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent. |
ContentType |
||
The algorithm used to encrypt EDI message. Enum values:
|
AS2EncryptionAlgorithm |
||
The chain of certificates used to encrypt EDI message. |
Certificate[] |
||
The value of the From header of AS2 message. |
String |
||
Sets the name of a parameter to be passed in the exchange In Body. |
String |
||
The template used to format MDN message. |
String |
||
The request URI of EDI message. |
/ |
String |
|
The value included in the Server message header identifying the AS2 Server. |
Camel AS2 Server Endpoint |
String |
|
The Server Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint. |
camel.apache.org |
String |
|
The port number of server. |
Integer |
||
The list of algorithms, in order of preference, requested to generate a message integrity check (MIC) returned in message dispostion notification (MDN). |
String[] |
||
The algorithm used to sign EDI message. Enum values:
|
AS2SignatureAlgorithm |
||
The chain of certificates used to sign EDI message. |
Certificate[] |
||
The key used to sign the EDI message. |
PrivateKey |
||
The value of Subject header of AS2 message. |
String |
||
The host name (IP or DNS name) of target host. |
String |
||
The port number of target host. -1 indicates the scheme default port. |
Integer |
||
The value included in the User-Agent message header identifying the AS2 user agent. |
Camel AS2 Client Endpoint |
String |
|
To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By default the consumer will deal with exceptions, that will be logged at WARN or ERROR level and ignored. |
ExceptionHandler |
||
Sets the exchange pattern when the consumer creates an exchange. Enum values:
|
ExchangePattern |
||
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 |
API Parameters (2 APIs)
The AS2 endpoint is an API based component and has additional parameters based on which API name and API method is used.
The API name and API method is located in the endpoint URI as the apiName/methodName
path parameters:
as2:apiName/methodName
There are 2 API names as listed in the table below:
API Name | Type | Description |
---|---|---|
Producer |
Sends EDI Messages over HTTP |
|
Consumer |
Receives EDI Messages over HTTP |
Each API is documented in the following sections to come.
API: client
Only producer is supported
The client API is defined in the syntax as follows:
as2:client/methodName?[parameters]
The 1 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)
Method | Alias | Description |
---|---|---|
Send ediMessage to trading partner |
Method send
Signatures:
-
org.apache.http.protocol.HttpCoreContext send(String ediMessage, String requestUri, String subject, String from, String as2From, String as2To, org.apache.camel.component.as2.api.AS2MessageStructure as2MessageStructure, org.apache.http.entity.ContentType ediMessageContentType, String ediMessageTransferEncoding, org.apache.camel.component.as2.api.AS2SignatureAlgorithm signingAlgorithm, java.security.cert.Certificate[] signingCertificateChain, java.security.PrivateKey signingPrivateKey, org.apache.camel.component.as2.api.AS2CompressionAlgorithm compressionAlgorithm, String dispositionNotificationTo, String[] signedReceiptMicAlgorithms, org.apache.camel.component.as2.api.AS2EncryptionAlgorithm encryptingAlgorithm, java.security.cert.Certificate[] encryptingCertificateChain, String attachedFileName);
The as2/send API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
as2From |
AS2 name of sender |
String |
as2MessageStructure |
The structure of AS2 to send; see AS2MessageStructure |
AS2MessageStructure |
as2To |
AS2 name of recipient |
String |
attachedFileName |
The name of the attached file or null if user doesn’t want to specify it |
String |
compressionAlgorithm |
The algorithm used to compress the message or null if sending EDI message uncompressed |
AS2CompressionAlgorithm |
dispositionNotificationTo |
An RFC2822 address to request a receipt or null if no receipt requested |
String |
ediMessage |
EDI message to transport |
String |
ediMessageContentType |
The content type of EDI message |
ContentType |
ediMessageTransferEncoding |
The transfer encoding used to transport EDI message |
String |
encryptingAlgorithm |
The algorithm used to encrypt the message or null if sending EDI message unencrypted |
AS2EncryptionAlgorithm |
encryptingCertificateChain |
The chain of certificates used to encrypt the message or null if sending EDI message unencrypted |
Certificate[] |
from |
RFC2822 address of sender |
String |
requestUri |
Resource location to deliver message |
String |
signedReceiptMicAlgorithms |
The senders list of signing algorithms for signing receipt, in preferred order, or null if requesting an unsigned receipt. |
String[] |
signingAlgorithm |
The algorithm used to sign the message or null if sending EDI message unsigned |
AS2SignatureAlgorithm |
signingCertificateChain |
The chain of certificates used to sign the message or null if sending EDI message unsigned |
Certificate[] |
signingPrivateKey |
The private key used to sign EDI message |
PrivateKey |
subject |
Message subject |
String |
In addition to the parameters above, the as2 API can also use any of the Query Parameters (31 parameters).
Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header.
The message header name must be of the format CamelAs2.parameter
.
The inBody
parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere
would override a CamelAs2.myParameterNameHere
header.
API: server
Only consumer is supported
The server API is defined in the syntax as follows:
as2:server/methodName?[parameters]
The 1 method(s) is listed in the table below, followed by detailed syntax for each method. (API methods can have a shorthand alias name which can be used in the syntax instead of the name)
Method | Alias | Description |
---|---|---|
Method listen
Signatures:
-
void listen(String requestUriPattern, org.apache.http.protocol.HttpRequestHandler handler);
The as2/listen API method has the parameters listed in the table below:
Parameter | Description | Type |
---|---|---|
requestUriPattern |
String |
In addition to the parameters above, the as2 API can also use any of the Query Parameters (31 parameters).
Any of the parameters can be provided in either the endpoint URI, or dynamically in a message header.
The message header name must be of the format CamelAs2.parameter
.
The inBody
parameter overrides message header, i.e. the endpoint parameter inBody=myParameterNameHere
would override a CamelAs2.myParameterNameHere
header.
Spring Boot Auto-Configuration
When using as2 with Spring Boot make sure to use the following Maven dependency to have support for auto configuration:
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-as2-starter</artifactId>
<version>x.x.x</version>
<!-- use the same version as your Camel core version -->
</dependency>
The component supports 5 options, which are listed below.
Name | Description | Default | Type |
---|---|---|---|
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 |
|
Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions occurred while the consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored. |
false |
Boolean |
|
Component configuration. The option is a org.apache.camel.component.as2.AS2Configuration type. |
AS2Configuration |
||
Whether to enable auto configuration of the as2 component. This is enabled by default. |
Boolean |
||
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 |