Search in sources :

Example 16 with SessionLog

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);
    }
}
Also used : AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) SAXNotSupportedException(org.xml.sax.SAXNotSupportedException) SAXNotRecognizedException(org.xml.sax.SAXNotRecognizedException) ParserConfigurationException(javax.xml.parsers.ParserConfigurationException) SAXParserFactory(javax.xml.parsers.SAXParserFactory)

Example 17 with SessionLog

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;
}
Also used : DefaultSessionLog(org.eclipse.persistence.logging.DefaultSessionLog) SessionLog(org.eclipse.persistence.logging.SessionLog) ConversionManager(org.eclipse.persistence.internal.helper.ConversionManager) PrivilegedNewInstanceFromClass(org.eclipse.persistence.internal.security.PrivilegedNewInstanceFromClass) ValidationException(org.eclipse.persistence.exceptions.ValidationException) PrivilegedActionException(java.security.PrivilegedActionException) SessionLoaderException(org.eclipse.persistence.exceptions.SessionLoaderException)

Example 18 with SessionLog

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);
}
Also used : SessionLog(org.eclipse.persistence.logging.SessionLog)

Example 19 with SessionLog

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);
    }
}
Also used : DynamicClassLoader(org.eclipse.persistence.dynamic.DynamicClassLoader) EntityTransaction(jakarta.persistence.EntityTransaction) DynamicEntity(org.eclipse.persistence.dynamic.DynamicEntity) DynamicType(org.eclipse.persistence.dynamic.DynamicType) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) DynamicHelper(org.eclipse.persistence.dynamic.DynamicHelper) RollbackException(jakarta.persistence.RollbackException) SessionLog(org.eclipse.persistence.logging.SessionLog) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) JPADynamicTypeBuilder(org.eclipse.persistence.jpa.dynamic.JPADynamicTypeBuilder) DynamicTypeBuilder(org.eclipse.persistence.dynamic.DynamicTypeBuilder) JPADynamicHelper(org.eclipse.persistence.jpa.dynamic.JPADynamicHelper) Session(org.eclipse.persistence.sessions.Session) Test(org.junit.Test)

Example 20 with SessionLog

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));
    }
}
Also used : CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) SortedSet(java.util.SortedSet) Set(java.util.Set) NavigableSet(java.util.NavigableSet) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) LinkedHashSet(java.util.LinkedHashSet) WebApplicationException(jakarta.ws.rs.WebApplicationException) ArrayList(java.util.ArrayList) Reader(java.io.Reader) InputStreamReader(java.io.InputStreamReader) MessageBodyReader(jakarta.ws.rs.ext.MessageBodyReader) JAXBContext(jakarta.xml.bind.JAXBContext) UnmarshalException(jakarta.xml.bind.UnmarshalException) Unmarshaller(jakarta.xml.bind.Unmarshaller) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Queue(java.util.Queue) InputStreamReader(java.io.InputStreamReader) StreamSource(javax.xml.transform.stream.StreamSource) JAXBException(jakarta.xml.bind.JAXBException) JAXBElement(jakarta.xml.bind.JAXBElement) Deque(java.util.Deque) LinkedList(java.util.LinkedList) SessionLog(org.eclipse.persistence.logging.SessionLog) AbstractSessionLog(org.eclipse.persistence.logging.AbstractSessionLog) ContainerPolicy(org.eclipse.persistence.internal.queries.ContainerPolicy) CollectionContainerPolicy(org.eclipse.persistence.internal.queries.CollectionContainerPolicy) Collection(java.util.Collection)

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