use of com.helger.web.fileupload.IFileItem in project peppol-practical by phax.
the class PagePublicToolsSMPSML method _updateSMPatSML.
private void _updateSMPatSML(@Nonnull final WebPageExecutionContext aWPEC, @Nonnull final FormErrorList aFormErrors) {
final HCNodeList aNodeList = aWPEC.getNodeList();
final Locale aDisplayLocale = aWPEC.getDisplayLocale();
final ISMLConfigurationManager aSMLConfigurationMgr = PPMetaManager.getSMLConfigurationMgr();
final String sSMLID = aWPEC.params().getAsString(FIELD_SML_ID);
final ISMLConfiguration aSMLInfo = aSMLConfigurationMgr.getSMLInfoOfID(sSMLID);
final String sSMPID = aWPEC.params().getAsString(FIELD_SMP_ID);
final String sPhysicalAddress = aWPEC.params().getAsString(FIELD_PHYSICAL_ADDRESS);
final String sLogicalAddress = aWPEC.params().getAsString(FIELD_LOGICAL_ADDRESS);
final IFileItem aKeyStoreFile = aWPEC.params().getAsFileItem(FIELD_KEYSTORE);
final String sKeyStorePassword = aWPEC.params().getAsString(FIELD_KEYSTORE_PW);
final boolean bIsPeppol = aSMLInfo != null && aSMLInfo.getSMPAPIType() == ESMPAPIType.PEPPOL;
if (aSMLInfo == null)
aFormErrors.addFieldError(FIELD_SML_ID, "A valid SML must be selected!");
if (StringHelper.hasNoText(sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "A non-empty SMP ID must be provided!");
else if (!RegExHelper.stringMatchesPattern(CPPApp.PATTERN_SMP_ID, sSMPID))
aFormErrors.addFieldError(FIELD_SMP_ID, "The provided SMP ID contains invalid characters. It must match the following regular expression: " + CPPApp.PATTERN_SMP_ID);
if (StringHelper.hasNoText(sPhysicalAddress))
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "A physical address must be provided!");
else if (!RegExHelper.stringMatchesPattern(IPV4Addr.PATTERN_IPV4, sPhysicalAddress))
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided physical address does not seem to be an IPv4 address!");
else {
final String[] aParts = StringHelper.getExplodedArray('.', sPhysicalAddress, 4);
final byte[] aBytes = new byte[] { (byte) StringParser.parseInt(aParts[0], -1), (byte) StringParser.parseInt(aParts[1], -1), (byte) StringParser.parseInt(aParts[2], -1), (byte) StringParser.parseInt(aParts[3], -1) };
try {
InetAddress.getByAddress(aBytes);
} catch (final Exception ex) {
aFormErrors.addFieldError(FIELD_PHYSICAL_ADDRESS, "The provided IP address does not resolve to a valid host. " + AppCommonUI.getTechnicalDetailsString(ex, false));
}
}
if (StringHelper.hasNoText(sLogicalAddress))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "A logical address must be provided in the form 'http://smp.example.org'!");
else {
final URL aURL = URLHelper.getAsURL(sLogicalAddress);
if (aURL == null)
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address seems not be a URL! Please use the form 'http://smp.example.org'");
else {
if (bIsPeppol) {
if (!"http".equals(aURL.getProtocol()))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the 'http' protocol and may not use the '" + aURL.getProtocol() + "' protocol. According to the Peppol SMP specification, no other protocols than 'http' are allowed!");
// -1 means default port
if (aURL.getPort() != 80 && aURL.getPort() != -1)
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address must use the default http port 80 and not port " + aURL.getPort() + ". According to the Peppol SMP specification, no other ports are allowed!");
if (StringHelper.hasText(aURL.getPath()) && !"/".equals(aURL.getPath()))
aFormErrors.addFieldError(FIELD_LOGICAL_ADDRESS, "The provided logical address may not contain a path (" + aURL.getPath() + ") because according to the Peppol SMP specifications it must run in the root (/) path!");
}
}
}
final SSLSocketFactory aSocketFactory = _loadKeyStoreAndCreateSSLSocketFactory(EKeyStoreType.JKS, SECURITY_PROVIDER, aKeyStoreFile, sKeyStorePassword, aFormErrors, aDisplayLocale);
if (aFormErrors.isEmpty()) {
try {
final ManageServiceMetadataServiceCaller aCaller = _create(aSMLInfo.getSMLInfo(), aSocketFactory);
aCaller.update(sSMPID, sPhysicalAddress, sLogicalAddress);
final String sMsg = "Successfully updated SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' at the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
LOGGER.info(sMsg);
aNodeList.addChild(success(sMsg));
AuditHelper.onAuditExecuteSuccess("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL());
} catch (final Exception ex) {
final String sMsg = "Error updating SMP '" + sSMPID + "' with physical address '" + sPhysicalAddress + "' and logical address '" + sLogicalAddress + "' to the SML '" + aSMLInfo.getManagementServiceURL() + "'.";
aNodeList.addChild(error(sMsg).addChild(AppCommonUI.getTechnicalDetailsUI(ex, true)));
AuditHelper.onAuditExecuteFailure("smp-sml-update", sSMPID, sPhysicalAddress, sLogicalAddress, aSMLInfo.getManagementServiceURL(), ex.getClass(), ex.getMessage());
}
} else
aNodeList.addChild(BootstrapWebPageUIHandler.INSTANCE.createIncorrectInputBox(aWPEC));
}
Aggregations