Skip to content

Fix Jaxb2Marshaller when mtomEnabled and schema validation are both set - #37120

Open
arimu1 wants to merge 1 commit into
spring-projects:mainfrom
arimu1:fix/mtom-schema-validation-sws-1030
Open

Fix Jaxb2Marshaller when mtomEnabled and schema validation are both set#37120
arimu1 wants to merge 1 commit into
spring-projects:mainfrom
arimu1:fix/mtom-schema-validation-sws-1030

Conversation

@arimu1

@arimu1 arimu1 commented Aug 7, 2026

Copy link
Copy Markdown

Overview

When Jaxb2Marshaller has both mtomEnabled=true and a configured schema/schemas, marshalling fails with:

cvc-type.3.1.2: Element '…' is a simple type, so it must have no element information item [children].

XOP packaging replaces xs:base64Binary simple content with xop:Include element children. JAXB applies the Schema to the XOP-encoded stream, so validation rejects valid logical content.

Reported via spring-projects/spring-ws#1030 (SWS-958); sample: https://github.com/mpeterka/spring-ws-mtom (testMarshallMtom).

The bug lives in spring-oxm (Jaxb2Marshaller), not in Spring WS itself.

Fix

When MTOM is active and a schema is configured:

  1. Validate the logical infoset first: marshall with schema, with a non-XOP AttachmentMarshaller (isXOPPackage() == false) so base64Binary stays simple content and @XmlAttachmentRef/SWA still get a placeholder content id.
  2. MTOM-encode without schema: marshall with the real MimeContainer attachment marshaller so xop:Include is written without re-validating the XOP package.

This matches the expected order from the issue: validate → replace with MTOM includes → send.

Tests

  • marshalAttachmentsWithSchema — MTOM + matching XSD succeeds and still adds attachments
  • marshalAttachmentsWithSchemaRejectsInvalidGraph — wrong schema still fails before attachments are added
  • Existing marshalAttachments unchanged
./gradlew :spring-oxm:test --tests org.springframework.oxm.jaxb.Jaxb2MarshallerTests \
  --tests org.springframework.oxm.jaxb.Jaxb2UnmarshallerTests

24 + 12 tests green (Temurin 25).

Related

  • Fixes spring-projects/spring-ws#1030
  • Does not change inbound unmarshalling + schema (still XOP-on-the-wire vs logical schema); server-side PayloadValidatingInterceptor can be a follow-up if needed.

When mtomEnabled and a Schema are both configured, validate the logical
infoset first (non-XOP base64Binary simple content, SWA placeholders),
then MTOM-encode without Schema so xop:Include children do not fail
cvc-type.3.1.2.

Fixes spring-projects/spring-ws#1030 (SWS-958).

Signed-off-by: arimu1 <19286898+arimu1@users.noreply.github.com>
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Aug 7, 2026
@sbrannen sbrannen added the in: data Issues in data modules (jdbc, orm, oxm, tx) label Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

in: data Issues in data modules (jdbc, orm, oxm, tx) status: waiting-for-triage An issue we've not yet triaged or decided on

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Soap MTOM: mtomEnabled=true and XSD schemas=... fails [SWS-958]

3 participants