use of com.helger.smpclient.peppol.SMPClientReadOnly in project phoss-directory by phax.
the class SMPBusinessCardProvider method getBusinessCard.
@Nullable
public PDExtendedBusinessCard getBusinessCard(@Nonnull final IParticipantIdentifier aParticipantID) {
final HttpClientSettings aHCS = new HttpClientSettings().setProxyHost(_getHttpProxy()).setProxyCredentials(_getHttpProxyCredentials());
PDExtendedBusinessCard aBC;
if (m_aSMPURI != null) {
// Use a preselected SMP URI
switch(m_eSMPMode) {
case PEPPOL:
{
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aSMPURI);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
break;
}
case OASIS_BDXR_V1:
{
final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aSMPURI);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
break;
}
case OASIS_BDXR_V2:
{
final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aSMPURI);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
break;
}
default:
throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
}
} else {
// SML auto detect
aBC = null;
for (final ISMLInfo aSML : m_aSMLInfoProvider.get()) {
// Create SMP client and query SMP
switch(m_eSMPMode) {
case PEPPOL:
{
try {
final SMPClientReadOnly aSMPClient = new SMPClientReadOnly(m_aURLProvider, aParticipantID, aSML);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardPeppolSMP(aParticipantID, aSMPClient, aHCS);
} catch (final SMPDNSResolutionException ex) {
// Happens if a non-existing URL is queried
}
break;
}
case OASIS_BDXR_V1:
{
try {
final BDXRClientReadOnly aSMPClient = new BDXRClientReadOnly(m_aURLProvider, aParticipantID, aSML);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardBDXR1(aParticipantID, aSMPClient, aHCS);
} catch (final SMPDNSResolutionException ex) {
// Happens if a non-existing URL is queried
}
break;
}
case OASIS_BDXR_V2:
{
try {
final BDXR2ClientReadOnly aSMPClient = new BDXR2ClientReadOnly(m_aURLProvider, aParticipantID, aSML);
_configureSMPClient(aSMPClient);
aBC = getBusinessCardBDXR2(aParticipantID, aSMPClient, aHCS);
} catch (final SMPDNSResolutionException ex) {
// Happens if a non-existing URL is queried
}
break;
}
default:
throw new IllegalStateException("Unsupported SMP mode " + m_eSMPMode);
}
// Found one?
if (aBC != null)
break;
}
}
if (aBC != null)
LOGGER.info("Found BusinessCard for '" + aParticipantID.getURIEncoded() + "' with " + aBC.getBusinessCard().businessEntities().size() + " entities and " + aBC.getDocumentTypeCount() + " document types");
return aBC;
}
use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.
the class Phase4PeppolWebAppListener method _initPeppolAS4.
private static void _initPeppolAS4() {
// Check if crypto properties are okay
final KeyStore aKS = AS4CryptoFactoryProperties.getDefaultInstance().getKeyStore();
if (aKS == null)
throw new InitializationException("Failed to load configured Keystore");
LOGGER.info("Successfully loaded configured key store from the crypto factory");
final PrivateKeyEntry aPKE = AS4CryptoFactoryProperties.getDefaultInstance().getPrivateKeyEntry();
if (aPKE == null)
throw new InitializationException("Failed to load configured private key");
LOGGER.info("Successfully loaded configured private key from the crypto factory");
// No OCSP check for performance
final X509Certificate aAPCert = (X509Certificate) aPKE.getCertificate();
final EPeppolCertificateCheckResult eCheckResult = PeppolCertificateChecker.checkPeppolAPCertificate(aAPCert, MetaAS4Manager.getTimestampMgr().getCurrentDateTime(), ETriState.FALSE, null);
if (eCheckResult.isInvalid())
throw new InitializationException("The provided certificate is not a valid Peppol certificate. Check result: " + eCheckResult);
LOGGER.info("Successfully checked that the provided Peppol AP certificate is valid.");
final String sSMPURL = AS4Configuration.getConfig().getAsString("smp.url");
final String sAPURL = AS4Configuration.getThisEndpointAddress();
if (StringHelper.hasText(sSMPURL) && StringHelper.hasText(sAPURL)) {
Phase4PeppolServletConfiguration.setReceiverCheckEnabled(true);
Phase4PeppolServletConfiguration.setSMPClient(new SMPClientReadOnly(URLHelper.getAsURI(sSMPURL)));
Phase4PeppolServletConfiguration.setAS4EndpointURL(sAPURL);
Phase4PeppolServletConfiguration.setAPCertificate(aAPCert);
LOGGER.info(CAS4.LIB_NAME + " Peppol receiver checks are enabled");
} else {
Phase4PeppolServletConfiguration.setReceiverCheckEnabled(false);
LOGGER.warn(CAS4.LIB_NAME + " Peppol receiver checks are disabled");
}
}
use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.
the class MainPhase4PeppolSenderQvaliaLargeFile 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 Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/large-files/base-example-large-16m.xml")).getDocumentElement();
if (aPayloadElement == null)
throw new IllegalStateException("Failed to read XML file to be send");
// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0007:5567321707");
final IAS4ClientBuildMessageCallback aBuildMessageCallback = 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() + "'");
}
};
// Invalid certificate is valid until 2029
final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
final ESimpleUserMessageSendResult eResult;
eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_INVOICE_V3, new Phase4PeppolValidatonResultHandler()).compressPayload(false).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.
the class MainPhase4PeppolSenderQvaliaOrder 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 Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/test-order.xml")).getDocumentElement();
if (aPayloadElement == null)
throw new IllegalStateException("Failed to read XML file to be send");
// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0007:5567321707");
final ESimpleUserMessageSendResult eResult;
eResult = Phase4PeppolSender.builder().documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Order-2::Order##urn:fdc:peppol.eu:poacc:trns:order:3::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:poacc:bis:ordering:3")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationConfiguration(PeppolValidation3_13_0.VID_OPENPEPPOL_ORDER_V3, new Phase4PeppolValidatonResultHandler()).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
use of com.helger.smpclient.peppol.SMPClientReadOnly in project phase4 by phax.
the class MainPhase4PeppolSenderQvaliaUBL 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 Element aPayloadElement = DOMReader.readXMLDOM(new File("src/test/resources/examples/example-ubl-en-qvalia.xml")).getDocumentElement();
if (aPayloadElement == null)
throw new IllegalStateException("Failed to read XML file to be send");
// Start configuring here
final IParticipantIdentifier aReceiverID = Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("0007:5567321707");
final IAS4ClientBuildMessageCallback aBuildMessageCallback = 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() + "'");
}
};
// Add EN16931 rulesets
final IValidationExecutorSetRegistry<IValidationSourceXML> aVESRegistry = Phase4PeppolValidation.createDefaultRegistry();
EN16931Validation.initEN16931(aVESRegistry);
// Invalid certificate is valid until 2029
final IAS4CryptoFactory cf = AS4CryptoFactoryProperties.getDefaultInstance();
final ESimpleUserMessageSendResult eResult;
eResult = Phase4PeppolSender.builder().httpRetrySettings(new HttpRetrySettings().setMaxRetries(0)).cryptoFactory(cf).documentTypeID(Phase4PeppolSender.IF.createDocumentTypeIdentifierWithDefaultScheme("urn:oasis:names:specification:ubl:schema:xsd:Invoice-2::Invoice##urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0::2.1")).processID(Phase4PeppolSender.IF.createProcessIdentifierWithDefaultScheme("urn:fdc:peppol.eu:2017:poacc:billing:01:1.0")).senderParticipantID(Phase4PeppolSender.IF.createParticipantIdentifierWithDefaultScheme("9915:phase4-test-sender")).receiverParticipantID(aReceiverID).senderPartyID("POP000306").payload(aPayloadElement).smpClient(new SMPClientReadOnly(Phase4PeppolSender.URL_PROVIDER, aReceiverID, ESML.DIGIT_TEST)).rawResponseConsumer(new AS4RawResponseConsumerWriteToFile()).validationRegistry(aVESRegistry).validationConfiguration(EN16931Validation.VID_UBL_INVOICE_137, new Phase4PeppolValidatonResultHandler()).buildMessageCallback(aBuildMessageCallback).sendMessageAndCheckForReceipt();
LOGGER.info("Peppol send result: " + eResult);
} catch (final Exception ex) {
LOGGER.error("Error sending Peppol message via AS4", ex);
} finally {
WebScopeManager.onGlobalEnd();
}
}
Aggregations