Search in sources :

Example 1 with SBDMarshaller

use of com.helger.sbdh.SBDMarshaller 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 OpenAS2Exception {
    try {
        // 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 sMessageID = aDD.getInstanceIdentifier();
            // Get the endpoint information required from the recipient
            final EndpointType aReceiverEndpoint = _getReceiverEndpoint(aDD.getReceiverAsIdentifier(), aDD.getDocumentTypeAsIdentifier(), aDD.getProcessAsIdentifier(), sMessageID);
            if (aReceiverEndpoint == null) {
                throw new OpenAS2Exception(sMessageID + " Failed to resolve endpoint for provided receiver/documentType/process - not handling document");
            }
            // Check if the message is for us
            _checkIfReceiverEndpointURLMatches(aReceiverEndpoint, sMessageID);
            // Get the recipient certificate from the SMP
            _checkIfEndpointCertificateMatches(aReceiverEndpoint, sMessageID);
        } else {
            s_aLogger.info("Endpoint checks for the AS2 AP are disabled");
        }
        // Handle incoming document via SPI
        for (final IAS2IncomingSBDHandlerSPI aHandler : m_aHandlers) aHandler.handleIncomingSBD(aSBD);
    } catch (final Exception ex) {
        // Something went wrong
        throw WrappedOpenAS2Exception.wrap(ex);
    }
}
Also used : SBDMarshaller(com.helger.sbdh.SBDMarshaller) PeppolSBDHDocument(com.helger.peppol.sbdh.PeppolSBDHDocument) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception) StandardBusinessDocument(org.unece.cefact.namespaces.sbdh.StandardBusinessDocument) EndpointType(com.helger.peppol.smp.EndpointType) PeppolSBDHDocumentReader(com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader) WrappedOpenAS2Exception(com.helger.as2lib.exception.WrappedOpenAS2Exception) CertificateException(java.security.cert.CertificateException) OpenAS2Exception(com.helger.as2lib.exception.OpenAS2Exception)

Aggregations

OpenAS2Exception (com.helger.as2lib.exception.OpenAS2Exception)1 WrappedOpenAS2Exception (com.helger.as2lib.exception.WrappedOpenAS2Exception)1 PeppolSBDHDocument (com.helger.peppol.sbdh.PeppolSBDHDocument)1 PeppolSBDHDocumentReader (com.helger.peppol.sbdh.read.PeppolSBDHDocumentReader)1 EndpointType (com.helger.peppol.smp.EndpointType)1 SBDMarshaller (com.helger.sbdh.SBDMarshaller)1 CertificateException (java.security.cert.CertificateException)1 StandardBusinessDocument (org.unece.cefact.namespaces.sbdh.StandardBusinessDocument)1