Java 类javax.enterprise.inject.spi.DefinitionException 实例源码

项目:camel-cdi    文件:XmlCdiBeanFactory.java   
private SyntheticBean<?> proxyFactoryBean(Bean<?> context, CamelProxyFactoryDefinition proxy, URL url) {
    if (isEmpty(proxy.getServiceRef()) && isEmpty(proxy.getServiceUrl()))
        throw new DefinitionException(
            format("Missing [%s] or [%s] attribute for imported bean [%s] from resource [%s]",
                "serviceRef", "serviceUrl", proxy.getId(), url));

    return new XmlProxyFactoryBean<>(manager,
        new SyntheticAnnotated(proxy.getServiceInterface(),
            manager.createAnnotatedType(proxy.getServiceInterface()).getTypeClosure(),
            APPLICATION_SCOPED, ANY, NamedLiteral.of(proxy.getId())),
        proxy.getServiceInterface(),
        bean -> "imported bean [" + proxy.getId() + "] "
            + "from resource [" + url + "] "
            + "with qualifiers " + bean.getQualifiers(),
        context, proxy);
}
项目:tomee    文件:Assembler.java   
private void checkBuiltInResourceTypes(final ResourceReference reference, final String jndi) {
    final Class<?> resourceType = reference.getResourceType();
    if ("java:comp/BeanManager".equals(jndi) && resourceType != BeanManager.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a BeanManager");
    } else if ("java:comp/TransactionSynchronizationRegistry".equals(jndi) && resourceType != TransactionSynchronizationRegistry.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a TransactionSynchronizationRegistry");
    } else if ("java:comp/TransactionManager".equals(jndi) && resourceType != TransactionManager.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a TransactionManager");
    } else if ("java:comp/ValidatorFactory".equals(jndi) && resourceType != ValidatorFactory.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a ValidatorFactory");
    } else if ("java:comp/Validator".equals(jndi) && resourceType != Validator.class) {
        throw new DefinitionException(
                "Resource " + reference.getJndiName() + " in " + reference.getOwnerClass() + " can't be cast to a Validator");
    }
}
项目:tomee    文件:AppValidator.java   
public AppModule validate(final AppModule appModule) {
    final ClassLoader loader = Thread.currentThread().getContextClassLoader();
    Thread.currentThread().setContextClassLoader(appModule.getClassLoader()); // be sure to not mix classloaders
    try {
        final ValidationRule[] rules = getValidationRules();
        for (int i = 0; i < rules.length; i++) {
            rules[i].validate(appModule);
        }
    } catch (final DefinitionException de) {
        throw de;
    } catch (final Throwable e) {
        e.printStackTrace(System.out);
        final ValidationError err = new ValidationError("cannot.validate");
        err.setCause(e);
        err.setDetails(e.getMessage());
        appModule.getValidation().addError(err);
    } finally {
        Thread.currentThread().setContextClassLoader(loader);
    }
    return appModule;
}
项目:tomee    文件:CheckInjectionPointUsage.java   
@Override
public void validate(final EjbModule ejbModule) {
    if (ejbModule.getBeans() == null) {
        return;
    }

    try {
        for (final Field field : ejbModule.getFinder().findAnnotatedFields(Inject.class)) {
            if (!field.getType().equals(InjectionPoint.class) || !HttpServlet.class.isAssignableFrom(field.getDeclaringClass())) {
                continue;
            }

            final Annotation[] annotations = field.getAnnotations();
            if (annotations.length == 1 || (annotations.length == 2 && field.getAnnotation(Default.class) != null)) {
                throw new DefinitionException("Can't inject InjectionPoint in " + field.getDeclaringClass());
            } // else we should check is there is no other qualifier than @Default but too early
        }
    } catch (final NoClassDefFoundError noClassDefFoundError) {
        // ignored: can't check but maybe it is because of an optional dep so ignore it
        // not important to skip it since the failure will be reported elsewhere
        // this validator doesn't check it
    }
}
项目:tomee    文件:CdiEjbBean.java   
@Override
public InjectionTarget<T> createInjectionTarget(final Bean<T> bean) {
    final EjbInjectionTargetImpl<T> injectionTarget = new EjbInjectionTargetImpl<T>(getAnnotatedType(), createInjectionPoints(bean), getWebBeansContext());
    final InjectionTarget<T> it = getWebBeansContext().getWebBeansUtil().fireProcessInjectionTargetEvent(injectionTarget, getAnnotatedType()).getInjectionTarget();

    for (final InjectionPoint ip : it.getInjectionPoints()) {
        if (ip.getType() != UserTransaction.class) {
            continue;
        }
        if (beanContext.getTransactionType() != TransactionType.BeanManaged) {
            throw new DefinitionException("@Inject UserTransaction is only valid for BeanManaged beans");
        }
    }

    if (!EjbInjectionTargetImpl.class.isInstance(it)) {
        return new EjbInjectionTargetImpl<T>(injectionTarget, it);
    }
    return it;
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureRatioPosTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB2.jar")
        .addClasses(CircuitBreakerClientForValidationFailureRatioPos.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB2.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureReqVolNegTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB5.jar")
        .addClasses(CircuitBreakerClientForValidationReqVolNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB5.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidRetryJitterTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry4.jar")
        .addClasses(RetryClientForValidationJitter.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry4.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidBulkheadAsynchQueueTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidBulkhead3.jar")
        .addClasses(BulkheadClientForValidationAsynchQueue.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidBulkhead3.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidRetryDelayTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry1.jar")
        .addClasses(RetryClientForValidationDelay.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry1.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidRetryDelayDurationTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy2() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry3.jar")
        .addClasses(RetryClientForValidationDelayDuration.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry3.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidBulkheadValueTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidBulkhead1.jar")
        .addClasses(BulkheadClientForValidation.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidBulkhead1.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureRatioNegTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB3.jar")
        .addClasses(CircuitBreakerClientForValidationFailureRatioNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB3.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureReqVol0Test.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB4.jar")
        .addClasses(CircuitBreakerClientForValidationReqVol0.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB4.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidTimeoutValueTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidTimeout.jar")
        .addClasses(TimeoutClientForValidation.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidTimeout.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureSuccessNegTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB7.jar")
        .addClasses(CircuitBreakerClientForValidationSuccessNeg.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB7.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerFailureSuccess0Test.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB6.jar")
        .addClasses(CircuitBreakerClientForValidationSuccess0.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB6.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidCircuitBreakerDelayTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidCB1.jar")
        .addClasses(CircuitBreakerClientForValidationDelay.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidCB1.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:InvalidRetryMaxRetriesTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalidRetry2.jar")
        .addClasses(RetryClientForValidationMaxRetries.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidRetry2.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:IncompatibleFallbackPolicies.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalid.jar")
        .addClasses(FallbackClientWithBothFallbacks.class, IncompatibleFallbackHandler.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidFallbackPolicy.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:IncompatibleFallbackMethodWithArgsTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deployAnotherApp() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "ftInvalid.jar")
            .addClasses(FallbackMethodWithArgsClient.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftInvalidFallbackMethodWithArgs.war")
            .addAsLibrary(testJar);
    return war;
}
项目:microprofile-fault-tolerance    文件:IncompatibleFallbackTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
        .create(JavaArchive.class, "ftInvalid.jar")
        .addClasses(FallbackClient.class, IncompatibleFallbackHandler.class)
        .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
        .as(JavaArchive.class);

    return ShrinkWrap
        .create(WebArchive.class, "ftInvalidFallbackHandler.war")
        .addAsLibrary(testJar);
}
项目:microprofile-fault-tolerance    文件:IncompatibleFallbackMethodTest.java   
@Deployment
@ShouldThrowException(value = DefinitionException.class, testable = true)
public static WebArchive deployAnotherApp() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "ftInvalid.jar")
            .addClasses(FallbackMethodClient.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "ftInvalidFallbackMethod.war")
            .addAsLibrary(testJar);
    return war;
}
项目:wildfly-swarm    文件:SwarmDeploymentExceptionTransformer.java   
public Throwable transform(Throwable throwable) {

        // Arquillian sometimes returns InvocationException with nested
        // exception and sometimes exception itself
        @SuppressWarnings("unchecked")
        List<Throwable> throwableList = ExceptionUtils.getThrowableList(throwable);
        if (throwableList.isEmpty())
            return throwable;

        Throwable root = null;

        if (throwableList.size() == 1) {
            root = throwable;
        } else {
            root = ExceptionUtils.getRootCause(throwable);
        }

        if (root instanceof DeploymentException || root instanceof DefinitionException) {
            return root;
        }
        if (isFragmentFound(DEPLOYMENT_EXCEPTION_FRAGMENTS, root)) {
            return new DeploymentException(root.getMessage());
        }
        if (isFragmentFound(DEFINITION_EXCEPTION_FRAGMENTS, root)) {
            return new DefinitionException(root.getMessage());
        }
        return throwable;
    }
项目:tomee    文件:CdiEjbBean.java   
public CdiEjbBean(final BeanContext bc, final WebBeansContext webBeansContext, final Class beanClass, final AnnotatedType<T> at,
                  final InjectionTargetFactoryImpl<T> factory, final BeanAttributes<T> attributes) {
    super(webBeansContext, toSessionType(bc.getComponentType()), at,
            new EJBBeanAttributesImpl<T>(bc, attributes),
            beanClass, factory);
    this.beanContext = bc;
    bc.set(Bean.class, this);
    passivatingId = bc.getDeploymentID() + getReturnType().getName();

    final boolean stateful = BeanType.STATEFUL.equals(bc.getComponentType());
    final boolean isDependent = getScope().equals(Dependent.class);
    isDependentAndStateful = isDependent && stateful;
    if (webBeansContext.getBeanManagerImpl().isPassivatingScope(getScope()) && stateful) {
        if (!getBeanContext().isPassivable()) {
            throw new DefinitionException(
                    getBeanContext().getBeanClass()
                            + " is a not apssivation-capable @Stateful with a scope "
                            + getScope().getSimpleName() + " which need passivation");
        }
        passivable = true;
    } else {
        passivable = false;
    }
    if (!isDependent) {
        for (final Type type : attributes.getTypes()) {
            if (ParameterizedType.class.isInstance(type)) {
                throw new DefinitionException("Parameterized session bean should be @Dependent: " + beanClass);
            }
        }
    }
    if (getAnnotatedType().isAnnotationPresent(Interceptor.class) || getAnnotatedType().isAnnotationPresent(Decorator.class)) {
        throw new DefinitionException("An EJB can't be an interceptor or a decorator: " + beanClass);
    }
}
项目:wildfly-swarm    文件:AsynchronousMethodNotFutureTest.java   
@ShouldThrowException(DefinitionException.class)
@Deployment
public static JavaArchive createTestArchive() {
    return TestArchive.createBase("AsynchronousMethodNotFutureTest.jar")
            .addPackage(AsynchronousMethodNotFutureTest.class.getPackage());
}
项目:wildfly-swarm    文件:ParameterizedFallbackMethodTest.java   
@ShouldThrowException(DefinitionException.class)
@Deployment
public static JavaArchive createTestArchive() {
    return TestArchive.createBase("ParameterizedFallbackMethodTest.jar")
            .addPackage(ParameterizedFallbackMethodTest.class.getPackage());
}
项目:camel-cdi    文件:XmlCdiBeanFactory.java   
private static DefinitionException attributeNotSupported(String attribute, ErrorHandlerType type, String id) {
    return new DefinitionException(
        format("Attribute [%s] is not supported by error handler type [%s], in error handler with id [%s]",
            attribute, type, id));
}
项目:tomee    文件:AnnotationDeployer.java   
private static void failIfCdiProducer(final Member member, final String type) {
    if (FieldMember.class.isInstance(member) && FieldMember.class.cast(member).field.getAnnotation(Produces.class) != null) {
        throw new DefinitionException(FieldMember.class.cast(member).field + " is not a " + type);
    }
}