use of com.helger.phase4.ebms3header.Ebms3UserMessage 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.Ebms3UserMessage in project phase4 by phax.
the class CEFCompatibilityValidatorTest method testValidateUserMessageNoMessageID.
@Test
public void testValidateUserMessageNoMessageID() {
final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
aUserMessage.setMessageInfo(new Ebms3MessageInfo());
VALIDATOR.validateUserMessage(aUserMessage, m_aErrorList);
assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("MessageInfo/MessageId is missing")));
}
use of com.helger.phase4.ebms3header.Ebms3UserMessage 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.Ebms3UserMessage in project phase4 by phax.
the class StoringServletMessageProcessorSPI method processAS4UserMessage.
@Nonnull
public AS4MessageProcessorResult processAS4UserMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IPMode aPMode, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
LOGGER.info("Received AS4 user message");
_dumpSoap(aMessageMetadata, aState);
// Dump all incoming attachments (but only if they are repeatable)
if (aIncomingAttachments != null) {
int nAttachmentIndex = 0;
for (final WSS4JAttachment aIncomingAttachment : aIncomingAttachments) {
if (aIncomingAttachment.isRepeatable())
_dumpIncomingAttachment(aMessageMetadata, aIncomingAttachment, nAttachmentIndex);
nAttachmentIndex++;
}
}
return AS4MessageProcessorResult.createSuccess();
}
use of com.helger.phase4.ebms3header.Ebms3UserMessage in project phase4 by phax.
the class ExampleReceiveMessageProcessorSPI method processAS4UserMessage.
@Nonnull
public AS4MessageProcessorResult processAS4UserMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final IPMode aPMode, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aIncomingAttachments, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
LOGGER.info("Received AS4 user message");
_dumpSoap(aMessageMetadata, aState);
if (aIncomingAttachments != null) {
int nIndex = 1;
for (final WSS4JAttachment aIncomingAttachment : aIncomingAttachments) {
final File aFile = StorageHelper.getStorageFile(aMessageMetadata, "-" + nIndex + ".payload");
if (StreamHelper.copyInputStreamToOutputStream(aIncomingAttachment.getSourceStream(), FileHelper.getOutputStream(aFile)).isFailure())
LOGGER.error("Failed to write incoming attachment [" + nIndex + "] to '" + aFile.getAbsolutePath() + "'");
else
LOGGER.info("Wrote incoming attachment [" + nIndex + "] to '" + aFile.getAbsolutePath() + "'");
++nIndex;
}
}
return AS4MessageProcessorResult.createSuccess();
}
Aggregations