Skip to content

Commit

Permalink
Merge pull request quarkus-qe#688 from pjgg/backport_2.7_1
Browse files Browse the repository at this point in the history
[2.7] Bulk - Backport from upstream _1
  • Loading branch information
michalvavrik authored Jun 7, 2022
2 parents a408a66 + 7c90be9 commit fc66b29
Show file tree
Hide file tree
Showing 479 changed files with 1,906 additions and 1,116 deletions.
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,11 @@ Variants:
- Using `OIDC Client Filter` extension to automatically acquire the access token from Keycloak when calling to the RestClient.
- Using `OIDC Token Propagation` extension to propagate the tokens from the source REST call to the target RestClient.

### `security/keycloak-oidc-client-reactive`

Verifies special cases of using reactive OIDC client:
- Proper handling of `Authorization` request header by `OidcClientRequestReactiveFilter`: the filter should always add a single`Authorization` header, not duplicate it in multiple request attempts.

### `securty/oidc-client-mutual-tls`

Verifies OIDC client can be authenticated as part of the `Mutual TLS` (`mTLS`) authentication process
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.ts.http.graphql;
package io.quarkus.ts.http.graphql.telemetry;

public class Person {
private final String name;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.ts.http.graphql;
package io.quarkus.ts.http.graphql.telemetry;

import java.util.NoSuchElementException;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package io.quarkus.ts.http.graphql;
package io.quarkus.ts.http.graphql.telemetry;

import static io.quarkus.ts.http.graphql.Utils.createQuery;
import static io.quarkus.ts.http.graphql.Utils.sendQuery;
import static io.quarkus.ts.http.graphql.telemetry.Utils.createQuery;
import static io.quarkus.ts.http.graphql.telemetry.Utils.sendQuery;
import static io.restassured.RestAssured.given;
import static org.awaitility.Awaitility.await;

Expand All @@ -20,7 +20,7 @@
import io.restassured.response.Response;

@QuarkusScenario
public class TelemetryIT {
public class GraphQLTelemetryIT {
private static final int GRPC_COLLECTOR_PORT = 14250;

@JaegerContainer(restPort = GRPC_COLLECTOR_PORT)
Expand All @@ -41,7 +41,7 @@ void verifyTelemetry() {
await().atMost(1, TimeUnit.MINUTES).pollInterval(Duration.ofSeconds(10)).untilAsserted(() -> {
String operation = "graphql";
Response traces = given().when()
.queryParam("operation", operation)
.queryParam("operationName", operation)
.queryParam("lookback", "1h")
.queryParam("limit", 10)
.queryParam("service", "graphql-telemetry")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.quarkus.ts.http.graphql.telemetry;

import io.quarkus.test.scenarios.OpenShiftScenario;

@OpenShiftScenario
public class OpenShiftGraphQLTelemetryIT extends GraphQLTelemetryIT {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.quarkus.ts.http.graphql;
package io.quarkus.ts.http.graphql.telemetry;

import static io.restassured.RestAssured.given;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import io.restassured.response.Response;

@QuarkusScenario
public class TracingIT {
public class GraphQLTracingIT {
private static final String SERVICE_NAME = "graphql-service";

@JaegerContainer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
import io.quarkus.test.scenarios.OpenShiftScenario;

@OpenShiftScenario
public class OpenShiftTelemetryIT extends TelemetryIT {
public class OpenShiftGraphQLTracingIT extends GraphQLTracingIT {

}

This file was deleted.

4 changes: 4 additions & 0 deletions http/http-advanced-reactive/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
<groupId>com.squareup.okhttp3</groupId>
<artifactId>okhttp</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.resteasy</groupId>
<artifactId>resteasy-multipart-provider</artifactId>
</dependency>
</dependencies>
<profiles>
<!-- Skipped on Windows as does not support Linux Containers / Testcontainers -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public Hello(String content) {
public String getContent() {
return content;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package io.quarkus.ts.http.advanced.reactive;

import static io.quarkus.ts.http.advanced.reactive.HelloResource.NAME;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;

import io.smallrye.mutiny.Uni;

@Path("/hello")
public class HelloAllResource {
private static final String TEMPLATE = "Hello all, %s!";
public static final String ALL_ENDPOINT_PATH = "/all";

@Path(ALL_ENDPOINT_PATH)
@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<Hello> get(@QueryParam(NAME) @DefaultValue("World") String name) {
return Uni.createFrom().item(new Hello(String.format(TEMPLATE, name)));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,13 @@

@Path("/hello")
public class HelloResource {

private static final String TEMPLATE = "Hello, %s!";
public static final String NAME = "name";

@GET
@Produces(MediaType.APPLICATION_JSON)
public Uni<Hello> get(@QueryParam("name") @DefaultValue("World") String name) {
public Uni<Hello> get(@QueryParam(NAME) @DefaultValue("World") String name) {
return Uni.createFrom().item(new Hello(String.format(TEMPLATE, name)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package io.quarkus.ts.http.advanced.reactive;

import static io.quarkus.ts.http.advanced.reactive.MediaTypeResource.MEDIA_TYPE_PATH;
import static javax.ws.rs.core.HttpHeaders.ACCEPT_ENCODING;
import static javax.ws.rs.core.HttpHeaders.ACCEPT_LANGUAGE;
import static javax.ws.rs.core.MediaType.APPLICATION_JSON;
import static javax.ws.rs.core.MediaType.APPLICATION_OCTET_STREAM;
import static javax.ws.rs.core.MediaType.APPLICATION_XML;
import static javax.ws.rs.core.MediaType.MULTIPART_FORM_DATA;
import static javax.ws.rs.core.MediaType.TEXT_HTML;
import static javax.ws.rs.core.MediaType.TEXT_PLAIN;

import java.io.IOException;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.core.HttpHeaders;
import javax.ws.rs.core.Response;
import javax.ws.rs.ext.Provider;

import io.quarkus.vertx.web.RouteFilter;
import io.vertx.ext.web.RoutingContext;

@Path(MEDIA_TYPE_PATH)
public class MediaTypeResource {

public static final String MEDIA_TYPE_PATH = "/media-type";
private static final String IMAGE_PNG = "image/png";
private static final String IMAGE_JPEG = "image/jpeg";
private static final String TEXT_CSS = "text/css";
private static final String TEXT_XML = "text/xml";
public static final String APPLICATION_YAML = "application/yaml";
public static final String ENGLISH = "en";
public static final String JAPANESE = "ja";
public static final String ANY_ENCODING = "*";

@Produces({ APPLICATION_JSON, APPLICATION_XML, TEXT_HTML, TEXT_PLAIN, APPLICATION_OCTET_STREAM,
MULTIPART_FORM_DATA, IMAGE_PNG, IMAGE_JPEG, APPLICATION_YAML, TEXT_CSS, TEXT_XML })
@GET
public Response getMediaType() {
return Response.ok(new MediaTypeWrapper()).build();
}

public static class ContentNegotiationRoutingFilter {
@RouteFilter
void addHeaders(final RoutingContext rc) {
rc.response().headers().add(HttpHeaders.VARY, ACCEPT_LANGUAGE);
rc.response().headers().add(ACCEPT_LANGUAGE, ENGLISH);
rc.next();
}
}

@Provider
public static class ContentNegotiationContainerResponseFilter implements
ContainerResponseFilter {
@Override
public void filter(final ContainerRequestContext requestContext, final ContainerResponseContext responseContext)
throws IOException {
responseContext.getHeaders().add(HttpHeaders.VARY, ACCEPT_ENCODING);
responseContext.getHeaders().add(ACCEPT_ENCODING, ANY_ENCODING);
responseContext.getHeaders().add(ACCEPT_LANGUAGE, JAPANESE);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package io.quarkus.ts.http.advanced.reactive;

import javax.ws.rs.core.MediaType;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class MediaTypeWrapper {

private MediaType mediaType;

public MediaType getMediaType() {
return mediaType;
}

public void setMediaType(MediaType mediaType) {
this.mediaType = mediaType;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 javax.ws.rs.WebApplicationException;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.MultivaluedMap;
import javax.ws.rs.ext.MessageBodyWriter;
import javax.ws.rs.ext.Provider;

import com.fasterxml.jackson.databind.ObjectMapper;

@Provider
public class MediaTypeWrapperSerializer implements MessageBodyWriter<MediaTypeWrapper> {

@Override
public boolean isWriteable(Class<?> type, Type genericType, Annotation[] annotations,
MediaType mediaType) {
return type == MediaTypeWrapper.class;
}

@Override
public void writeTo(MediaTypeWrapper mediaTypeWrapper, Class<?> type,
Type genericType, Annotation[] annotations, MediaType mediaType,
MultivaluedMap<String, Object> httpHeaders, OutputStream entityStream)
throws IOException, WebApplicationException {
mediaTypeWrapper.setMediaType(mediaType);
entityStream.write(new ObjectMapper().writeValueAsBytes(mediaTypeWrapper));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package io.quarkus.ts.http.advanced.reactive;

import io.quarkus.runtime.annotations.RegisterForReflection;

@RegisterForReflection
public class MultipartFormDataDTO {

private final String text;
private final String file;

public MultipartFormDataDTO(String text, String file) {
this.text = text;
this.file = file;
}

public String getText() {
return text;
}

public String getFile() {
return file;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package io.quarkus.ts.http.advanced.reactive;

import static io.quarkus.ts.http.advanced.reactive.MultipartResource.MULTIPART_FORM_PATH;

import java.io.IOException;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;

import javax.ws.rs.Consumes;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.Response.Status;

import org.apache.commons.io.IOUtils;
import org.jboss.logging.Logger;
import org.jboss.resteasy.plugins.providers.multipart.MultipartFormDataInput;

@Path(MULTIPART_FORM_PATH)
public class MultipartResource {

private static final Logger LOGGER = Logger.getLogger(MediaTypeResource.class);
public static final String TEXT = "text";
public static final String FILE = "file";
public static final String MULTIPART_FORM_PATH = "/multipart-form-data";

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Produces(MediaType.APPLICATION_JSON)
public Response multipartFormData(final MultipartFormDataInput input) {
var inputPartText = input.getFormDataMap().get(TEXT).stream().findAny().orElse(null);
if (inputPartText != null) {
try {
String fileContent = IOUtils.toString(input.getFormDataPart(FILE, InputStream.class, null),
StandardCharsets.UTF_8);
String text = inputPartText.getBodyAsString();
return Response.ok(new MultipartFormDataDTO(text, fileContent)).build();
} catch (IOException e) {
LOGGER.errorf("Failed to retrieve form field value: %s", e.getMessage());
}
} else {
LOGGER.warnf("Multipart Form Data does not contain value of form field '%s'.", TEXT);
}
return Response.status(Status.BAD_REQUEST).build();
}
}
Loading

0 comments on commit fc66b29

Please sign in to comment.