use of com.helger.phase4.CAS4 in project phase4 by phax.
the class MainCEFeInvoicingConnectivityTest method main.
public static void main(final String[] args) {
WebScopeManager.onGlobalBegin(MockServletContext.create());
// Dump (for debugging purpose only)
AS4DumpManager.setIncomingDumper(new AS4IncomingDumperFileBased());
AS4DumpManager.setOutgoingDumper(new AS4OutgoingDumperFileBased());
try (final WebScoped w = new WebScoped()) {
// Read a UBL Invoice
final byte[] aPayloadBytes = SimpleFileIO.getAllFileBytes(new File("src/test/resources/examples/base-example.xml"));
if (aPayloadBytes == null)
throw new IllegalStateException();
final IAS4ClientBuildMessageCallback x1 = new IAS4ClientBuildMessageCallback() {
public void onAS4Message(final AbstractAS4Message<?> aMsg) {
final AS4UserMessage aUserMsg = (AS4UserMessage) aMsg;
LOGGER.info("Sending out AS4 message with message ID '" + aUserMsg.getEbms3UserMessage().getMessageInfo().getMessageId() + "'");
LOGGER.info("Sending out AS4 message with conversation ID '" + aUserMsg.getEbms3UserMessage().getCollaborationInfo().getConversationId() + "'");
}
public void onSoapDocument(@Nonnull final Document aDoc) {
if (false)
LOGGER.info("SOAP Document:\n" + XMLWriter.getNodeAsString(aDoc, new XMLWriterSettings().setIndent(EXMLSerializeIndent.INDENT_AND_ALIGN)));
}
};
// TODO The message ID to use in the UI
final String sAS4MessageID = "36999089-662a-441f-95fd-470bec2b538e-100@phase4";
final ESimpleUserMessageSendResult eRes = Phase4CEFSender.builder().cryptoFactory(CF).httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).action("TC1Leg1").service("tc1", "bdx:noprocess").senderParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", YOUR_ID)).receiverParticipantID(new SimpleParticipantIdentifier("connectivity-partid-qns", "domibus-gitb")).fromPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").fromPartyID(YOUR_ID).fromRole(CAS4.DEFAULT_INITIATOR_URL).toPartyIDType("urn:oasis:names:tc:ebcore:partyid-type:unregistered").toPartyID("domibus-gitb").toRole(CAS4.DEFAULT_RESPONDER_URL).messageID(sAS4MessageID).payload(Phase4OutgoingAttachment.builder().data(aPayloadBytes).filename("businessContentPayload").compressionGZIP().mimeType(CMimeType.TEXT_XML).contentID("message").build()).buildMessageCallback(x1).endpointDetailProvider(new AS4EndpointDetailProviderConstant(CertificateHelper.convertStringToCertficateOrNull("-----BEGIN CERTIFICATE-----\r\n" + "MIIDOzCCAiOgAwIBAgIJAKbwaKpEwNTKMA0GCSqGSIb3DQEBCwUAMDQxDTALBgNV\r\n" + "BAoMBEdJVEIxDTALBgNVBAsMBEdJVEIxFDASBgNVBAMMC2dpdGItZW5naW5lMB4X\r\n" + "DTE0MTIyNDEzMjIzNFoXDTI0MTIyMTEzMjIzNFowNDENMAsGA1UECgwER0lUQjEN\r\n" + "MAsGA1UECwwER0lUQjEUMBIGA1UEAwwLZ2l0Yi1lbmdpbmUwggEiMA0GCSqGSIb3\r\n" + "DQEBAQUAA4IBDwAwggEKAoIBAQCpNuRRMhpd2SvNKsZe/WTxm4zuX2Zc5by3zGcm\r\n" + "uzwePdMCnCXk2FAUH67qS9r5VBa4USfiB7l1piyLrNwYWGRDo5OeWIz6Q821/1v7\r\n" + "UHq7FfB0LFPcJ+mOwrDqS+VL0MjcSW4pocJHrpFwObWHTY/R4WmW2xwGOKVh0OUL\r\n" + "UhqQsHDnDhCzFaEWhS8n1lUw3GRipwKLyYvXK8XgLceEmh+j0+cdmIj4a1L4oza/\r\n" + "UgBnCqSob+vowgClyZnGVihE9K8eLLwCSLlIiD+bXWf0VJPLXBNLdNIkRRC0QO0j\r\n" + "T9TuE5TF3SknkA5D0NFp023Alz7jieI0D6JE78QyNQN6y6QRAgMBAAGjUDBOMB0G\r\n" + "A1UdDgQWBBQpAkry20hAcvlw+4poxQC8TI+EgTAfBgNVHSMEGDAWgBQpAkry20hA\r\n" + "cvlw+4poxQC8TI+EgTAMBgNVHRMEBTADAQH/MA0GCSqGSIb3DQEBCwUAA4IBAQBS\r\n" + "dfmT3E9uvhiEgVefdwXkkxqlXLQQxfjaqVRVzPTHLqdVs/nBK+iQNhqg+6eLcaGQ\r\n" + "yyDy88vwQ85rqwOFbZd05esIFXYl0pgl1pVsb7HmMNmKT3UPay3HDlHX45ZoexDU\r\n" + "pza4OcrauEM8Yg/5i9dCIPC1GiHebJpYusMVfP78b+5DAyARrHtcb0EJ8rOLxHh6\r\n" + "K2S4EHI6sqQkGHEt1z4m66LyK+vnkLGaq3y6MWEufh78eICDyyVz0DhdIhr18ZHX\r\n" + "dpcsH2VOkE36KnWSo0spEXa6ZtP8MqQ60kJgBt4XcuArKfjIGC6vB6dE0NzXngBD\r\n" + "PHgMfmHJW018/6eN/f0q\r\n" + "-----END CERTIFICATE-----"), "https://www.itb.ec.europa.eu/cef/domibus/services/msh")).sendMessageAndCheckForReceipt();
LOGGER.info("Sending AS4 message to CEF with result " + eRes);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class PeppolCompatibilityValidator method validateUserMessage.
@Override
public void validateUserMessage(@Nonnull final Ebms3UserMessage aUserMsg, @Nonnull final ErrorList aErrorList) {
ValueEnforcer.notNull(aUserMsg, "UserMsg");
if (aUserMsg.getMessageInfo() == null) {
aErrorList.add(_createError("MessageInfo is missing"));
} else {
if (StringHelper.hasNoText(aUserMsg.getMessageInfo().getMessageId()))
aErrorList.add(_createError("MessageInfo/MessageId is missing"));
{
// Check if originalSender and finalRecipient are present
// Since these two properties are mandatory
final Ebms3MessageProperties aMessageProperties = aUserMsg.getMessageProperties();
if (aMessageProperties == null)
aErrorList.add(_createError("MessageProperties is missing but 'originalSender' and 'finalRecipient' properties are required"));
else {
final List<Ebms3Property> aProps = aMessageProperties.getProperty();
if (aProps.isEmpty())
aErrorList.add(_createError("MessageProperties/Property must not be empty"));
else {
String sOriginalSenderC1 = null;
String sFinalRecipientC4 = null;
for (final Ebms3Property sProperty : aProps) {
if (sProperty.getName().equals(CAS4.ORIGINAL_SENDER))
sOriginalSenderC1 = sProperty.getValue();
else if (sProperty.getName().equals(CAS4.FINAL_RECIPIENT))
sFinalRecipientC4 = sProperty.getValue();
}
if (StringHelper.hasNoText(sOriginalSenderC1))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.ORIGINAL_SENDER + "' property is empty or not existant but mandatory"));
if (StringHelper.hasNoText(sFinalRecipientC4))
aErrorList.add(_createError("MessageProperties/Property '" + CAS4.FINAL_RECIPIENT + "' property is empty or not existant but mandatory"));
}
}
}
}
if (aUserMsg.getPartyInfo() == null) {
aErrorList.add(_createError("PartyInfo is missing"));
} else {
final Ebms3From aFrom = aUserMsg.getPartyInfo().getFrom();
if (aFrom != null) {
if (aFrom.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/From must contain no more than one PartyID"));
else if (aFrom.getPartyIdCount() == 1) {
if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aFrom.getPartyIdAtIndex(0).getType())) {
aErrorList.add(_createError("PartyInfo/From[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aFrom.getPartyIdAtIndex(0).getType() + "'"));
}
}
}
final Ebms3To aTo = aUserMsg.getPartyInfo().getTo();
if (aTo != null) {
if (aTo.getPartyIdCount() > 1)
aErrorList.add(_createError("PartyInfo/To must contain no more than one PartyID"));
else if (aTo.getPartyIdCount() == 1) {
if (!PeppolPMode.DEFAULT_PARTY_TYPE_ID.equals(aTo.getPartyIdAtIndex(0).getType())) {
aErrorList.add(_createError("PartyInfo/To[0]/@type must be '" + PeppolPMode.DEFAULT_PARTY_TYPE_ID + "' instead of '" + aTo.getPartyIdAtIndex(0).getType() + "'"));
}
}
}
}
if (aUserMsg.getCollaborationInfo() == null) {
aErrorList.add(_createError("CollaborationInfo is missing"));
} else {
final Ebms3AgreementRef aAgreementRef = aUserMsg.getCollaborationInfo().getAgreementRef();
if (aAgreementRef == null) {
aErrorList.add(_createError("CollaborationInfo/AgreementRef is missing"));
} else {
if (!PeppolPMode.DEFAULT_AGREEMENT_ID.equals(aAgreementRef.getValue()))
aErrorList.add(_createError("CollaborationInfo/AgreementRef must be '" + PeppolPMode.DEFAULT_AGREEMENT_ID + "' instead of '" + aAgreementRef.getValue() + "'"));
if (StringHelper.hasText(aAgreementRef.getType()))
aErrorList.add(_createError("CollaborationInfo/AgreementRef/@type must not be set"));
}
}
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class CEFPMode method createCEFPMode.
/**
* One-Way Version of the CEF pmode uses one-way push
*
* @param sInitiatorID
* Initiator ID
* @param sResponderID
* Responder ID
* @param sResponderAddress
* Responder URL
* @param aPModeIDProvider
* PMode ID provider
* @param bPersist
* <code>true</code> to persist the PMode in the PModeManager,
* <code>false</code> to have it only in memory.
* @return New PMode
*/
@Nonnull
public static PMode createCEFPMode(@Nonnull @Nonempty final String sInitiatorID, @Nonnull @Nonempty final String sResponderID, @Nullable final String sResponderAddress, @Nonnull final IPModeIDProvider aPModeIDProvider, final boolean bPersist) {
final PModeParty aInitiator = PModeParty.createSimple(sInitiatorID, CAS4.DEFAULT_INITIATOR_URL);
final PModeParty aResponder = PModeParty.createSimple(sResponderID, CAS4.DEFAULT_RESPONDER_URL);
final PMode aPMode = new PMode(aPModeIDProvider.getPModeID(sInitiatorID, sResponderID), aInitiator, aResponder, DEFAULT_AGREEMENT_ID, EMEP.ONE_WAY, EMEPBinding.PUSH, generatePModeLeg(sResponderAddress), (PModeLeg) null, (PModePayloadService) null, generatePModeReceptionAwareness());
if (bPersist) {
// Ensure it is stored
MetaAS4Manager.getPModeMgr().createOrUpdatePMode(aPMode);
}
return aPMode;
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class AS4eSENSCEFOneWayFuncTest method testEsens_TA20.
/**
* Prerequisite:<br>
* SMSH and RMSH are configured to exchange AS4 messages according to the
* e-SENS profile: One-Way/Push MEP. SMSH sends an AS4 User Message including
* a TRACKINGIDENTIFIER property set by the producer.<br>
* <br>
* Predicate: <br>
* The RMSH returns a non-repudiation receipt within a HTTP response with
* status code 2XX and the received AS4 message contains the
* TRACKINGIDENTIFIER property.
*
* @throws Exception
* In case of error
*/
@Test
public void testEsens_TA20() throws Exception {
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(m_aPayload != null, null);
final Ebms3CollaborationInfo aEbms3CollaborationInfo;
final Ebms3PartyInfo aEbms3PartyInfo;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(m_aESENSOneWayPMode.getID(), DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, AS4TestConstants.CEF_INITIATOR_ID, CAS4.DEFAULT_RESPONDER_URL, AS4TestConstants.CEF_RESPONDER_ID);
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
final String sTrackerIdentifier = "trackingidentifier";
aEbms3MessageProperties.addProperty(MessageHelperMethods.createEbms3Property(sTrackerIdentifier, "tracker"));
final AS4UserMessage aDoc = AS4UserMessage.create(aEbms3MessageInfo, aEbms3PayloadInfo, aEbms3CollaborationInfo, aEbms3PartyInfo, aEbms3MessageProperties, m_eSoapVersion).setMustUnderstand(true);
final Document aSignedDoc = AS4Signer.createSignedMessage(m_aCryptoFactory, aDoc.getAsSoapDocument(m_aPayload), m_eSoapVersion, aDoc.getMessagingID(), null, s_aResMgr, false, AS4SigningParams.createDefault());
final NodeList aNL = aSignedDoc.getElementsByTagName("eb:MessageProperties");
assertEquals(aNL.item(0).getLastChild().getAttributes().getNamedItem("name").getTextContent(), sTrackerIdentifier);
final String sResponse = sendPlainMessage(new HttpXMLEntity(aSignedDoc, m_eSoapVersion.getMimeType()), true, null);
assertTrue(sResponse.contains(AS4TestConstants.NON_REPUDIATION_INFORMATION));
}
use of com.helger.phase4.CAS4 in project phase4 by phax.
the class AS4eSENSCEFOneWayFuncTest method testEsens_TA03.
/**
* Prerequisite:<br>
* SMSH and RMSH are configured to exchange AS4 messages according to the
* e-SENS profile: One-Way/Push MEP. SMSH and RMSH exchange several AS4 User
* Messages.<br>
* <br>
* Predicate: <br>
* Each exchanged AS4 message contains single ORIGIN and DESTINATION elements.
* <br>
* Goal: "Both UserMessage/PartyInfo/From and UserMessage/PartyInfo/To must
* not include more than one PartyId element"
*
* @throws Exception
* In case of error
*/
@Test
public void testEsens_TA03() throws Exception {
// Add properties
final ICommonsList<Ebms3Property> aEbms3Properties = AS4TestConstants.getEBMSProperties();
final Ebms3MessageInfo aEbms3MessageInfo = MessageHelperMethods.createEbms3MessageInfo();
final Ebms3PayloadInfo aEbms3PayloadInfo = MessageHelperMethods.createEbms3PayloadInfo(m_aPayload != null, null);
final Ebms3CollaborationInfo aEbms3CollaborationInfo;
final Ebms3PartyInfo aEbms3PartyInfo;
aEbms3CollaborationInfo = MessageHelperMethods.createEbms3CollaborationInfo(m_aESENSOneWayPMode.getID(), DEFAULT_AGREEMENT, AS4TestConstants.TEST_SERVICE_TYPE, MockPModeGenerator.SOAP11_SERVICE, AS4TestConstants.TEST_ACTION, AS4TestConstants.TEST_CONVERSATION_ID);
aEbms3PartyInfo = MessageHelperMethods.createEbms3PartyInfo(CAS4.DEFAULT_INITIATOR_URL, AS4TestConstants.CEF_INITIATOR_ID, CAS4.DEFAULT_RESPONDER_URL, AS4TestConstants.CEF_RESPONDER_ID);
aEbms3PartyInfo.getTo().addPartyId(MessageHelperMethods.createEbms3PartyId("Second ID"));
// Check if we added a second party id
assertTrue(aEbms3PartyInfo.getTo().getPartyId().size() == 2);
final Ebms3MessageProperties aEbms3MessageProperties = MessageHelperMethods.createEbms3MessageProperties(aEbms3Properties);
final Ebms3UserMessage aUserMessage = new Ebms3UserMessage();
aUserMessage.setPartyInfo(aEbms3PartyInfo);
aUserMessage.setCollaborationInfo(aEbms3CollaborationInfo);
aUserMessage.setMessageProperties(aEbms3MessageProperties);
aUserMessage.setPayloadInfo(aEbms3PayloadInfo);
aUserMessage.setMessageInfo(aEbms3MessageInfo);
final Document aDoc = new AS4UserMessage(ESoapVersion.AS4_DEFAULT, aUserMessage).getAsSoapDocument(m_aPayload);
sendPlainMessage(new HttpXMLEntity(aDoc, m_eSoapVersion.getMimeType()), false, EEbmsError.EBMS_VALUE_INCONSISTENT.getErrorCode());
}
Aggregations