Search in sources :

Example 11 with SessionLog

use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.

the class EntityManagerJUnitTestSuite method testServerDetectionLogging.

/**
 * Bug #476018
 * This test verifies that EclipseLink prints server detection related log
 * messages at appropriate level - FINE in session log, FINER in other cases
 */
public void testServerDetectionLogging() {
    if (isOnServer()) {
        return;
    }
    closeEntityManagerFactory();
    SessionLog original = AbstractSessionLog.getLog();
    try {
        AbstractSessionLog.setLog(new LogWrapper());
        // check session log for "Configured server platform message"
        Map<String, Object> properties = new HashMap<>();
        properties.putAll(JUnitTestCaseHelper.getDatabaseProperties());
        properties.put(PersistenceUnitProperties.LOGGING_LEVEL, original.getLevelString());
        properties.put(PersistenceUnitProperties.LOGGING_LOGGER, LogWrapper.class.getName());
        EntityManagerFactoryImpl emf = (EntityManagerFactoryImpl) Persistence.createEntityManagerFactory(getPersistenceUnitName(), properties);
        emf.refreshMetadata(properties);
        SimpleSessionLogWrapper wr = (SimpleSessionLogWrapper) emf.getServerSession().getSessionLog();
        assertEquals("configured_server_platform should be printed at FINE level", wr.getLevel() <= SessionLog.FINE, wr.expected());
        // it may happen that logging is not fully configured as that happens
        // after detecting server platform; in such case, messages are printed out
        // by an instance of DefaultSessionLog
        LogWrapper lw = new LogWrapper("detect_server_platform");
        AbstractSessionLog.setLog(lw);
        AbstractSessionLog.getLog().setSession(null);
        lw.setSession(null);
        ServerPlatformUtils.detectServerPlatform(null);
        assertEquals("detect_server_platform should be printed at FINER level", lw.getLevel() <= SessionLog.FINER, lw.expected());
        lw = new LogWrapper("detect_server_platform");
        AbstractSessionLog.setLog(lw);
        Session ss = wr.getSession();
        AbstractSessionLog.getLog().setSession(ss);
        AbstractSessionLog.getLog().getSession().setSessionLog(lw);
        lw.setSession(ss);
        ServerPlatformUtils.detectServerPlatform((ServerSession) ss);
        assertEquals("detect_server_platform should be printed at FINER level", lw.getLevel() <= SessionLog.FINER, lw.expected());
    } finally {
        AbstractSessionLog.setLog(original);
        closeEntityManagerFactory();
    }
}
Also used : SessionLog(org.eclipse.persistence.logging.SessionLog) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) HashMap(java.util.HashMap) SimpleSessionLogWrapper(org.eclipse.persistence.testing.tests.weaving.SimpleSessionLogWrapper) EntityManagerFactoryImpl(org.eclipse.persistence.internal.jpa.EntityManagerFactoryImpl) SimpleSessionLogWrapper(org.eclipse.persistence.testing.tests.weaving.SimpleSessionLogWrapper) ClientSession(org.eclipse.persistence.sessions.server.ClientSession) Session(org.eclipse.persistence.sessions.Session) ServerSession(org.eclipse.persistence.sessions.server.ServerSession) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) AbstractSession(org.eclipse.persistence.internal.sessions.AbstractSession)

Example 12 with SessionLog

use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.

the class XMLHelper method createXPathFactory.

/**
 * Returns properly configured (e.g. security features) factory
 * - securityProcessing == is set based on security processing property, default is true
 */
public static XPathFactory createXPathFactory(boolean disableSecureProcessing) throws IllegalStateException {
    SessionLog logger = AbstractSessionLog.getLog();
    try {
        XPathFactory factory = XPathFactory.newInstance();
        if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
            logger.log(SessionLog.FINE, SessionLog.MOXY, "xpath_factory", new Object[] { factory });
        }
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
        return factory;
    } catch (XPathFactoryConfigurationException ex) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, ex);
        throw new IllegalStateException(ex);
    } catch (AbstractMethodError er) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, er);
        throw new IllegalStateException(er);
    }
}
Also used : AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) XPathFactory(javax.xml.xpath.XPathFactory) XPathFactoryConfigurationException(javax.xml.xpath.XPathFactoryConfigurationException)

Example 13 with SessionLog

use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.

the class XMLHelper method createTransformerFactory.

/**
 * Returns properly configured (e.g. security features) factory
 * - securityProcessing == is set based on security processing property, default is true
 */
public static TransformerFactory createTransformerFactory(boolean disableSecureProcessing) throws IllegalStateException {
    SessionLog logger = AbstractSessionLog.getLog();
    try {
        TransformerFactory factory = TransformerFactory.newInstance();
        if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
            logger.log(SessionLog.FINE, SessionLog.MOXY, "transformer_factory", new Object[] { factory });
        }
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
        return factory;
    } catch (TransformerConfigurationException ex) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, ex);
        throw new IllegalStateException(ex);
    } catch (AbstractMethodError er) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, er);
        throw new IllegalStateException(er);
    }
}
Also used : AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) TransformerFactory(javax.xml.transform.TransformerFactory) TransformerConfigurationException(javax.xml.transform.TransformerConfigurationException)

Example 14 with SessionLog

use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.

the class XMLHelper method createSchemaFactory.

/**
 * Returns properly configured (e.g. security features) schema factory
 * - namespaceAware == true
 * - securityProcessing == is set based on security processing property, default is true
 */
public static SchemaFactory createSchemaFactory(final String language, boolean disableSecureProcessing) throws IllegalStateException {
    SessionLog logger = AbstractSessionLog.getLog();
    try {
        SchemaFactory factory = SchemaFactory.newInstance(language);
        if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
            logger.log(SessionLog.FINE, SessionLog.MOXY, "schema_factory", new Object[] { factory });
        }
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
        return factory;
    } catch (SAXNotRecognizedException ex) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, ex);
        throw new IllegalStateException(ex);
    } catch (SAXNotSupportedException ex) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, ex);
        throw new IllegalStateException(ex);
    } catch (AbstractMethodError er) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, er);
        throw new IllegalStateException(er);
    }
}
Also used : SchemaFactory(javax.xml.validation.SchemaFactory) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException)

Example 15 with SessionLog

use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.

the class XMLHelper method createDocumentBuilderFactory.

/**
 * Returns properly configured (e.g. security features) factory
 * - namespaceAware == true
 * - securityProcessing == is set based on security processing property, default is true
 */
public static DocumentBuilderFactory createDocumentBuilderFactory(boolean disableSecureProcessing) throws IllegalStateException {
    SessionLog logger = AbstractSessionLog.getLog();
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
            logger.log(SessionLog.FINE, SessionLog.MOXY, "documentbuilder_factory", new Object[] { factory });
        }
        factory.setNamespaceAware(true);
        factory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, !isXMLSecurityDisabled(disableSecureProcessing));
        return factory;
    } catch (ParserConfigurationException ex) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, ex);
        throw new IllegalStateException(ex);
    } catch (AbstractMethodError er) {
        logger.logThrowable(SessionLog.SEVERE, SessionLog.MOXY, er);
        throw new IllegalStateException(er);
    }
}
Also used : AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException)

Aggregations

SessionLog (org.eclipse.persistence.logging.SessionLog)24 AbstractSessionLog (org.eclipse.persistence.logging.AbstractSessionLog)17 DefaultSessionLog (org.eclipse.persistence.logging.DefaultSessionLog)5 PrivilegedActionException (java.security.PrivilegedActionException)3 HashMap (java.util.HashMap)3 ValidationException (org.eclipse.persistence.exceptions.ValidationException)3 PrivilegedNewInstanceFromClass (org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass)3 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 JAXBContext (jakarta.xml.bind.JAXBContext)2 JAXBElement (jakarta.xml.bind.JAXBElement)2 JAXBException (jakarta.xml.bind.JAXBException)2 PropertyException (jakarta.xml.bind.PropertyException)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 ParserConfigurationException (javax.xml.parsers.ParserConfigurationException)2 ClassReader (org.eclipse.persistence.internal.libraries.asm.ClassReader)2 EclipseLinkClassReader (org.eclipse.persistence.internal.libraries.asm.EclipseLinkClassReader)2 PrefixMapperNamespaceResolver (org.eclipse.persistence.internal.oxm.record.namespaces.PrefixMapperNamespaceResolver)2 AbstractSession (org.eclipse.persistence.internal.sessions.AbstractSession)2 DatabaseSessionImpl (org.eclipse.persistence.internal.sessions.DatabaseSessionImpl)2