use of com.helger.phase4.ebms3header.Ebms3To in project phase4 by phax.
the class CEFCompatibilityValidatorTest method testValidateUserMessageMoreThanOnePartyID.
@Test
public void testValidateUserMessageMoreThanOnePartyID() {
final Ebms3PartyId aFirstId = MessageHelperMethods.createEbms3PartyId("type", "value");
final Ebms3PartyId aSecondId = MessageHelperMethods.createEbms3PartyId("type2", "value2");
final Ebms3From aFromPart = new Ebms3From();
aFromPart.addPartyId(aFirstId);
aFromPart.addPartyId(aSecondId);
final Ebms3To aToPart = new Ebms3To();
aToPart.addPartyId(aFirstId);
aToPart.addPartyId(aSecondId);
final Ebms3PartyInfo aPartyInfo = new Ebms3PartyInfo();
aPartyInfo.setFrom(aFromPart);
aPartyInfo.setTo(aToPart);
final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
aUserMessage.setPartyInfo(aPartyInfo);
VALIDATOR.validateUserMessage(aUserMessage, m_aErrorList);
assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("must contain no more than one PartyID")));
}
use of com.helger.phase4.ebms3header.Ebms3To in project phase4 by phax.
the class CEFCompatibilityValidator method validateUserMessage.
@Override
public void validateUserMessage(@Nonnull final Ebms3UserMessage aUserMsg, @Nonnull final ErrorList aErrorList) {
ValueEnforcer.notNull(aUserMsg, "UserMsg");
if (aUserMsg.getMessageInfo() == null) {
aErrorList.add(_createError("MessageInfo is missing"));
} else {
if (StringHelper.hasNoText(aUserMsg.getMessageInfo().getMessageId()))
aErrorList.add(_createError("MessageInfo/MessageId is missing"));
{
// Check if originalSender and finalRecipient are present
// Since these two properties are mandatory
final Ebms3MessageProperties aMessageProperties = aUserMsg.getMessageProperties();
if (aMessageProperties == null)
aErrorList.add(_createError("MessageProperties is missing but 'originalSender' and 'finalRecipient' properties are required"));
else {
final List<Ebms3Property> aProps = aMessageProperties.getProperty();
if (aProps.isEmpty())
aErrorList.add(_createError("MessageProperties/Property must not be empty"));
else {
String sOriginalSenderC1 = null;
String sFinalRecipientC4 = null;
for (final Ebms3Property sProperty : aProps) {
if (sProperty.getName().equals(CAS4.ORIGINAL_SENDER))
sOriginalSenderC1 = sProperty.getValue();
else if (sProperty.getName().equals(CAS4.FINAL_RECIPIENT))
sFinalRecipientC4 = sProperty.getValue();
}
if (StringHelper.hasNoText(sOriginalSenderC1))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.ORIGINAL_SENDER + "' property is empty or not existant but mandatory"));
if (StringHelper.hasNoText(sFinalRecipientC4))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.FINAL_RECIPIENT + "' property is empty or not existant but mandatory"));
}
}
}
}
if (aUserMsg.getPartyInfo() == null) {
aErrorList.add(_createError("PartyInfo is missing"));
} else {
final Ebms3From aFrom = aUserMsg.getPartyInfo().getFrom();
if (aFrom != null) {
if (aFrom.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/From must contain no more than one PartyID"));
}
final Ebms3To aTo = aUserMsg.getPartyInfo().getTo();
if (aTo != null) {
if (aTo.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/To must contain no more than one PartyID"));
}
}
}
use of com.helger.phase4.ebms3header.Ebms3To in project phase4 by phax.
the class Ebms3MessagingTest method testUserMessageWithTooManyPartyIds.
@Test
public void testUserMessageWithTooManyPartyIds() throws Exception {
final Ebms3Messaging aEbms3Messaging = new Ebms3Messaging();
final Ebms3UserMessage aEbms3UserMessage = new Ebms3UserMessage();
// Message Info
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
final String sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
final Ebms3CollaborationInfo aEbms3CollaborationInfo;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
final Ebms3PartyInfo aEbms3PartyInfo = new Ebms3PartyInfo();
// From => Sender
final Ebms3From aEbms3From = new Ebms3From();
aEbms3From.setRole(CAS4.DEFAULT_INITIATOR_URL);
aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3PartyInfo.setFrom(aEbms3From);
// To => Receiver
final Ebms3To aEbms3To = new Ebms3To();
aEbms3To.setRole(CAS4.DEFAULT_RESPONDER_URL);
aEbms3To.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3PartyInfo.setTo(aEbms3To);
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
aEbms3UserMessage.setPartyInfo(aEbms3PartyInfo);
aEbms3UserMessage.setPayloadInfo(aEbms3PayloadInfo);
aEbms3UserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
aEbms3UserMessage.setMessageProperties(aEbms3MessageProperties);
aEbms3UserMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
aEbms3Messaging.addUserMessage(aEbms3UserMessage);
final HttpEntity aEntity = new HttpXMLEntity(_getMessagingAsSoapDocument(aEbms3Messaging), SOAP_VERSION.getMimeType());
sendPlainMessage(aEntity, false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
use of com.helger.phase4.ebms3header.Ebms3To in project phase4 by phax.
the class MessageHelperMethods method createEbms3PartyInfo.
@Nonnull
public static Ebms3PartyInfo createEbms3PartyInfo(@Nonnull @Nonempty final String sFromRole, @Nullable final String sFromPartyIDType, @Nonnull @Nonempty final String sFromPartyID, @Nonnull @Nonempty final String sToRole, @Nullable final String sToPartyIDType, @Nonnull @Nonempty final String sToPartyID) {
ValueEnforcer.notEmpty(sFromRole, "FromRole");
ValueEnforcer.notEmpty(sFromPartyID, "FromPartyID");
ValueEnforcer.notEmpty(sToRole, "ToRole");
ValueEnforcer.notEmpty(sToPartyID, "ToPartyID");
final Ebms3PartyInfo aEbms3PartyInfo = new Ebms3PartyInfo();
// From => Sender
final Ebms3From aEbms3From = new Ebms3From();
aEbms3From.setRole(sFromRole);
aEbms3From.addPartyId(createEbms3PartyId(sFromPartyIDType, sFromPartyID));
aEbms3PartyInfo.setFrom(aEbms3From);
// To => Receiver
final Ebms3To aEbms3To = new Ebms3To();
aEbms3To.setRole(sToRole);
aEbms3To.addPartyId(createEbms3PartyId(sToPartyIDType, sToPartyID));
aEbms3PartyInfo.setTo(aEbms3To);
return aEbms3PartyInfo;
}
use of com.helger.phase4.ebms3header.Ebms3To in project phase4 by phax.
the class PeppolCompatibilityValidator method validateUserMessage.
@Override
public void validateUserMessage(@Nonnull final Ebms3UserMessage aUserMsg, @Nonnull final ErrorList aErrorList) {
ValueEnforcer.notNull(aUserMsg, "UserMsg");
if (aUserMsg.getMessageInfo() == null) {
aErrorList.add(_createError("MessageInfo is missing"));
} else {
if (StringHelper.hasNoText(aUserMsg.getMessageInfo().getMessageId()))
aErrorList.add(_createError("MessageInfo/MessageId is missing"));
{
// Check if originalSender and finalRecipient are present
// Since these two properties are mandatory
final Ebms3MessageProperties aMessageProperties = aUserMsg.getMessageProperties();
if (aMessageProperties == null)
aErrorList.add(_createError("MessageProperties is missing but 'originalSender' and 'finalRecipient' properties are required"));
else {
final List<Ebms3Property> aProps = aMessageProperties.getProperty();
if (aProps.isEmpty())
aErrorList.add(_createError("MessageProperties/Property must not be empty"));
else {
String sOriginalSenderC1 = null;
String sFinalRecipientC4 = null;
for (final Ebms3Property sProperty : aProps) {
if (sProperty.getName().equals(CAS4.ORIGINAL_SENDER))
sOriginalSenderC1 = sProperty.getValue();
else if (sProperty.getName().equals(CAS4.FINAL_RECIPIENT))
sFinalRecipientC4 = sProperty.getValue();
}
if (StringHelper.hasNoText(sOriginalSenderC1))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.ORIGINAL_SENDER + "' property is empty or not existant but mandatory"));
if (StringHelper.hasNoText(sFinalRecipientC4))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.FINAL_RECIPIENT + "' property is empty or not existant but mandatory"));
}
}
}
}
if (aUserMsg.getPartyInfo() == null) {
aErrorList.add(_createError("PartyInfo is missing"));
} else {
final Ebms3From aFrom = aUserMsg.getPartyInfo().getFrom();
if (aFrom != null) {
if (aFrom.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/From must contain no more than one PartyID"));
else if (aFrom.getPartyIdCount() == 1) {
if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aFrom.getPartyIdAtIndex(0).getType())) {
aErrorList.add(_createError("PartyInfo/From[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aFrom.getPartyIdAtIndex(0).getType() + "'"));
}
}
}
final Ebms3To aTo = aUserMsg.getPartyInfo().getTo();
if (aTo != null) {
if (aTo.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/To must contain no more than one PartyID"));
else if (aTo.getPartyIdCount() == 1) {
if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aTo.getPartyIdAtIndex(0).getType())) {
aErrorList.add(_createError("PartyInfo/To[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aTo.getPartyIdAtIndex(0).getType() + "'"));
}
}
}
}
if (aUserMsg.getCollaborationInfo() == null) {
aErrorList.add(_createError("CollaborationInfo is missing"));
} else {
final Ebms3AgreementRef aAgreementRef = aUserMsg.getCollaborationInfo().getAgreementRef();
if (aAgreementRef == null) {
aErrorList.add(_createError("CollaborationInfo/AgreementRef is missing"));
} else {
if (!PeppolPMode.DEFAULT_AGREEMENT_ID.equals(aAgreementRef.getValue()))
aErrorList.add(_createError("CollaborationInfo/AgreementRef must be '" + PeppolPMode.DEFAULT_AGREEMENT_ID + "' instead of '" + aAgreementRef.getValue() + "'"));
if (StringHelper.hasText(aAgreementRef.getType()))
aErrorList.add(_createError("CollaborationInfo/AgreementRef/@type must not be set"));
}
}
}
Aggregations