Search in sources :

Example 11 with InitializationException

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;
}
Also used : TransformerFactoryConfigurationError(javax.xml.transform.TransformerFactoryConfigurationError) TransformerFactory(javax.xml.transform.TransformerFactory) Enumeration(java.util.Enumeration) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InitializationException(com.helger.commons.exception.InitializationException) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException) InitializationException(com.helger.commons.exception.InitializationException) Nonnull(javax.annotation.Nonnull)

Example 12 with InitializationException

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);
    }
}
Also used : InternalErrorBuilder(com.helger.photon.core.interror.InternalErrorBuilder) InitializationException(com.helger.commons.exception.InitializationException) URI(java.net.URI) InitializationException(com.helger.commons.exception.InitializationException)

Example 13 with InitializationException

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);
    }
}
Also used : PDLucene(com.helger.pd.indexer.lucene.PDLucene) InternalErrorBuilder(com.helger.photon.core.interror.InternalErrorBuilder) InitializationException(com.helger.commons.exception.InitializationException) PDStorageManager(com.helger.pd.indexer.storage.PDStorageManager) InitializationException(com.helger.commons.exception.InitializationException)

Example 14 with InitializationException

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);
    }
}
Also used : InitializationException(com.helger.commons.exception.InitializationException) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 15 with InitializationException

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);
    }
}
Also used : InitializationException(com.helger.commons.exception.InitializationException) IParticipantIdentifier(com.helger.peppolid.IParticipantIdentifier) Test(org.junit.Test)

Aggregations

InitializationException (com.helger.commons.exception.InitializationException)22 KeyStore (java.security.KeyStore)4 Nonnull (javax.annotation.Nonnull)4 X509Certificate (java.security.cert.X509Certificate)3 EPeppolCertificateCheckResult (com.helger.peppol.utils.EPeppolCertificateCheckResult)2 IParticipantIdentifier (com.helger.peppolid.IParticipantIdentifier)2 InternalErrorBuilder (com.helger.photon.core.interror.InternalErrorBuilder)2 LoadedKeyStore (com.helger.security.keystore.LoadedKeyStore)2 SMPClientReadOnly (com.helger.smpclient.peppol.SMPClientReadOnly)2 IMicroDocument (com.helger.xml.microdom.IMicroDocument)2 IMicroElement (com.helger.xml.microdom.IMicroElement)2 File (java.io.File)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 TransformerConfigurationException (javax.xml.transform.TransformerConfigurationException)2 Test (org.junit.Test)2 CommonsLinkedHashSet (com.helger.commons.collection.impl.CommonsLinkedHashSet)1 PDTFromString (com.helger.commons.datetime.PDTFromString)1 ClassPathResource (com.helger.commons.io.resource.ClassPathResource)1 FileSystemResource (com.helger.commons.io.resource.FileSystemResource)1 MimeType (com.helger.commons.mime.MimeType)1