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();
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations