use of com.helger.phase4.ebms3header.Ebms3SignalMessage in project phase4 by phax.
the class ENTSOGCompatibilityValidatorTest method testValidateSignalMessageNoMessageID.
@Test
public void testValidateSignalMessageNoMessageID() {
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
aSignalMessage.setMessageInfo(new Ebms3MessageInfo());
VALIDATOR.validateSignalMessage(aSignalMessage, m_aErrorList);
assertTrue(m_aErrorList.containsAny(x -> x.getErrorText(LOCALE).contains("MessageInfo/MessageId is missing")));
}
use of com.helger.phase4.ebms3header.Ebms3SignalMessage in project phase4 by phax.
the class AS4ErrorMessage method create.
@Nonnull
public static AS4ErrorMessage create(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nonnull final ICommonsList<Ebms3Error> aErrorMessages) {
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
// Message Info
aSignalMessage.setMessageInfo(aEbms3MessageInfo);
// Error Message
aSignalMessage.setError(aErrorMessages);
return new AS4ErrorMessage(eSoapVersion, aSignalMessage);
}
use of com.helger.phase4.ebms3header.Ebms3SignalMessage in project phase4 by phax.
the class AS4PullRequestMessage method create.
@Nonnull
public static AS4PullRequestMessage create(@Nonnull final ESoapVersion eSoapVersion, @Nonnull final Ebms3MessageInfo aEbms3MessageInfo, @Nullable final String sMPC, @Nullable final List<Object> aAny) {
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
// Message Info
aSignalMessage.setMessageInfo(aEbms3MessageInfo);
// PullRequest
if (StringHelper.hasText(sMPC)) {
final Ebms3PullRequest aEbms3PullRequest = new Ebms3PullRequest();
aEbms3PullRequest.setMpc(sMPC);
aSignalMessage.setPullRequest(aEbms3PullRequest);
}
aSignalMessage.setAny(aAny);
return new AS4PullRequestMessage(eSoapVersion, aSignalMessage);
}
use of com.helger.phase4.ebms3header.Ebms3SignalMessage in project phase4 by phax.
the class Ebms3MessagingTest method testMoreThenOneSignalMessage.
@Test
public void testMoreThenOneSignalMessage() throws Exception {
final Ebms3Messaging aEbms3Messaging = new Ebms3Messaging();
final List<Ebms3SignalMessage> aSignalMsgList = new ArrayList<>();
final Ebms3SignalMessage aSignalMessage = new Ebms3SignalMessage();
aSignalMessage.setAny(null);
// Message Info
aSignalMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
// PullRequest
final Ebms3PullRequest aEbms3PullRequest = new Ebms3PullRequest();
aEbms3PullRequest.setMpc(AS4TestConstants.DEFAULT_MPC);
aSignalMessage.setPullRequest(aEbms3PullRequest);
aEbms3Messaging.setSignalMessage(aSignalMsgList);
aSignalMsgList.add(aSignalMessage);
aSignalMsgList.add(aSignalMessage);
final HttpEntity aEntity = new HttpXMLEntity(_getMessagingAsSoapDocument(aEbms3Messaging), SOAP_VERSION.getMimeType());
sendPlainMessage(aEntity, false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
use of com.helger.phase4.ebms3header.Ebms3SignalMessage in project phase4 by phax.
the class AS4RequestHandler method _invokeSPIsForIncoming.
/**
* Invoke custom SPI message processors
*
* @param aHttpHeaders
* The received HTTP headers. Never <code>null</code>.
* @param aEbmsUserMessage
* Current user message. Either this OR signal message must be
* non-<code>null</code>.
* @param aEbmsSignalMessage
* The signal message to use. Either this OR user message must be
* non-<code>null</code>.
* @param aPayloadNode
* Optional SOAP body payload (only if direct SOAP msg, not for MIME).
* May be <code>null</code>.
* @param aDecryptedAttachments
* Original attachments from source message. May be <code>null</code>.
* @param aPMode
* PMode to be used - may be <code>null</code> for Receipt messages.
* @param aState
* The current state. Never <code>null</<code></code>.
* @param aErrorMessagesTarget
* The list of error messages to be filled if something goes wrong.
* Never <code>null</code>.
* @param aResponseAttachmentsTarget
* The list of attachments to be added to the response. Never
* <code>null</code>.
* @param aSPIResult
* The result object to be filled. May not be <code>null</code>.
*/
private void _invokeSPIsForIncoming(@Nonnull final HttpHeaderMap aHttpHeaders, @Nullable final Ebms3UserMessage aEbmsUserMessage, @Nullable final Ebms3SignalMessage aEbmsSignalMessage, @Nullable final Node aPayloadNode, @Nullable final ICommonsList<WSS4JAttachment> aDecryptedAttachments, @Nullable final IPMode aPMode, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aErrorMessagesTarget, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachmentsTarget, @Nonnull final SPIInvocationResult aSPIResult) {
ValueEnforcer.isTrue(aEbmsUserMessage != null || aEbmsSignalMessage != null, "User OR Signal Message must be present");
ValueEnforcer.isFalse(aEbmsUserMessage != null && aEbmsSignalMessage != null, "Only one of User OR Signal Message may be present");
final boolean bIsUserMessage = aEbmsUserMessage != null;
final String sMessageID = bIsUserMessage ? aEbmsUserMessage.getMessageInfo().getMessageId() : aEbmsSignalMessage.getMessageInfo().getMessageId();
// Get all processors
final ICommonsList<IAS4ServletMessageProcessorSPI> aAllProcessors = m_aProcessorSupplier.get();
if (LOGGER.isDebugEnabled())
LOGGER.debug("Trying to invoke the following " + aAllProcessors.size() + " SPIs on message ID '" + sMessageID + "': " + aAllProcessors);
if (aAllProcessors.isEmpty())
LOGGER.error("No IAS4ServletMessageProcessorSPI is available to process an incoming message");
// Invoke ALL non-null SPIs
for (final IAS4ServletMessageProcessorSPI aProcessor : aAllProcessors) if (aProcessor != null)
try {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Invoking AS4 message processor " + aProcessor + " for incoming message");
// Main processing
final AS4MessageProcessorResult aResult;
final ICommonsList<Ebms3Error> aProcessingErrorMessages = new CommonsArrayList<>();
if (bIsUserMessage) {
aResult = aProcessor.processAS4UserMessage(m_aMessageMetadata, aHttpHeaders, aEbmsUserMessage, aPMode, aPayloadNode, aDecryptedAttachments, aState, aProcessingErrorMessages);
} else {
aResult = aProcessor.processAS4SignalMessage(m_aMessageMetadata, aHttpHeaders, aEbmsSignalMessage, aPMode, aState, aProcessingErrorMessages);
}
// Result returned?
if (aResult == null)
throw new IllegalStateException("No result object present from AS4 message processor " + aProcessor + " - this is a programming error");
if (aProcessingErrorMessages.isNotEmpty() || aResult.isFailure()) {
if (aProcessingErrorMessages.isNotEmpty()) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("AS4 message processor " + aProcessor + " had processing errors - breaking. Details: " + aProcessingErrorMessages);
if (aResult.isSuccess())
LOGGER.warn("Processing errors are present but success was returned by a previous AS4 message processor " + aProcessor + " - considering the whole processing to be failed instead");
aErrorMessagesTarget.addAll(aProcessingErrorMessages);
}
if (aResult.isFailure() && aResult.hasErrorMessage()) {
aErrorMessagesTarget.add(EEbmsError.EBMS_OTHER.getAsEbms3Error(m_aLocale, sMessageID, "Invoked AS4 message processor SPI " + aProcessor + " on '" + sMessageID + "' returned a failure: " + aResult.getErrorMessage()));
}
// Stop processing
return;
}
// SPI invocation returned success and no errors
{
final String sAsyncResultURL = aResult.getAsyncResponseURL();
if (StringHelper.hasText(sAsyncResultURL)) {
// URL present
if (aSPIResult.hasAsyncResponseURL()) {
// A second processor returned a response URL - not allowed
final String sErrorMsg = "Invoked AS4 message processor SPI " + aProcessor + " on '" + sMessageID + "' failed: the previous processor already returned an async response URL; it is not possible to handle two URLs. Please check your SPI implementations.";
LOGGER.error(sErrorMsg);
aErrorMessagesTarget.add(EEbmsError.EBMS_VALUE_INCONSISTENT.getAsEbms3Error(m_aLocale, sMessageID, sErrorMsg));
// Stop processing
return;
}
aSPIResult.setAsyncResponseURL(sAsyncResultURL);
LOGGER.info("Using asynchronous response URL '" + sAsyncResultURL + "' for message ID '" + sMessageID + "'");
}
}
if (bIsUserMessage) {
// User message specific processing result handling
// empty
} else {
// Signal message specific processing result handling
assert aResult instanceof AS4SignalMessageProcessorResult;
if (aEbmsSignalMessage.getReceipt() == null) {
final Ebms3UserMessage aPullReturnUserMsg = ((AS4SignalMessageProcessorResult) aResult).getPullReturnUserMessage();
if (aSPIResult.hasPullReturnUserMsg()) {
// to the pullrequest initiator
if (aPullReturnUserMsg != null) {
final String sErrorMsg = "Invoked AS4 message processor SPI " + aProcessor + " on '" + sMessageID + "' failed: the previous processor already returned a usermessage; it is not possible to return two usermessage. Please check your SPI implementations.";
LOGGER.warn(sErrorMsg);
aErrorMessagesTarget.add(EEbmsError.EBMS_VALUE_INCONSISTENT.getAsEbms3Error(m_aLocale, sMessageID, sErrorMsg));
// Stop processing
return;
}
} else {
// Initial return user msg
if (aPullReturnUserMsg == null) {
// No message contained in the MPC
final String sErrorMsg = "Invoked AS4 message processor SPI " + aProcessor + " on '" + sMessageID + "' returned a failure: no UserMessage contained in the MPC";
LOGGER.warn(sErrorMsg);
aErrorMessagesTarget.add(EEbmsError.EBMS_EMPTY_MESSAGE_PARTITION_CHANNEL.getAsEbms3Error(m_aLocale, sMessageID, sErrorMsg));
// Stop processing
return;
}
// We have something :)
aSPIResult.setPullReturnUserMsg(aPullReturnUserMsg);
}
} else {
if (LOGGER.isDebugEnabled())
LOGGER.debug("The AS4 EbmsSignalMessage already has a Receipt");
}
}
// Add response attachments, payloads
aResult.addAllAttachmentsTo(aResponseAttachmentsTarget);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Successfully invoked AS4 message processor " + aProcessor);
} catch (final AS4DecompressException ex) {
LOGGER.error("Failed to decompress AS4 payload", ex);
// Hack for invalid GZip content from WSS4JAttachment.getSourceStream
aErrorMessagesTarget.add(EEbmsError.EBMS_DECOMPRESSION_FAILURE.getAsEbms3Error(m_aLocale, sMessageID));
return;
} catch (final RuntimeException ex) {
// Re-throw
throw ex;
} catch (final Exception ex) {
throw new IllegalStateException("Error processing incoming AS4 message with processor " + aProcessor, ex);
}
// Remember success
aSPIResult.setSuccess(true);
}
Aggregations