forked from quarkusio/quarkus
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Detect MessageBodyReader/Writer from META-INF/services/javax.ws.rs.ex…
…t.Providers Resolves: quarkusio#27970
- Loading branch information
Showing
9 changed files
with
193 additions
and
3 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
16 changes: 16 additions & 0 deletions
16
...-kotlin/standard/src/main/kotlin/io/quarkus/it/resteasy/reactive/kotlin/SharedResource.kt
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,16 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
import io.quarkus.it.shared.Shared | ||
import javax.ws.rs.Consumes | ||
import javax.ws.rs.POST | ||
import javax.ws.rs.Path | ||
import javax.ws.rs.Produces | ||
|
||
@Path("/shared") | ||
class SharedResource { | ||
|
||
@Consumes("application/json") | ||
@Produces("application/json") | ||
@POST | ||
fun returnAsIs(shared: Shared) = shared | ||
} |
26 changes: 26 additions & 0 deletions
26
...lin/standard/src/test/kotlin/io/quarkus/it/resteasy/reactive/kotlin/SharedResourceTest.kt
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,26 @@ | ||
package io.quarkus.it.resteasy.reactive.kotlin | ||
|
||
import io.quarkus.test.junit.QuarkusTest | ||
import io.restassured.http.ContentType | ||
import io.restassured.module.kotlin.extensions.Given | ||
import io.restassured.module.kotlin.extensions.Then | ||
import io.restassured.module.kotlin.extensions.When | ||
import org.hamcrest.CoreMatchers | ||
import org.junit.jupiter.api.Test | ||
|
||
@QuarkusTest | ||
class SharedResourceTest { | ||
|
||
@Test | ||
fun testReturnAsIs() { | ||
Given { | ||
body("""{ "message": "will not be used" }""") | ||
contentType(ContentType.JSON) | ||
} When { | ||
post("/shared") | ||
} Then { | ||
statusCode(200) | ||
body(CoreMatchers.`is`("""{"message": "canned+canned"}""")) | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
integration-tests/shared-library/src/main/java/io/quarkus/it/shared/Shared.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,14 @@ | ||
package io.quarkus.it.shared; | ||
|
||
public class Shared { | ||
|
||
private final String message; | ||
|
||
public Shared(String message) { | ||
this.message = message; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
integration-tests/shared-library/src/main/java/io/quarkus/it/shared/SharedProvider.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,44 @@ | ||
package io.quarkus.it.shared; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.io.OutputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.WebApplicationException; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.MultivaluedMap; | ||
import javax.ws.rs.ext.MessageBodyReader; | ||
import javax.ws.rs.ext.MessageBodyWriter; | ||
|
||
@Produces("application/json") | ||
@Consumes("application/json") | ||
public class SharedProvider implements MessageBodyReader<Shared>, MessageBodyWriter<Shared> { | ||
@Override | ||
public boolean isReadable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return Shared.class.equals(type); | ||
} | ||
|
||
@Override | ||
public Shared readFrom(Class<Shared> type, Type genericType, Annotation[] annotations, MediaType mediaType, | ||
MultivaluedMap<String, String> httpHeaders, InputStream entityStream) | ||
throws IOException, WebApplicationException { | ||
return new Shared("canned"); | ||
} | ||
|
||
@Override | ||
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations, MediaType mediaType) { | ||
return Shared.class.equals(type); | ||
} | ||
|
||
@Override | ||
public void writeTo(Shared shared, Class<?> type, Type genericType, Annotation[] annotations, | ||
MediaType mediaType, MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream) | ||
throws IOException, WebApplicationException { | ||
entityStream.write(String.format("{\"message\": \"canned+%s\"}", shared.getMessage()).getBytes(StandardCharsets.UTF_8)); | ||
} | ||
} |
1 change: 1 addition & 0 deletions
1
...ation-tests/shared-library/src/main/resources/META-INF/services/javax.ws.rs.ext.Providers
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 @@ | ||
io.quarkus.it.shared.SharedProvider |