# dk2k/camel-as2-usage architecture

> Architecture diagram of the GitHub repository dk2k/camel-as2-usage, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-19). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/dk2k/camel-as2-usage
- Repository: https://github.com/dk2k/camel-as2-usage

## Overview

##### Project type and purpose
– This is a Java-based integration/demo project using Apache Camel to illustrate AS2 (Applicability Statement 2) messaging: sending, receiving, and processing MDNs against either Mendelson’s public test server or a local stub. There is no database or UI; it’s a messaging middleware/service.

##### File structure
– Top-level:
- pom.xml (Maven build)
- src/main/java/ru/outofrange/as2/config (CamelConfig)
- src/main/java/ru/outofrange/as2/route (three RouteBuilders)
- src/main/java/ru/outofrange/cert (two CertLoader implementations)
- src/main/resources (application.properties + certificates)
– Test harness via a single JUnit ContextTest – boots Spring Boot/CamelContext, then you POST to HTTP endpoints to drive the routes.

##### README for additional insights
– Two modes:
A) Send to Mendelson testserver (external AS2 endpoint) on HTTP →3400/link.
B) Send/receive locally via self-signed cert on port 3500.
– Boolean flag NEED_SIGNED_ENCRYPTED toggles plain vs. signed/encrypted AS2.
– MDN response template is hardcoded by Camel’s AS2 component.

1. Spring Boot App (`MyApplication`)
2. Camel Context (instantiated by `CamelConfig`)
3. Route 1: AS2 Server (`AS2ServerRouteBuilder`)
4. Route 2: Mendelson AS2 Client (`MendelsonAs2ClientRouteBuilder`)
5. Route 3: Localhost Stub AS2 Client (`LocalhostStubAS2ClientRouteBuilder`)
6. Cert Loader Services (`MendelsonCertLoader`, `SelfSignedCertLoader`)
7. External Services:
- Mendelson Test Server (https://testas2.mendelson-e-c.com)
- (Optional) Local stub server
b. Relationships & interactions:
– Data flow starts when a user issues an HTTP POST (e.g., via Postman) to either `http://localhost:3400/link` or `http://localhost:3500/link`.
– The HTTP endpoint is exposed by one of the Camel routes.
– Incoming message is wrapped in an AS2Request by the Camel AS2 component.
– The route picks up certificate(s) from the CertLoader (depending on mode).
– The AS2 producer sends the AS2 request to the target (Mendelson’s endpoint or the stub).
– On receipt, AS2ServerRouteBuilder acts as the HTTP listener on port 3500, processes incoming AS2, and returns an MDN.
– MDN flows back to the client route and is logged or further processed using JavaMail multipart utilities.
c. Architectural patterns & principles:
– Dependency Injection: `@Configuration` class wires CamelContext, routes, and certificate loaders.
– Modular routes: each AS2 flow is encapsulated in its own RouteBuilder.
– Strategy pattern: two implementations of `CertLoader` toggle between Mendelson cert and self-signed cert.
d. Key technologies & frameworks:
– Apache Camel (core, camel-as2 component)
– Spring Boot (auto-configuration, dependency injection)
– JavaMail (for multipart MDN processing)
– OpenSSL-generated certificates (X.509, PKCS#12)

##### Detail without overthinking
– Capture each Java package/module as a functional block.
– Don’t just show “Camel” – break out each RouteBuilder and CertLoader.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    App["MyApplication"]:::internal
    Config["CamelConfig"]:::config
    AppProps["application.properties"]:::resource
    Pom["pom.xml"]:::resource
    Test["ContextTest"]:::resource

    subgraph "Configuration"
        Config
        AppProps
    end

    subgraph "Routes"
        ServerRoute["AS2ServerRouteBuilder\n(port 3500)"]:::internal
        MendelsonRoute["MendelsonAs2ClientRouteBuilder\n(port 3400)"]:::internal
        LocalRoute["LocalhostStubAS2ClientRouteBuilder\n(port 3500)"]:::internal
    end

    subgraph "Cert Loaders"
        MendelsonLoader["MendelsonCertLoader"]:::config
        SelfLoader["SelfSignedCertLoader"]:::config
    end

    subgraph "Certificates"
        MendPfx["key3.pfx"]:::resource
        MendCer["key4.cer"]:::resource
        SelfCA["test_cacert.crt"]:::resource
        SelfKey["test_private_key.pem"]:::resource
    end

    subgraph "External Systems"
        MendelsonServer["Mendelson Test Server\n(testas2.mendelson-e-c.com)"]:::external
        LocalStub["Local Stub AS2 Server"]:::external
    end

    %% Application wiring
    App -->|boots| Config
    Config -->|creates CamelContext| ServerRoute
    Config -->|creates CamelContext| MendelsonRoute
    Config -->|creates CamelContext| LocalRoute

    %% Test harness
    Test -->|invokes HTTP POST| MendelsonRoute
    Test -->|invokes HTTP POST| LocalRoute

    %% Client flows
    click App "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/java/ru/outofrange/MyApplication.java"
    click Config "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/java/ru/outofrange/as2/config/CamelConfig.java"
    click ServerRoute "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/java/ru/outofrange/as2/route/AS2ServerRouteBuilder.java"
    click MendelsonRoute "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/java/ru/outofrange/as2/route/MendelsonAs2ClientRouteBuilder.java"
    click LocalRoute "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/java/ru/outofrange/as2/route/LocalhostStubAS2ClientRouteBuilder.java"

    %% Mendelson flow
    MendelsonRoute -->|"loads cert"| MendelsonLoader
    MendelsonLoader -->|"uses"| MendPfx
    MendelsonLoader -->|"uses"| MendCer
    MendelsonRoute -->|"AS2Producer"| MendelsonServer
    MendelsonServer -.->|"MDN response"| MendelsonRoute

    %% Local flow
    LocalRoute -->|"loads cert"| SelfLoader
    SelfLoader -->|"uses"| SelfCA
    SelfLoader -->|"uses"| SelfKey
    LocalRoute -->|"AS2Producer"| LocalStub
    LocalStub -.->|"MDN response"| LocalRoute
    LocalStub --> ServerRoute
    ServerRoute -.->|"MDN to client"| LocalRoute

    %% Resources and project
    click AppProps "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/resources/application.properties"
    click MendPfx "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/resources/mendelson_cert/key3.pfx"
    click MendCer "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/resources/mendelson_cert/key4.cer"
    click SelfCA "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/resources/self_signed_cert/test_cacert.crt"
    click SelfKey "https://github.com/dk2k/camel-as2-usage/blob/main/src/main/resources/self_signed_cert/test_private_key.pem"
    click Pom "https://github.com/dk2k/camel-as2-usage/blob/main/pom.xml"
    click Test "https://github.com/dk2k/camel-as2-usage/blob/main/src/test/java/ru/outofrange/ContextTest.java"

    %% Styles
    classDef internal fill:#d0f0c0,stroke:#2d662d,color:#000
    classDef config fill:#c0d0f0,stroke:#223366,color:#000
    classDef external fill:#f0c080,stroke:#665522,color:#000
    classDef resource fill:#f0d0d0,stroke:#662222,color:#000
```
