Search in sources :

Example 6 with OpenAS2Exception

use of com.helger.as2lib.exception.OpenAS2Exception in project as2-server by phax.

the class XMLCommandRegistry method loadMultiCommand.

protected void loadMultiCommand(@Nonnull final IMicroElement aCommand, @Nullable final MultiCommand parent) throws OpenAS2Exception {
    final MultiCommand cmd = new MultiCommand();
    cmd.initDynamicComponent(getSession(), AS2XMLHelper.getAllAttrsWithLowercaseName(aCommand));
    if (parent != null)
        parent.getCommands().add(cmd);
    else
        addCommand(cmd);
    for (final IMicroElement aChildElement : aCommand.getAllChildElements()) {
        final String sChildName = aChildElement.getNodeName();
        if (sChildName.equals("command"))
            loadCommand(aChildElement, cmd);
        else if (sChildName.equals("multicommand"))
            loadMultiCommand(aChildElement, cmd);
        else
            throw new OpenAS2Exception("Undefined child tag: " + sChildName);
    }
}
Also used : OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) IMicroElement(com.helger.xml.microdom.IMicroElement)

Example 7 with OpenAS2Exception

use of com.helger.as2lib.exception.OpenAS2Exception in project as2-server by phax.

the class XMLCommandRegistry method load.

public void load(@Nonnull final InputStream in) throws OpenAS2Exception {
    final IMicroDocument aDoc = MicroReader.readMicroXML(in);
    final IMicroElement eRoot = aDoc.getDocumentElement();
    clearCommands();
    for (final IMicroElement eElement : eRoot.getAllChildElements()) {
        final String sNodeName = eElement.getTagName();
        if (sNodeName.equals("command"))
            loadCommand(eElement, null);
        else if (sNodeName.equals("multicommand"))
            loadMultiCommand(eElement, null);
        else
            throw new OpenAS2Exception("Undefined tag: " + sNodeName);
    }
}
Also used : OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) IMicroElement(com.helger.xml.microdom.IMicroElement) IMicroDocument(com.helger.xml.microdom.IMicroDocument)

Example 8 with OpenAS2Exception

use of com.helger.as2lib.exception.OpenAS2Exception in project as2-peppol-servlet by phax.

the class AS2ServletSBDModule method _checkIfEndpointCertificateMatches.

private static void _checkIfEndpointCertificateMatches(@Nonnull final EndpointType aRecipientEndpoint, @Nonnull final String sMessageID) throws OpenAS2Exception {
    final X509Certificate aOurCert = AS2PeppolServletConfiguration.getAPCertificate();
    if (aOurCert == null)
        throw new OpenAS2Exception("The certificate of this AP is not configured!");
    final String sRecipientCertString = aRecipientEndpoint.getCertificate();
    X509Certificate aRecipientCert = null;
    try {
        aRecipientCert = CertificateHelper.convertStringToCertficate(sRecipientCertString);
    } catch (final CertificateException t) {
        throw new OpenAS2Exception(sMessageID + " Internal error: Failed to convert looked up endpoint certificate string '" + sRecipientCertString + "' to an X.509 certificate!", t);
    }
    if (aRecipientCert == null) {
        // No certificate found - most likely because of invalid SMP entry
        throw new OpenAS2Exception(sMessageID + " No certificate found in looked up endpoint! Is this AP maybe NOT contained in an SMP?");
    }
    // Certificate found
    if (s_aLogger.isDebugEnabled())
        s_aLogger.debug(sMessageID + " Conformant recipient certificate present: " + aRecipientCert.toString());
    // Compare serial numbers
    if (!aOurCert.getSerialNumber().equals(aRecipientCert.getSerialNumber())) {
        final String sErrorMsg = sMessageID + " Certificate retrieved from SMP lookup (" + aRecipientCert + ") does not match this APs configured Certificate (" + aOurCert + ") - different serial numbers - ignoring document";
        s_aLogger.error(sErrorMsg);
        throw new OpenAS2Exception(sErrorMsg);
    }
    if (s_aLogger.isDebugEnabled())
        s_aLogger.debug(sMessageID + " The certificate of the SMP lookup matches our certificate");
}
Also used : WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) CertificateException(java.security.cert.CertificateException) X509Certificate(java.security.cert.X509Certificate)

Example 9 with OpenAS2Exception

use of com.helger.as2lib.exception.OpenAS2Exception in project as2-peppol-servlet by phax.

the class AS2ServletSBDModule method _checkIfReceiverEndpointURLMatches.

private static void _checkIfReceiverEndpointURLMatches(@Nonnull final EndpointType aRecipientEndpoint, @Nonnull final String sMessageID) throws OpenAS2Exception {
    // Get our public endpoint address from the configuration
    final String sOwnAPUrl = AS2PeppolServletConfiguration.getAS2EndpointURL();
    if (StringHelper.hasNoText(sOwnAPUrl))
        throw new OpenAS2Exception("The endpoint URL of this AP is not configured!");
    if (s_aLogger.isDebugEnabled())
        s_aLogger.debug(sMessageID + " Our AP URL is " + sOwnAPUrl);
    final String sRecipientAPUrl = SMPClientReadOnly.getEndpointAddress(aRecipientEndpoint);
    if (s_aLogger.isDebugEnabled())
        s_aLogger.debug(sMessageID + " Recipient AP URL is " + sRecipientAPUrl);
    // Is it for us?
    if (sRecipientAPUrl == null || !sRecipientAPUrl.contains(sOwnAPUrl)) {
        final String sErrorMsg = sMessageID + " Internal error: The request is targeted for '" + sRecipientAPUrl + "' and is not for us (" + sOwnAPUrl + ")";
        s_aLogger.error(sErrorMsg);
        throw new OpenAS2Exception(sErrorMsg);
    }
}
Also used : WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception)

Aggregations

OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)9 WrappedOpenAS2Exception (com.helger.as2lib.exception.WrappedOpenAS2Exception)5 IMicroElement (com.helger.xml.microdom.IMicroElement)3 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IOException (java.io.IOException)2 CertificateException (java.security.cert.CertificateException)2 AS2ServerXMLSession (com.helger.as2.app.session.AS2ServerXMLSession)1 CommandManager (com.helger.as2.cmd.CommandManager)1 CommandResult (com.helger.as2.cmd.CommandResult)1 ICommand (com.helger.as2.cmd.ICommand)1 ICommandRegistry (com.helger.as2.cmd.ICommandRegistry)1 AbstractCommandProcessor (com.helger.as2.cmdprocessor.AbstractCommandProcessor)1 CommandTokenizer (com.helger.as2.util.CommandTokenizer)1 IStringMap (com.helger.commons.collection.attr.IStringMap)1 StringMap (com.helger.commons.collection.attr.StringMap)1 CommonsArrayList (com.helger.commons.collection.impl.CommonsArrayList)1 NonBlockingBufferedReader (com.helger.commons.io.stream.NonBlockingBufferedReader)1 NonBlockingBufferedWriter (com.helger.commons.io.stream.NonBlockingBufferedWriter)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 PeppolSBDHDocumentReader (com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader)1