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>

URI format

as2://apiName/methodName

apiName can be one of:

  • client

  • server

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

bridgeErrorHandler (consumer)

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

lazyStartProducer (producer)

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

autowiredEnabled (advanced)

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

configuration (advanced)

Component configuration.

AS2Configuration

Endpoint Options

The AS2 endpoint is configured using URI syntax:

as2:apiName/methodName

with the following path and query parameters:

Path Parameters (2 parameters)

Name Description Default Type

apiName (common)

Required What kind of operation to perform.

Enum values:

  • CLIENT

  • SERVER

AS2ApiName

methodName (common)

Required What sub operation to use for the selected operation.

String

Query Parameters (31 parameters)

Name Description Default Type

as2From (common)

The value of the AS2From header of AS2 message.

String

as2MessageStructure (common)

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:

  • PLAIN

  • SIGNED

  • ENCRYPTED

  • SIGNED_ENCRYPTED

  • PLAIN_COMPRESSED

  • SIGNED_COMPRESSED

  • ENCRYPTED_COMPRESSED

  • ENCRYPTED_COMPRESSED_SIGNED

AS2MessageStructure

as2To (common)

The value of the AS2To header of AS2 message.

String

as2Version (common)

The version of the AS2 protocol.

Enum values:

  • 1.0

  • 1.1

1.1

String

attachedFileName (common)

The name of the attached file.

String

clientFqdn (common)

The Client Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint.

camel.apache.org

String

compressionAlgorithm (common)

The algorithm used to compress EDI message.

Enum values:

  • ZLIB

AS2CompressionAlgorithm

decryptingPrivateKey (common)

The key used to encrypt the EDI message.

PrivateKey

dispositionNotificationTo (common)

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

ediMessageTransferEncoding (common)

The transfer encoding of EDI message.

String

ediMessageType (common)

The content type of EDI message. One of application/edifact, application/edi-x12, application/edi-consent.

ContentType

encryptingAlgorithm (common)

The algorithm used to encrypt EDI message.

Enum values:

  • AES128_CBC

  • AES192_CBC

  • AES256_CBC

  • AES128_CCM

  • AES192_CCM

  • AES256_CCM

  • AES128_GCM

  • AES192_GCM

  • AES256_GCM

  • CAMELLIA128_CBC

  • CAMELLIA192_CBC

  • CAMELLIA256_CBC

  • CAST5_CBC

  • DES_CBC

  • DES_EDE3_CBC

  • GOST28147_GCFB

  • IDEA_CBC

  • RC2_CBC

  • RC4

  • SEED_CBC

AS2EncryptionAlgorithm

encryptingCertificateChain (common)

The chain of certificates used to encrypt EDI message.

Certificate[]

from (common)

The value of the From header of AS2 message.

String

inBody (common)

Sets the name of a parameter to be passed in the exchange In Body.

String

mdnMessageTemplate (common)

The template used to format MDN message.

String

requestUri (common)

The request URI of EDI message.

/

String

server (common)

The value included in the Server message header identifying the AS2 Server.

Camel AS2 Server Endpoint

String

serverFqdn (common)

The Server Fully Qualified Domain Name (FQDN). Used in message ids sent by endpoint.

camel.apache.org

String

serverPortNumber (common)

The port number of server.

Integer

signedReceiptMicAlgorithms (common)

The list of algorithms, in order of preference, requested to generate a message integrity check (MIC) returned in message dispostion notification (MDN).

String[]

signingAlgorithm (common)

The algorithm used to sign EDI message.

Enum values:

  • SHA3_224WITHRSA

  • SHA3_256WITHRSA

  • SHA3_384withRSA

  • SHA3_512WITHRSA

  • MD5WITHRSA

  • SHA1WITHRSA

  • MD2WITHRSA

  • SHA224WITHRSA

  • SHA256WITHRSA

  • SHA384WITHRSA

  • SHA512WITHRSA

  • RIPEMD128WITHRSA

  • RIPEMD160WITHRSA

  • RIPEMD256WITHRSA

  • SHA224WITHDSA

  • SHA256WITHDSA

  • SHA384WITHDSA

  • SHA512WITHDSA

  • SHA3_224WITHDSA

  • SHA3_256WITHDSA

  • SHA3_384WITHDSA

  • SHA3_512WITHDSA

  • SHA1WITHDSA

  • SHA3_224WITHECDSA

  • SHA3_256WITHECDSA

  • SHA3_384WITHECDSA

  • SHA3_512WITHECDSA

  • SHA1WITHECDSA

  • SHA224WITHECDSA

  • SHA256WITHECDSA

  • SHA384WITHECDSA

  • SHA512WITHECDSA

  • SHA1WITHPLAIN_ECDSA

  • SHA224WITHPLAIN_ECDSA

  • SHA256WITHPLAIN_ECDSA

  • SHA384WITHPLAIN_ECDSA

  • SHA512WITHPLAIN_ECDSA

  • RIPEMD160WITHPLAIN_ECDSA

  • SHA1WITHRSAANDMGF1

  • SHA224WITHRSAANDMGF1

  • SHA256WITHRSAANDMGF1

  • SHA384WITHRSAANDMGF1

  • SHA512WITHRSAANDMGF1

  • SHA3_224WITHRSAANDMGF1

  • SHA3_256WITHRSAANDMGF1

  • SHA3_384WITHRSAANDMGF1

  • SHA3_512WITHRSAANDMGF1

AS2SignatureAlgorithm

signingCertificateChain (common)

The chain of certificates used to sign EDI message.

Certificate[]

signingPrivateKey (common)

The key used to sign the EDI message.

PrivateKey

subject (common)

The value of Subject header of AS2 message.

String

targetHostname (common)

The host name (IP or DNS name) of target host.

String

targetPortNumber (common)

The port number of target host. -1 indicates the scheme default port.

Integer

userAgent (common)

The value included in the User-Agent message header identifying the AS2 user agent.

Camel AS2 Client Endpoint

String

exceptionHandler (consumer (advanced))

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

exchangePattern (consumer (advanced))

Sets the exchange pattern when the consumer creates an exchange.

Enum values:

  • InOnly

  • InOut

  • InOptionalOut

ExchangePattern

lazyStartProducer (producer (advanced))

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

client

Producer

Sends EDI Messages over HTTP

server

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

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

listen

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

camel.component.as2.autowired-enabled

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

camel.component.as2.bridge-error-handler

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

camel.component.as2.configuration

Component configuration. The option is a org.apache.camel.component.as2.AS2Configuration type.

AS2Configuration

camel.component.as2.enabled

Whether to enable auto configuration of the as2 component. This is enabled by default.

Boolean

camel.component.as2.lazy-start-producer

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