Search in sources :

Example 1 with InjectionException

use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.

the class PersistenceContextAnnotationProcessor method buildProvider.

@Override
public MinijaxProvider<EntityManager> buildProvider(final MinijaxInjectorState state, final Class<EntityManager> type, final Annotation[] annotations) {
    final PersistenceContext persistenceContext = getPersistenceContextAnnotation(annotations);
    final EntityManagerFactory emf = factories.get(persistenceContext.name());
    if (emf == null) {
        throw new InjectionException("Persistence context \"" + persistenceContext.name() + "\" not found");
    }
    return new EntityManagerProvider(emf);
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) EntityManagerFactory(jakarta.persistence.EntityManagerFactory) PersistenceContext(jakarta.persistence.PersistenceContext)

Example 2 with InjectionException

use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.

the class ConstructorProvider method get.

@Override
public T get(final Object context) {
    try {
        final T result = ctor.newInstance(getParams(paramProviders, context));
        initImpl(result, context);
        return result;
    } catch (final InvocationTargetException ex) {
        final Throwable inner = ex.getCause();
        throw new InjectionException(inner.getMessage(), inner);
    } catch (final Exception e) {
        throw new InjectionException(String.format("Can't instantiate %s", ctor), e);
    }
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException) InjectionException(jakarta.enterprise.inject.InjectionException) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 3 with InjectionException

use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.

the class EntityProvider method get.

@SuppressWarnings("unchecked")
@Override
public T get(final Object obj) {
    final MinijaxRequestContext context = (MinijaxRequestContext) obj;
    // If you call getInputStream -- even if you don't read from it -- the input stream is moved.
    if (entityClass == MultivaluedMap.class) {
        return (T) context.getForm().asForm().asMap();
    }
    final InputStream entityStream = context.getEntityStream();
    try {
        return EntityUtils.readEntity(entityClass, genericType, annotations, mediaType, context, entityStream);
    } catch (final IOException ex) {
        throw new InjectionException(ex.getMessage(), ex);
    }
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) MinijaxRequestContext(org.minijax.rs.MinijaxRequestContext) InputStream(java.io.InputStream) IOException(java.io.IOException)

Example 4 with InjectionException

use of jakarta.enterprise.inject.InjectionException in project minijax by minijax.

the class MinijaxInjector method buildProvider.

@SuppressWarnings("unchecked")
private <T> MinijaxProvider<T> buildProvider(final Key<T> key, final Set<Key<?>> chain, final Annotation[] fieldAnnotations) {
    FieldAnnotationProcessor<T> processor = null;
    if (fieldAnnotations != null) {
        for (final Annotation fieldAnnotation : fieldAnnotations) {
            final FieldAnnotationProcessor<T> p = (FieldAnnotationProcessor<T>) fieldAnnotationProcessors.get(fieldAnnotation.annotationType());
            if (p != null) {
                if (processor != null) {
                    throw new InjectionException("Conflicting field annotations");
                }
                processor = p;
            }
        }
    }
    if (processor == null) {
        processor = new DefaultFieldAnnotationProcessor<>();
    }
    MinijaxProvider<T> provider = processor.buildProvider(new MinijaxInjectorState(this, key, chain), key.getType(), fieldAnnotations);
    final Annotation[] typeAnnotations = key.getType().getAnnotations();
    for (final Annotation typeAnnotation : typeAnnotations) {
        final TypeAnnotationProcessor<T> p = (TypeAnnotationProcessor<T>) typeAnnotationProcessors.get(typeAnnotation.annotationType());
        if (p != null) {
            provider = p.buildProvider(provider, typeAnnotations);
        }
    }
    return provider;
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) TypeAnnotationProcessor(org.minijax.cdi.annotation.TypeAnnotationProcessor) FieldAnnotationProcessor(org.minijax.cdi.annotation.FieldAnnotationProcessor) DefaultFieldAnnotationProcessor(org.minijax.cdi.annotation.DefaultFieldAnnotationProcessor) Annotation(java.lang.annotation.Annotation)

Example 5 with InjectionException

use of jakarta.enterprise.inject.InjectionException in project helidon by oracle.

the class CDISEPlatform method initializeExternalTransactionController.

/**
 * Overrides the {@link
 * ServerPlatformBase#initializeExternalTransactionController()}
 * method to {@linkplain #disableJTA() disable JTA} if there is no
 * {@link TransactionManager} bean present in CDI before invoking
 * the {@linkplain
 * ServerPlatformBase#initializeExternalTransactionController()
 * superclass implementation}.
 *
 * <p>This method also acquires a {@link DataSource} from
 * {@linkplain CDI CDI} proactively, and {@linkplain
 * JNDIConnector#setDataSource(DataSource) installs it} to
 * pre&euml;mpt any JNDI operations.</p>
 *
 * @exception ValidationException if a {@link DataSource} could
 * not be acquired
 *
 * @see ServerPlatformBase#initializeExternalTransactionController()
 *
 * @see Session#getDatasourceLogin()
 *
 * @see DatasourceLogin#getConnector()
 *
 * @see JNDIConnector
 *
 * @see JNDIConnector#getName()
 *
 * @see JNDIConnector#setDataSource(DataSource)
 */
@Override
public void initializeExternalTransactionController() {
    final CDI<Object> cdi = CDI.current();
    assert cdi != null;
    if (cdi.select(TransactionManager.class).isUnsatisfied()) {
        this.disableJTA();
    }
    super.initializeExternalTransactionController();
    // See https://github.com/oracle/helidon/issues/949.  This is
    // the only spot where we can actually change the Connector
    // that is used by EclipseLink to look up a data source during
    // JPA "SE mode" persistence unit acquisition such that it
    // doesn't get overwritten by other EclipseLink internals.
    final Session session = this.getDatabaseSession();
    if (session != null) {
        final Object login = session.getDatasourceLogin();
        if (login instanceof DatasourceLogin) {
            final Object connector = ((DatasourceLogin) login).getConnector();
            if (connector instanceof JNDIConnector) {
                final JNDIConnector jndiConnector = (JNDIConnector) connector;
                final String dataSourceName = jndiConnector.getName();
                if (dataSourceName != null) {
                    try {
                        jndiConnector.setDataSource(cdi.select(DataSource.class, NamedLiteral.of(dataSourceName)).get());
                    } catch (final InjectionException injectionExceptionOfAnyKind) {
                        throw ValidationException.cannotAcquireDataSource(dataSourceName, injectionExceptionOfAnyKind);
                    }
                }
            }
        }
    }
}
Also used : InjectionException(jakarta.enterprise.inject.InjectionException) DatasourceLogin(org.eclipse.persistence.sessions.DatasourceLogin) TransactionManager(jakarta.transaction.TransactionManager) JNDIConnector(org.eclipse.persistence.sessions.JNDIConnector) DatabaseSession(org.eclipse.persistence.sessions.DatabaseSession) Session(org.eclipse.persistence.sessions.Session)

Aggregations

InjectionException (jakarta.enterprise.inject.InjectionException)6 Annotation (java.lang.annotation.Annotation)2 InjectionPoint (jakarta.enterprise.inject.spi.InjectionPoint)1 ProcessInjectionPoint (jakarta.enterprise.inject.spi.ProcessInjectionPoint)1 EntityManagerFactory (jakarta.persistence.EntityManagerFactory)1 PersistenceContext (jakarta.persistence.PersistenceContext)1 TransactionManager (jakarta.transaction.TransactionManager)1 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 DatabaseSession (org.eclipse.persistence.sessions.DatabaseSession)1 DatasourceLogin (org.eclipse.persistence.sessions.DatasourceLogin)1 JNDIConnector (org.eclipse.persistence.sessions.JNDIConnector)1 Session (org.eclipse.persistence.sessions.Session)1 DefaultFieldAnnotationProcessor (org.minijax.cdi.annotation.DefaultFieldAnnotationProcessor)1 FieldAnnotationProcessor (org.minijax.cdi.annotation.FieldAnnotationProcessor)1 TypeAnnotationProcessor (org.minijax.cdi.annotation.TypeAnnotationProcessor)1 MinijaxRequestContext (org.minijax.rs.MinijaxRequestContext)1