Skip to content

Conversation

@szabarna
Copy link
Contributor

@szabarna szabarna commented Jun 3, 2025

Problem

Our AS2 integration partner relies on the Content-Type header to determine how to process received files. To support this, we wanted to use OpenAS2’s dynamic content-type lookup feature, which maps file extensions to MIME types using a properties file.

However, despite configuring the feature correctly (both at the system and partnership level), the Content-Type was never resolved dynamically at runtime.
Root Cause

After adding debug logs and tracing execution, we discovered that while the Partnership objects were configured correctly (e.g., useDynamicContentTypeMapping=true and mapping files loaded), the Partnership instance used during message processing was a copy of the original.

The method Partnership#copy(...) did not copy over the internal fields related to dynamic lookup, namely:

this.useDynamicContentTypeLookup = partnership.useDynamicContentTypeLookup;
this.contentTypeFromFileExtensionMap = partnership.contentTypeFromFileExtensionMap;
this.overrideContentTypeFromFileExtensionMap = partnership.overrideContentTypeFromFileExtensionMap;

As a result, even if the original Partnership had dynamic lookup enabled and properly loaded mappings, the copied instance behaved as if the feature was disabled.
Fix

We added the three missing fields to the copy(...) method of the Partnership class:

this.useDynamicContentTypeLookup = partnership.useDynamicContentTypeLookup;
this.contentTypeFromFileExtensionMap = partnership.contentTypeFromFileExtensionMap;
this.overrideContentTypeFromFileExtensionMap = partnership.overrideContentTypeFromFileExtensionMap;

This ensures that the copied instance retains all necessary dynamic lookup configuration.
Why the Tests Didn't Catch It

The DynamicContentTypeTest test suite uses the original Partnership object directly — it never triggers a copy(). As such, dynamic lookup worked in the test scenario but failed in production, where the copied instance is used during message handling (e.g., in MessageBuilderModule).
Result

With this fix, dynamic content-type lookup now functions as intended in real deployments. The correct Content-Type is determined based on file extension mappings defined in system-level or partnership-specific configuration files.

Copy link
Contributor

@uhurusurfa uhurusurfa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🌟 Awesome - thanks for debugging the issue and submitting a PR - very much appreciated.

@uhurusurfa uhurusurfa merged commit b43ef86 into OpenAS2:master Jun 4, 2025
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants