Search in sources :

Example 1 with EndpointType

use of com.helger.smpclient.peppol.jaxb.EndpointType in project as2-peppol-servlet by phax.

the class AS2ServletSBDModule method handle.

public void handle(@Nonnull final String sAction, @Nonnull final IMessage aMsg, @Nullable final Map<String, Object> aOptions) throws AS2Exception {
    try {
        // Set the signing algorithm, so that the MIC calculation is done
        // correctly
        aMsg.partnership().setSigningAlgorithm(m_eAS2Version.getCryptoAlgorithmSign());
        aMsg.partnership().setVerifyUseCertificateInBodyPart(ETriState.TRUE);
        // Interpret content as SBD
        final StandardBusinessDocument aSBD = new SBDMarshaller().read(aMsg.getData().getInputStream());
        if (aSBD == null)
            throw new IllegalArgumentException("Failed to interpret the passed document as a Standard Business Document!");
        if (AS2PeppolServletConfiguration.isReceiverCheckEnabled()) {
            final PeppolSBDHDocument aDD = new PeppolSBDHDocumentReader().extractData(aSBD);
            final String sLogPrefix = "[" + aDD.getInstanceIdentifier() + "] ";
            // Get the endpoint information required from the recipient
            final EndpointType aReceiverEndpoint = _getReceiverEndpoint(sLogPrefix, aDD.getReceiverAsIdentifier(), aDD.getDocumentTypeAsIdentifier(), aDD.getProcessAsIdentifier());
            if (aReceiverEndpoint == null) {
                throw new AS2Exception(sLogPrefix + "Failed to resolve endpoint for provided receiver/documentType/process - not handling document");
            }
            // Check if the message is for us
            _checkIfReceiverEndpointURLMatches(sLogPrefix, aReceiverEndpoint);
            // Get the recipient certificate from the SMP
            _checkIfEndpointCertificateMatches(sLogPrefix, aReceiverEndpoint);
        } else {
            LOGGER.info("Endpoint checks for the AS2 AP are disabled");
        }
        // Handle incoming document via SPI
        final HttpHeaderMap aHeaders = aMsg.headers().getClone();
        for (final IAS2IncomingSBDHandlerSPI aHandler : m_aHandlers) aHandler.handleIncomingSBD(aHeaders, aSBD);
    } catch (final Exception ex) {
        // Something went wrong
        throw WrappedAS2Exception.wrap(ex);
    }
}
Also used : SBDMarshaller(com.helger.sbdh.SBDMarshaller) HttpHeaderMap(com.helger.commons.http.HttpHeaderMap) PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) StandardBusinessDocument(org.unece.cefact.namespaces.sbdh.StandardBusinessDocument) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) EndpointType(com.helger.smpclient.peppol.jaxb.EndpointType) PeppolSBDHDocumentReader(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader) AS2Exception(com.helger.as2lib.exception.AS2Exception) WrappedAS2Exception(com.helger.as2lib.exception.WrappedAS2Exception) CertificateException(java.security.cert.CertificateException)

Aggregations

AS2Exception (com.helger.as2lib.exception.AS2Exception)1 WrappedAS2Exception (com.helger.as2lib.exception.WrappedAS2Exception)1 HttpHeaderMap (com.helger.commons.http.HttpHeaderMap)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 PeppolSBDHDocumentReader (com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader)1 SBDMarshaller (com.helger.sbdh.SBDMarshaller)1 EndpointType (com.helger.smpclient.peppol.jaxb.EndpointType)1 CertificateException (java.security.cert.CertificateException)1 StandardBusinessDocument (org.unece.cefact.namespaces.sbdh.StandardBusinessDocument)1