phax / phase4

phase4 - AS4 client and server for integration into existing systems. Specific support for Peppol and CEF eDelivery built-in.
Apache License 2.0
154 stars 47 forks source link

IllegalArgumentException in PModeManager#createOrUpdatePMode when changing a PMode #118

Closed sopgreg closed 1 year ago

sopgreg commented 1 year ago

I got this exception when changing the role of the initiator for a given PMode-ID, but this can be verified with other changes as well. The issue can be reproduced as follows:

PMode pMode = ENTSOGPMode.createENTSOGPMode("SenderX", "ResponderY", "https://localhost:8443/as4",
        (i, r) -> "PModeId", true);

pModeManager.createOrUpdatePMode(pMode);

PMode pMode2 = ENTSOGPMode.createENTSOGPMode("SenderX", "ResponderY", "https://localhost:8443/as4",
        (i, r) -> "PModeId", true);
// alter the role of the initiator
var initiator = pMode2.getInitiator();
var newInitiator = new PModeParty(initiator.getIDType(), initiator.getID(), "ZSH", initiator.getUserName(), initiator.getPassword());
pMode2.setInitiator(newInitiator);

pModeManager.createOrUpdatePMode(pMode2);

A IllegalArgumentException will be thrown in com.helger.dao.wal.AbstractMapBasedWALDAO#_addItem

grafik

The issue likely occurs because the check, if the PMode already exists in the current list of PModes, uses a different filter to check for and does not find the PMode already in the map, and then continues to create a new item (instead of an update).

grafik

phax commented 1 year ago

This is now finally also fixed in v2.2.0. The new rule to identify a "double PMode" is either by the same PMode ID (ID is always unique) or if all fields (ID type, ID value, role, username, password) from Initiator and Sender are identical.