use of com.helger.commons.exception.InitializationException in project ph-schematron by phax.
the class SchematronTransformerFactory method createTransformerFactorySaxonFirst.
/**
* Create a new {@link TransformerFactory} trying to invoke the Saxon
* implementation first using the class
* {@value #SAXON_TRANSFORMER_FACTORY_CLASS}.
*
* @param aClassLoader
* The optional class loader to be used. May be <code>null</code>.
* @param aErrorListener
* An optional XSLT error listener to be used. May be
* <code>null</code>.
* @param aURIResolver
* An optional XSLT URI resolver to be used. May be <code>null</code>.
* @return A new {@link TransformerFactory} and not <code>null</code>.
* @throws InitializationException
* In case initialization fails.
*/
@Nonnull
public static TransformerFactory createTransformerFactorySaxonFirst(@Nullable final ClassLoader aClassLoader, @Nullable final ErrorListener aErrorListener, @Nullable final URIResolver aURIResolver) {
if (LOGGER.isDebugEnabled())
LOGGER.debug("Calling createTransformerFactorySaxonFirst");
final ClassLoader aEffectiveClassLoader = aClassLoader != null ? aClassLoader : ClassLoaderHelper.getContextClassLoader();
TransformerFactory aFactory;
try {
// Try Saxon first
aFactory = TransformerFactory.newInstance(SAXON_TRANSFORMER_FACTORY_CLASS, aEffectiveClassLoader);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created TransformerFactory with Saxon using '" + SAXON_TRANSFORMER_FACTORY_CLASS + "'");
// Maintain position #52
aFactory.setFeature(FeatureKeys.LINE_NUMBERING, true);
// Allow XInclude #86
aFactory.setFeature(FeatureKeys.XINCLUDE, true);
// Debug/testing only
if (false)
aFactory.setFeature(FeatureKeys.TRACE_OPTIMIZER_DECISIONS, true);
if (false)
aFactory.setFeature(FeatureKeys.COMPILE_WITH_TRACING, true);
} catch (final TransformerFactoryConfigurationError | TransformerConfigurationException ex) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Failed to create TransformerFactory with Saxon.", ex);
try {
LOGGER.debug("Done checking implementations using classloader " + aEffectiveClassLoader);
final Enumeration<URL> x = aEffectiveClassLoader.getResources("META-INF/services/javax.xml.transform.TransformerFactory");
while (x.hasMoreElements()) {
LOGGER.debug(" " + x.nextElement().toExternalForm());
}
LOGGER.debug("Done checking implementations");
} catch (final Exception ex2) {
LOGGER.error("Error determining implementations", ex2);
}
}
try {
// Try default afterwards
aFactory = TransformerFactory.newInstance();
} catch (final TransformerFactoryConfigurationError ex2) {
throw new InitializationException("Failed to create XML TransformerFactory", ex2);
}
}
if (aErrorListener != null)
aFactory.setErrorListener(aErrorListener);
if (aURIResolver != null)
aFactory.setURIResolver(aURIResolver);
if (LOGGER.isDebugEnabled())
LOGGER.debug("Created TransformerFactory is " + aFactory);
return aFactory;
}
use of com.helger.commons.exception.InitializationException in project phoss-directory by phax.
the class PDMetaManager method onAfterInstantiation.
@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
try {
m_aLucene = new PDLucene();
m_aStorageMgr = new PDStorageManager(m_aLucene);
m_aIndexerMgr = new PDIndexerManager(m_aStorageMgr);
LOGGER.info(ClassHelper.getClassLocalName(this) + " was initialized");
} catch (final Exception ex) {
if (GlobalDebug.isProductionMode()) {
new InternalErrorBuilder().setThrowable(ex).addErrorMessage(ClassHelper.getClassLocalName(this) + " init failed").handle();
}
throw new InitializationException("Failed to init " + ClassHelper.getClassLocalName(this), ex);
}
}
use of com.helger.commons.exception.InitializationException in project phoss-directory by phax.
the class PDPMetaManager method onAfterInstantiation.
@Override
protected void onAfterInstantiation(@Nonnull final IScope aScope) {
try {
m_aSMLInfoMgr = new SMLInfoManager(SML_INFO_XML);
final URI aFixedSMPURI = PDServerConfiguration.getFixedSMPURI();
if (aFixedSMPURI != null) {
// Use only the configured SMP
PDMetaManager.setBusinessCardProvider(SMPBusinessCardProvider.createForFixedSMP(PDServerConfiguration.getSMPMode(), aFixedSMPURI));
} else {
// Auto detect SMLs
PDMetaManager.setBusinessCardProvider(SMPBusinessCardProvider.createWithSMLAutoDetect(PDServerConfiguration.getSMPMode(), PDServerConfiguration.getURLProvider(), m_aSMLInfoMgr::getAllSorted));
}
LOGGER.info(ClassHelper.getClassLocalName(this) + " was initialized");
} catch (final Exception ex) {
if (GlobalDebug.isProductionMode()) {
new InternalErrorBuilder().setThrowable(ex).addErrorMessage(ClassHelper.getClassLocalName(this) + " init failed").handle();
}
throw new InitializationException("Failed to init " + ClassHelper.getClassLocalName(this), ex);
}
}
use of com.helger.commons.exception.InitializationException in project as2-lib by phax.
the class AbstractCertificateFactory method initEmptyKeyStore.
/**
* This method is responsible to create a new empty keystore based on the
* configured type.
*
* @throws AS2Exception
* In case of error
* @see #getKeyStoreType()
* @see #createNewKeyStore(EKeyStoreType)
* @see #setKeyStore(KeyStore)
*/
protected void initEmptyKeyStore() throws AS2Exception {
try {
final String sKeyStoreType = getKeyStoreType();
final EKeyStoreType eKeyStoreType = EKeyStoreType.getFromIDCaseInsensitiveOrDefault(sKeyStoreType, DEFAULT_KEY_STORE_TYPE);
if (LOGGER.isInfoEnabled())
LOGGER.info("Using internal keystore of type " + eKeyStoreType);
final KeyStore aKeyStore = createNewKeyStore(eKeyStoreType);
if (aKeyStore == null) {
debugLog(() -> "initDynamicComponent -> no keystore");
throw new InitializationException("Failed to create new keystore with type " + eKeyStoreType);
}
setKeyStore(aKeyStore);
} catch (final GeneralSecurityException ex) {
debugLog(() -> "initDynamicComponent -> " + _debug(ex));
throw WrappedAS2Exception.wrap(ex);
}
}
use of com.helger.commons.exception.InitializationException in project phoss-smp by phax.
the class RegistrationHookWriteToSML method _createSMLCaller.
@Nonnull
private static ManageParticipantIdentifierServiceCaller _createSMLCaller() {
// SML endpoint (incl. the service name)
final ISMLInfo aSMLInfo = SMPMetaManager.getSettings().getSMLInfo();
if (aSMLInfo == null)
throw new IllegalStateException("Failed to get SML manage participant endpoint URL");
final URL aSMLEndpointURL = aSMLInfo.getManageParticipantIdentifierEndpointAddress();
final String sEndpointURL = aSMLEndpointURL.toExternalForm();
final String sLowerURL = sEndpointURL.toLowerCase(Locale.US);
if (LOGGER.isInfoEnabled())
LOGGER.info("Performing SML query to '" + sEndpointURL + "'");
// SSL socket factory
final SSLSocketFactory aSocketFactory;
if (sLowerURL.startsWith("https://")) {
// https connection
if (!SMPKeyManager.isKeyStoreValid())
throw new InitializationException("Cannot init registration hook to SML, because private key/certificate setup has errors: " + SMPKeyManager.getInitializationError());
try {
aSocketFactory = SMPKeyManager.getInstance().createSSLContext().getSocketFactory();
} catch (final Exception ex) {
throw new IllegalStateException("Failed to init SSLContext for SML access", ex);
}
} else {
// Local, http only access - no socket factory
aSocketFactory = null;
}
// Hostname verifier
final HostnameVerifier aHostnameVerifier;
if (sLowerURL.contains("//localhost") || sLowerURL.contains("//127.0.0.1")) {
// Accept all hostnames
aHostnameVerifier = new HostnameVerifierVerifyAll(false);
} else
aHostnameVerifier = null;
// Build WS client
final ManageParticipantIdentifierServiceCaller ret = new ManageParticipantIdentifierServiceCaller(aSMLEndpointURL);
ret.setSSLSocketFactory(aSocketFactory);
ret.setHostnameVerifier(aHostnameVerifier);
final Integer aConnectionTimeoutMS = SMPServerConfiguration.getSMLConnectionTimeoutMS();
if (aConnectionTimeoutMS != null)
ret.setConnectionTimeoutMS(aConnectionTimeoutMS.intValue());
final int nRequestTimeoutMS = SMPServerConfiguration.getSMLRequestTimeoutMS();
if (nRequestTimeoutMS >= 0)
ret.setRequestTimeoutMS(nRequestTimeoutMS);
return ret;
}
Aggregations