You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ja...@apache.org on 2023/04/24 09:33:47 UTC
[camel-quarkus] branch main updated: Improve handling of optional FHIR schematron and hapi-fhir-server dependencies
This is an automated email from the ASF dual-hosted git repository.
jamesnetherton pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git
The following commit(s) were added to refs/heads/main by this push:
new 36518a0eaa Improve handling of optional FHIR schematron and hapi-fhir-server dependencies
36518a0eaa is described below
commit 36518a0eaacc897ba83ddeb96c17410be193f3df
Author: James Netherton <ja...@gmail.com>
AuthorDate: Fri Apr 21 11:27:14 2023 +0100
Improve handling of optional FHIR schematron and hapi-fhir-server dependencies
Fixes #4811
---
.../component/fhir/deployment/FhirProcessor.java | 73 +++++++++++++++++-----
extensions/fhir/runtime/pom.xml | 4 --
.../quarkus/component/fhir/IsSchematronAbsent.java | 32 ++++++++++
.../fhir/graal/SchematronSubstitutions.java | 55 ++++++++++++++++
poms/bom/pom.xml | 15 -----
poms/bom/src/main/generated/flattened-full-pom.xml | 15 -----
.../src/main/generated/flattened-reduced-pom.xml | 15 -----
.../generated/flattened-reduced-verbose-pom.xml | 15 -----
8 files changed, 146 insertions(+), 78 deletions(-)
diff --git a/extensions/fhir/deployment/src/main/java/org/apache/camel/quarkus/component/fhir/deployment/FhirProcessor.java b/extensions/fhir/deployment/src/main/java/org/apache/camel/quarkus/component/fhir/deployment/FhirProcessor.java
index 2104b953bd..9b75409c94 100644
--- a/extensions/fhir/deployment/src/main/java/org/apache/camel/quarkus/component/fhir/deployment/FhirProcessor.java
+++ b/extensions/fhir/deployment/src/main/java/org/apache/camel/quarkus/component/fhir/deployment/FhirProcessor.java
@@ -16,37 +16,36 @@
*/
package org.apache.camel.quarkus.component.fhir.deployment;
+import java.lang.reflect.Modifier;
+import java.util.function.BooleanSupplier;
+
import ca.uhn.fhir.rest.client.apache.ApacheRestfulClientFactory;
import ca.uhn.fhir.rest.client.api.IClientInterceptor;
import ca.uhn.fhir.rest.server.exceptions.BaseServerResponseException;
-import ca.uhn.fhir.rest.server.interceptor.CaptureResourceSourceFromHeaderInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.ResponseHighlighterInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.ResponseValidatingInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.auth.AuthorizationInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.auth.SearchNarrowingInterceptor;
-import ca.uhn.fhir.rest.server.interceptor.consent.ConsentInterceptor;
import ca.uhn.fhir.util.jar.DependencyLogImpl;
import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
+import io.quarkus.deployment.GeneratedClassGizmoAdaptor;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.AdditionalApplicationArchiveMarkerBuildItem;
import io.quarkus.deployment.builditem.CombinedIndexBuildItem;
import io.quarkus.deployment.builditem.ExtensionSslNativeSupportBuildItem;
import io.quarkus.deployment.builditem.FeatureBuildItem;
+import io.quarkus.deployment.builditem.GeneratedClassBuildItem;
import io.quarkus.deployment.builditem.nativeimage.NativeImageResourceBundleBuildItem;
import io.quarkus.deployment.builditem.nativeimage.ReflectiveClassBuildItem;
+import io.quarkus.deployment.pkg.steps.NativeBuild;
+import io.quarkus.gizmo.ClassCreator;
+import io.quarkus.gizmo.Gizmo;
+import io.quarkus.gizmo.MethodCreator;
+import org.apache.camel.quarkus.component.fhir.IsSchematronAbsent;
import org.jboss.jandex.DotName;
import org.jboss.jandex.IndexView;
final class FhirProcessor {
private static final String FEATURE = "camel-fhir";
+ private static final String RESTFUL_SERVER_UTILS_CLASS_NAME = "ca.uhn.fhir.rest.server.RestfulServerUtils";
private static final String[] INTERCEPTOR_CLASSES = {
- ConsentInterceptor.class.getName(),
- SearchNarrowingInterceptor.class.getName(),
- AuthorizationInterceptor.class.getName(),
- ResponseValidatingInterceptor.class.getName(),
- ResponseHighlighterInterceptor.class.getName(),
- CaptureResourceSourceFromHeaderInterceptor.class.getName(),
IClientInterceptor.class.getName(),
};
@@ -94,12 +93,58 @@ final class FhirProcessor {
reflectiveClass.produce(ReflectiveClassBuildItem.builder(clientInterceptors).methods().build());
reflectiveClass.produce(ReflectiveClassBuildItem.builder(INTERCEPTOR_CLASSES).methods().build());
- reflectiveClass.produce(ReflectiveClassBuildItem.builder(SchematronBaseValidator.class)
- .fields().build());
reflectiveClass.produce(ReflectiveClassBuildItem.builder(DependencyLogImpl.class)
.fields().build());
reflectiveClass.produce(ReflectiveClassBuildItem.builder(ApacheRestfulClientFactory.class)
.methods().fields().build());
}
+ @BuildStep(onlyIfNot = IsSchematronAbsent.class)
+ void registerSchematronForReflection(BuildProducer<ReflectiveClassBuildItem> reflectiveClass) {
+ reflectiveClass.produce(ReflectiveClassBuildItem.builder(SchematronBaseValidator.class)
+ .fields().build());
+ }
+
+ @BuildStep(onlyIf = { NativeBuild.class, IsFhirServerAbsent.class })
+ void generateRestfulServerUtils(BuildProducer<GeneratedClassBuildItem> generatedClass) {
+ // Avoid having redundant hapi-fhir-server on the classpath and generate RestfulServerUtils.createEtag to satisfy native compilation.
+ try (ClassCreator classCreator = ClassCreator.builder()
+ .className(RESTFUL_SERVER_UTILS_CLASS_NAME)
+ .classOutput(new GeneratedClassGizmoAdaptor(generatedClass, false))
+ .setFinal(true)
+ .superClass(Object.class.getName())
+ .build()) {
+
+ /*
+ * Original implementation of createETag is:
+ *
+ * public static String createEtag(String theVersionId) {
+ * return "W/\"" + theVersionId + '"';
+ * }
+ */
+ try (MethodCreator methodCreator = classCreator.getMethodCreator("createEtag", String.class, String.class)) {
+ methodCreator.setModifiers(Modifier.PUBLIC | Modifier.STATIC);
+
+ Gizmo.StringBuilderGenerator stringBuilder = Gizmo.newStringBuilder(methodCreator);
+ stringBuilder.append("W/");
+ stringBuilder.append('"');
+ stringBuilder.append(methodCreator.getMethodParam(0));
+ stringBuilder.append('"');
+
+ methodCreator.returnValue(stringBuilder.callToString());
+ }
+ }
+ }
+
+ static final class IsFhirServerAbsent implements BooleanSupplier {
+ @Override
+ public boolean getAsBoolean() {
+ try {
+ Class.forName(RESTFUL_SERVER_UTILS_CLASS_NAME);
+ return false;
+ } catch (ClassNotFoundException e) {
+ return true;
+ }
+ }
+ }
}
diff --git a/extensions/fhir/runtime/pom.xml b/extensions/fhir/runtime/pom.xml
index 162217314b..cf84ccdee4 100644
--- a/extensions/fhir/runtime/pom.xml
+++ b/extensions/fhir/runtime/pom.xml
@@ -64,10 +64,6 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-fhir</artifactId>
</dependency>
- <dependency>
- <groupId>ca.uhn.hapi.fhir</groupId>
- <artifactId>hapi-fhir-server</artifactId>
- </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-hl7org-dstu2</artifactId>
diff --git a/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/IsSchematronAbsent.java b/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/IsSchematronAbsent.java
new file mode 100644
index 0000000000..44544efda4
--- /dev/null
+++ b/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/IsSchematronAbsent.java
@@ -0,0 +1,32 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.fhir;
+
+import java.util.function.BooleanSupplier;
+
+public final class IsSchematronAbsent implements BooleanSupplier {
+
+ @Override
+ public boolean getAsBoolean() {
+ try {
+ Class.forName("com.helger.schematron.ISchematronResource");
+ return false;
+ } catch (ClassNotFoundException e) {
+ return true;
+ }
+ }
+}
diff --git a/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/graal/SchematronSubstitutions.java b/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/graal/SchematronSubstitutions.java
new file mode 100644
index 0000000000..b89aaa08e2
--- /dev/null
+++ b/extensions/fhir/runtime/src/main/java/org/apache/camel/quarkus/component/fhir/graal/SchematronSubstitutions.java
@@ -0,0 +1,55 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.quarkus.component.fhir.graal;
+
+import java.util.function.BooleanSupplier;
+
+import ca.uhn.fhir.context.FhirContext;
+import ca.uhn.fhir.validation.schematron.SchematronBaseValidator;
+import ca.uhn.fhir.validation.schematron.SchematronProvider;
+import com.oracle.svm.core.annotate.Delete;
+import com.oracle.svm.core.annotate.Substitute;
+import com.oracle.svm.core.annotate.TargetClass;
+
+final class SchematronSubstitutions {
+}
+
+@TargetClass(value = SchematronProvider.class, onlyWith = IsSchematronAbsent.class)
+final class SubstituteSchematronProvider {
+ @Substitute
+ public static boolean isSchematronAvailable(FhirContext theFhirContext) {
+ return false;
+ }
+}
+
+@TargetClass(value = SchematronBaseValidator.class, onlyWith = IsSchematronAbsent.class)
+@Delete
+final class DeleteSchematronBaseValidator {
+}
+
+final class IsSchematronAbsent implements BooleanSupplier {
+
+ @Override
+ public boolean getAsBoolean() {
+ try {
+ Class.forName("com.helger.schematron.ISchematronResource");
+ return false;
+ } catch (ClassNotFoundException e) {
+ return true;
+ }
+ }
+}
diff --git a/poms/bom/pom.xml b/poms/bom/pom.xml
index b181cab2fe..665958b82c 100644
--- a/poms/bom/pom.xml
+++ b/poms/bom/pom.xml
@@ -5919,21 +5919,6 @@
<artifactId>hapi-fhir-client</artifactId>
<version>${hapi-fhir.version}</version>
</dependency>
- <dependency>
- <groupId>ca.uhn.hapi.fhir</groupId>
- <artifactId>hapi-fhir-server</artifactId>
- <version>${hapi-fhir.version}</version>
- <exclusions>
- <exclusion>
- <groupId>com.sun.activation</groupId>
- <artifactId>jakarta.activation</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.mail</groupId>
- <artifactId>jakarta.mail</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
diff --git a/poms/bom/src/main/generated/flattened-full-pom.xml b/poms/bom/src/main/generated/flattened-full-pom.xml
index d1e5cb18a6..8a7bed5fac 100644
--- a/poms/bom/src/main/generated/flattened-full-pom.xml
+++ b/poms/bom/src/main/generated/flattened-full-pom.xml
@@ -5818,21 +5818,6 @@
<artifactId>hapi-fhir-client</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>6.2.4</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
- <dependency>
- <groupId>ca.uhn.hapi.fhir</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>hapi-fhir-server</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <version>6.2.4</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <exclusions>
- <exclusion>
- <groupId>com.sun.activation</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>jakarta.activation</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- </exclusion>
- <exclusion>
- <groupId>com.sun.mail</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>jakarta.mail</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>hapi-fhir-structures-dstu2.1</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
diff --git a/poms/bom/src/main/generated/flattened-reduced-pom.xml b/poms/bom/src/main/generated/flattened-reduced-pom.xml
index 1cdbf3f476..52189fa026 100644
--- a/poms/bom/src/main/generated/flattened-reduced-pom.xml
+++ b/poms/bom/src/main/generated/flattened-reduced-pom.xml
@@ -5818,21 +5818,6 @@
<artifactId>hapi-fhir-client</artifactId>
<version>6.2.4</version>
</dependency>
- <dependency>
- <groupId>ca.uhn.hapi.fhir</groupId>
- <artifactId>hapi-fhir-server</artifactId>
- <version>6.2.4</version>
- <exclusions>
- <exclusion>
- <groupId>com.sun.activation</groupId>
- <artifactId>jakarta.activation</artifactId>
- </exclusion>
- <exclusion>
- <groupId>com.sun.mail</groupId>
- <artifactId>jakarta.mail</artifactId>
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId>
<artifactId>hapi-fhir-structures-dstu2.1</artifactId>
diff --git a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml
index c02674ed26..bd661b1912 100644
--- a/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml
+++ b/poms/bom/src/main/generated/flattened-reduced-verbose-pom.xml
@@ -5818,21 +5818,6 @@
<artifactId>hapi-fhir-client</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<version>6.2.4</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
</dependency>
- <dependency>
- <groupId>ca.uhn.hapi.fhir</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>hapi-fhir-server</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <version>6.2.4</version><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <exclusions>
- <exclusion>
- <groupId>com.sun.activation</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>jakarta.activation</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- </exclusion>
- <exclusion>
- <groupId>com.sun.mail</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- <artifactId>jakarta.mail</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
- </exclusion>
- </exclusions>
- </dependency>
<dependency>
<groupId>ca.uhn.hapi.fhir</groupId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->
<artifactId>hapi-fhir-structures-dstu2.1</artifactId><!-- org.apache.camel.quarkus:camel-quarkus-bom:${project.version} -->