forked from eclipse-ee4j/jersey
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix issue with optional CDI in BV module
Fixes eclipse-ee4j#4542 Signed-off-by: jansupol <[email protected]>
- Loading branch information
Showing
6 changed files
with
246 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2020 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 | ||
--> | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<parent> | ||
<artifactId>project</artifactId> | ||
<groupId>org.glassfish.jersey.tests.integration</groupId> | ||
<version>2.32.0-SNAPSHOT</version> | ||
</parent> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<artifactId>jersey-4542</artifactId> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.ext</groupId> | ||
<artifactId>jersey-bean-validation</artifactId> | ||
<scope>provided</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-external</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework</groupId> | ||
<artifactId>jersey-test-framework-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.jboss.weld.se</groupId> | ||
<artifactId>weld-se-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
</project> |
51 changes: 51 additions & 0 deletions
51
.../src/main/java/org.glassfish.jersey.tests.integration.jersey4542/ValidationInflector.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (c) 2020 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.jersey4542; | ||
|
||
import java.io.IOException; | ||
|
||
import javax.ws.rs.container.ContainerRequestContext; | ||
|
||
import javax.validation.constraints.NotNull; | ||
|
||
import org.glassfish.jersey.message.internal.ReaderWriter; | ||
import org.glassfish.jersey.process.Inflector; | ||
|
||
/** | ||
* @author Michal Gajdos | ||
*/ | ||
public class ValidationInflector implements Inflector<ContainerRequestContext, String> { | ||
|
||
@NotNull | ||
@Override | ||
public String apply(final ContainerRequestContext requestContext) { | ||
return get(requestContext); | ||
} | ||
|
||
@NotNull | ||
public String get(@NotNull final ContainerRequestContext requestContext) { | ||
try { | ||
final String entity = ReaderWriter.readFromAsString( | ||
requestContext.getEntityStream(), | ||
requestContext.getMediaType()); | ||
|
||
return entity.isEmpty() ? null : entity; | ||
} catch (IOException e) { | ||
return "error"; | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
...st/java/org.glassfish.jersey.tests.integration.jersey4542/ProgrammaticValidationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Copyright (c) 2020 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.jersey4542; | ||
|
||
import java.util.HashSet; | ||
import java.util.Set; | ||
|
||
import javax.ws.rs.client.Entity; | ||
import javax.ws.rs.core.Application; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.glassfish.jersey.inject.hk2.Hk2InjectionManagerFactory; | ||
import org.glassfish.jersey.logging.LoggingFeature; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.server.model.Resource; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
|
||
import static org.junit.Assert.assertEquals; | ||
|
||
import org.glassfish.jersey.test.external.ExternalTestContainerFactory; | ||
import org.jboss.weld.environment.se.Weld; | ||
import org.junit.Assume; | ||
import org.junit.Before; | ||
import org.junit.Test; | ||
|
||
/** | ||
* Bean Validation tests for programmatically created resources. | ||
* | ||
* @author Michal Gajdos | ||
*/ | ||
public class ProgrammaticValidationTest extends JerseyTest { | ||
|
||
Weld weld; | ||
|
||
@Before | ||
public void setup() { | ||
Assume.assumeTrue(Hk2InjectionManagerFactory.isImmediateStrategy()); | ||
} | ||
|
||
@Override | ||
public void setUp() throws Exception { | ||
if (Hk2InjectionManagerFactory.isImmediateStrategy()) { | ||
if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) { | ||
weld = new Weld(); | ||
weld.initialize(); | ||
} | ||
super.setUp(); | ||
} | ||
} | ||
|
||
@Override | ||
public void tearDown() throws Exception { | ||
if (Hk2InjectionManagerFactory.isImmediateStrategy()) { | ||
if (!ExternalTestContainerFactory.class.isAssignableFrom(getTestContainerFactory().getClass())) { | ||
weld.shutdown(); | ||
} | ||
super.tearDown(); | ||
} | ||
} | ||
|
||
@Override | ||
protected Application configure() { | ||
final Set<Resource> resources = new HashSet<>(); | ||
|
||
Resource.Builder resourceBuilder = Resource.builder("class"); | ||
resourceBuilder | ||
.addMethod("POST") | ||
.handledBy(ValidationInflector.class); | ||
resources.add(resourceBuilder.build()); | ||
|
||
return new ResourceConfig().register(LoggingFeature.class).registerResources(resources); | ||
} | ||
|
||
@Test | ||
public void testInflectorClass() throws Exception { | ||
final Response response = target("class").request().post(Entity.entity("value", MediaType.TEXT_PLAIN_TYPE)); | ||
|
||
assertEquals(200, response.getStatus()); | ||
assertEquals("value", response.readEntity(String.class)); | ||
} | ||
|
||
@Test | ||
public void testInflectorClassNegative() throws Exception { | ||
final Response response = target("class").request().post(Entity.entity(null, MediaType.TEXT_PLAIN_TYPE)); | ||
|
||
assertEquals(500, response.getStatus()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
tests/integration/jersey-4542/src/test/resources/META-INF/beans.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2020 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 | ||
--> | ||
|
||
<beans/> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters