Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.8.2 backports 2 #12546

Merged
merged 16 commits into from
Oct 6, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/amazon-kms.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ The easiest way to start working with KMS is to run a local instance as a contai

[source,shell,subs="verbatim,attributes"]
----
docker run --rm --name local-kms 8011:4599 -e SERVICES=kms -e START_WEB=0 -d localstack/localstack:0.11.1
docker run --rm --name local-kms --publish 8011:4599 -e SERVICES=kms -e START_WEB=0 -d localstack/localstack:0.11.1
----
This starts a KMS instance that is accessible on port `8011`.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/amazon-s3.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ The easiest way to start working with S3 is to run a local instance as a contain

[source,shell,subs="verbatim,attributes"]
----
docker run -it --publish 8008:4566 -e SERVICES=s3 -e START_WEB=0 localstack/localstack
docker run -it --publish 8008:4566 -e SERVICES=s3 -e START_WEB=0 localstack/localstack:0.11.5
----
This starts a S3 instance that is accessible on port `8008`.

Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/hibernate-orm-panache-kotlin.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class Person: PanacheEntity {

As you can see our entities remain simple. There is, however, a slight difference from the Java version. The Kotlin
language doesn't support the notion of static methods in quite the same way as Java does. Instead, we must use a
[companion object](https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.html#companion-objects):
https://kotlinlang.org/docs/tutorials/kotlin-for-py/objects-and-companion-objects.html#companion-objects[companion object]:

[source,kotlin]
----
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/kafka-streams.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ to your project by running the following command in your project base directory:

[source,bash]
----
./mvnw quarkus:add-extension -Dextensions="kafka"
./mvnw quarkus:add-extension -Dextensions="quarkus-smallrye-reactive-messaging-kafka"
----

This will add the following to your `pom.xml`:
Expand Down
8 changes: 4 additions & 4 deletions docs/src/main/asciidoc/reactive-sql-clients.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ The same logic applies when saving a `Fruit`:
.src/main/java/org/acme/vertx/Fruit.java
----
public Uni<Long> save(PgPool client) {
return client.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING (id)").execute(Tuple.of(name))
return client.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING id").execute(Tuple.of(name))
.onItem().transform(pgRowSet -> pgRowSet.iterator().next().getLong("id"));
}
----
Expand Down Expand Up @@ -502,9 +502,9 @@ The following snippet shows how to run 2 insertions in the same transaction:
----
public static Uni<Void> insertTwoFruits(PgPool client, Fruit fruit1, Fruit fruit2) {
return SqlClientHelper.inTransactionUni(client, tx -> {
Uni<RowSet<Row>> insertOne = tx.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING (id)")
Uni<RowSet<Row>> insertOne = tx.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING id")
.execute(Tuple.of(fruit1.name));
Uni<RowSet<Row>> insertTwo = tx.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING (id)")
Uni<RowSet<Row>> insertTwo = tx.preparedQuery("INSERT INTO fruits (name) VALUES ($1) RETURNING id")
.execute(Tuple.of(fruit2.name));

return insertOne.and(insertTwo)
Expand All @@ -522,7 +522,7 @@ You can also create dependent actions as follows:
----
return SqlClientHelper.inTransactionUni(client, tx -> tx

.preparedQuery("INSERT INTO person (firstname,lastname) VALUES ($1,$2) RETURNING (id)")
.preparedQuery("INSERT INTO person (firstname,lastname) VALUES ($1,$2) RETURNING id")
.execute(Tuple.of(person.getFirstName(), person.getLastName()))

.onItem().transformToUni(id -> tx.preparedQuery("INSERT INTO addr (person_id,addrline1) VALUES ($1,$2)")
Expand Down
2 changes: 1 addition & 1 deletion docs/src/main/asciidoc/security-jwt.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ in order for the token to be accepted as valid.
<3> The `group` claim provides the groups and top-level roles associated with the JWT bearer.
<4> The `birthday` claim. It can be considered to be a sensitive claim so you may want to consider encrypting the claims, see <<generate-jwt-tokens, Generate JWT tokens with SmallRye JWT>>.

Note for this code to work we need the content of the RSA private key that corresponds to the public key we have in the TokenSecuredResource application. Take the following PEM content and place it into `security-jwt-quickstart/src/main/resources/META-INF/resources/privateKey.pem`:
Note for this code to work we need the content of the RSA private key that corresponds to the public key we have in the TokenSecuredResource application. Take the following PEM content and place it into `security-jwt-quickstart/src/test/resources/privateKey.pem`:

.RSA Private Key PEM Content
[source, text]
Expand Down
Original file line number Diff line number Diff line change
@@ -1,25 +1,39 @@
package io.quarkus.hibernate.envers.deployment;

import java.util.Arrays;
import java.util.List;

import io.quarkus.deployment.Feature;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
import io.quarkus.deployment.logging.LogCleanupFilterBuildItem;
import io.quarkus.hibernate.envers.HibernateEnversBuildTimeConfig;
import io.quarkus.hibernate.envers.HibernateEnversRecorder;
import io.quarkus.hibernate.orm.deployment.AdditionalJpaModelBuildItem;

public final class QuarkusHibernateEnversProcessor {
public final class HibernateEnversProcessor {

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(Feature.HIBERNATE_ENVERS);
}

@BuildStep
List<AdditionalJpaModelBuildItem> addJpaModelClasses() {
return Arrays.asList(
new AdditionalJpaModelBuildItem(org.hibernate.envers.DefaultRevisionEntity.class),
new AdditionalJpaModelBuildItem(org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity.class));
}

@BuildStep
public void registerEnversReflections(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false, "org.hibernate.envers.DefaultRevisionEntity"));
reflectiveClass.produce(new ReflectiveClassBuildItem(true, false,
"org.hibernate.envers.DefaultTrackingModifiedEntitiesRevisionEntity"));
reflectiveClass
.produce(new ReflectiveClassBuildItem(false, false, "org.hibernate.tuple.entity.DynamicMapEntityTuplizer"));
reflectiveClass.produce(
Expand All @@ -32,4 +46,10 @@ public void applyConfig(HibernateEnversRecorder recorder,
HibernateEnversBuildTimeConfig buildTimeConfig) {
recorder.registerHibernateEnversIntegration(buildTimeConfig);
}

@BuildStep
void setupLogFilters(BuildProducer<LogCleanupFilterBuildItem> filters) {
filters.produce(new LogCleanupFilterBuildItem("org.hibernate.envers.boot.internal.EnversServiceImpl",
"Envers integration enabled"));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import io.quarkus.deployment.builditem.LaunchModeBuildItem;
import io.quarkus.deployment.builditem.LogCategoryBuildItem;
import io.quarkus.deployment.builditem.ServiceStartBuildItem;
import io.quarkus.deployment.builditem.SystemPropertyBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
Expand Down Expand Up @@ -500,16 +501,17 @@ public void build(HibernateOrmRecorder recorder, HibernateOrmConfig hibernateOrm

@BuildStep
@Record(RUNTIME_INIT)
public void startPersistenceUnits(HibernateOrmRecorder recorder, BeanContainerBuildItem beanContainer,
public ServiceStartBuildItem startPersistenceUnits(HibernateOrmRecorder recorder, BeanContainerBuildItem beanContainer,
List<JdbcDataSourceBuildItem> dataSourcesConfigured,
JpaEntitiesBuildItem jpaEntities, List<NonJpaModelBuildItem> nonJpaModels,
List<HibernateOrmIntegrationRuntimeConfiguredBuildItem> integrationsRuntimeConfigured,
List<JdbcDataSourceSchemaReadyBuildItem> schemaReadyBuildItem) throws Exception {
if (!hasEntities(jpaEntities, nonJpaModels)) {
return;
if (hasEntities(jpaEntities, nonJpaModels)) {
recorder.startAllPersistenceUnits(beanContainer.getValue());
}

recorder.startAllPersistenceUnits(beanContainer.getValue());
return new ServiceStartBuildItem("Hibernate ORM");

}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import org.jboss.jandex.AnnotationTarget;
import org.jboss.jandex.AnnotationValue;
import org.jboss.jandex.ClassInfo;
import org.jboss.jandex.CompositeIndex;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
import org.jboss.jandex.MethodInfo;
Expand All @@ -47,6 +48,7 @@

import io.quarkus.arc.BeanDestroyer;
import io.quarkus.arc.deployment.AdditionalBeanBuildItem;
import io.quarkus.arc.deployment.BeanArchiveIndexBuildItem;
import io.quarkus.arc.deployment.BeanContainerListenerBuildItem;
import io.quarkus.arc.deployment.BeanRegistrarBuildItem;
import io.quarkus.arc.processor.BeanConfigurator;
Expand Down Expand Up @@ -162,7 +164,9 @@ void setup(BuildProducer<FeatureBuildItem> feature,
}

@BuildStep
void processInterfaces(CombinedIndexBuildItem combinedIndexBuildItem,
void processInterfaces(
CombinedIndexBuildItem combinedIndexBuildItem,
BeanArchiveIndexBuildItem beanArchiveIndexBuildItem,
Capabilities capabilities,
PackageConfig packageConfig,
BuildProducer<NativeImageProxyDefinitionBuildItem> proxyDefinition,
Expand All @@ -177,7 +181,7 @@ void processInterfaces(CombinedIndexBuildItem combinedIndexBuildItem,
Map<DotName, ClassInfo> interfaces = new HashMap<>();
Set<Type> returnTypes = new HashSet<>();

IndexView index = combinedIndexBuildItem.getIndex();
IndexView index = CompositeIndex.create(beanArchiveIndexBuildItem.getIndex(), combinedIndexBuildItem.getIndex());

findInterfaces(index, interfaces, returnTypes, REGISTER_REST_CLIENT);
findInterfaces(index, interfaces, returnTypes, PATH);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package io.quarkus.spring.web.runtime;

import java.lang.annotation.Annotation;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;
import java.util.function.Function;

import org.eclipse.microprofile.config.ConfigProvider;
import org.springframework.web.bind.annotation.RequestMapping;

import io.quarkus.runtime.test.TestHttpEndpointProvider;

public class SpringWebEndpointProvider implements TestHttpEndpointProvider {
@Override
public Function<Class<?>, String> endpointProvider() {
return new Function<Class<?>, String>() {
@Override
public String apply(Class<?> aClass) {
String[] paths = getPath(aClass);
if (paths == null) {
return null;
}
String value;
if (paths.length == 0) {
value = "";
} else {
value = paths[0];
if (value.startsWith("/")) {
value = value.substring(1);
}
}
//TODO: there is not really any way to handle @ApplicationPath, we could do something for @QuarkusTest apps but we can't for
//native apps, so we just have to document the limitation
String path = "/";
Optional<String> appPath = ConfigProvider.getConfig().getOptionalValue("quarkus.resteasy.path", String.class);
if (appPath.isPresent()) {
path = appPath.get();
}
if (!path.endsWith("/")) {
path = path + "/";
}
value = path + value;
return value;
}
};
}

private String[] getPath(Class<?> aClass) {
String[] value = null;
for (Annotation annotation : aClass.getAnnotations()) {
if (annotation.annotationType().getName().equals(RequestMapping.class.getName())) {
try {
value = (String[]) annotation.annotationType().getMethod("value").invoke(annotation);
break;
} catch (IllegalAccessException | InvocationTargetException | NoSuchMethodException e) {
throw new RuntimeException(e);
}
}
}
if (value == null) {
for (Class<?> i : aClass.getInterfaces()) {
value = getPath(i);
if (value != null) {
break;
}
}
}
if (value == null) {
if (aClass.getSuperclass() != Object.class) {
value = getPath(aClass.getSuperclass());
}
}
return value;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
io.quarkus.spring.web.runtime.SpringWebEndpointProvider
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
import io.quarkus.deployment.builditem.CapabilityBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceDirectoryBuildItem;
import io.quarkus.deployment.builditem.nativeimage.RuntimeInitializedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ServiceProviderBuildItem;
import io.quarkus.deployment.util.ServiceUtil;
Expand Down Expand Up @@ -85,10 +86,10 @@ public void registerTikaParsersResources(BuildProducer<NativeImageResourceBuildI
}

@BuildStep
public void registerPdfBoxResources(BuildProducer<NativeImageResourceBuildItem> resource) {
resource.produce(new NativeImageResourceBuildItem("org/apache/pdfbox/resources/glyphlist/additional.txt"));
resource.produce(new NativeImageResourceBuildItem("org/apache/pdfbox/resources/glyphlist/glyphlist.txt"));
resource.produce(new NativeImageResourceBuildItem("org/apache/pdfbox/resources/glyphlist/zapfdingbats.txt"));
public void registerPdfBoxResources(BuildProducer<NativeImageResourceDirectoryBuildItem> resource) {
resource.produce(new NativeImageResourceDirectoryBuildItem("org/apache/pdfbox/resources/glyphlist"));
resource.produce(new NativeImageResourceDirectoryBuildItem("org/apache/fontbox/cmap"));
resource.produce(new NativeImageResourceDirectoryBuildItem("org/apache/fontbox/unicode"));
}

@BuildStep
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,15 @@

import static io.restassured.RestAssured.given;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.params.provider.Arguments.arguments;

import java.util.stream.Stream;

import org.junit.jupiter.api.Test;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import org.junit.jupiter.params.provider.ValueSource;

import io.quarkus.test.junit.QuarkusTest;
import io.quarkus.test.security.TestSecurity;
Expand All @@ -22,9 +29,21 @@ void testGet() {
.body(is("secure"));
}

@Test
@TestSecurity
void testGetWithSecEnabled() {
@ParameterizedTest
@ValueSource(ints = 1) //https://github.com/quarkusio/quarkus/issues/12413
void testGetWithSecEnabled(int ignore) {
given()
.when()
.get("/secure")
.then()
.statusCode(401);
}

@TestSecurity
@ParameterizedTest
@MethodSource("arrayParams") //https://github.com/quarkusio/quarkus/issues/12413
void testGetUnAuthorized(int[] ignoredPrimitives, String[] ignored) {
given()
.when()
.get("/secure")
Expand Down Expand Up @@ -63,4 +82,9 @@ void testTestUserCorrectRole() {
.body(is("testUser"));
}

static Stream<Arguments> arrayParams() {
return Stream.of(
arguments(new int[] { 1, 2 }, new String[] { "hello", "world" }));
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package io.quarkus.it.spring.web;

import static org.hamcrest.Matchers.containsString;

import org.junit.jupiter.api.Test;

import io.quarkus.test.common.http.TestHTTPEndpoint;
import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;

@QuarkusTest
@TestHTTPEndpoint(GreetingController.class)
public class TestHTTPEndpointTest {

@Test
public void testJsonResult() {
RestAssured.when().get("/json/hello").then()
.contentType("application/json")
.body(containsString("hello"));
}
}
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static io.restassured.RestAssured.given;
import static org.hamcrest.CoreMatchers.containsString;
import static org.hamcrest.CoreMatchers.is;
import static org.hamcrest.CoreMatchers.startsWith;

import java.io.ByteArrayOutputStream;
import java.io.InputStream;
Expand All @@ -29,6 +30,17 @@ public void testGetTextFromPdfFormat() throws Exception {
checkText("application/pdf", "pdf");
}

@Test
public void testGetTextFromPdfFormatWithFonts() throws Exception {
given()
.when().header("Content-Type", "application/pdf")
.body(readQuarkusFile("americanexpress.pdf"))
.post("/parse/text")
.then()
.statusCode(200)
.body(startsWith("American express card"));
}

@Test
public void testGetMetadataFromTextFormat() throws Exception {
checkMetadata("text/plain", "txt");
Expand Down