use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class XMLHelper method createParserFactory.
/**
* Returns properly configured (e.g. security features) parser factory
* - namespaceAware == true
* - securityProcessing == is set based on security processing property, default is true
*/
public static SAXParserFactory createParserFactory(boolean disableSecureProcessing) throws IllegalStateException {
SessionLog logger = AbstractSessionLog.getLog();
try {
SAXParserFactory factory = SAXParserFactory.newInstance();
if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
logger.log(SessionLog.FINE, SessionLog.MOXY, "saxparser_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 (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 SessionsFactory method buildJavaLogConfig.
/**
* INTERNAL:
*/
@SuppressWarnings({ "unchecked" })
protected SessionLog buildJavaLogConfig(JavaLogConfig javaLogConfig, AbstractSession session) {
SessionLog javaLog = null;
try {
// use ConversionManager to avoid loading the JDK 1.4 class unless it is needed.
ConversionManager conversionManager = new ConversionManager();
conversionManager.setLoader(getClass().getClassLoader());
javaLog = ((Class<SessionLog>) conversionManager.convertObject("org.eclipse.persistence.logging.JavaLog", Class.class)).getConstructor().newInstance();
javaLog.setSession(session);
} catch (Exception exception) {
throw ValidationException.unableToLoadClass("org.eclipse.persistence.logging.JavaLog", exception);
}
// Process the common elements from LogConfig
processLogConfig(javaLogConfig, javaLog);
return javaLog;
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class IsolatedHashMapTest method testIsolationInRealContext.
/**
* Test partition isolation in real context with real {@link ServerPlatform}.
*/
public void testIsolationInRealContext() {
final SessionLog log = getServerSession().getSessionLog();
log.log(SessionLog.INFO, "IsolatedHashMapTest.testIsolationInRealContext()");
doIsolationCheck(map, supportPartitions ? serverPlatform.getPartitionID() : DEFAULT_PARTITION_ID, log);
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class SimpleQueryTestSuite method testJPQLQuery.
/**
* Tests whether dynamic entity descriptor is available in session during query execution when it was created
* right before it.
*/
@Test
public void testJPQLQuery() {
final SessionLog log = em.unwrap(Session.class).getSessionLog();
final EntityTransaction et = em.getTransaction();
try {
et.begin();
DynamicHelper helper = new JPADynamicHelper(em);
DynamicClassLoader dcl = helper.getDynamicClassLoader();
Class<?> javaType = dcl.createDynamicClass("model.Simple");
DynamicTypeBuilder typeBuilder = new JPADynamicTypeBuilder(javaType, null, "SIMPLE_TYPE_1");
typeBuilder.setPrimaryKeyFields("SID");
typeBuilder.addDirectMapping("id", int.class, "SID");
typeBuilder.addDirectMapping("value1", String.class, "VAL_1");
DynamicType dt = typeBuilder.getType();
helper.addTypes(false, false, dt);
DynamicEntity dt1 = dt.newDynamicEntity();
dt1.set("id", 1);
dt1.set("value1", "some string");
em.persist(dt1);
em.flush();
DynamicEntity jpqlEntity = em.createQuery("SELECT s FROM Simple s", dt.getJavaClass()).getSingleResult();
DynamicEntity foundEntity = em.find(dt.getJavaClass(), 1);
Assert.assertEquals(jpqlEntity, foundEntity);
et.commit();
} catch (RollbackException e) {
et.rollback();
throw new RuntimeException(e);
}
}
use of org.eclipse.persistence.logging.SessionLog in project eclipselink by eclipse-ee4j.
the class MOXyJsonProvider method readFrom.
/*
* @see jakarta.ws.rs.ext.MessageBodyReader#readFrom(java.lang.Class, java.lang.reflect.Type, java.lang.annotation.Annotation[], jakarta.ws.rs.core.MediaType, jakarta.ws.rs.core.MultivaluedMap, java.io.InputStream)
*/
@Override
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException, WebApplicationException {
try {
if (null == genericType) {
genericType = type;
}
Set<Class<?>> domainClasses = getDomainClasses(genericType);
JAXBContext jaxbContext = getJAXBContext(domainClasses, annotations, mediaType, httpHeaders);
SessionLog logger = AbstractSessionLog.getLog();
if (logger.shouldLog(SessionLog.FINE, SessionLog.MOXY)) {
logger.log(SessionLog.FINE, SessionLog.MOXY, "moxy_read_from_moxy_json_provider", new Object[0]);
}
Unmarshaller unmarshaller = jaxbContext.createUnmarshaller();
unmarshaller.setProperty(UnmarshallerProperties.MEDIA_TYPE, MediaType.APPLICATION_JSON);
unmarshaller.setProperty(UnmarshallerProperties.JSON_ATTRIBUTE_PREFIX, attributePrefix);
unmarshaller.setProperty(UnmarshallerProperties.JSON_INCLUDE_ROOT, includeRoot);
unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_PREFIX_MAPPER, namespacePrefixMapper);
unmarshaller.setProperty(UnmarshallerProperties.JSON_NAMESPACE_SEPARATOR, namespaceSeperator);
if (null != valueWrapper) {
unmarshaller.setProperty(UnmarshallerProperties.JSON_VALUE_WRAPPER, valueWrapper);
}
unmarshaller.setProperty(UnmarshallerProperties.JSON_WRAPPER_AS_ARRAY_NAME, wrapperAsArrayName);
preReadFrom(type, genericType, annotations, mediaType, httpHeaders, unmarshaller);
StreamSource jsonSource;
Map<String, String> mediaTypeParameters = null;
if (null != mediaType) {
mediaTypeParameters = mediaType.getParameters();
}
if (null != mediaTypeParameters && mediaTypeParameters.containsKey(CHARSET)) {
String charSet = mediaTypeParameters.get(CHARSET);
Reader entityReader = new InputStreamReader(entityStream, charSet);
jsonSource = new StreamSource(entityReader);
} else {
jsonSource = new StreamSource(entityStream);
}
Class<?> domainClass = getDomainClass(domainClasses);
JAXBElement<?> jaxbElement = unmarshaller.unmarshal(jsonSource, domainClass);
if (type.isAssignableFrom(JAXBElement.class)) {
return jaxbElement;
} else {
Object value = jaxbElement.getValue();
if (value instanceof ArrayList) {
if (type.isArray()) {
ArrayList<Object> arrayList = (ArrayList<Object>) value;
int arrayListSize = arrayList.size();
boolean wrapItemInJAXBElement = wrapItemInJAXBElement(genericType);
Object array;
if (wrapItemInJAXBElement) {
array = Array.newInstance(JAXBElement.class, arrayListSize);
} else {
array = Array.newInstance(domainClass, arrayListSize);
}
for (int x = 0; x < arrayListSize; x++) {
Object element = handleJAXBElement(arrayList.get(x), domainClass, wrapItemInJAXBElement);
Array.set(array, x, element);
}
return array;
} else {
ContainerPolicy containerPolicy;
if (type.isAssignableFrom(List.class) || type.isAssignableFrom(ArrayList.class) || type.isAssignableFrom(Collection.class)) {
containerPolicy = new CollectionContainerPolicy(ArrayList.class);
} else if (type.isAssignableFrom(Set.class)) {
containerPolicy = new CollectionContainerPolicy(HashSet.class);
} else if (type.isAssignableFrom(Deque.class) || type.isAssignableFrom(Queue.class)) {
containerPolicy = new CollectionContainerPolicy(LinkedList.class);
} else if (type.isAssignableFrom(NavigableSet.class) || type.isAssignableFrom(SortedSet.class)) {
containerPolicy = new CollectionContainerPolicy(TreeSet.class);
} else {
containerPolicy = new CollectionContainerPolicy(type);
}
Object container = containerPolicy.containerInstance();
boolean wrapItemInJAXBElement = wrapItemInJAXBElement(genericType);
for (Object element : (Collection<Object>) value) {
element = handleJAXBElement(element, domainClass, wrapItemInJAXBElement);
containerPolicy.addInto(element, container, null);
}
return container;
}
} else {
return value;
}
}
} catch (UnmarshalException unmarshalException) {
ResponseBuilder builder = Response.status(Status.BAD_REQUEST);
throw new WebApplicationException(unmarshalException, builder.build());
} catch (JAXBException jaxbException) {
throw new WebApplicationException(jaxbException);
} catch (NullPointerException nullPointerException) {
throw new WebApplicationException(JSONException.errorInvalidDocument(nullPointerException));
}
}
Aggregations