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

项目:wildfly-microprofile-config    文件:ConfigExtension.java   
public void validate(@Observes AfterDeploymentValidation add, BeanManager bm) {
    List<String> deploymentProblems = new ArrayList<>();

    Config config = ConfigProvider.getConfig();
    for (InjectionPoint injectionPoint : injectionPoints) {
        Type type = injectionPoint.getType();
        ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
        if (type instanceof Class) {
            String key = getConfigKey(injectionPoint, configProperty);

            if (!config.getOptionalValue(key, (Class)type).isPresent()) {
                String defaultValue = configProperty.defaultValue();
                if (defaultValue == null ||
                        defaultValue.equals(ConfigProperty.UNCONFIGURED_VALUE)) {
                    deploymentProblems.add("No Config Value exists for " + key);
                }
            }
        }
    }

    if (!deploymentProblems.isEmpty()) {
        add.addDeploymentProblem(new DeploymentException("Error while validating Configuration\n"
                + String.join("\n", deploymentProblems)));
    }

}
项目:wildfly-swarm    文件:JWTAuthContextInfoProvider.java   
@Produces
Optional<JWTAuthContextInfo> getOptionalContextInfo() {
    if (!publicKeyPemEnc.isPresent()) {
        return Optional.empty();
    }
    JWTAuthContextInfo contextInfo = new JWTAuthContextInfo();
    try {
        RSAPublicKey pk = (RSAPublicKey) KeyUtils.decodePublicKey(publicKeyPemEnc.get());
        contextInfo.setSignerKey(pk);
    } catch (Exception e) {
        throw new DeploymentException(e);
    }
    if (issuedBy != null && !issuedBy.equals("NONE")) {
        contextInfo.setIssuedBy(issuedBy);
    }
    if (expGracePeriodSecs.isPresent()) {
        contextInfo.setExpGracePeriodSecs(expGracePeriodSecs.get());
    }
    return Optional.of(contextInfo);
}
项目:wildfly-swarm    文件:MPJWTExtension.java   
void processClaimValueInjections(@Observes ProcessInjectionPoint pip) {
    log.debugf("pipRaw: %s", pip.getInjectionPoint());
    InjectionPoint ip = pip.getInjectionPoint();
    if (ip.getAnnotated().isAnnotationPresent(Claim.class) && ip.getType() instanceof Class) {
        Class rawClass = (Class) ip.getType();
        if (Modifier.isFinal(rawClass.getModifiers())) {
            Claim claim = ip.getAnnotated().getAnnotation(Claim.class);
            rawTypes.add(ip.getType());
            rawTypeQualifiers.add(claim);
            log.debugf("+++ Added Claim raw type: %s", ip.getType());
            Class declaringClass = ip.getMember().getDeclaringClass();
            Annotation[] appScoped = declaringClass.getAnnotationsByType(ApplicationScoped.class);
            Annotation[] sessionScoped = declaringClass.getAnnotationsByType(SessionScoped.class);
            if ((appScoped != null && appScoped.length > 0) || (sessionScoped != null && sessionScoped.length > 0)) {
                String err = String.format("A raw type cannot be injected into application/session scope: IP=%s", ip);
                pip.addDefinitionError(new DeploymentException(err));
            }

        }
    }
}
项目:javaConfig    文件:ConfigExtension.java   
public void validate(@Observes AfterDeploymentValidation add) {
    List<String> deploymentProblems = new ArrayList<>();

    config = ConfigProvider.getConfig();

    for (InjectionPoint injectionPoint : injectionPoints) {
        Type type = injectionPoint.getType();
        ConfigProperty configProperty = injectionPoint.getAnnotated().getAnnotation(ConfigProperty.class);
        if (type instanceof Class) {
            // a direct injection of a ConfigProperty
            // that means a Converter must exist.
            String key = ConfigInjectionBean.getConfigKey(injectionPoint, configProperty);
            if (!config.getOptionalValue(key, (Class) type).isPresent()) {
                deploymentProblems.add("No Config Value exists for " + key);
            }
        }
    }

    if (!deploymentProblems.isEmpty()) {
        add.addDeploymentProblem(new DeploymentException("Error while validating Configuration\n"
                                                         + String.join("\n", deploymentProblems)));
    }

}
项目:camel-cdi    文件:CamelContextOsgiProducer.java   
@Override
public T produce(CreationalContext<T> cc) {
    T context = super.produce(cc);

    // Register the context in the OSGi registry
    BundleContext bundle = BundleContextUtils.getBundleContext(getClass());
    context.getManagementStrategy().addEventNotifier(new OsgiCamelContextPublisher(bundle));

    if (!(context instanceof DefaultCamelContext))
        // Fail fast for the time being to avoid side effects by some methods get declared on the CamelContext interface
        throw new DeploymentException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");

    DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
    adapted.setRegistry(OsgiCamelContextHelper.wrapRegistry(context, context.getRegistry(), bundle));
    CamelContextNameStrategy strategy = context.getNameStrategy();
    OsgiCamelContextHelper.osgiUpdate(adapted, bundle);
    // FIXME: the above call should not override explicit strategies provided by the end user or should decorate them instead of overriding them completely
    if (!(strategy instanceof DefaultCamelContextNameStrategy))
        context.setNameStrategy(strategy);

    return context;
}
项目:camel-cdi    文件:CdiCamelExtension.java   
private boolean addRouteToContext(Bean<?> routeBean, Bean<?> contextBean, BeanManager manager, AfterDeploymentValidation adv) {
    try {
        CamelContext context = getReference(manager, CamelContext.class, contextBean);
        try {
            Object route = getReference(manager, Object.class, routeBean);
            if (route instanceof RoutesBuilder)
                context.addRoutes((RoutesBuilder) route);
            else if (route instanceof RouteContainer)
                context.addRouteDefinitions(((RouteContainer) route).getRoutes());
            else
                throw new IllegalArgumentException(
                    "Invalid routes type [" + routeBean.getBeanClass().getName() + "], "
                        + "must be either of type RoutesBuilder or RouteContainer!");
            return true;
        } catch (Exception cause) {
            adv.addDeploymentProblem(
                new DeploymentException("Error adding routes of type [" + routeBean.getBeanClass().getName() + "] "
                    + "to Camel context [" + context.getName() + "]", cause));
        }
    } catch (Exception exception) {
        adv.addDeploymentProblem(exception);
    }
    return false;
}
项目:ConfigJSR    文件:MissingConverterOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "missingConverterOnInstanceInjectionTest.jar")
            .addClass(CustomConverterBean.class)
            .addAsManifestResource(new StringAsset("my.customtype.value=xxxxx"), "javaconfig.properties")
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "missingConverterOnInstanceInjectionTest.war")
            .addAsLibrary(testJar);
    return war;
}
项目:ConfigJSR    文件:MissingValueOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "missingValueOnInstanceInjectionTest.jar")
            .addClass(ConfigOwner.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "missingValueOnInstanceInjectionTest.war")
            .addAsLibrary(testJar);
    return war;
}
项目:ConfigJSR    文件:WrongConverterOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "wrongConverterOnInstanceInjectionTest.jar")
            .addClass(ConfigOwner.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsManifestResource(new StringAsset("my.long.value=xxxxx"), "javaconfig.properties")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "wrongConverterOnInstanceInjectionTest.war")
            .addAsLibrary(testJar);
    return war;
}
项目:microprofile-config    文件:MissingConverterOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "missingConverterOnInstanceInjectionTest.jar")
            .addClass(CustomConverterBean.class)
            .addAsManifestResource(new StringAsset("my.customtype.value=xxxxx"), "microprofile-config.properties")
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "missingConverterOnInstanceInjectionTest.war")
            .addAsLibrary(testJar);
    return war;
}
项目:microprofile-config    文件:MissingValueOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "missingValueOnInstanceInjectionTest.jar")
            .addClass(ConfigOwner.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "missingValueOnInstanceInjectionTest.war")
            .addAsLibrary(testJar);
    return war;
}
项目:microprofile-config    文件:WrongConverterOnInstanceInjectionTest.java   
@ShouldThrowException(DeploymentException.class)
@Deployment
public static WebArchive deploy() {
    JavaArchive testJar = ShrinkWrap
            .create(JavaArchive.class, "wrongConverterOnInstanceInjectionTest.jar")
            .addClass(ConfigOwner.class)
            .addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
            .addAsManifestResource(new StringAsset("my.long.value=xxxxx"), "microprofile-config.properties")
            .as(JavaArchive.class);

    WebArchive war = ShrinkWrap
            .create(WebArchive.class, "wrongConverterOnInstanceInjectionTest.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;
    }
项目:wildfly-swarm    文件:MPJWTExtension.java   
/**
 * Collect the types of all Provider injection points annotated with {@linkplain Claim}.
 *
 * @param pip - the injection point event information
 */
void processClaimProviderInjections(@Observes ProcessInjectionPoint<?, ? extends Provider> pip) {
    log.debugf("pip: %s", pip.getInjectionPoint());
    final InjectionPoint ip = pip.getInjectionPoint();
    if (ip.getAnnotated().isAnnotationPresent(Claim.class)) {
        Claim claim = ip.getAnnotated().getAnnotation(Claim.class);
        if (claim.value().length() == 0 && claim.standard() == Claims.UNKNOWN) {
            throw new DeploymentException("@Claim at: " + ip + " has no name or valid standard enum setting");
        }
        boolean usesEnum = claim.standard() != Claims.UNKNOWN;
        final String claimName = usesEnum ? claim.standard().name() : claim.value();
        log.debugf("Checking Provider Claim(%s), ip: %s", claimName, ip);
        ClaimIP claimIP = claims.get(claimName);
        Type matchType = ip.getType();
        Type actualType = ((ParameterizedType) matchType).getActualTypeArguments()[0];
        // Don't add Optional as this is handled specially
        if (!optionalOrJsonValue(actualType)) {
            rawTypes.add(actualType);
        } else if (!actualType.getTypeName().startsWith("javax.json.Json")) {
            // Validate that this is not an Optional<JsonValue>
            Type innerType = ((ParameterizedType) actualType).getActualTypeArguments()[0];
            if (!innerType.getTypeName().startsWith("javax.json.Json")) {
                providerOptionalTypes.add(actualType);
                providerQualifiers.add(claim);
            }
        }
        rawTypeQualifiers.add(claim);
        ClaimIPType key = new ClaimIPType(claimName, actualType);
        if (claimIP == null) {
            claimIP = new ClaimIP(actualType, actualType, false, claim);
            claimIP.setProviderSite(true);
            claims.put(key, claimIP);
        }
        claimIP.getInjectionPoints().add(ip);
        log.debugf("+++ Added Provider Claim(%s) ip: %s", claimName, ip);

    }
}
项目:camel-cdi    文件:CamelContextProducer.java   
@Override
public T produce(CreationalContext<T> cc) {
    T context = super.produce(cc);

    // Do not override the name if it's been already set (in the bean constructor for example)
    if (context.getNameStrategy() instanceof DefaultCamelContextNameStrategy)
        context.setNameStrategy(nameStrategy(annotated));

    // Add bean registry and Camel injector
    if (context instanceof DefaultCamelContext) {
        DefaultCamelContext adapted = context.adapt(DefaultCamelContext.class);
        adapted.setRegistry(new CdiCamelRegistry(manager));
        adapted.setInjector(new CdiCamelInjector(context.getInjector(), manager));
    } else {
        // Fail fast for the time being to avoid side effects by the time these two methods get declared on the CamelContext interface
        throw new DeploymentException("Camel CDI requires Camel context [" + context.getName() + "] to be a subtype of DefaultCamelContext");
    }

    // Add event notifier if at least one observer is present
    Set<Annotation> qualifiers = annotated.getAnnotations().stream()
        .filter(isAnnotationType(Named.class).negate()
            .and(q -> manager.isQualifier(q.annotationType())))
        .collect(toSet());
    qualifiers.add(Any.Literal.INSTANCE);
    if (qualifiers.size() == 1)
        qualifiers.add(Default.Literal.INSTANCE);
    qualifiers.retainAll(manager.getExtension(CdiCamelExtension.class).getObserverEvents());
    if (!qualifiers.isEmpty())
        context.getManagementStrategy().addEventNotifier(new CdiEventNotifier(manager, qualifiers));

    return context;
}