Skip to content

Commit c15de11

Browse files
authored
Merge pull request #3845 from jGauravGupta/PAYARA-2518
addAnnotatedType now provide ID to prevent warning and provides new variants of CDI extension that allows integrators to prevent warnings regarding scanning all types.
2 parents 501befb + 393bb60 commit c15de11

File tree

8 files changed

+215
-76
lines changed

8 files changed

+215
-76
lines changed

connectors/jetty-connector/src/test/java/org/glassfish/jersey/jetty/connector/AsyncTest.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,8 @@ public void handleTimeout(AsyncResponse asyncResponse) {
110110
}
111111
});
112112
asyncResponse.setTimeout(1, TimeUnit.SECONDS);
113+
asyncResponse.resume(Response.status(Response.Status.SERVICE_UNAVAILABLE)
114+
.entity("Operation time out.").build());
113115

114116
new Thread(new Runnable() {
115117

connectors/jetty-connector/src/test/java/org/glassfish/jersey/jetty/connector/HelloWorldTest.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,6 @@ protected Application configure() {
7171

7272
@Override
7373
protected void configureClient(ClientConfig config) {
74-
config.property(ClientProperties.ASYNC_THREADPOOL_SIZE, 20);
7574
config.connectorProvider(new JettyConnectorProvider());
7675
}
7776

ext/cdi/jersey-cdi1x-servlet/src/main/java/org/glassfish/jersey/ext/cdi1x/servlet/internal/CdiExternalRequestScopeExtension.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
*
1414
* SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0
1515
*/
16-
16+
// Portions Copyright [2018] Payara Foundation and/or affiliates
1717
package org.glassfish.jersey.ext.cdi1x.servlet.internal;
1818

1919
import java.lang.annotation.Annotation;
@@ -57,7 +57,7 @@ public class CdiExternalRequestScopeExtension implements Extension {
5757
*/
5858
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscoveryEvent, final BeanManager beanManager) {
5959
requestScopeType = beanManager.createAnnotatedType(CdiExternalRequestScope.class);
60-
beforeBeanDiscoveryEvent.addAnnotatedType(requestScopeType);
60+
beforeBeanDiscoveryEvent.addAnnotatedType(requestScopeType, "Jersey " + CdiExternalRequestScope.class.getName());
6161
}
6262

6363
/**

ext/cdi/jersey-cdi1x-transaction/src/main/java/org/glassfish/jersey/ext/cdi1x/transaction/internal/TransactionalExceptionInterceptorProvider.java

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package org.glassfish.jersey.ext.cdi1x.transaction.internal;
1818

19+
import static java.lang.annotation.ElementType.FIELD;
20+
import static java.lang.annotation.ElementType.METHOD;
21+
import static java.lang.annotation.ElementType.PARAMETER;
22+
import static java.lang.annotation.ElementType.TYPE;
23+
import static java.lang.annotation.RetentionPolicy.RUNTIME;
24+
1925
import java.lang.annotation.Retention;
2026
import java.lang.annotation.Target;
2127
import java.util.List;
2228
import java.util.Set;
2329

24-
import javax.ws.rs.WebApplicationException;
25-
import javax.ws.rs.ext.ExceptionMapper;
26-
2730
import javax.annotation.Priority;
2831
import javax.enterprise.event.Observes;
2932
import javax.enterprise.inject.spi.AfterTypeDiscovery;
@@ -33,6 +36,8 @@
3336
import javax.inject.Qualifier;
3437
import javax.interceptor.Interceptor;
3538
import javax.transaction.TransactionalException;
39+
import javax.ws.rs.WebApplicationException;
40+
import javax.ws.rs.ext.ExceptionMapper;
3641

3742
import org.glassfish.jersey.ext.cdi1x.internal.CdiUtil;
3843
import org.glassfish.jersey.ext.cdi1x.internal.GenericCdiBeanSupplier;
@@ -41,12 +46,6 @@
4146
import org.glassfish.jersey.internal.inject.InjectionManager;
4247
import org.glassfish.jersey.server.spi.ComponentProvider;
4348

44-
import static java.lang.annotation.ElementType.FIELD;
45-
import static java.lang.annotation.ElementType.METHOD;
46-
import static java.lang.annotation.ElementType.PARAMETER;
47-
import static java.lang.annotation.ElementType.TYPE;
48-
import static java.lang.annotation.RetentionPolicy.RUNTIME;
49-
5049
/**
5150
* Jersey CDI extension that provides means to retain {@link WebApplicationException}
5251
* thrown from JAX-RS components implemented as CDI transactional beans.
@@ -100,10 +99,17 @@ private void afterTypeDiscovery(@Observes final AfterTypeDiscovery afterTypeDisc
10099
}
101100

102101
@SuppressWarnings("unused")
103-
private void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanDiscovery, final javax.enterprise.inject.spi
104-
.BeanManager beanManager) {
105-
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(WebAppExceptionHolder.class));
106-
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(WebAppExceptionInterceptor.class));
107-
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(TransactionalExceptionMapper.class));
102+
private void beforeBeanDiscovery(@Observes BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager) {
103+
addAnnotatedTypes(beforeBeanDiscovery, beanManager,
104+
WebAppExceptionHolder.class,
105+
WebAppExceptionInterceptor.class,
106+
TransactionalExceptionMapper.class
107+
);
108+
}
109+
110+
private static void addAnnotatedTypes(BeforeBeanDiscovery beforeBeanDiscovery, BeanManager beanManager, Class<?>... types) {
111+
for (Class<?> type : types) {
112+
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(type), "Jersey " + type.getName());
113+
}
108114
}
109115
}

ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java

Lines changed: 65 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -448,8 +448,72 @@ public boolean isAnnotationPresent(final Class<? extends Annotation> annotationT
448448
};
449449
}
450450

451+
private boolean containsJaxRsParameterizedCtor(final AnnotatedType annotatedType) {
452+
return containAnnotatedParameters(annotatedType.getConstructors(), JaxRsParamProducer.JAX_RS_STRING_PARAM_ANNOTATIONS);
453+
}
454+
455+
private boolean containsJaxRsConstructorInjection(final AnnotatedType annotatedType) {
456+
return containAnnotatedParameters(annotatedType.getConstructors(), JAX_RS_INJECT_ANNOTATIONS);
457+
}
458+
459+
private boolean containsJaxRsMethodInjection(final AnnotatedType annotatedType) {
460+
return containAnnotatedParameters(annotatedType.getMethods(), JAX_RS_INJECT_ANNOTATIONS);
461+
}
462+
463+
private boolean containsJaxRsFieldInjection(final AnnotatedType annotatedType) {
464+
return containAnnotation(annotatedType.getFields(), JAX_RS_INJECT_ANNOTATIONS);
465+
}
466+
467+
private boolean containAnnotatedParameters(final Collection<AnnotatedCallable> annotatedCallables,
468+
final Set<Class<? extends Annotation>> annotationSet) {
469+
for (final AnnotatedCallable c : annotatedCallables) {
470+
if (containAnnotation(c.getParameters(), annotationSet)) {
471+
return true;
472+
}
473+
}
474+
return false;
475+
}
476+
477+
private boolean containAnnotation(final Collection<Annotated> elements,
478+
final Set<Class<? extends Annotation>> annotationSet) {
479+
for (final Annotated element : elements) {
480+
if (hasAnnotation(element, annotationSet)) {
481+
return true;
482+
}
483+
}
484+
return false;
485+
}
486+
487+
private static boolean hasAnnotation(final Annotated element, final Set<Class<? extends Annotation>> annotations) {
488+
for (final Class<? extends Annotation> a : annotations) {
489+
if (element.isAnnotationPresent(a)) {
490+
return true;
491+
}
492+
}
493+
return false;
494+
}
495+
451496
@SuppressWarnings("unused")
452-
private void processAnnotatedType(@Observes
497+
private void afterTypeDiscovery(@Observes final AfterTypeDiscovery afterTypeDiscovery) {
498+
if (LOGGER.isLoggable(Level.CONFIG) && !jerseyVetoedTypes.isEmpty()) {
499+
LOGGER.config(LocalizationMessages.CDI_TYPE_VETOED(customHk2TypesProvider,
500+
listElements(new StringBuilder().append("\n"), jerseyVetoedTypes).toString()));
501+
}
502+
}
503+
504+
@SuppressWarnings("unused")
505+
private void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanDiscovery, final BeanManager beanManager) {
506+
beforeBeanDiscovery.addAnnotatedType(
507+
beanManager.createAnnotatedType(JaxRsParamProducer.class),
508+
"Jersey " + JaxRsParamProducer.class.getName()
509+
);
510+
beforeBeanDiscovery.addAnnotatedType(
511+
beanManager.createAnnotatedType(ProcessJAXRSAnnotatedTypes.class),
512+
"Jersey " + ProcessJAXRSAnnotatedTypes.class.getName()
513+
);
514+
}
515+
516+
public void processAnnotatedType(//@Observes
453517
// We can not apply the following constraint
454518
// if we want to fully support {@link org.glassfish.jersey.ext.cdi1x.spi.Hk2CustomBoundTypesProvider}.
455519
// Covered by tests/integration/cdi-with-jersey-injection-custom-cfg-webapp test application:
@@ -535,64 +599,6 @@ public boolean isAnnotationPresent(final Class<? extends Annotation> annotationT
535599
}
536600
}
537601

538-
private boolean containsJaxRsParameterizedCtor(final AnnotatedType annotatedType) {
539-
return containAnnotatedParameters(annotatedType.getConstructors(), JaxRsParamProducer.JAX_RS_STRING_PARAM_ANNOTATIONS);
540-
}
541-
542-
private boolean containsJaxRsConstructorInjection(final AnnotatedType annotatedType) {
543-
return containAnnotatedParameters(annotatedType.getConstructors(), JAX_RS_INJECT_ANNOTATIONS);
544-
}
545-
546-
private boolean containsJaxRsMethodInjection(final AnnotatedType annotatedType) {
547-
return containAnnotatedParameters(annotatedType.getMethods(), JAX_RS_INJECT_ANNOTATIONS);
548-
}
549-
550-
private boolean containsJaxRsFieldInjection(final AnnotatedType annotatedType) {
551-
return containAnnotation(annotatedType.getFields(), JAX_RS_INJECT_ANNOTATIONS);
552-
}
553-
554-
private boolean containAnnotatedParameters(final Collection<AnnotatedCallable> annotatedCallables,
555-
final Set<Class<? extends Annotation>> annotationSet) {
556-
for (final AnnotatedCallable c : annotatedCallables) {
557-
if (containAnnotation(c.getParameters(), annotationSet)) {
558-
return true;
559-
}
560-
}
561-
return false;
562-
}
563-
564-
private boolean containAnnotation(final Collection<Annotated> elements,
565-
final Set<Class<? extends Annotation>> annotationSet) {
566-
for (final Annotated element : elements) {
567-
if (hasAnnotation(element, annotationSet)) {
568-
return true;
569-
}
570-
}
571-
return false;
572-
}
573-
574-
private static boolean hasAnnotation(final Annotated element, final Set<Class<? extends Annotation>> annotations) {
575-
for (final Class<? extends Annotation> a : annotations) {
576-
if (element.isAnnotationPresent(a)) {
577-
return true;
578-
}
579-
}
580-
return false;
581-
}
582-
583-
@SuppressWarnings("unused")
584-
private void afterTypeDiscovery(@Observes final AfterTypeDiscovery afterTypeDiscovery) {
585-
if (LOGGER.isLoggable(Level.CONFIG) && !jerseyVetoedTypes.isEmpty()) {
586-
LOGGER.config(LocalizationMessages.CDI_TYPE_VETOED(customHk2TypesProvider,
587-
listElements(new StringBuilder().append("\n"), jerseyVetoedTypes).toString()));
588-
}
589-
}
590-
591-
@SuppressWarnings("unused")
592-
private void beforeBeanDiscovery(@Observes final BeforeBeanDiscovery beforeBeanDiscovery,
593-
final javax.enterprise.inject.spi.BeanManager beanManager) {
594-
beforeBeanDiscovery.addAnnotatedType(beanManager.createAnnotatedType(JaxRsParamProducer.class));
595-
}
596602

597603
@SuppressWarnings("unused")
598604
private void processInjectionTarget(@Observes final ProcessInjectionTarget event) {
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
/*
2+
* Copyright (c) 2018 Payara Foundation and/or its affiliates. All rights reserved.
3+
*
4+
* The contents of this file are subject to the terms of either the GNU
5+
* General Public License Version 2 only ("GPL") or the Common Development
6+
* and Distribution License("CDDL") (collectively, the "License"). You
7+
* may not use this file except in compliance with the License. You can
8+
* obtain a copy of the License at
9+
* https://github.com/payara/Payara/blob/master/LICENSE.txt
10+
* See the License for the specific
11+
* language governing permissions and limitations under the License.
12+
*
13+
* When distributing the software, include this License Header Notice in each
14+
* file and include the License file at glassfish/legal/LICENSE.txt.
15+
*
16+
* GPL Classpath Exception:
17+
* The Payara Foundation designates this particular file as subject to the "Classpath"
18+
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
19+
* file that accompanied this code.
20+
*
21+
* Modifications:
22+
* If applicable, add the following below the License Header, with the fields
23+
* enclosed by brackets [] replaced by your own identifying information:
24+
* "Portions Copyright [year] [name of copyright owner]"
25+
*
26+
* Contributor(s):
27+
* If you wish your version of this file to be governed by only the CDDL or
28+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
29+
* elects to include this software in this distribution under the [CDDL or GPL
30+
* Version 2] license." If you don't indicate a single choice of license, a
31+
* recipient has the option to distribute your version of this file under
32+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
33+
* its licensees as provided above. However, if you add GPL Version 2 code
34+
* and therefore, elected the GPL Version 2 license, then the option applies
35+
* only if the new code is made subject to such option by the copyright
36+
* holder.
37+
*/
38+
package org.glassfish.jersey.ext.cdi1x.internal;
39+
40+
import javax.enterprise.event.Observes;
41+
import javax.enterprise.inject.spi.BeanManager;
42+
import javax.enterprise.inject.spi.Extension;
43+
import javax.enterprise.inject.spi.ProcessAnnotatedType;
44+
45+
public class ProcessAllAnnotatedTypes implements Extension {
46+
47+
public void processAnnotatedType(@Observes ProcessAnnotatedType<?> processAnnotatedType, BeanManager beanManager) {
48+
CdiComponentProvider cdiComponentProvider = beanManager.getExtension(CdiComponentProvider.class);
49+
cdiComponentProvider.processAnnotatedType(processAnnotatedType);
50+
}
51+
52+
}
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
/*
2+
* Copyright (c) 2017-2018 Payara Foundation and/or its affiliates. All rights reserved.
3+
*
4+
* The contents of this file are subject to the terms of either the GNU
5+
* General Public License Version 2 only ("GPL") or the Common Development
6+
* and Distribution License("CDDL") (collectively, the "License"). You
7+
* may not use this file except in compliance with the License. You can
8+
* obtain a copy of the License at
9+
* https://github.com/payara/Payara/blob/master/LICENSE.txt
10+
* See the License for the specific
11+
* language governing permissions and limitations under the License.
12+
*
13+
* When distributing the software, include this License Header Notice in each
14+
* file and include the License file at glassfish/legal/LICENSE.txt.
15+
*
16+
* GPL Classpath Exception:
17+
* The Payara Foundation designates this particular file as subject to the "Classpath"
18+
* exception as provided by the Payara Foundation in the GPL Version 2 section of the License
19+
* file that accompanied this code.
20+
*
21+
* Modifications:
22+
* If applicable, add the following below the License Header, with the fields
23+
* enclosed by brackets [] replaced by your own identifying information:
24+
* "Portions Copyright [year] [name of copyright owner]"
25+
*
26+
* Contributor(s):
27+
* If you wish your version of this file to be governed by only the CDDL or
28+
* only the GPL Version 2, indicate your decision by adding "[Contributor]
29+
* elects to include this software in this distribution under the [CDDL or GPL
30+
* Version 2] license." If you don't indicate a single choice of license, a
31+
* recipient has the option to distribute your version of this file under
32+
* either the CDDL, the GPL Version 2 or to extend the choice of license to
33+
* its licensees as provided above. However, if you add GPL Version 2 code
34+
* and therefore, elected the GPL Version 2 license, then the option applies
35+
* only if the new code is made subject to such option by the copyright
36+
* holder.
37+
*/
38+
package org.glassfish.jersey.ext.cdi1x.internal;
39+
40+
import javax.enterprise.event.Observes;
41+
import javax.enterprise.inject.spi.BeanManager;
42+
import javax.enterprise.inject.spi.Extension;
43+
import javax.enterprise.inject.spi.ProcessAnnotatedType;
44+
import javax.enterprise.inject.spi.WithAnnotations;
45+
import javax.ws.rs.ApplicationPath;
46+
import javax.ws.rs.BeanParam;
47+
import javax.ws.rs.FormParam;
48+
import javax.ws.rs.HeaderParam;
49+
import javax.ws.rs.MatrixParam;
50+
import javax.ws.rs.PathParam;
51+
import javax.ws.rs.QueryParam;
52+
import javax.ws.rs.core.Context;
53+
54+
public class ProcessJAXRSAnnotatedTypes implements Extension {
55+
56+
public void processAnnotatedType(
57+
@Observes
58+
@WithAnnotations({
59+
Context.class,
60+
ApplicationPath.class,
61+
HeaderParam.class,
62+
QueryParam.class,
63+
FormParam.class,
64+
MatrixParam.class,
65+
BeanParam.class,
66+
PathParam.class})
67+
ProcessAnnotatedType<?> processAnnotatedType, BeanManager beanManager) {
68+
69+
beanManager.getExtension(CdiComponentProvider.class)
70+
.processAnnotatedType(processAnnotatedType);
71+
}
72+
73+
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
org.glassfish.jersey.ext.cdi1x.internal.CdiComponentProvider
2+
org.glassfish.jersey.ext.cdi1x.internal.ProcessAllAnnotatedTypes

0 commit comments

Comments
 (0)