use of com.helger.smpclient.peppol.ISMPServiceMetadataProvider in project phase4 by phax.
the class Phase4PeppolServletConfiguration method getAsReceiverCheckData.
/**
* Get the statically configured data as a
* {@link Phase4PeppolReceiverCheckData} instance. Returns <code>null</code>
* if the checks are disabled, or if at least one mandatory field is not set.
*
* @return The instance data or <code>null</code>.
* @since 0.9.13
*/
@Nullable
public static Phase4PeppolReceiverCheckData getAsReceiverCheckData() {
if (!isReceiverCheckEnabled())
return null;
final ISMPServiceMetadataProvider aSMPClient = getSMPClient();
final String sAS4EndpointURL = getAS4EndpointURL();
final X509Certificate aAPCertificate = getAPCertificate();
if (aSMPClient == null || StringHelper.hasNoText(sAS4EndpointURL) || aAPCertificate == null)
return null;
return new Phase4PeppolReceiverCheckData(aSMPClient, sAS4EndpointURL, aAPCertificate);
}
use of com.helger.smpclient.peppol.ISMPServiceMetadataProvider 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);
}
}
}
Aggregations