diff --git a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java index 7a9800447f..724b7c0d12 100644 --- a/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java +++ b/ext/cdi/jersey-cdi1x/src/main/java/org/glassfish/jersey/ext/cdi1x/internal/CdiComponentProvider.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. + * Copyright (c) 2013, 2019 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 @@ -75,6 +75,7 @@ import org.glassfish.jersey.internal.inject.AbstractBinder; import org.glassfish.jersey.internal.inject.Binder; import org.glassfish.jersey.internal.inject.Bindings; +import org.glassfish.jersey.internal.inject.CustomAnnotationLiteral; import org.glassfish.jersey.internal.inject.ForeignRequestScopeBridge; import org.glassfish.jersey.internal.inject.InjectionManager; import org.glassfish.jersey.internal.inject.InstanceBinding; @@ -306,7 +307,8 @@ public boolean bind(final Class clazz, final Set> providerContracts) ? new RequestScopedCdiBeanSupplier(clazz, injectionManager, beanManager, isCdiManaged) : new GenericCdiBeanSupplier(clazz, injectionManager, beanManager, isCdiManaged); - SupplierInstanceBinding builder = Bindings.supplier(beanFactory).to(clazz); + SupplierInstanceBinding builder = Bindings.supplier(beanFactory) + .to(clazz).qualifiedBy(CustomAnnotationLiteral.INSTANCE); for (final Class contract : providerContracts) { builder.to(contract); } diff --git a/tests/integration/jersey-3670/pom.xml b/tests/integration/jersey-3670/pom.xml new file mode 100644 index 0000000000..f4bca76caa --- /dev/null +++ b/tests/integration/jersey-3670/pom.xml @@ -0,0 +1,66 @@ + + + + + 4.0.0 + + + org.glassfish.jersey.tests.integration + project + 2.29-SNAPSHOT + + + jersey-3670 + war + jersey-tests-integration-jersey-3670 + + JERSEY-3670 - Broken ParamConverterProvider ordering in 2.26 + + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-external + test + + + javax.validation + validation-api + + + org.glassfish.jersey.connectors + jersey-grizzly-connector + test + + + org.glassfish.jersey.test-framework.providers + jersey-test-framework-provider-grizzly2 + test + + + + + + + org.apache.maven.plugins + maven-compiler-plugin + + + + + diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java new file mode 100644 index 0000000000..711cf96a7d --- /dev/null +++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyApplication.java @@ -0,0 +1,33 @@ +/* + * Copyright (c) 2019 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.integration.jersey3670; + +import javax.ws.rs.core.Application; +import java.util.LinkedHashSet; +import java.util.Set; + +public class MyApplication extends Application { + + @Override + public Set> getClasses() { + LinkedHashSet> classes = new LinkedHashSet<>(); + classes.add(MyResource.class); + classes.add(MyConverterProvider.class); + return classes; + } + +} \ No newline at end of file diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java new file mode 100644 index 0000000000..e0053f69fd --- /dev/null +++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyConverterProvider.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2019 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.integration.jersey3670; + +import javax.annotation.Priority; +import javax.ws.rs.ext.ParamConverter; +import javax.ws.rs.ext.ParamConverterProvider; +import java.lang.annotation.Annotation; +import java.lang.reflect.Type; + +@Priority(0) +public class MyConverterProvider implements ParamConverterProvider { + + @Override + public ParamConverter getConverter(Class rawType, Type genericType, Annotation[] annotations) { + + if (rawType.equals(Integer.class)) { + + /* + * Dummy ParamConverter which always returns "42". + */ + return (ParamConverter) new ParamConverter() { + @Override + public Integer fromString(String value) { + return 42; + } + + @Override + public String toString(Integer value) { + throw new UnsupportedOperationException(); + } + }; + + } + return null; + } +} \ No newline at end of file diff --git a/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java new file mode 100644 index 0000000000..d7aeb6a5eb --- /dev/null +++ b/tests/integration/jersey-3670/src/main/java/org/glassfish/jersey/tests/integration/jersey3670/MyResource.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2019 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.integration.jersey3670; + +import javax.validation.executable.ExecutableType; +import javax.validation.executable.ValidateOnExecution; +import javax.ws.rs.GET; +import javax.ws.rs.Path; +import javax.ws.rs.PathParam; + +@Path("/param/{value}") +@ValidateOnExecution(type = ExecutableType.NONE) +public class MyResource { + + @PathParam("value") + private Integer value; + + @GET + public String get() { + return "Value injected via @PathParam: " + value; + } + +} \ No newline at end of file diff --git a/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml b/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml new file mode 100644 index 0000000000..e90af995c7 --- /dev/null +++ b/tests/integration/jersey-3670/src/main/webapp/WEB-INF/beans.xml @@ -0,0 +1,24 @@ + + + + + diff --git a/tests/integration/jersey-3670/src/main/webapp/index.html b/tests/integration/jersey-3670/src/main/webapp/index.html new file mode 100644 index 0000000000..21715b1c82 --- /dev/null +++ b/tests/integration/jersey-3670/src/main/webapp/index.html @@ -0,0 +1,36 @@ + + + + + + + Jersey Provider Priority (issue 3670) + + +

Jersey Provider Priority (issue 3670)

+ + + + \ No newline at end of file diff --git a/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java b/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java new file mode 100644 index 0000000000..a166ed18ca --- /dev/null +++ b/tests/integration/jersey-3670/src/test/java/org/glassfish/jersey/tests/integration/jersey3670/ExternalApplicationParamConverterTest.java @@ -0,0 +1,49 @@ +/* + * Copyright (c) 2019 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 + * http://www.eclipse.org/legal/epl-2.0. + * + * This Source Code may also be made available under the following Secondary + * Licenses when the conditions for such availability set forth in the + * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, + * version 2 with the GNU Classpath Exception, which is available at + * https://www.gnu.org/software/classpath/license.html. + * + * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 + */ + +package org.glassfish.jersey.tests.integration.jersey3670; + +import org.glassfish.jersey.test.JerseyTest; +import org.glassfish.jersey.test.grizzly.GrizzlyTestContainerFactory; +import org.glassfish.jersey.test.spi.TestContainerException; +import org.glassfish.jersey.test.spi.TestContainerFactory; +import org.junit.Test; + +import javax.ws.rs.core.Application; + +import static org.junit.Assert.assertEquals; + +public class ExternalApplicationParamConverterTest extends JerseyTest { + + private static final String CHECK_STRING = "Value injected via @PathParam: 42"; + + @Override + protected Application configure() { + return new MyApplication(); + } + + @Override + protected TestContainerFactory getTestContainerFactory() throws TestContainerException { + return new GrizzlyTestContainerFactory(); + } + + @Test + public void testExternalParamConverterValue() { + final String resp = target("/param/1").request().get(String.class); + assertEquals(CHECK_STRING, resp); + } + +} diff --git a/tests/integration/pom.xml b/tests/integration/pom.xml index 77d9154887..e003f99558 100644 --- a/tests/integration/pom.xml +++ b/tests/integration/pom.xml @@ -1,7 +1,7 @@