use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class PersistenceWeaver method transform.
/**
* INTERNAL:
* Perform dynamic byte code weaving of class.
* @param loader The defining loader of the class to be transformed, may be {@code null}
* if the bootstrap loader.
* @param className The name of the class in the internal form of fully qualified class and interface
* names.
* @param classBeingRedefined If this is a redefine, the class being redefined, otherwise {@code null}.
* @param protectionDomain The protection domain of the class being defined or redefined.
* @param classfileBuffer The input byte buffer in class file format (must not be modified).
* @return A well-formed class file buffer (the result of the transform), or {@code null} if no transform
* is performed.
*/
@Override
public byte[] transform(final ClassLoader loader, final String className, final Class<?> classBeingRedefined, final ProtectionDomain protectionDomain, final byte[] classfileBuffer) throws TransformerException {
final SessionLog log = AbstractSessionLog.getLog();
// PERF: Is finest logging on weaving turned on?
final boolean shouldLogFinest = log.shouldLog(SessionLog.FINEST, SessionLog.WEAVER);
final Map<String, ClassDetails> classDetailsMap = this.classDetailsMap;
// Check if cleared already.
if (classDetailsMap == null) {
return null;
}
try {
/*
* The ClassFileTransformer callback - when called by the JVM's
* Instrumentation implementation - is invoked for every class loaded.
* Thus, we must check the classDetailsMap to see if we are 'interested'
* in the class.
*/
final ClassDetails classDetails = classDetailsMap.get(Helper.toSlashedClassName(className));
if (classDetails != null) {
if (shouldLogFinest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "begin_weaving_class", className);
}
ClassReader classReader = null;
try {
classReader = new ClassReader(classfileBuffer);
} catch (IllegalArgumentException iae) {
// in such case log a warning and try to re-read the class without class version check
if (log.shouldLog(SessionLog.FINE, SessionLog.WEAVER)) {
SessionLogEntry entry = new SessionLogEntry(null, SessionLog.FINE, SessionLog.WEAVER, iae);
entry.setMessage(ExceptionLocalization.buildMessage("unsupported_classfile_version", new Object[] { className }));
log.log(entry);
}
classReader = new EclipseLinkClassReader(classfileBuffer);
}
final String reflectiveIntrospectionProperty = PrivilegedAccessHelper.getSystemProperty(SystemProperties.WEAVING_REFLECTIVE_INTROSPECTION);
final ClassWriter classWriter = reflectiveIntrospectionProperty != null ? new ClassWriter(ClassWriter.COMPUTE_FRAMES) : new ComputeClassWriter(loader, ClassWriter.COMPUTE_FRAMES);
final ClassWeaver classWeaver = new ClassWeaver(classWriter, classDetails);
final ClassVisitor sv = new SerialVersionUIDAdder(classWeaver);
classReader.accept(sv, 0);
if (classWeaver.alreadyWeaved) {
if (shouldLogFinest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "end_weaving_class", className);
}
return null;
}
if (classWeaver.weaved) {
final byte[] bytes = classWriter.toByteArray();
final String outputPath = PrivilegedAccessHelper.getSystemProperty(SystemProperties.WEAVING_OUTPUT_PATH, "");
if (!outputPath.equals("")) {
Helper.outputClassFile(className, bytes, outputPath);
}
// PERF: Don't execute this set of if statements with logging turned off.
if (shouldLogFinest) {
if (classWeaver.weavedPersistenceEntity) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "weaved_persistenceentity", className);
}
if (classWeaver.weavedChangeTracker) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "weaved_changetracker", className);
}
if (classWeaver.weavedLazy) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "weaved_lazy", className);
}
if (classWeaver.weavedFetchGroups) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "weaved_fetchgroups", className);
}
if (classWeaver.weavedRest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "weaved_rest", className);
}
log.log(SessionLog.FINEST, SessionLog.WEAVER, "end_weaving_class", className);
}
return bytes;
}
if (shouldLogFinest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "end_weaving_class", className);
}
} else {
if (shouldLogFinest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "transform_missing_class_details", className);
}
}
} catch (Throwable exception) {
if (log.shouldLog(SessionLog.WARNING, SessionLog.WEAVER)) {
log.log(SessionLog.WARNING, SessionLog.WEAVER, "exception_while_weaving", new Object[] { className, exception.getLocalizedMessage() });
if (shouldLogFinest) {
log.logThrowable(SessionLog.FINEST, SessionLog.WEAVER, exception);
}
}
}
if (shouldLogFinest) {
log.log(SessionLog.FINEST, SessionLog.WEAVER, "transform_existing_class_bytes", className);
}
// Returning null means 'use existing class bytes'.
return null;
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class JAXBUnmarshaller method setProperty.
/**
* Set a property on the JAXBUnmarshaller. Attempting to set any unsupported
* property will result in a jakarta.xml.bind.PropertyException.
* @see org.eclipse.persistence.jaxb.UnmarshallerProperties
*/
@Override
public void setProperty(String key, Object value) throws PropertyException {
if (key == null) {
throw new IllegalArgumentException();
}
SessionLog logger = AbstractSessionLog.getLog();
if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
logger.log(SessionLog.FINE, SessionLog.MOXY, "moxy_set_unmarshaller_property", new Object[] { key, value });
}
if (MOXySystemProperties.moxyLogPayload != null && xmlUnmarshaller.isLogPayload() == null) {
xmlUnmarshaller.setLogPayload(MOXySystemProperties.moxyLogPayload);
}
if (key.equals(UnmarshallerProperties.MEDIA_TYPE)) {
MediaType mType = null;
if (value instanceof MediaType) {
mType = (MediaType) value;
} else if (value instanceof String) {
mType = MediaType.getMediaType((String) value);
}
if (mType == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setMediaType(mType);
} else if (key.equals(UnmarshallerProperties.UNMARSHALLING_CASE_INSENSITIVE)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setCaseInsensitive((Boolean) value);
} else if (key.equals(UnmarshallerProperties.AUTO_DETECT_MEDIA_TYPE)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setAutoDetectMediaType((Boolean) value);
} else if (key.equals(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX)) {
xmlUnmarshaller.setAttributePrefix((String) value);
} else if (UnmarshallerProperties.JSON_INCLUDE_ROOT.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setIncludeRoot((Boolean) value);
} else if (UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER.equals(key)) {
if (value == null) {
xmlUnmarshaller.setNamespaceResolver(null);
} else if (value instanceof Map) {
Map<String, String> namespaces = (Map<String, String>) value;
NamespaceResolver nr = new NamespaceResolver();
Iterator<Entry<String, String>> namesapcesIter = namespaces.entrySet().iterator();
for (int i = 0; i < namespaces.size(); i++) {
Entry<String, String> nextEntry = namesapcesIter.next();
nr.put(nextEntry.getValue(), nextEntry.getKey());
}
xmlUnmarshaller.setNamespaceResolver(nr);
} else if (value instanceof NamespacePrefixMapper) {
xmlUnmarshaller.setNamespaceResolver(new PrefixMapperNamespaceResolver((NamespacePrefixMapper) value, null));
}
} else if (UnmarshallerProperties.JSON_VALUE_WRAPPER.equals(key)) {
xmlUnmarshaller.setValueWrapper((String) value);
} else if (UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
xmlUnmarshaller.setNamespaceSeparator((Character) value);
} else if (UnmarshallerProperties.JSON_USE_XSD_TYPES_WITH_PREFIX.equals(key)) {
xmlUnmarshaller.getJsonTypeConfiguration().setUseXsdTypesWithPrefix((Boolean) value);
} else if (UnmarshallerProperties.JSON_TYPE_COMPATIBILITY.equals(key)) {
xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeCompatibility((Boolean) value);
} else if (UnmarshallerProperties.JSON_TYPE_ATTRIBUTE_NAME.equals(key)) {
xmlUnmarshaller.getJsonTypeConfiguration().setJsonTypeAttributeName((String) value);
} else if (UnmarshallerProperties.ID_RESOLVER.equals(key)) {
setIDResolver((IDResolver) value);
} else if (SUN_ID_RESOLVER.equals(key) || SUN_JSE_ID_RESOLVER.equals(key)) {
if (value == null) {
setIDResolver(null);
} else {
setIDResolver(new IDResolverWrapper(value));
}
} else if (UnmarshallerProperties.OBJECT_GRAPH.equals(key)) {
if (value instanceof ObjectGraphImpl) {
xmlUnmarshaller.setUnmarshalAttributeGroup(((ObjectGraphImpl) value).getAttributeGroup());
} else if (value instanceof String || value == null) {
xmlUnmarshaller.setUnmarshalAttributeGroup(value);
} else {
throw org.eclipse.persistence.exceptions.JAXBException.invalidValueForObjectGraph(value);
}
} else if (UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME.equals(key)) {
xmlUnmarshaller.setWrapperAsCollectionName((Boolean) value);
} else if (UnmarshallerProperties.BEAN_VALIDATION_MODE.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
this.beanValidationMode = ((BeanValidationMode) value);
} else if (UnmarshallerProperties.BEAN_VALIDATION_FACTORY.equals(key)) {
// Null value is allowed
this.prefValidatorFactory = value;
} else if (UnmarshallerProperties.BEAN_VALIDATION_GROUPS.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
this.beanValidationGroups = ((Class<?>[]) value);
} else if (UnmarshallerProperties.BEAN_VALIDATION_NO_OPTIMISATION.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
this.bvNoOptimisation = ((boolean) value);
} else if (UnmarshallerProperties.DISABLE_SECURE_PROCESSING.equals(key)) {
if (value == null) {
throw new PropertyException(key, Constants.EMPTY_STRING);
}
boolean disabled = value instanceof String ? Boolean.parseBoolean((String) value) : (boolean) value;
xmlUnmarshaller.setDisableSecureProcessing(disabled);
} else if (UnmarshallerProperties.MOXY_LOG_PAYLOAD.equals(key)) {
xmlUnmarshaller.setLogPayload(((boolean) value));
} else if (UnmarshallerProperties.MOXY_LOGGING_LEVEL.equals(key)) {
if (value instanceof String) {
AbstractSessionLog.getLog().setLevel(LogLevel.toValue((String) value).getId(), SessionLog.MOXY);
} else {
AbstractSessionLog.getLog().setLevel(((LogLevel) value).getId(), SessionLog.MOXY);
}
} else {
throw new PropertyException(key, value);
}
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class MetadataAsmFactory method buildClassMetadata.
/**
* Build the class metadata for the class name using ASM to read the class
* byte codes.
*/
protected void buildClassMetadata(MetadataClass metadataClass, String className, boolean isLazy) {
ClassMetadataVisitor visitor = new ClassMetadataVisitor(metadataClass, isLazy);
InputStream stream = null;
try {
String resourceString = className.replace('.', '/') + ".class";
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
final String f_resourceString = resourceString;
stream = AccessController.doPrivileged(new PrivilegedAction<InputStream>() {
@Override
public InputStream run() {
return m_loader.getResourceAsStream(f_resourceString);
}
});
} else {
stream = m_loader.getResourceAsStream(resourceString);
}
ClassReader reader = new ClassReader(stream);
Attribute[] attributes = new Attribute[0];
reader.accept(visitor, attributes, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
} catch (IllegalArgumentException iae) {
// class was probably compiled with some newer than officially
// supported and tested JDK
// in such case log a warning and try to re-read the class
// without class version check
SessionLog log = getLogger().getSession() != null ? getLogger().getSession().getSessionLog() : AbstractSessionLog.getLog();
if (log.shouldLog(SessionLog.WARNING, SessionLog.METADATA)) {
SessionLogEntry entry = new SessionLogEntry(getLogger().getSession(), SessionLog.WARNING, SessionLog.METADATA, iae);
entry.setMessage(ExceptionLocalization.buildMessage("unsupported_classfile_version", new Object[] { className }));
log.log(entry);
}
if (stream != null) {
try {
ClassReader reader = new EclipseLinkClassReader(stream);
Attribute[] attributes = new Attribute[0];
reader.accept(visitor, attributes, ClassReader.SKIP_CODE | ClassReader.SKIP_DEBUG | ClassReader.SKIP_FRAMES);
} catch (Exception e) {
// our fall-back failed, this is severe
if (log.shouldLog(SessionLog.SEVERE, SessionLog.METADATA)) {
SessionLogEntry entry = new SessionLogEntry(getLogger().getSession(), SessionLog.SEVERE, SessionLog.METADATA, e);
entry.setMessage(ExceptionLocalization.buildMessage("unsupported_classfile_version", new Object[] { className }));
log.log(entry);
}
addMetadataClass(getVirtualMetadataClass(className));
}
} else {
addMetadataClass(getVirtualMetadataClass(className));
}
} catch (Exception exception) {
SessionLog log = getLogger().getSession() != null ? getLogger().getSession().getSessionLog() : AbstractSessionLog.getLog();
if (log.shouldLog(SessionLog.FINEST, SessionLog.METADATA)) {
log.logThrowable(SessionLog.FINEST, SessionLog.METADATA, exception);
}
addMetadataClass(getVirtualMetadataClass(className));
} finally {
try {
if (stream != null) {
stream.close();
}
} catch (IOException ignore) {
// Ignore.
}
}
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class FailoverBase method prepare.
@Before
public void prepare() {
DatabaseLogin login = new DatabaseLogin();
login.useDirectDriverConnect();
login.setDriverClass(EmulatedDriver.class);
login.setConnectionString("jdbc:emulateddriver");
login.getPlatform().setPingSQL("SELECT 1");
Project p = new Project(login);
ClassDescriptor cd = Address.descriptor();
p.addDescriptor(cd);
session = createSession(p);
SessionLog log = new DefaultSessionLog(new OutputStreamWriter(System.out));
int logLevel = AbstractSessionLog.translateStringToLoggingLevel(System.getProperty(PersistenceUnitProperties.LOGGING_LEVEL, "INFO"));
session.setSessionLog(log);
session.setLogLevel(logLevel);
session.login();
// this will actually store the results on the driver for subsequent connections.
EmulatedConnection con = (EmulatedConnection) ((DatabaseSessionImpl) session).getAccessor().getConnection();
Vector<DatabaseField> pingFields = new Vector<DatabaseField>() {
{
add(new DatabaseField("1"));
}
};
con.putRows("SELECT 1", new Vector() {
{
add(new ArrayRecord(pingFields, pingFields.toArray(new DatabaseField[0]), new Object[] { "1" }));
}
});
con.putRows(Address.getSQL(), Address.getData(cd));
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class SessionsFactory method processSessionConfig.
/**
* INTERNAL:
* Process the common elements from a SessionConfig.
*/
protected void processSessionConfig(SessionConfig sessionConfig, AbstractSession session) {
// Name
session.setName(sessionConfig.getName().trim());
// Session Event Manager
processSessionEventManagerConfig(sessionConfig.getSessionEventManagerConfig(), session);
// server platform
((DatabaseSessionImpl) session).setServerPlatform(buildServerPlatformConfig(sessionConfig.getServerPlatformConfig(), (DatabaseSessionImpl) session));
// Session Log - BUG# 3442865, don't set the log if it is null
SessionLog log = buildSessionLog(sessionConfig.getLogConfig(), session);
if (log != null) {
session.setSessionLog(log);
}
// Remote command manager
buildRemoteCommandManagerConfig(sessionConfig.getRemoteCommandManagerConfig(), session);
// Profiler - XML Schema default is null
if (sessionConfig.getProfiler() != null) {
if (sessionConfig.getProfiler().equals("eclipselink")) {
session.setProfiler(new PerformanceProfiler());
}
}
// Exception handler
String exceptionHandlerClassName = sessionConfig.getExceptionHandlerClass();
if (exceptionHandlerClassName != null) {
try {
@SuppressWarnings({ "unchecked" }) Class<ExceptionHandler> exceptionHandlerClass = (Class<ExceptionHandler>) m_classLoader.loadClass(exceptionHandlerClassName);
if (PrivilegedAccessHelper.shouldUsePrivilegedAccess()) {
session.setExceptionHandler(AccessController.doPrivileged(new PrivilegedNewInstanceFromClass<>(exceptionHandlerClass)));
} else {
session.setExceptionHandler(PrivilegedAccessHelper.newInstanceFromClass(exceptionHandlerClass));
}
} catch (Exception e) {
throw SessionLoaderException.failedToLoadTag("exception-handler-class", exceptionHandlerClassName, e);
}
}
// Session customizer will be processed in the buildSessions method.
// Ensures it is run last.
}
Aggregations