Search in sources :

Example 1 with Ebms3SignalMessage

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")));
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) PModeLegSecurity(com.helger.phase4.model.pmode.leg.PModeLegSecurity) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) EMEP(com.helger.phase4.model.EMEP) ErrorList(com.helger.commons.error.list.ErrorList) ETriState(com.helger.commons.state.ETriState) ESoapVersion(com.helger.phase4.soap.ESoapVersion) Assert.assertNotSame(org.junit.Assert.assertNotSame) EPModeSendReceiptReplyPattern(com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern) ECryptoAlgorithmSign(com.helger.phase4.crypto.ECryptoAlgorithmSign) Locale(java.util.Locale) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) PMode(com.helger.phase4.model.pmode.PMode) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) ClassRule(org.junit.ClassRule) PModeLegErrorHandling(com.helger.phase4.model.pmode.leg.PModeLegErrorHandling) PhotonAppWebTestRule(com.helger.photon.app.mock.PhotonAppWebTestRule) Before(org.junit.Before) Ebms3PartyId(com.helger.phase4.ebms3header.Ebms3PartyId) PModeLegProtocol(com.helger.phase4.model.pmode.leg.PModeLegProtocol) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) ECryptoAlgorithmSignDigest(com.helger.phase4.crypto.ECryptoAlgorithmSignDigest) EWSSVersion(com.helger.phase4.wss.EWSSVersion) Assert.assertTrue(org.junit.Assert.assertTrue) EMEPBinding(com.helger.phase4.model.EMEPBinding) Test(org.junit.Test) Ebms3To(com.helger.phase4.ebms3header.Ebms3To) ECryptoAlgorithmCrypt(com.helger.phase4.crypto.ECryptoAlgorithmCrypt) Ebms3From(com.helger.phase4.ebms3header.Ebms3From) Ignore(org.junit.Ignore) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) IPModeIDProvider(com.helger.phase4.model.pmode.IPModeIDProvider) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) Test(org.junit.Test)

Example 2 with Ebms3SignalMessage

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);
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) Nonnull(javax.annotation.Nonnull)

Example 3 with Ebms3SignalMessage

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);
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) Ebms3PullRequest(com.helger.phase4.ebms3header.Ebms3PullRequest) Nonnull(javax.annotation.Nonnull)

Example 4 with Ebms3SignalMessage

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());
}
Also used : Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) HttpEntity(org.apache.http.HttpEntity) Ebms3PullRequest(com.helger.phase4.ebms3header.Ebms3PullRequest) ArrayList(java.util.ArrayList) Ebms3Messaging(com.helger.phase4.ebms3header.Ebms3Messaging) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Test(org.junit.Test)

Example 5 with Ebms3SignalMessage

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);
}
Also used : AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) IAS4ServletMessageProcessorSPI(com.helger.phase4.servlet.spi.IAS4ServletMessageProcessorSPI) Ebms3Error(com.helger.phase4.ebms3header.Ebms3Error) AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) MessagingException(javax.mail.MessagingException) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Phase4Exception(com.helger.phase4.util.Phase4Exception) IOException(java.io.IOException) AS4MessageProcessorResult(com.helger.phase4.servlet.spi.AS4MessageProcessorResult) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) AS4SignalMessageProcessorResult(com.helger.phase4.servlet.spi.AS4SignalMessageProcessorResult) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList)

Aggregations

Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)15 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)11 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)8 Nonnull (javax.annotation.Nonnull)8 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)6 PModeLeg (com.helger.phase4.model.pmode.leg.PModeLeg)6 Locale (java.util.Locale)6 Ebms3PartyId (com.helger.phase4.ebms3header.Ebms3PartyId)5 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)5 Ebms3PullRequest (com.helger.phase4.ebms3header.Ebms3PullRequest)5 MessageHelperMethods (com.helger.phase4.messaging.domain.MessageHelperMethods)5 Phase4Exception (com.helger.phase4.util.Phase4Exception)5 Node (org.w3c.dom.Node)5 ErrorList (com.helger.commons.error.list.ErrorList)4 ETriState (com.helger.commons.state.ETriState)4 ECryptoAlgorithmCrypt (com.helger.phase4.crypto.ECryptoAlgorithmCrypt)4 ECryptoAlgorithmSign (com.helger.phase4.crypto.ECryptoAlgorithmSign)4 ECryptoAlgorithmSignDigest (com.helger.phase4.crypto.ECryptoAlgorithmSignDigest)4 Ebms3From (com.helger.phase4.ebms3header.Ebms3From)4 Ebms3To (com.helger.phase4.ebms3header.Ebms3To)4