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.
Compatibility with RestEasy injecting no Configuration
Signed-off-by: jansupol <[email protected]>
- Loading branch information
Showing
5 changed files
with
210 additions
and
6 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
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,100 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<!-- | ||
Copyright (c) 2025 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"> | ||
|
||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>org.glassfish.jersey.tests.integration</groupId> | ||
<artifactId>project</artifactId> | ||
<version>3.1.99-SNAPSHOT</version> | ||
</parent> | ||
|
||
<artifactId>spring-boot</artifactId> | ||
|
||
<packaging>war</packaging> | ||
<name>jersey-tests-integration-spring6</name> | ||
|
||
<description> | ||
Jersey tests for Spring.Boot / Resteasy integration | ||
</description> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>org.jboss.resteasy</groupId> | ||
<artifactId>resteasy-client</artifactId> | ||
<version>6.2.11.Final</version> | ||
<exclusions> | ||
<exclusion> | ||
<artifactId>commons-logging</artifactId> | ||
<groupId>commons-logging</groupId> | ||
</exclusion> | ||
</exclusions> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.test-framework</groupId> | ||
<artifactId>jersey-test-framework-core</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.glassfish.jersey.containers</groupId> | ||
<artifactId>jersey-container-servlet</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.providers</groupId> | ||
<artifactId>jersey-test-framework-provider-grizzly2</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>commons-logging</groupId> | ||
<artifactId>commons-logging</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.glassfish.jersey.media</groupId> | ||
<artifactId>jersey-media-json-jackson</artifactId> | ||
<scope>test</scope> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-compiler-plugin</artifactId> | ||
</plugin> | ||
<plugin> | ||
<groupId>org.apache.maven.plugins</groupId> | ||
<artifactId>maven-failsafe-plugin</artifactId> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
91 changes: 91 additions & 0 deletions
91
...steasy-client/src/test/java/org/glassfish/jersey/tests/springboot/RestEasyClientTest.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,91 @@ | ||
/* | ||
* Copyright (c) 2025 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.springboot; | ||
|
||
import jakarta.ws.rs.POST; | ||
import jakarta.ws.rs.Path; | ||
import jakarta.ws.rs.Produces; | ||
import jakarta.ws.rs.client.Entity; | ||
import jakarta.ws.rs.core.Application; | ||
import jakarta.ws.rs.core.Configuration; | ||
import jakarta.ws.rs.core.Context; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.core.Response; | ||
import jakarta.ws.rs.ext.Providers; | ||
import org.glassfish.jersey.jackson.internal.DefaultJacksonJaxbJsonProvider; | ||
import org.glassfish.jersey.server.ResourceConfig; | ||
import org.glassfish.jersey.test.JerseyTest; | ||
import org.jboss.resteasy.client.jaxrs.ResteasyClient; | ||
import org.jboss.resteasy.client.jaxrs.internal.ResteasyClientBuilderImpl; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.util.concurrent.CountDownLatch; | ||
|
||
public class RestEasyClientTest extends JerseyTest { | ||
|
||
private static final CountDownLatch readFromLatch = new CountDownLatch(1); | ||
|
||
@Path("/") | ||
public static class RestEasyClientTestResource { | ||
@POST | ||
@Path("/test") | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public String testPost(String echo) { | ||
return echo; | ||
} | ||
} | ||
|
||
@Override | ||
protected Application configure() { | ||
return new ResourceConfig(RestEasyClientTestResource.class); | ||
} | ||
|
||
@Test | ||
public void test() throws InterruptedException { | ||
try (final ResteasyClient client = new ResteasyClientBuilderImpl().build()) { | ||
client.register(TestDefaultJacksonJaxbJsonProvider.class); | ||
|
||
try (final Response r = client.target(target().getUri()).path("/test") | ||
.request().post(Entity.entity("{\"test\": \"test\"}", MediaType.APPLICATION_JSON))) { | ||
Object o = r.readEntity(Object.class); | ||
Assertions.assertTrue(o.toString().contains("test")); | ||
readFromLatch.await(); | ||
Assertions.assertEquals(0, readFromLatch.getCount(), "DefaultJacksonJaxbJsonProvider has not been used"); | ||
} | ||
} | ||
} | ||
|
||
public static class TestDefaultJacksonJaxbJsonProvider extends DefaultJacksonJaxbJsonProvider { | ||
public TestDefaultJacksonJaxbJsonProvider(@Context Providers providers, @Context Configuration config) { | ||
super(providers, config); | ||
} | ||
|
||
@Override | ||
public Object readFrom(Class<Object> type, Type genericType, Annotation[] annotations, MediaType mediaType, | ||
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) throws IOException { | ||
readFromLatch.countDown(); | ||
return super.readFrom(type, genericType, annotations, mediaType, httpHeaders, entityStream); | ||
} | ||
} | ||
|
||
} |