Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
import com.helger.phase4.model.message.EAS4MessageType;
import com.helger.phase4.model.message.MessageHelperMethods;
import com.helger.phase4.model.pmode.IPMode;
import com.helger.phase4.model.pmode.PModeReceptionAwareness;
import com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern;
import com.helger.phase4.model.pmode.leg.PModeLeg;
import com.helger.phase4.model.pmode.leg.PModeLegSecurity;
Expand Down Expand Up @@ -1709,34 +1710,49 @@ private IAS4ResponseFactory _handleIncomingSoapMessageAndInvokeSPIs (@NonNull fi
{
final String sProfileID = aIncomingState.getProfileID ();

if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Now checking for duplicate message with message ID '" +
sMessageID +
"' and profile ID '" +
sProfileID +
"'");

// Run duplicate message check
final boolean bIsDuplicate = MetaAS4Manager.getIncomingDuplicateMgr ()
.registerAndCheck (sMessageID,
sProfileID,
aPMode == null ? null : aPMode.getID ())
.isBreak ();
if (bIsDuplicate)
// Duplicate detection can be disabled per PMode (PMode[].ReceptionAwareness.DetectDuplicates).
// Without a PMode, or without an explicit setting, duplicates are always detected.
final PModeReceptionAwareness aReceptionAwareness = aPMode == null ? null : aPMode.getReceptionAwareness ();
if (aReceptionAwareness != null && !aReceptionAwareness.isDuplicateDetection ())
{
final String sDetails = "Not invoking SPIs, because message with Message ID '" +
sMessageID +
"' was already handled (this is a duplicate)";
LOGGER.error (sDetails);
aEbmsErrorMessages.add (EEbmsError.EBMS_PHASE4_DUPLICATE.errorBuilder (m_aLocale)
.refToMessageInError (sMessageID)
.errorDetail (sDetails)
.build ());
if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Not checking for duplicate message with message ID '" +
sMessageID +
"', because PMode '" +
aPMode.getID () +
"' disables duplicate detection");
}
else
{
if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Message with ID '" + sMessageID + "' is not a duplicate");
LOGGER.debug ("Now checking for duplicate message with message ID '" +
sMessageID +
"' and profile ID '" +
sProfileID +
"'");

// Run duplicate message check
final boolean bIsDuplicate = MetaAS4Manager.getIncomingDuplicateMgr ()
.registerAndCheck (sMessageID,
sProfileID,
aPMode == null ? null : aPMode.getID ())
.isBreak ();
if (bIsDuplicate)
{
final String sDetails = "Not invoking SPIs, because message with Message ID '" +
sMessageID +
"' was already handled (this is a duplicate)";
LOGGER.error (sDetails);
aEbmsErrorMessages.add (EEbmsError.EBMS_PHASE4_DUPLICATE.errorBuilder (m_aLocale)
.refToMessageInError (sMessageID)
.errorDetail (sDetails)
.build ());
}
else
{
if (LOGGER.isDebugEnabled ())
LOGGER.debug ("Message with ID '" + sMessageID + "' is not a duplicate");
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,19 @@
import org.w3c.dom.Node;

import com.helger.base.concurrent.ThreadHelper;
import com.helger.collection.commons.CommonsHashMap;
import com.helger.collection.commons.ICommonsMap;
import com.helger.io.resource.ClassPathResource;
import com.helger.phase4.AS4TestConstants;
import com.helger.phase4.config.AS4Configuration;
import com.helger.phase4.logging.Phase4LoggerFactory;
import com.helger.phase4.messaging.http.HttpXMLEntity;
import com.helger.phase4.mgr.MetaAS4Manager;
import com.helger.phase4.model.ESoapVersion;
import com.helger.phase4.model.error.EEbmsError;
import com.helger.phase4.model.pmode.IPMode;
import com.helger.phase4.model.pmode.PMode;
import com.helger.phase4.model.pmode.PModeReceptionAwareness;
import com.helger.phase4.server.message.MockMessages;
import com.helger.xml.serialize.read.DOMReader;

Expand Down Expand Up @@ -102,4 +108,38 @@ public void testDuplicateSignedMessage () throws Exception
// Send second
sendPlainMessageExpectError (aEntity, EEbmsError.EBMS_PHASE4_DUPLICATE.getErrorCode ());
}

@Test
public void testDuplicateDetectionDisabledInPMode () throws Exception
{
final Node aPayload = DOMReader.readXMLDOM (new ClassPathResource (AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));

// Disable duplicate detection in all PModes of the receiving side
final ICommonsMap <PMode, PModeReceptionAwareness> aOldValues = new CommonsHashMap <> ();
for (final IPMode aPMode : MetaAS4Manager.getPModeMgr ().getAll ())
if (aPMode instanceof final PMode aRealPMode)
{
aOldValues.put (aRealPMode, aRealPMode.getReceptionAwareness ());
final PModeReceptionAwareness aRA = PModeReceptionAwareness.createDefault ();
aRA.setDuplicateDetection (false);
aRealPMode.setReceptionAwareness (aRA);
}
assertTrue (aOldValues.isNotEmpty ());

try
{
final Document aDoc = MockMessages.createUserMessageNotSigned (m_eSoapVersion, aPayload, null)
.getAsSoapDocument (aPayload);
final HttpEntity aEntity = new HttpXMLEntity (aDoc, m_eSoapVersion.getMimeType ());

// The same message is accepted twice, because the PMode disables duplicate detection
sendPlainMessageExpectSuccess (aEntity);
sendPlainMessageExpectSuccess (aEntity);
}
finally
{
for (final var aEntry : aOldValues.entrySet ())
aEntry.getKey ().setReceptionAwareness (aEntry.getValue ());
}
}
}
Loading