Skip to content

Dynamic content type fix #446

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 4, 2025

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