use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class AS2XMLHelper method mapAttributeNodes.
/**
* @param aNode
* Start node. May not be <code>null</code>.
* @param sNodeName
* The element name to be queried relative to the start node.
* @param sNodeKeyName
* The attribute name of the key.
* @param sNodeValueName
* The attribute name of the value.
* @return The non-<code>null</code> {@link Map}.
* @throws AS2Exception
* In case a node is missing a key or value attribute.
*/
@Nonnull
@ReturnsMutableCopy
public static ICommonsOrderedMap<String, String> mapAttributeNodes(@Nonnull final IMicroElement aNode, @Nonnull final String sNodeName, @Nonnull final String sNodeKeyName, @Nonnull final String sNodeValueName) throws AS2Exception {
ValueEnforcer.notNull(aNode, "Node");
ValueEnforcer.notNull(sNodeName, "NodeName");
ValueEnforcer.notNull(sNodeKeyName, "NodeKeyName");
ValueEnforcer.notNull(sNodeValueName, "NodeValueName");
final ICommonsOrderedMap<String, String> ret = new CommonsLinkedHashMap<>();
int nIndex = 0;
for (final IMicroElement eChild : aNode.getAllChildElements(sNodeName)) {
final String sName = eChild.getAttributeValue(sNodeKeyName);
if (sName == null)
throw new AS2Exception(sNodeName + "[" + nIndex + "] does not have key attribute '" + sNodeKeyName + "'");
final String sValue = eChild.getAttributeValue(sNodeValueName);
if (sValue == null)
throw new AS2Exception(sNodeName + "[" + nIndex + "] does not have value attribute '" + sNodeValueName + "'");
ret.put(sName, sValue);
++nIndex;
}
return ret;
}
use of com.helger.as2lib.exception.AS2Exception 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);
}
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class AbstractAS2MDNReceiveXServletHandler method onServletInit.
@Override
public void onServletInit(@Nonnull final ICommonsMap<String, String> aInitParams) throws ServletException {
super.onServletInit(aInitParams);
try {
m_aReceiver = getSession().getMessageProcessor().getModuleOfClass(AS2ServletMDNReceiverModule.class);
if (m_aReceiver == null)
throw new ServletException("Failed to retrieve 'AS2ServletMDNReceiverModule' which is a mandatory module! Please ensure your configuration file contains at least the module '" + AS2ServletMDNReceiverModule.class.getName() + "'");
} catch (final AS2Exception ex) {
throw new ServletException("Failed to init AS2 configuration", ex);
}
LOGGER.info("Successfully initialized AS2 configuration");
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class AS2ServletXMLSession method _load.
private void _load(@Nullable final InputStream aIS) throws AS2Exception {
if (aIS != null) {
final IMicroDocument aDoc = MicroReader.readMicroXML(aIS);
final IMicroElement eRoot = aDoc.getDocumentElement();
for (final IMicroElement eRootChild : eRoot.getAllChildElements()) {
final String sNodeName = eRootChild.getTagName();
if (sNodeName.equals(EL_CERTIFICATES))
_loadCertificateFactory(eRootChild);
else if (sNodeName.equals(EL_PROCESSOR))
_loadMessageProcessor(eRootChild);
else if (sNodeName.equals(EL_PARTNERSHIPS))
_loadPartnershipFactory(eRootChild);
else
throw new AS2Exception("Undefined tag: " + sNodeName);
}
}
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class AS2ServerXMLSession method load.
protected void load(@Nonnull @WillClose final InputStream aIS) throws AS2Exception {
final IMicroDocument aDoc = MicroReader.readMicroXML(aIS);
final IMicroElement eRoot = aDoc.getDocumentElement();
// Special global attributes
final String sCryptoVerifyUseCertificateInBodyPart = eRoot.getAttributeValue(ATTR_CRYPTO_VERIFY_USE_CERTIFICATE_IN_BODY_PART);
if (sCryptoVerifyUseCertificateInBodyPart != null)
setCryptoVerifyUseCertificateInBodyPart(StringParser.parseBool(sCryptoVerifyUseCertificateInBodyPart, DEFAULT_CRYPTO_VERIFY_USE_CERTIFICATE_IN_BODY_PART));
final String sCryptoSignIncludeCertificateInBodyPart = eRoot.getAttributeValue(ATTR_CRYPTO_SIGN_INCLUDE_CERTIFICATE_IN_BODY_PART);
if (sCryptoSignIncludeCertificateInBodyPart != null)
setCryptoSignIncludeCertificateInBodyPart(StringParser.parseBool(sCryptoSignIncludeCertificateInBodyPart, DEFAULT_CRYPTO_SIGN_INCLUDE_CERTIFICATE_IN_BODY_PART));
for (final IMicroElement eRootChild : eRoot.getAllChildElements()) {
final String sNodeName = eRootChild.getTagName();
if (sNodeName.equals(EL_CERTIFICATES))
loadCertificates(eRootChild);
else if (sNodeName.equals(EL_PROCESSOR))
loadMessageProcessor(eRootChild);
else if (sNodeName.equals(EL_CMDPROCESSOR))
loadCommandProcessors(eRootChild);
else if (sNodeName.equals(EL_PARTNERSHIPS))
loadPartnerships(eRootChild);
else if (sNodeName.equals(EL_COMMANDS))
loadCommands(eRootChild);
else
throw new AS2Exception("Undefined tag: " + sNodeName);
}
}
Aggregations