Skip to content

Commit

Permalink
Improved
Browse files Browse the repository at this point in the history
  • Loading branch information
phax committed Sep 6, 2024
1 parent a8eddae commit dc2247b
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,9 @@
import com.helger.commons.collection.impl.ICommonsMap;
import com.helger.commons.equals.EqualsHelper;
import com.helger.commons.error.IError;
import com.helger.commons.error.list.ErrorList;
import com.helger.commons.state.ESuccess;
import com.helger.commons.string.StringHelper;
import com.helger.jaxb.validation.CollectingValidationEventHandler;
import com.helger.phase4.attachment.EAS4CompressionMode;
import com.helger.phase4.attachment.WSS4JAttachment;
import com.helger.phase4.ebms3header.Ebms3CollaborationInfo;
Expand Down Expand Up @@ -231,17 +231,17 @@ public ESuccess processHeaderElement (@Nonnull final Document aSoapDoc,
final Locale aLocale = aIncomingState.getLocale ();

// Parse EBMS3 Messaging object
final CollectingValidationEventHandler aCVEH = new CollectingValidationEventHandler ();
final Ebms3Messaging aMessaging = new Ebms3MessagingMarshaller ().setValidationEventHandler (aCVEH).read (aElement);
final ErrorList aErrorList = new ErrorList ();
final Ebms3Messaging aMessaging = new Ebms3MessagingMarshaller ().setCollectErrors (aErrorList).read (aElement);

// If the ebms3reader above fails aMessaging will be null => invalid/not
// wellformed
if (aMessaging == null)
if (aMessaging == null || aErrorList.containsAtLeastOneError ())
{
// Errorcode/Id would be null => not conform with Ebms3ErrorMessage since
// the message always needs a errorcode =>
// Invalid Header == not wellformed/invalid xml
for (final IError aError : aCVEH.getErrorList ())
for (final IError aError : aErrorList)
{
final String sDetails = "Header error: " + aError.getAsString (aLocale);
LOGGER.error (sDetails);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,32 @@ public static AS4ReceiptMessage create (@Nonnull final ESoapVersion eSoapVersion
else
LOGGER.info ("Non-repudiation is disabled, hence returning the source UserMessage in the Receipt");

// It is not possible to directly contain the original UserMessage,
// because the XSD requires
// <xsd:any namespace="##other" processContents="lax"
// maxOccurs="unbounded"/>
// And UserMessage and SignalMessage share the same namespace NS
// As the Receipt cannot be empty, it is wrapped in another element
// of another namespace instead to work
final Document aUserMsgDoc = AS4UserMessage.create (eSoapVersion, aEbms3UserMessageToRespond)
.getAsSoapDocument ();
final Document aWrappedDoc = XMLFactory.newDocument ();
final Element eWrappedRoot = (Element) aWrappedDoc.appendChild (aWrappedDoc.createElementNS ("urn:fdc:phase4:ns:wrapper",
"OriginalUserMessage"));
eWrappedRoot.appendChild (aWrappedDoc.adoptNode (aUserMsgDoc.getDocumentElement ()));
aEbms3Receipt.addAny (eWrappedRoot);
// If the original usermessage is not signed, the receipt will contain
// the original message part without wss4j security

if (false)
{
// It is not possible to directly contain the original UserMessage,
// because the XSD requires
// <xsd:any namespace="##other" processContents="lax"
// maxOccurs="unbounded"/>
// And UserMessage and SignalMessage share the same namespace NS
aEbms3Receipt.addAny (AS4UserMessage.create (eSoapVersion, aEbms3UserMessageToRespond)
.getAsSoapDocument ()
.getDocumentElement ());
}
else
{
// As the Receipt cannot be empty, it is wrapped in another element
// of another namespace instead to work
final Document aUserMsgDoc = AS4UserMessage.create (eSoapVersion, aEbms3UserMessageToRespond)
.getAsSoapDocument ();
final Document aWrappedDoc = XMLFactory.newDocument ();
final Element eWrappedRoot = (Element) aWrappedDoc.appendChild (aWrappedDoc.createElementNS ("urn:fdc:phase4:ns:wrapper",
"OriginalUserMessage"));
eWrappedRoot.appendChild (aWrappedDoc.adoptNode (aUserMsgDoc.getDocumentElement ()));
aEbms3Receipt.addAny (eWrappedRoot);
}
}
aSignalMessage.setReceipt (aEbms3Receipt);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import javax.xml.namespace.QName;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;

import com.helger.commons.ValueEnforcer;
Expand Down Expand Up @@ -108,8 +109,8 @@ public final IMPLTYPE setMustUnderstand (final boolean bMustUnderstand)
public final Document getAsSoapDocument (@Nullable final Node aSoapBodyPayload)
{
// Convert to DOM Node
final Document aEbms3Document = new Ebms3MessagingMarshaller ().getAsDocument (m_aMessaging);
if (aEbms3Document == null)
final Element aEbms3Element = new Ebms3MessagingMarshaller ().getAsElement (m_aMessaging);
if (aEbms3Element == null)
throw new IllegalStateException ("Failed to write EBMS3 Messaging to XML");

final Node aRealSoapBodyPayload = aSoapBodyPayload instanceof Document ? ((Document) aSoapBodyPayload).getDocumentElement ()
Expand All @@ -123,7 +124,7 @@ public final Document getAsSoapDocument (@Nullable final Node aSoapBodyPayload)
final Soap11Envelope aSoapEnv = new Soap11Envelope ();
aSoapEnv.setHeader (new Soap11Header ());
aSoapEnv.setBody (new Soap11Body ());
aSoapEnv.getHeader ().addAny (aEbms3Document.getDocumentElement ());
aSoapEnv.getHeader ().addAny (aEbms3Element);
if (aRealSoapBodyPayload != null)
aSoapEnv.getBody ().addAny (aRealSoapBodyPayload);
final Document ret = new Soap11EnvelopeMarshaller ().getAsDocument (aSoapEnv);
Expand All @@ -137,7 +138,7 @@ public final Document getAsSoapDocument (@Nullable final Node aSoapBodyPayload)
final Soap12Envelope aSoapEnv = new Soap12Envelope ();
aSoapEnv.setHeader (new Soap12Header ());
aSoapEnv.setBody (new Soap12Body ());
aSoapEnv.getHeader ().addAny (aEbms3Document.getDocumentElement ());
aSoapEnv.getHeader ().addAny (aEbms3Element);
if (aRealSoapBodyPayload != null)
aSoapEnv.getBody ().addAny (aRealSoapBodyPayload);
final Document ret = new Soap12EnvelopeMarshaller ().getAsDocument (aSoapEnv);
Expand Down

0 comments on commit dc2247b

Please sign in to comment.