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 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 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 PDClientTest method testNonExistingPort.
@Test
@Ignore("Avoid long connection timeout")
public void testNonExistingPort() {
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test");
try (final PDClient aClient = new PDClient("http://193.10.8.211:7999")) {
if (aClient.deleteServiceGroupFromIndex(aPI).isSuccess()) {
aClient.isServiceGroupRegistered(aPI);
aClient.addServiceGroupToIndex(aPI);
}
} catch (final InitializationException ex) {
LOGGER.error("Failed to invoke PDClient", ex);
}
}
use of com.helger.commons.exception.InitializationException in project phoss-directory by phax.
the class PDClientTest method testTestServer.
@Test
public void testTestServer() {
final IParticipantIdentifier aPI = PeppolIdentifierFactory.INSTANCE.createParticipantIdentifierWithDefaultScheme("9915:test");
try (final PDClient aClient = new PDClient("https://test-directory.peppol.eu")) {
if (aClient.deleteServiceGroupFromIndex(aPI).isSuccess()) {
aClient.isServiceGroupRegistered(aPI);
aClient.addServiceGroupToIndex(aPI);
}
} catch (final InitializationException ex) {
LOGGER.error("Failed to invoke PDClient", ex);
}
}
Aggregations