Search in sources :

Example 21 with ESoapVersion

use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.

the class MockMessages method createErrorMessageSigned.

@Nonnull
public static Document createErrorMessageSigned(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final ICommonsList<WSS4JAttachment> aAttachments, @Nonnull final AS4ResourceHelper aResMgr) throws WSSecurityException {
    final ICommonsList<Ebms3Error> aEbms3ErrorList = new CommonsArrayList<>(EEbmsError.EBMS_INVALID_HEADER.getAsEbms3Error(Locale.US, null));
    final AS4ErrorMessage aErrorMsg = AS4ErrorMessage.create(eSOAPVersion, "srcmsgid", aEbms3ErrorList).setMustUnderstand(true);
    return AS4Signer.createSignedMessage(AS4CryptoFactoryProperties.getDefaultInstance(), aErrorMsg.getAsSoapDocument(), eSOAPVersion, aErrorMsg.getMessagingID(), aAttachments, aResMgr, false, AS4SigningParams.createDefault());
}
Also used : Ebms3Error(com.helger.phase4.ebms3header.Ebms3Error) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) AS4ErrorMessage(com.helger.phase4.messaging.domain.AS4ErrorMessage) Nonnull(javax.annotation.Nonnull)

Example 22 with ESoapVersion

use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.

the class UserMessageDuplicateTest method testDuplicateSignedMessage.

@Test
public void testDuplicateSignedMessage() throws Exception {
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    final ESoapVersion eSOAPVersion = ESoapVersion.AS4_DEFAULT;
    final Document aDoc = MockMessages.createUserMessageSigned(eSOAPVersion, aPayload, null, s_aResMgr);
    final HttpEntity aEntity = new HttpXMLEntity(aDoc, eSOAPVersion.getMimeType());
    // Send first
    final String sResponse = sendPlainMessage(aEntity, true, null);
    assertTrue(sResponse.contains(AS4TestConstants.RECEIPT_ASSERTCHECK));
    // Send second
    sendPlainMessage(aEntity, false, EEbmsError.EBMS_OTHER.getErrorCode());
}
Also used : HttpEntity(org.apache.http.HttpEntity) ESoapVersion(com.helger.phase4.soap.ESoapVersion) Node(org.w3c.dom.Node) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) Document(org.w3c.dom.Document) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Test(org.junit.Test)

Example 23 with ESoapVersion

use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.

the class AS4RequestHandler method handleRequest.

/**
 * This is the main handling routine when called from an abstract
 * (non-Servlet) API
 *
 * @param aServletRequestIS
 *        The input stream with the request data. May not be
 *        <code>null</code>.
 * @param aRequestHttpHeaders
 *        The HTTP headers of the request. May not be <code>null</code>.
 * @param aHttpResponse
 *        The HTTP response to be filled. May not be <code>null</code>.
 * @throws Phase4Exception
 *         in case the request is missing certain prerequisites. Since 0.9.11
 * @throws IOException
 *         In case of IO errors
 * @throws MessagingException
 *         MIME related errors
 * @throws WSSecurityException
 *         In case of WSS4J errors
 * @see #handleRequest(InputStream, HttpHeaderMap, IAS4ResponseAbstraction)
 *      for a more generic API
 */
public void handleRequest(@Nonnull @WillClose final InputStream aServletRequestIS, @Nonnull final HttpHeaderMap aRequestHttpHeaders, @Nonnull final IAS4ResponseAbstraction aHttpResponse) throws Phase4Exception, IOException, MessagingException, WSSecurityException {
    final IAS4ParsedMessageCallback aCallback = (aHttpHeaders, aSoapDocument, eSoapVersion, aIncomingAttachments) -> {
        // SOAP document and SOAP version are determined
        // Collect all runtime errors
        final ICommonsList<Ebms3Error> aErrorMessages = new CommonsArrayList<>();
        final IAS4ResponseFactory aResponder = _handleSoapMessage(aHttpHeaders, aSoapDocument, eSoapVersion, aIncomingAttachments, aErrorMessages);
        if (aResponder != null) {
            // Response present -> send back
            final IAS4OutgoingDumper aRealOutgoingDumper = m_aOutgoingDumper != null ? m_aOutgoingDumper : AS4DumpManager.getOutgoingDumper();
            aResponder.applyToResponse(aHttpResponse, aRealOutgoingDumper);
        } else {
            // Success, HTTP No Content
            aHttpResponse.setStatus(CHttp.HTTP_NO_CONTENT);
        }
        AS4HttpDebug.debug(() -> "RECEIVE-END with " + (aResponder != null ? "EBMS message" : "no content"));
    };
    AS4IncomingHandler.parseAS4Message(m_aIAF, m_aResHelper, m_aMessageMetadata, aServletRequestIS, aRequestHttpHeaders, aCallback, m_aIncomingDumper);
}
Also used : AS4DecompressException(com.helger.phase4.attachment.AS4DecompressException) StreamHelper(com.helger.commons.io.stream.StreamHelper) BasicHttpPoster(com.helger.phase4.http.BasicHttpPoster) EMimeContentType(com.helger.commons.mime.EMimeContentType) ESoapVersion(com.helger.phase4.soap.ESoapVersion) HttpHeaderMap(com.helger.commons.http.HttpHeaderMap) HttpXMLEntity(com.helger.phase4.http.HttpXMLEntity) LoggerFactory(org.slf4j.LoggerFactory) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) MessagingException(javax.mail.MessagingException) EPModeSendReceiptReplyPattern(com.helger.phase4.model.pmode.leg.EPModeSendReceiptReplyPattern) AS4CryptParams(com.helger.phase4.crypto.AS4CryptParams) NonBlockingByteArrayOutputStream(com.helger.commons.io.stream.NonBlockingByteArrayOutputStream) EAS4MessageType(com.helger.phase4.messaging.domain.EAS4MessageType) WSSecurityException(org.apache.wss4j.common.ext.WSSecurityException) Nonempty(com.helger.commons.annotation.Nonempty) Locale(java.util.Locale) Document(org.w3c.dom.Document) IAS4IncomingMessageMetadata(com.helger.phase4.messaging.IAS4IncomingMessageMetadata) IAS4RetryCallback(com.helger.phase4.client.IAS4RetryCallback) PModeLeg(com.helger.phase4.model.pmode.leg.PModeLeg) IAS4IncomingAttachmentFactory(com.helger.phase4.attachment.IAS4IncomingAttachmentFactory) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) CGlobal(com.helger.commons.CGlobal) AS4SigningParams(com.helger.phase4.crypto.AS4SigningParams) IAS4ServletMessageProcessorSPI(com.helger.phase4.servlet.spi.IAS4ServletMessageProcessorSPI) HttpEntity(org.apache.http.HttpEntity) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) IThrowingRunnable(com.helger.commons.callback.IThrowingRunnable) IAS4ParsedMessageCallback(com.helger.phase4.servlet.AS4IncomingHandler.IAS4ParsedMessageCallback) SOAPHeaderElementProcessorRegistry(com.helger.phase4.servlet.soap.SOAPHeaderElementProcessorRegistry) ISuccessIndicator(com.helger.commons.state.ISuccessIndicator) AS4SignalMessageProcessorResult(com.helger.phase4.servlet.spi.AS4SignalMessageProcessorResult) AS4DumpManager(com.helger.phase4.dump.AS4DumpManager) HttpRetrySettings(com.helger.phase4.http.HttpRetrySettings) Ebms3Error(com.helger.phase4.ebms3header.Ebms3Error) AS4ErrorMessage(com.helger.phase4.messaging.domain.AS4ErrorMessage) ICommonsList(com.helger.commons.collection.impl.ICommonsList) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) HttpMimeMessageEntity(com.helger.phase4.http.HttpMimeMessageEntity) CHttp(com.helger.commons.http.CHttp) PhotonWorkerPool(com.helger.photon.app.PhotonWorkerPool) Ebms3SignalMessage(com.helger.phase4.ebms3header.Ebms3SignalMessage) MessageHelperMethods(com.helger.phase4.messaging.domain.MessageHelperMethods) ResponseHandlerXml(com.helger.httpclient.response.ResponseHandlerXml) AS4Signer(com.helger.phase4.messaging.crypto.AS4Signer) AS4ServletMessageProcessorManager(com.helger.phase4.servlet.mgr.AS4ServletMessageProcessorManager) WillClose(javax.annotation.WillClose) ServletInputStream(javax.servlet.ServletInputStream) AS4MessageProcessorResult(com.helger.phase4.servlet.spi.AS4MessageProcessorResult) AS4HttpDebug(com.helger.phase4.http.AS4HttpDebug) MetaAS4Manager(com.helger.phase4.mgr.MetaAS4Manager) CompletableFuture(java.util.concurrent.CompletableFuture) IAS4CryptoFactory(com.helger.phase4.crypto.IAS4CryptoFactory) Supplier(java.util.function.Supplier) Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) AS4Encryptor(com.helger.phase4.messaging.crypto.AS4Encryptor) Charset(java.nio.charset.Charset) EAS4MessageMode(com.helger.phase4.messaging.EAS4MessageMode) Node(org.w3c.dom.Node) IAS4IncomingDumper(com.helger.phase4.dump.IAS4IncomingDumper) AS4ResourceHelper(com.helger.phase4.util.AS4ResourceHelper) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) Nonnull(javax.annotation.Nonnull) Phase4Exception(com.helger.phase4.util.Phase4Exception) Nullable(javax.annotation.Nullable) EEbmsError(com.helger.phase4.error.EEbmsError) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) MimeMessageCreator(com.helger.phase4.messaging.mime.MimeMessageCreator) OutputStream(java.io.OutputStream) IRequestWebScopeWithoutResponse(com.helger.web.scope.IRequestWebScopeWithoutResponse) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Logger(org.slf4j.Logger) CommonsArrayList(com.helger.commons.collection.impl.CommonsArrayList) HasInputStream(com.helger.commons.io.stream.HasInputStream) IPMode(com.helger.phase4.model.pmode.IPMode) StringHelper(com.helger.commons.string.StringHelper) IPModeResolver(com.helger.phase4.model.pmode.resolve.IPModeResolver) AS4MimeMessage(com.helger.phase4.messaging.mime.AS4MimeMessage) EMEPBinding(com.helger.phase4.model.EMEPBinding) IOException(java.io.IOException) WSS4JAttachment(com.helger.phase4.attachment.WSS4JAttachment) XMLWriter(com.helger.xml.serialize.write.XMLWriter) ValueEnforcer(com.helger.commons.ValueEnforcer) AS4UserMessage(com.helger.phase4.messaging.domain.AS4UserMessage) IHasInputStream(com.helger.commons.io.IHasInputStream) MEPHelper(com.helger.phase4.model.MEPHelper) IMimeType(com.helger.commons.mime.IMimeType) CAS4(com.helger.phase4.CAS4) AS4XMLHelper(com.helger.phase4.util.AS4XMLHelper) InputStream(java.io.InputStream) IAS4ParsedMessageCallback(com.helger.phase4.servlet.AS4IncomingHandler.IAS4ParsedMessageCallback) IAS4OutgoingDumper(com.helger.phase4.dump.IAS4OutgoingDumper) ICommonsList(com.helger.commons.collection.impl.ICommonsList)

Example 24 with ESoapVersion

use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.

the class AS4RequestHandler method _createReversedUserMessage.

/**
 * Takes an UserMessage and switches properties to reverse the direction. So
 * previously it was C1 => C4, now its C4 => C1 Also adds attachments if there
 * are some that should be added.
 *
 * @param eSoapVersion
 *        of the message
 * @param sResponseMessageID
 *        The AS4 message ID of the response
 * @param aUserMessage
 *        the message that should be reversed
 * @param aResponseAttachments
 *        attachment that should be added
 * @return the reversed usermessage in document form
 */
@Nonnull
private static AS4UserMessage _createReversedUserMessage(@Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final ICommonsList<WSS4JAttachment> aResponseAttachments) {
    // Use current time
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(sResponseMessageID, aUserMessage.getMessageInfo().getMessageId());
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(false, aResponseAttachments);
    // Invert from and to role from original user message
    final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3ReversePartyInfo(aUserMessage.getPartyInfo());
    // Should be exactly the same as incoming message
    final Ebms3CollaborationInfo aEbms3CollaborationInfo = aUserMessage.getCollaborationInfo();
    // Need to switch C1 and C4 around from the original usermessage
    // TODO make customizable via profile
    final Ebms3MessageProperties aEbms3MessageProperties = new Ebms3MessageProperties();
    {
        Ebms3Property aFinalRecipient = null;
        Ebms3Property aOriginalSender = null;
        for (final Ebms3Property aProp : aUserMessage.getMessageProperties().getProperty()) {
            if (aProp.getName().equals(CAS4.ORIGINAL_SENDER))
                aOriginalSender = aProp;
            else if (aProp.getName().equals(CAS4.FINAL_RECIPIENT))
                aFinalRecipient = aProp;
        }
        if (aOriginalSender == null)
            throw new IllegalStateException("Failed to determine new OriginalSender");
        if (aFinalRecipient == null)
            throw new IllegalStateException("Failed to determine new FinalRecipient");
        aFinalRecipient.setName(CAS4.ORIGINAL_SENDER);
        aOriginalSender.setName(CAS4.FINAL_RECIPIENT);
        aEbms3MessageProperties.addProperty(aFinalRecipient);
        aEbms3MessageProperties.addProperty(aOriginalSender);
    }
    return AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSoapVersion);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 25 with ESoapVersion

use of com.helger.phase4.soap.ESoapVersion in project phase4 by phax.

the class AS4RequestHandler method _createResponseReceiptMessage.

/**
 * @param aState
 *        The processing state of the incoming message. Never
 *        <code>null</code>.
 * @param aSoapDocument
 *        document which should be used as source for the receipt to convert
 *        it to non-repudiation information. Can be <code>null</code>.
 * @param eSoapVersion
 *        SOAPVersion which should be used
 * @param aEffectiveLeg
 *        the leg that is used to determined, how the receipt should be build
 * @param aUserMessage
 *        used if no non-repudiation information is needed, prints the
 *        usermessage in receipt. Can be <code>null</code>.
 * @param aResponseAttachments
 *        that should be sent back if needed. Can be <code>null</code>.
 * @throws WSSecurityException
 */
@Nonnull
private IAS4ResponseFactory _createResponseReceiptMessage(@Nonnull final IAS4MessageState aState, @Nullable final Document aSoapDocument, @Nonnull final ESoapVersion eSoapVersion, @Nonnull @Nonempty final String sResponseMessageID, @Nonnull final PModeLeg aEffectiveLeg, @Nullable final Ebms3UserMessage aUserMessage, @Nullable final ICommonsList<WSS4JAttachment> aResponseAttachments) throws WSSecurityException {
    final AS4ReceiptMessage aReceiptMessage = AS4ReceiptMessage.create(eSoapVersion, sResponseMessageID, aUserMessage, aSoapDocument, _isSendNonRepudiationInformation(aEffectiveLeg)).setMustUnderstand(true);
    // We've got our response
    final Document aResponseDoc = aReceiptMessage.getAsSoapDocument();
    final AS4SigningParams aSigningParams = new AS4SigningParams().setFromPMode(aEffectiveLeg.getSecurity());
    final Document aSignedDoc = _signResponseIfNeeded(aResponseAttachments, aSigningParams, aResponseDoc, aEffectiveLeg.getProtocol().getSoapVersion(), aReceiptMessage.getMessagingID());
    return new AS4ResponseFactoryXML(m_aMessageMetadata, aState, sResponseMessageID, aSignedDoc, eSoapVersion.getMimeType());
}
Also used : AS4SigningParams(com.helger.phase4.crypto.AS4SigningParams) AS4ReceiptMessage(com.helger.phase4.messaging.domain.AS4ReceiptMessage) Document(org.w3c.dom.Document) Nonnull(javax.annotation.Nonnull)

Aggregations

Nonnull (javax.annotation.Nonnull)29 Document (org.w3c.dom.Document)13 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)12 ESoapVersion (com.helger.phase4.soap.ESoapVersion)12 Ebms3MessageInfo (com.helger.phase4.ebms3header.Ebms3MessageInfo)9 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)9 AS4UserMessage (com.helger.phase4.messaging.domain.AS4UserMessage)9 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)8 Ebms3CollaborationInfo (com.helger.phase4.ebms3header.Ebms3CollaborationInfo)8 Ebms3MessageProperties (com.helger.phase4.ebms3header.Ebms3MessageProperties)8 Ebms3PartyInfo (com.helger.phase4.ebms3header.Ebms3PartyInfo)8 Ebms3PayloadInfo (com.helger.phase4.ebms3header.Ebms3PayloadInfo)8 Node (org.w3c.dom.Node)8 Ebms3Error (com.helger.phase4.ebms3header.Ebms3Error)6 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)6 IOException (java.io.IOException)6 MessagingException (javax.mail.MessagingException)6 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)6 AS4DecompressException (com.helger.phase4.attachment.AS4DecompressException)5 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)5