-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1949 from jcarranzan/backports/3.8.6-backports-41411
Test coverage for ensuring the MessageBodyWriter is used with null Accept header
- Loading branch information
Showing
8 changed files
with
136 additions
and
0 deletions.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
...ced-reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/CustomHeaderResponse.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,13 @@ | ||
package io.quarkus.ts.http.advanced.reactive; | ||
|
||
public class CustomHeaderResponse { | ||
private final String content; | ||
|
||
public CustomHeaderResponse(String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
...reactive/src/main/java/io/quarkus/ts/http/advanced/reactive/HeadersMessageBodyWriter.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,29 @@ | ||
package io.quarkus.ts.http.advanced.reactive; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.ext.MessageBodyWriter; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class HeadersMessageBodyWriter implements MessageBodyWriter<CustomHeaderResponse> { | ||
|
||
@Override | ||
public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { | ||
return CustomHeaderResponse.class.isAssignableFrom(aClass) && MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType); | ||
} | ||
|
||
@Override | ||
public void writeTo(CustomHeaderResponse customHeaderResponse, Class<?> aClass, Type type, Annotation[] annotations, | ||
MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) | ||
throws IOException, WebApplicationException { | ||
final String content = "Headers response: " + customHeaderResponse.getContent(); | ||
outputStream.write(content.getBytes()); | ||
} | ||
} |
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
14 changes: 14 additions & 0 deletions
14
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/CustomHeaderResponse.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.ts.http.advanced; | ||
|
||
public class CustomHeaderResponse { | ||
|
||
private final String content; | ||
|
||
public CustomHeaderResponse(String content) { | ||
this.content = content; | ||
} | ||
|
||
public String getContent() { | ||
return content; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
http/http-advanced/src/main/java/io/quarkus/ts/http/advanced/HeadersMessageBodyWriter.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,29 @@ | ||
package io.quarkus.ts.http.advanced; | ||
|
||
import java.io.IOException; | ||
import java.io.OutputStream; | ||
import java.lang.annotation.Annotation; | ||
import java.lang.reflect.Type; | ||
|
||
import jakarta.ws.rs.WebApplicationException; | ||
import jakarta.ws.rs.core.MediaType; | ||
import jakarta.ws.rs.core.MultivaluedMap; | ||
import jakarta.ws.rs.ext.MessageBodyWriter; | ||
import jakarta.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
public class HeadersMessageBodyWriter implements MessageBodyWriter<CustomHeaderResponse> { | ||
|
||
@Override | ||
public boolean isWriteable(Class aClass, Type type, Annotation[] annotations, MediaType mediaType) { | ||
return CustomHeaderResponse.class.isAssignableFrom(aClass) && MediaType.TEXT_PLAIN_TYPE.isCompatible(mediaType); | ||
} | ||
|
||
@Override | ||
public void writeTo(CustomHeaderResponse customHeaderResponse, Class<?> aClass, Type type, Annotation[] annotations, | ||
MediaType mediaType, MultivaluedMap<String, Object> multivaluedMap, OutputStream outputStream) | ||
throws IOException, WebApplicationException { | ||
final String content = "Headers response: " + customHeaderResponse.getContent(); | ||
outputStream.write(content.getBytes()); | ||
} | ||
} |
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