diff --git a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/AbstractCdiBeanSupplier.java b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/AbstractCdiBeanSupplier.java index b681a2c3a2..9e438f1681 100644 --- a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/AbstractCdiBeanSupplier.java +++ b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/AbstractCdiBeanSupplier.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2014, 2021 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2014, 2023 Oracle and/or its affiliates. All rights reserved. * * This program and the accompanying materials are made available under the * terms of the Eclipse Public License v. 2.0, which is available at @@ -16,10 +16,13 @@ package org.glassfish.jersey.ext.cdi1x.internal; +import java.io.PrintWriter; +import java.io.StringWriter; import java.lang.annotation.Annotation; import java.util.Iterator; import java.util.NoSuchElementException; import java.util.Set; +import java.util.logging.Logger; import javax.enterprise.context.spi.Contextual; import javax.enterprise.context.spi.CreationalContext; @@ -44,6 +47,8 @@ */ public abstract class AbstractCdiBeanSupplier implements DisposableSupplier { + private static final Logger LOGGER = Logger.getLogger(AbstractCdiBeanSupplier.class.getName()); + final Class clazz; final InstanceManager referenceProvider; final Annotation[] qualifiers; @@ -115,7 +120,16 @@ private static T produce(InjectionTarget target, CreationalContext ctx try { return target.produce(ctx); } catch (Exception e) { - return im.create(clazz); + LOGGER.fine(LocalizationMessages.CDI_FAILED_LOADING(clazz, e.getMessage())); + try { + return im.create(clazz); + } catch (RuntimeException re) { + StringWriter sw = new StringWriter(); + PrintWriter pw = new PrintWriter(sw); + e.printStackTrace(pw); + LOGGER.warning(LocalizationMessages.CDI_FAILED_LOADING(clazz, sw.toString())); + throw re; + } } } diff --git a/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties b/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties index ee1f8e70d4..fcd79f3b05 100644 --- a/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties +++ b/ext/cdi/jersey-cdi1x/src/main/resources/org/glassfish/jersey/ext/cdi1x/internal/localization.properties @@ -1,5 +1,5 @@ # -# Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. +# Copyright (c) 2013, 2023 Oracle and/or its affiliates. All rights reserved. # Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved. # # This program and the accompanying materials are made available under the @@ -21,6 +21,7 @@ cdi.class.being.checked=Class, {0}, is being checked with Jersey CDI component p cdi.class.bound.with.cdi=Class, {0}, has been bound by Jersey CDI component provider. cdi.hk2.bean.registered=CDI beans backed by HK2 have been registered for the following types: {0} cdi.lookup.failed=Error when lookup instance of class, {0}, in CDI. +cdi.failed.loading=CDI failed instantiating the class {0} with {1}, falling back to HK2. cdi.multiple.locators.into.simple.app=Trying to register multiple service locators into single service locator application. cdi.provider.initialized=Jersey CDI component provider initialized. cdi.request.scoped.components.recognized=The following CDI types were recognized as request scoped components in Jersey: {0}.