/** * Verify the content of all contained fields so that all know issues are captured before sending. * This method is automatically called before the message is send (see {@link * #sendSynchronous()}). All verification warnings and errors are handled via the message handler. * * @throws AS2ClientBuilderException In case the message handler throws an exception in case of an * error. * @see #setMessageHandler(IAS2ClientBuilderMessageHandler) */ public void verifyContent() throws AS2ClientBuilderException { if (m_aKeyStoreFile == null) m_aMessageHandler.error("No AS2 key store is defined"); else { if (!m_aKeyStoreFile.exists()) m_aMessageHandler.error( "The provided AS2 key store '" + m_aKeyStoreFile.getAbsolutePath() + "' does not exist."); else if (!m_aKeyStoreFile.isFile()) m_aMessageHandler.error( "The provided AS2 key store '" + m_aKeyStoreFile.getAbsolutePath() + "' is not a file but potentially a directory."); else if (!m_aKeyStoreFile.canWrite()) m_aMessageHandler.error( "The provided AS2 key store '" + m_aKeyStoreFile.getAbsolutePath() + "' is not writable. As it is dynamically modified, it must be writable."); } if (m_sKeyStorePassword == null) m_aMessageHandler.error( "No key store password provided. If you need an empty password, please provide an empty String!"); if (StringHelper.hasNoText(m_sAS2Subject)) m_aMessageHandler.error("The AS2 message subject is missing"); if (StringHelper.hasNoText(m_sSenderAS2ID)) m_aMessageHandler.error("The AS2 sender ID is missing"); else if (!m_sSenderAS2ID.startsWith(APP_PREFIX)) m_aMessageHandler.warn( "The AS2 sender ID '" + m_sSenderAS2ID + "' should start with '" + APP_PREFIX + "' as required by the PEPPOL specification"); if (StringHelper.hasNoText(m_sSenderAS2Email)) m_aMessageHandler.error("The AS2 sender email address is missing"); else if (!EmailAddressHelper.isValid(m_sSenderAS2Email)) m_aMessageHandler.warn( "The AS2 sender email address '" + m_sSenderAS2Email + "' seems to be an invalid email address."); if (StringHelper.hasNoText(m_sSenderAS2KeyAlias)) m_aMessageHandler.error("The AS2 sender key alias is missing"); else if (!m_sSenderAS2KeyAlias.startsWith(APP_PREFIX)) m_aMessageHandler.warn( "The AS2 sender key alias '" + m_sSenderAS2KeyAlias + "' should start with '" + APP_PREFIX + "' for the use with the dynamic AS2 partnerships"); else if (m_sSenderAS2ID != null && !m_sSenderAS2ID.equals(m_sSenderAS2KeyAlias)) m_aMessageHandler.warn( "The AS2 sender key alias ('" + m_sSenderAS2KeyAlias + "') should match the AS2 sender ID ('" + m_sSenderAS2ID + "')"); if (StringHelper.hasNoText(m_sReceiverAS2ID)) m_aMessageHandler.error("The AS2 receiver ID is missing"); else if (!m_sReceiverAS2ID.startsWith(APP_PREFIX)) m_aMessageHandler.warn( "The AS2 receiver ID '" + m_sReceiverAS2ID + "' should start with '" + APP_PREFIX + "' as required by the PEPPOL specification"); if (StringHelper.hasNoText(m_sReceiverAS2KeyAlias)) m_aMessageHandler.error("The AS2 receiver key alias is missing"); else if (!m_sReceiverAS2KeyAlias.startsWith(APP_PREFIX)) m_aMessageHandler.warn( "The AS2 receiver key alias '" + m_sReceiverAS2KeyAlias + "' should start with '" + APP_PREFIX + "' for the use with the dynamic AS2 partnerships"); else if (m_sReceiverAS2ID != null && !m_sReceiverAS2ID.equals(m_sReceiverAS2KeyAlias)) m_aMessageHandler.warn( "The AS2 receiver key alias ('" + m_sReceiverAS2KeyAlias + "') should match the AS2 receiver ID ('" + m_sReceiverAS2ID + "')"); if (StringHelper.hasNoText(m_sReceiverAS2Url)) m_aMessageHandler.error("The AS2 receiver URL (AS2 endpoint URL) is missing"); else if (URLHelper.getAsURL(m_sReceiverAS2Url) == null) m_aMessageHandler.warn( "The provided AS2 receiver URL '" + m_sReceiverAS2Url + "' seems to be an invalid URL"); if (m_aReceiverCert == null) m_aMessageHandler.error( "The receiver X.509 certificate is missing. Usually this is extracted from the SMP response"); if (m_eSigningAlgo == null) m_aMessageHandler.error("The signing algorithm for the AS2 message is missing"); if (StringHelper.hasNoText(m_sMessageIDFormat)) m_aMessageHandler.error("The AS2 message ID format is missing."); if (m_aBusinessDocumentRes == null && m_aBusinessDocumentElement == null) m_aMessageHandler.error("The XML business document to be send is missing."); else if (m_aBusinessDocumentRes != null && !m_aBusinessDocumentRes.exists()) m_aMessageHandler.error( "The XML business document to be send '" + m_aBusinessDocumentRes.getPath() + "' does not exist."); if (m_aPeppolSenderID == null) m_aMessageHandler.error("The PEPPOL sender participant ID is missing"); else if (!IdentifierHelper.hasDefaultParticipantIdentifierScheme(m_aPeppolSenderID)) m_aMessageHandler.warn( "The PEPPOL sender participant ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolSenderID) + "' is using a non-standard scheme!"); if (m_aPeppolReceiverID == null) m_aMessageHandler.error("The PEPPOL receiver participant ID is missing"); else if (!IdentifierHelper.hasDefaultParticipantIdentifierScheme(m_aPeppolReceiverID)) m_aMessageHandler.warn( "The PEPPOL receiver participant ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolReceiverID) + "' is using a non-standard scheme!"); if (m_aPeppolDocumentTypeID == null) m_aMessageHandler.error("The PEPPOL document type ID is missing"); else if (!IdentifierHelper.hasDefaultDocumentTypeIdentifierScheme(m_aPeppolDocumentTypeID)) m_aMessageHandler.warn( "The PEPPOL document type ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolDocumentTypeID) + "' is using a non-standard scheme!"); if (m_aPeppolProcessID == null) m_aMessageHandler.error("The PEPPOL process ID is missing"); else if (!IdentifierHelper.hasDefaultProcessIdentifierScheme(m_aPeppolProcessID)) m_aMessageHandler.warn( "The PEPPOL process ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolProcessID) + "' is using a non-standard scheme!"); if (m_aValidationKey == null) m_aMessageHandler.warn( "The validation key determining the business document validation is missing. Therefore the outgoing business document is NOT validated!"); // Ensure that if a non-throwing message handler is installed, that the // sending is not performed! if (m_aMessageHandler.getErrorCount() > 0) throw new AS2ClientBuilderException( "Not all required fields are present so the PEPPOL AS2 client call can NOT be performed. See the message handler for details!"); }
/** * This method is responsible for performing the SMP client lookup if an SMP client was specified * via {@link #setSMPClient(SMPClientReadOnly)}. If any of the prerequisites mentioned there is * not fulfilled a warning is emitted via the {@link #getMessageHandler()} and nothing happens. If * all fields to be determined by the SMP are already no SMP lookup is performed either. If the * SMP lookup fails, a warning is emitted and nothing happens. * * @throws AS2ClientBuilderException In case SMP client lookup triggers an unrecoverable error via * the message handler */ protected void performSMPClientLookup() throws AS2ClientBuilderException { if (m_aSMPClient != null) { // Check pre-requisites if (m_aPeppolReceiverID == null) getMessageHandler() .warn("Cannot perform SMP lookup because the PEPPOL receiver ID is missing"); else if (m_aPeppolDocumentTypeID == null) getMessageHandler() .warn("Cannot perform SMP lookup because the PEPPOL document type ID is missing"); else if (m_aPeppolProcessID == null) getMessageHandler() .warn("Cannot perform SMP lookup because the PEPPOL process ID is missing"); else { // All prerequisites are matched // Check if all fields to be determined are present, to avoid // unnecessary lookup calls. if (m_sReceiverAS2Url == null || m_aReceiverCert == null || m_sReceiverAS2ID == null) { // Perform the lookup. SignedServiceMetadataType aServiceMetadata = null; try { if (s_aLogger.isDebugEnabled()) s_aLogger.debug( "Performing SMP lookup for receiver '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolReceiverID) + "' on document type '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolDocumentTypeID) + "' and process ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolProcessID) + "' using transport profile for AS2"); aServiceMetadata = m_aSMPClient.getServiceRegistration(m_aPeppolReceiverID, m_aPeppolDocumentTypeID); } catch (final SMPClientNotFoundException ex) { if (s_aLogger.isDebugEnabled()) s_aLogger.debug("No such SMP service registration", ex); else s_aLogger.warn("No such SMP service registration: " + ex.getMessage()); // Fall through } catch (final SMPClientException ex) { if (s_aLogger.isDebugEnabled()) s_aLogger.debug("Error querying the SMP", ex); else s_aLogger.warn("Error querying the SMP: " + ex.getMessage()); // Fall through } EndpointType aEndpoint = null; if (aServiceMetadata != null) { // Try to extract the endpoint from the service metadata aEndpoint = SMPClientReadOnly.getEndpoint( aServiceMetadata, m_aPeppolProcessID, ESMPTransportProfile.TRANSPORT_PROFILE_AS2); } // Interpret the result if (aEndpoint == null) { // No such SMP entry getMessageHandler() .warn( "Failed to perform SMP lookup for receiver '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolReceiverID) + "' on document type '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolDocumentTypeID) + "' and process ID '" + IdentifierHelper.getIdentifierURIEncoded(m_aPeppolProcessID) + "' using transport profile for AS2. " + (aServiceMetadata != null ? "The service metadata was gathered successfully." : "Failed to get the service metadata.")); } else { // Extract from SMP response if (m_sReceiverAS2Url == null) m_sReceiverAS2Url = SMPClientReadOnly.getEndpointAddress(aEndpoint); if (m_aReceiverCert == null) try { m_aReceiverCert = SMPClientReadOnly.getEndpointCertificate(aEndpoint); } catch (final CertificateException ex) { getMessageHandler() .error("Failed to build X.509 certificate from SMP client response", ex); } if (m_sReceiverAS2ID == null) try { m_sReceiverAS2ID = AS2ClientHelper.getSubjectCommonName(m_aReceiverCert); } catch (final CertificateException ex) { getMessageHandler() .error("Failed to get the Receiver AS ID from the provided certificate", ex); } } } else { if (s_aLogger.isDebugEnabled()) s_aLogger.debug("Not performing SMP lookup because all target fields are already set!"); } } } }