Search in sources :

Example 16 with IAS4MessageState

use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.

the class MockMessageProcessorSPI method processAS4SignalMessage.

@Nonnull
public AS4SignalMessageProcessorResult processAS4SignalMessage(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHttpHeaders, @Nonnull final Ebms3SignalMessage aSignalMessage, @Nullable final IPMode aPMode, @Nonnull final IAS4MessageState aState, @Nonnull final ICommonsList<Ebms3Error> aProcessingErrorMessages) {
    if (aSignalMessage.getReceipt() != null) {
        // Receipt - just acknowledge
        return AS4SignalMessageProcessorResult.createSuccess();
    }
    if (!aSignalMessage.getError().isEmpty()) {
        // Error - just acknowledge
        return AS4SignalMessageProcessorResult.createSuccess();
    }
    // Must be a pull-request
    final Ebms3PullRequest aPullRequest = aSignalMessage.getPullRequest();
    if (aPullRequest != null) {
        if (aPullRequest.getMpc().equals(MPC_FAILURE)) {
            return AS4SignalMessageProcessorResult.createFailure("Error in creating the usermessage - mock MPC 'failure' was used!");
        }
        // Empty MPC
        if (aPullRequest.getMpc().equals(MPC_EMPTY)) {
            return AS4SignalMessageProcessorResult.createSuccess();
        }
    }
    final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
    // Add properties
    final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
    final Ebms3MessageInfo aMessageInfo = aSignalMessage.getMessageInfo();
    final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo(aMessageInfo.getMessageId());
    final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
    final Ebms3CollaborationInfo aEbms3CollaborationInfo;
    final Ebms3PartyInfo aEbms3PartyInfo;
    aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo("PullPMode", DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
    aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "pullinitiator", CAS4.DEFAULT_RESPONDER_URL, "pullresponder");
    final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
    final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
    aUserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
    aUserMessage.setMessageInfo(aEbms3MessageInfo);
    aUserMessage.setMessageProperties(aEbms3MessageProperties);
    aUserMessage.setPartyInfo(aEbms3PartyInfo);
    aUserMessage.setPayloadInfo(aEbms3PayloadInfo);
    if (aPullRequest != null)
        aUserMessage.setMpc(aPullRequest.getMpc());
    return AS4SignalMessageProcessorResult.createSuccess(null, null, aUserMessage);
}
Also used : Ebms3MessageProperties(com.helger.phase4.ebms3header.Ebms3MessageProperties) Ebms3PayloadInfo(com.helger.phase4.ebms3header.Ebms3PayloadInfo) Ebms3PullRequest(com.helger.phase4.ebms3header.Ebms3PullRequest) Ebms3CollaborationInfo(com.helger.phase4.ebms3header.Ebms3CollaborationInfo) Node(org.w3c.dom.Node) Ebms3UserMessage(com.helger.phase4.ebms3header.Ebms3UserMessage) Ebms3MessageInfo(com.helger.phase4.ebms3header.Ebms3MessageInfo) ClassPathResource(com.helger.commons.io.resource.ClassPathResource) Ebms3PartyInfo(com.helger.phase4.ebms3header.Ebms3PartyInfo) Ebms3Property(com.helger.phase4.ebms3header.Ebms3Property) Nonnull(javax.annotation.Nonnull)

Example 17 with IAS4MessageState

use of com.helger.phase4.servlet.IAS4MessageState in project phase4 by phax.

the class CustomPeppolIncomingSBDHandlerSPI method handleIncomingSBD.

public void handleIncomingSBD(@Nonnull final IAS4IncomingMessageMetadata aMessageMetadata, @Nonnull final HttpHeaderMap aHeaders, @Nonnull final Ebms3UserMessage aUserMessage, @Nonnull final byte[] aSBDBytes, @Nonnull final StandardBusinessDocument aSBD, @Nonnull final PeppolSBDHDocument aPeppolSBD, @Nonnull final IAS4MessageState aState) throws Exception {
    // Get the service from the locator
    LOGGER.info("Retrieving the handler service.");
    final ISBDHandlerService service = SDBHandlerServiceLocator.getService(ESBDHHandlerServiceSelector.CUSTOM_PEPPOL_INCOMING);
    LOGGER.info("Successfully retrieved the handler service.");
    // Inject the parameters into the service
    LOGGER.info("Injecting parameters into the handler service.");
    service.setMessageMetadata(aMessageMetadata);
    service.setHttpHeaders(aHeaders);
    service.setUserMessage(aUserMessage);
    service.setStandardBusinessDocumentBytes(aSBDBytes);
    service.setStandardBusinessDocument(aSBD);
    service.setPeppolStandardBusinessDocumentHeader(aPeppolSBD);
    service.setMessageState(aState);
    // Handle the request, might raise an exception that needs to be dealt
    // carefully
    LOGGER.info("Handling request.");
    service.handle();
    LOGGER.info("Request handled with success.");
}
Also used : ISBDHandlerService(com.helger.phase4.springboot.service.ISBDHandlerService)

Aggregations

Nonnull (javax.annotation.Nonnull)9 Ebms3UserMessage (com.helger.phase4.ebms3header.Ebms3UserMessage)8 Phase4Exception (com.helger.phase4.util.Phase4Exception)7 IOException (java.io.IOException)7 AS4DecompressException (com.helger.phase4.attachment.AS4DecompressException)6 WSS4JAttachment (com.helger.phase4.attachment.WSS4JAttachment)6 Node (org.w3c.dom.Node)6 Ebms3Property (com.helger.phase4.ebms3header.Ebms3Property)5 MessagingException (javax.mail.MessagingException)5 WSSecurityException (org.apache.wss4j.common.ext.WSSecurityException)5 Document (org.w3c.dom.Document)5 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)4 Ebms3PullRequest (com.helger.phase4.ebms3header.Ebms3PullRequest)4 Ebms3SignalMessage (com.helger.phase4.ebms3header.Ebms3SignalMessage)4 IPMode (com.helger.phase4.model.pmode.IPMode)4 Nullable (javax.annotation.Nullable)4 ICommonsList (com.helger.commons.collection.impl.ICommonsList)3 ErrorList (com.helger.commons.error.list.ErrorList)3 HttpHeaderMap (com.helger.commons.http.HttpHeaderMap)3 IHasInputStream (com.helger.commons.io.IHasInputStream)3