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 PartnerMap method addPartner.
public void addPartner(@Nonnull final Partner aNewPartner) throws AS2Exception {
ValueEnforcer.notNull(aNewPartner, "NewPartner");
final String sName = aNewPartner.getName();
if (m_aMap.containsKey(sName))
throw new AS2Exception("Partner is defined more than once: '" + sName + "'");
m_aMap.put(sName, aNewPartner);
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class XMLPartnershipFactory method load.
protected void load(@Nullable @WillClose final InputStream aIS) throws AS2Exception {
final PartnerMap aNewPartners = new PartnerMap();
final PartnershipMap aNewPartnerships = new PartnershipMap();
if (aIS != null) {
final IMicroDocument aDocument = MicroReader.readMicroXML(aIS);
if (aDocument == null)
throw new AS2Exception("Failed to read the XML partnership information");
final IMicroElement aRoot = aDocument.getDocumentElement();
for (final IMicroElement eRootNode : aRoot.getAllChildElements()) {
final String sNodeName = eRootNode.getTagName();
if (sNodeName.equals("partner")) {
final Partner aNewPartner = loadPartner(eRootNode);
aNewPartners.addPartner(aNewPartner);
} else if (sNodeName.equals("partnership")) {
final Partnership aNewPartnership = loadPartnership(eRootNode, aNewPartners);
if (aNewPartnerships.getPartnershipByName(aNewPartnership.getName()) != null)
throw new AS2Exception("Partnership with name '" + aNewPartnership.getName() + "' is defined more than once");
aNewPartnerships.addPartnership(aNewPartnership);
} else {
if (LOGGER.isWarnEnabled())
LOGGER.warn("Invalid element '" + sNodeName + "' in XML partnership file");
}
}
}
setPartners(aNewPartners);
setPartnerships(aNewPartnerships);
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class XMLPartnershipFactory method refreshPartnershipFactory.
@OverridingMethodsMustInvokeSuper
public void refreshPartnershipFactory() throws AS2Exception {
try {
final File aFile = new File(getFilename());
load(FileHelper.getInputStream(aFile));
} catch (final Exception ex) {
throw WrappedAS2Exception.wrap(ex);
}
}
use of com.helger.as2lib.exception.AS2Exception in project as2-lib by phax.
the class XMLPartnershipFactory method storePartnership.
/**
* Store the current status of the partnerships to a file.
*
* @throws AS2Exception
* In case of an error
*/
public void storePartnership() throws AS2Exception {
final String sFilename = getFilename();
if (!isDisableBackup()) {
final File aBackupFile = _getUniqueBackupFile(sFilename);
if (LOGGER.isWarnEnabled())
LOGGER.info("backing up " + sFilename + " to " + aBackupFile.getName());
final File aSourceFile = new File(sFilename);
try {
AS2IOHelper.moveFile(aSourceFile, aBackupFile, true, true);
} catch (final IOException ex) {
new AS2Exception("Failed to move file " + aSourceFile + " to " + aBackupFile, ex).terminate();
}
}
final IMicroDocument aDoc = new MicroDocument();
final IMicroElement eRoot = aDoc.appendElement("partnerships");
for (final IPartner aPartner : getAllPartners()) {
final IMicroElement ePartner = eRoot.appendElement("partner");
for (final Map.Entry<String, String> aAttr : aPartner) ePartner.setAttribute(aAttr.getKey(), aAttr.getValue());
}
for (final Partnership aPartnership : getAllPartnerships()) {
final IMicroElement ePartnership = eRoot.appendElement("partnership");
ePartnership.setAttribute(ATTR_PARTNERSHIP_NAME, aPartnership.getName());
final IMicroElement eSender = ePartnership.appendElement("sender");
for (final Map.Entry<String, String> aAttr : aPartnership.getAllSenderIDs().entrySet()) eSender.setAttribute(aAttr.getKey(), aAttr.getValue());
final IMicroElement eReceiver = ePartnership.appendElement("receiver");
for (final Map.Entry<String, String> aAttr : aPartnership.getAllReceiverIDs().entrySet()) eReceiver.setAttribute(aAttr.getKey(), aAttr.getValue());
for (final Map.Entry<String, String> aAttr : aPartnership.getAllAttributes().entrySet()) ePartnership.appendElement("attribute").setAttribute("name", aAttr.getKey()).setAttribute("value", aAttr.getValue());
}
if (MicroWriter.writeToFile(aDoc, new File(sFilename)).isFailure())
throw new AS2Exception("Failed to write to file " + sFilename);
}
Aggregations