use of com.helger.phase4.CAS4 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);
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class DropFolderUserMessage method _send.
private static void _send(@Nonnull final IAS4CryptoFactory aCF, final Path aSendFile, final Path aIncomingDir) {
final StopWatch aSW = StopWatch.createdStarted();
boolean bSuccess = false;
LOGGER.info("Trying to send " + aSendFile.toString());
try (final AS4ResourceHelper aResHelper = new AS4ResourceHelper()) {
// Read generic SBD
final StandardBusinessDocument aSBD = SBDHReader.standardBusinessDocument().read(Files.newInputStream(aSendFile));
if (aSBD == null) {
LOGGER.error("Failed to read " + aSendFile.toString() + " as SBDH document!");
} else {
// Extract Peppol specific data
final PeppolSBDHDocument aSBDH = new PeppolSBDHDocumentReader(IF).extractData(aSBD);
final ISMPServiceMetadataProvider aSMPClient = new SMPClient(UP, aSBDH.getReceiverAsIdentifier(), ESML.DIGIT_TEST);
final EndpointType aEndpoint = aSMPClient.getEndpoint(aSBDH.getReceiverAsIdentifier(), aSBDH.getDocumentTypeAsIdentifier(), aSBDH.getProcessAsIdentifier(), ESMPTransportProfile.TRANSPORT_PROFILE_BDXR_AS4);
if (aEndpoint == null) {
LOGGER.error("Found no endpoint for:\n Receiver ID: " + aSBDH.getReceiverAsIdentifier().getURIEncoded() + "\n Document type ID: " + aSBDH.getDocumentTypeAsIdentifier().getURIEncoded() + "\n Process ID: " + aSBDH.getProcessAsIdentifier().getURIEncoded());
} else {
final KeyStore.PrivateKeyEntry aOurCert = aCF.getPrivateKeyEntry();
final X509Certificate aTheirCert = CertificateHelper.convertStringToCertficate(aEndpoint.getCertificate());
final AS4ClientUserMessage aClient = new AS4ClientUserMessage(aResHelper);
aClient.setSoapVersion(ESoapVersion.SOAP_12);
// Keystore data
aClient.setAS4CryptoFactory(aCF);
aClient.signingParams().setAlgorithmSign(ECryptoAlgorithmSign.RSA_SHA_512);
aClient.signingParams().setAlgorithmSignDigest(ECryptoAlgorithmSignDigest.DIGEST_SHA_512);
// FIXME Action, Service etc. are missing
aClient.setAction("xxx");
aClient.setServiceType("xxx");
aClient.setServiceValue("xxx");
aClient.setConversationID(MessageHelperMethods.createRandomConversationID());
aClient.setAgreementRefValue("xxx");
aClient.setFromRole(CAS4.DEFAULT_ROLE);
aClient.setFromPartyID(PeppolCertificateHelper.getSubjectCN((X509Certificate) aOurCert.getCertificate()));
aClient.setToRole(CAS4.DEFAULT_ROLE);
aClient.setToPartyID(PeppolCertificateHelper.getSubjectCN(aTheirCert));
aClient.ebms3Properties().setAll(MessageHelperMethods.createEbms3Property(CAS4.ORIGINAL_SENDER, aSBDH.getSenderScheme(), aSBDH.getSenderValue()), MessageHelperMethods.createEbms3Property(CAS4.FINAL_RECIPIENT, aSBDH.getReceiverScheme(), aSBDH.getReceiverValue()));
aClient.setPayload(SBDHWriter.standardBusinessDocument().getAsDocument(aSBD));
final IAS4ClientBuildMessageCallback aCallback = null;
final IAS4OutgoingDumper aOutgoingDumper = null;
final IAS4RetryCallback aRetryCallback = null;
final AS4ClientSentMessage<byte[]> aResponseEntity = aClient.sendMessageWithRetries(W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference()), new ResponseHandlerByteArray(), aCallback, aOutgoingDumper, aRetryCallback);
LOGGER.info("Successfully transmitted document with message ID '" + aResponseEntity.getMessageID() + "' for '" + aSBDH.getReceiverAsIdentifier().getURIEncoded() + "' to '" + W3CEndpointReferenceHelper.getAddress(aEndpoint.getEndpointReference()) + "' in " + aSW.stopAndGetMillis() + " ms");
if (aResponseEntity.hasResponse()) {
final String sMessageID = aResponseEntity.getMessageID();
final String sFilename = FilenameHelper.getAsSecureValidASCIIFilename(sMessageID) + "-response.xml";
final File aResponseFile = aIncomingDir.resolve(sFilename).toFile();
if (SimpleFileIO.writeFile(aResponseFile, aResponseEntity.getResponse()).isSuccess())
LOGGER.info("Response file was written to '" + aResponseFile.getAbsolutePath() + "'");
else
LOGGER.error("Error writing response file to '" + aResponseFile.getAbsolutePath() + "'");
}
bSuccess = true;
}
}
} catch (final Exception ex) {
LOGGER.error("Error sending " + aSendFile.toString(), ex);
}
// After the exception handler!
{
// Move to done or error directory?
final Path aDest = aSendFile.resolveSibling(bSuccess ? PATH_DONE : PATH_ERROR).resolve(aSendFile.getFileName());
try {
Files.move(aSendFile, aDest);
} catch (final IOException ex) {
LOGGER.error("Error moving from '" + aSendFile.toString() + "' to '" + aDest + "'", ex);
}
}
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class Ebms3MessagingTest method testUserMessageNoMessageProperties.
@Test
public void testUserMessageNoMessageProperties() throws Exception {
final Ebms3Messaging aEbms3Messaging = new Ebms3Messaging();
final Ebms3UserMessage aEbms3UserMessage = new Ebms3UserMessage();
// Message Info
final Node aPayload = DOMReader.readXMLDOM(new ClassPathResource(AS4TestConstants.TEST_SOAP_BODY_PAYLOAD_XML));
final String sPModeID = SOAP_12_PARTY_ID + "-" + SOAP_12_PARTY_ID;
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, null);
final Ebms3CollaborationInfo aEbms3CollaborationInfo;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID, DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
final Ebms3PartyInfo aEbms3PartyInfo = new Ebms3PartyInfo();
// From => Sender
final Ebms3From aEbms3From = new Ebms3From();
aEbms3From.setRole(CAS4.DEFAULT_INITIATOR_URL);
aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3From.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3PartyInfo.setFrom(aEbms3From);
// To => Receiver
final Ebms3To aEbms3To = new Ebms3To();
aEbms3To.setRole(CAS4.DEFAULT_RESPONDER_URL);
aEbms3To.addPartyId(MessageHelperMethods.createEbms3PartyId(SOAP_12_PARTY_ID));
aEbms3PartyInfo.setTo(aEbms3To);
aEbms3UserMessage.setPartyInfo(aEbms3PartyInfo);
aEbms3UserMessage.setPayloadInfo(aEbms3PayloadInfo);
aEbms3UserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
aEbms3UserMessage.setMessageProperties(MessageHelperMethods.createEbms3MessageProperties(null));
aEbms3UserMessage.setMessageInfo(MessageHelperMethods.createEbms3MessageInfo());
aEbms3Messaging.addUserMessage(aEbms3UserMessage);
final HttpEntity aEntity = new HttpXMLEntity(_getMessagingAsSoapDocument(aEbms3Messaging), SOAP_VERSION.getMimeType());
sendPlainMessage(aEntity, false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class MockMessages method testUserMessageNotSignedNotPModeConform.
@Nonnull
public static Document testUserMessageNotSignedNotPModeConform(@Nonnull final ESoapVersion eSOAPVersion, @Nullable final Node aPayload, @Nullable final ICommonsList<WSS4JAttachment> aAttachments) {
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
final String sPModeID = CAS4.DEFAULT_INITIATOR_URL + "-" + CAS4.DEFAULT_RESPONDER_URL;
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(aPayload != null, aAttachments);
final Ebms3CollaborationInfo aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(sPModeID + "x", DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, AS4TestConstants.TEST_SERVICE, MockMessageProcessorCheckingStreamsSPI.ACTION_FAILURE, AS4TestConstants.TEST_CONVERSATION_ID);
final Ebms3PartyInfo aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, "testt", CAS4.DEFAULT_RESPONDER_URL, "testt");
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, eSOAPVersion).setMustUnderstand(true);
return aDoc.getAsSoapDocument(aPayload);
}
Aggregations