From 99109fcc00269ecc80d06160445b908e8a240abe Mon Sep 17 00:00:00 2001 From: Keith Lustria Date: Wed, 18 Jan 2023 23:34:53 -0800 Subject: [PATCH] Replace OCI Java SDK shaded jar with v3 for OCI integration --- dependencies/pom.xml | 745 +++++++++++++++++- docs/includes/oci.adoc | 59 -- docs/mp/integrations/oci.adoc | 10 +- docs/se/integrations/oci.adoc | 12 +- examples/integrations/oci/README.md | 8 +- examples/integrations/oci/atp-cdi/pom.xml | 19 +- .../integrations/oci/atp/cdi/AtpResource.java | 6 +- .../integrations/oci/atp-reactive/pom.xml | 18 +- .../integrations/oci/metrics-reactive/pom.xml | 18 +- .../oci/objectstorage-cdi/pom.xml | 20 +- .../cdi/ObjectStorageResource.java | 6 +- .../oci/objectstorage-reactive/pom.xml | 18 +- examples/integrations/oci/vault-cdi/pom.xml | 24 +- .../integrations/oci/vault-reactive/pom.xml | 26 +- integrations/oci/sdk/cdi/pom.xml | 52 +- .../oci/sdk/cdi/OciExtension.java | 218 +---- .../sdk/cdi/src/main/java/module-info.java | 8 +- .../integrations/oci/sdk/cdi/TestSpike.java | 4 +- integrations/pom.xml | 3 +- 19 files changed, 873 insertions(+), 401 deletions(-) delete mode 100644 docs/includes/oci.adoc diff --git a/dependencies/pom.xml b/dependencies/pom.xml index 93935176e86..04600fa6fed 100644 --- a/dependencies/pom.xml +++ b/dependencies/pom.xml @@ -124,7 +124,7 @@ 4.4.11 4.1.86.Final 0.0.8.Final - 2.37.0 + 3.0.0 21.3.0.0 19.3.0.0 3.14.9 @@ -1422,6 +1422,8 @@ pom import + + + + + + + + com.oracle.oci.sdk + oci-java-sdk-circuitbreaker + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-common + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-common-httpclient-jersey3 + ${version.lib.oci} + false + + + + com.oracle.oci.sdk + oci-java-sdk-audit + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-containerengine + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-core + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-database + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dns + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-email + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-filestorage + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-identity + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-loadbalancer + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-objectstorage + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-addons-resteasy-client-configurator + ${version.lib.oci} + + + com.oracle.oci.sdk + oci-java-sdk-addons-sasl + ${version.lib.oci} + + + com.oracle.oci.sdk + oci-java-sdk-addons-graalvm + ${version.lib.oci} + + + com.oracle.oci.sdk + oci-java-sdk-resourcesearch + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-addons-apache + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-keymanagement + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-announcementsservice + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-healthchecks + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-waas + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-streaming + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-resourcemanager + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-monitoring + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-ons + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-autoscaling + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-budget + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-workrequests + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-limits + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-functions + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-events + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dts + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-oce + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-oda + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-analytics + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-integration + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-osmanagement + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-marketplace + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-apigateway + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-applicationmigration + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-datacatalog + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dataflow + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-datascience + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-nosql + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-secrets + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-vault + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-bds + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-encryption + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-cims + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-datasafe + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-mysql + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dataintegration + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-ocvp + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-usageapi + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-blockchain + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-loggingingestion + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-logging + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-loganalytics + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-managementdashboard + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-sch + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-loggingsearch + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-managementagent + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-cloudguard + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-opsi + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-computeinstanceagent + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-optimizer + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-tenantmanagercontrolplane + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-rover + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-databasemanagement + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-artifacts + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-apmsynthetics + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-goldengate + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-apmcontrolplane + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-apmtraces + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-networkloadbalancer + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-vulnerabilityscanning + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-databasemigration + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-servicecatalog + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-ailanguage + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-operatoraccesscontrol + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-bastion + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-genericartifactscontent + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-jms + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-devops + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-aianomalydetection + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-datalabelingservice + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-datalabelingservicedataplane + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-apmconfig + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-waf + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-certificates + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-certificatesmanagement + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-usage + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-databasetools + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-servicemanagerproxy + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-appmgmtcontrol + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-ospgateway + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-identitydataplane + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-visualbuilder + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-osubusage + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-osubsubscription + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-osuborganizationsubscription + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-osubbillingschedule + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dashboardservice + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-threatintelligence + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-aivision + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-aispeech + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-dataconnectivity + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-stackmonitoring + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-servicemesh + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-adm + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-licensemanager + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-onesubscription + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-governancerulescontrolplane + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-waa + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-networkfirewall + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-vnmonitoring + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-emwarehouse + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-lockbox + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-fusionapps + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-mediaservices + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-opa + ${version.lib.oci} + false + + + com.oracle.oci.sdk + oci-java-sdk-opensearch + ${version.lib.oci} + false + diff --git a/docs/includes/oci.adoc b/docs/includes/oci.adoc deleted file mode 100644 index ae639bd6930..00000000000 --- a/docs/includes/oci.adoc +++ /dev/null @@ -1,59 +0,0 @@ -/////////////////////////////////////////////////////////////////////////////// - - Copyright (c) 2022 Oracle and/or its affiliates. - - Licensed 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. - -/////////////////////////////////////////////////////////////////////////////// - -ifndef::rootdir[:rootdir: {docdir}/..] - -== Resolving javax and jakarta package compatibility issue with OCI SDK -[[oci-compatibility]] - -With Helidon 3, we are now implementing the MicroProfile 5 Platform and selected Jakarta EE 9.1 specifications. We are also going away from javax.* packages and fully embracing jakarta.* package. - -However, the current release 2.37.0 of OCI Java SDK is still using javax.* packages which created compatibility issues e.g. Helidon 3 uses JAX-RS 3.0.0 (jakarta package names) and the corresponding Jersey implementation. OCI SDK 2.37.0 uses JAX-RS Client 2.1.6 (javax package names) and the corresponding Jersey implementation. Therefore, the OCI SDK is incompatible with Helidon 3 applications and any application that uses JAX-RS 3. We have filed an issue with OCI SDK team, see https://github.com/oracle/oci-java-sdk/issues/371 for details on this. - -OCI SDK team has provided us with `shaded` jar as workaround as mentioned in the issue. - -Now, when you want to use modules from OCI SDK in your application, instead of using individual modules as defined in our OCI integration documentation, you need to use `full shaded` jar. - -[source,xml] ----- - - com.oracle.oci.sdk - oci-java-sdk-shaded-full - 2.37.0 - ----- - -Since the `full shaded` jar doesn't bring in its transitive dependencies, you will also need to define following dependencies in your application so that it works at runtime. - -[source,xml] ----- - - org.bouncycastle - bcpkix-jdk15on - 1.70 - runtime - - - org.slf4j - slf4j-jdk14 - 1.7.32 - runtime - ----- - -Please refer to our link:{helidon-github-tree-url}/examples/integrations/oci[OCI SDK Usage Examples] to see this in action. \ No newline at end of file diff --git a/docs/mp/integrations/oci.adoc b/docs/mp/integrations/oci.adoc index 12ea7e71c10..df734ab624e 100644 --- a/docs/mp/integrations/oci.adoc +++ b/docs/mp/integrations/oci.adoc @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// - Copyright (c) 2021, 2022 Oracle and/or its affiliates. + Copyright (c) 2021, 2023 Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -35,9 +35,7 @@ include::{rootdir}/includes/mp.adoc[] == Overview -Helidon MP OCI Integration provides easy access to Oracle Cloud Infrastructure using the OCI Java SDK. - -NOTE: OCI SDK uses JAX-RS Client 2.1.6 (javax package names), which makes it incompatible with Helidon 3 applications and any application that uses JAX-RS 3 (jakarta package naming). See <> for detailed information on how to work around this issue. +Helidon MP OCI Integration provides easy access to Oracle Cloud Infrastructure using the OCI Java SDK.` include::{rootdir}/includes/dependencies.adoc[] @@ -137,9 +135,7 @@ Once you have injected an ObjectStorage client you can use it as described in: * link:{oci-javasdk-objstore-javadoc-base-url}/package-summary.html[OCI SDK Object Storage Javadocs] * link:{oci-objstore-url}[OCI Object Storage Overview] -include::{rootdir}/includes/oci.adoc[leveloffset=+1] - == References * link:{integration-oci-sdk-cdi-javadoc-base-url}/io/helidon/integrations/oci/sdk/cdi/OciExtension.html[OciExtension] Javadocs -* link:{helidon-github-tree-url}/examples/integrations/oci[OCI SDK Usage Examples] \ No newline at end of file +* link:{helidon-github-tree-url}/examples/integrations/oci[OCI SDK Usage Examples] diff --git a/docs/se/integrations/oci.adoc b/docs/se/integrations/oci.adoc index f18120c006c..39d0e57b7bc 100644 --- a/docs/se/integrations/oci.adoc +++ b/docs/se/integrations/oci.adoc @@ -1,6 +1,6 @@ /////////////////////////////////////////////////////////////////////////////// - Copyright (c) 2021, 2022 Oracle and/or its affiliates. + Copyright (c) 2021, 2023 Oracle and/or its affiliates. Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. @@ -35,8 +35,6 @@ include::{rootdir}/includes/se.adoc[] Helidon SE OCI Integration provides easy access to Oracle Cloud Infrastructure using the OCI Java SDK. -NOTE: OCI SDK uses JAX-RS Client 2.1.6 (javax package names), which makes it incompatible with Helidon 3 applications and any application that uses JAX-RS 3 (jakarta package naming). See <> for detailed information on how to work around this issue. - == Usage It is recommended that you use the OCI Java SDK directly, in particular the Async clients. All you need to do is configure and create an OCI SDK Client object. The configuration primarily @@ -64,7 +62,8 @@ You also need to add the following dependency to your application for this ---- com.oracle.oci.sdk - oci-java-sdk-common + oci-java-sdk-common-httpclient-jersey3 + runtime ---- @@ -108,11 +107,8 @@ Once you have created an ObjectStorage client you can use it as described in: * link:{oci-javasdk-objstore-javadoc-base-url}/package-summary.html[OCI SDK Object Storage Javadocs] * link:{oci-objstore-url}[OCI Object Storage Overview] - -include::{rootdir}/includes/oci.adoc[leveloffset=+1] - == References * link:{helidon-github-tree-url}/examples/integrations/oci[OCI SDK Usage Examples] * link:https://docs.oracle.com/en-us/iaas/Content/home.htm[OCI Documentation] -] \ No newline at end of file +] diff --git a/examples/integrations/oci/README.md b/examples/integrations/oci/README.md index 7d84ab8ae82..ead822ac417 100644 --- a/examples/integrations/oci/README.md +++ b/examples/integrations/oci/README.md @@ -1,7 +1 @@ -# OCI SDK setup for Examples Build - -OCI SDK uses JAX-RS Client 2.1.6 (javax package names), which makes it incompatible with Helidon 3 applications and any application that uses JAX-RS 3 (jakarta package naming). - -Please see our [Guide](https://github.com/oracle/helidon/tree/master/docs/includes/oci.adoc) for detailed information on how to work around this issue. - -Once you have this setup, you can build examples in this repository directory. +# OCI Java SDK Examples diff --git a/examples/integrations/oci/atp-cdi/pom.xml b/examples/integrations/oci/atp-cdi/pom.xml index 994bbd54768..55c21d3b7de 100644 --- a/examples/integrations/oci/atp-cdi/pom.xml +++ b/examples/integrations/oci/atp-cdi/pom.xml @@ -1,7 +1,7 @@ - com.oracle.oci.sdk - oci-java-sdk-shaded-full + oci-java-sdk-common compile + + com.oracle.oci.sdk + oci-java-sdk-common-httpclient-jersey3 + runtime + + + jakarta.inject + jakarta.inject-api + provided + + + jakarta.ws.rs + jakarta.ws.rs-api + provided + org.eclipse.microprofile.config microprofile-config-api @@ -84,19 +88,21 @@ runtime true - - - org.slf4j - slf4j-api - runtime - + + + com.oracle.oci.sdk + oci-java-sdk-ailanguage + test + + + + com.oracle.oci.sdk + oci-java-sdk-streaming + test + org.junit.jupiter junit-jupiter-api diff --git a/integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/OciExtension.java b/integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/OciExtension.java index 14098186605..23596e73715 100644 --- a/integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/OciExtension.java +++ b/integrations/oci/sdk/cdi/src/main/java/io/helidon/integrations/oci/sdk/cdi/OciExtension.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -15,28 +15,25 @@ */ package io.helidon.integrations.oci.sdk.cdi; -import java.io.IOException; import java.lang.annotation.Annotation; import java.lang.invoke.MethodHandle; import java.lang.invoke.MethodHandles; import java.lang.invoke.MethodHandles.Lookup; import java.lang.reflect.ParameterizedType; import java.lang.reflect.Type; -import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.security.CodeSource; +import java.security.ProtectionDomain; import java.util.Arrays; import java.util.Collection; -import java.util.Collections; import java.util.EnumSet; -import java.util.HashMap; import java.util.HashSet; -import java.util.Map; import java.util.Objects; import java.util.Optional; import java.util.Set; import java.util.function.Consumer; -import java.util.function.Predicate; import java.util.function.Supplier; -import java.util.function.UnaryOperator; import java.util.logging.Logger; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -44,7 +41,6 @@ import com.oracle.bmc.Service; import com.oracle.bmc.auth.AbstractAuthenticationDetailsProvider; import com.oracle.bmc.common.ClientBuilderBase; -import com.oracle.bmc.http.ClientConfigurator; import jakarta.enterprise.event.Event; import jakarta.enterprise.event.Observes; import jakarta.enterprise.inject.AmbiguousResolutionException; @@ -61,12 +57,6 @@ import jakarta.inject.Singleton; import org.eclipse.microprofile.config.Config; import org.eclipse.microprofile.config.ConfigProvider; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.Priorities; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.client.Client; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.client.ClientBuilder; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.client.ClientRequestContext; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.client.ClientRequestFilter; -import shaded.com.oracle.oci.javasdk.javax.ws.rs.core.UriBuilder; import static java.lang.invoke.MethodType.methodType; @@ -718,7 +708,8 @@ private boolean isVetoed(Class c) { // not further process the class in question. The class // remains eligible for further processing; i.e. this is not a // CDI veto. - if (this.additionalVetoes.contains(c.getName())) { + if (equals(Service.class.getProtectionDomain(), c.getProtectionDomain()) + || this.additionalVetoes.contains(c.getName())) { LOGGER.fine(() -> "Vetoed " + c); return true; } @@ -970,7 +961,6 @@ private static Object produceClientBuilder(Instance instance, } // Permit arbitrary customization. fire(instance, builderInstance, qualifiers); - customizeEndpointResolution(builderInstance); return builderInstance; } @@ -1018,16 +1008,42 @@ private static boolean isUnsatisfied(BeanManager bm, Type type, Annotation[] qua } } - private static Class loadClassUnresolved(String name) throws ClassNotFoundException { - ClassLoader cl = Thread.currentThread().getContextClassLoader(); - return Class.forName(name, false, cl == null ? OciExtension.class.getClassLoader() : cl); + private static boolean equals(ProtectionDomain pd0, ProtectionDomain pd1) { + if (pd0 == null) { + return pd1 == null; + } else if (pd1 == null) { + return false; + } + return equals(pd0.getCodeSource(), pd1.getCodeSource()); } - private static void customizeEndpointResolution(ClientBuilderBase clientBuilder) { - EndpointAdjuster ea = EndpointAdjuster.of(clientBuilder.getClass().getName()); - if (ea != null) { - clientBuilder.additionalClientConfigurator(ea); + private static boolean equals(CodeSource cs0, CodeSource cs1) { + if (cs0 == null) { + return cs1 == null; + } else if (cs1 == null) { + return false; } + return equals(cs0.getLocation(), cs1.getLocation()); + } + + private static boolean equals(URL url0, URL url1) { + if (url0 == null) { + return url1 == null; + } else if (url1 == null) { + return false; + } + try { + return Objects.equals(url0.toURI(), url1.toURI()); + } catch (URISyntaxException uriSyntaxException) { + // Use URL#equals(Object) only as a last resort, since it + // involves DNS lookups (!). + return url0.equals(url1); + } + } + + private static Class loadClassUnresolved(String name) throws ClassNotFoundException { + ClassLoader cl = Thread.currentThread().getContextClassLoader(); + return Class.forName(name, false, cl == null ? OciExtension.class.getClassLoader() : cl); } @@ -1282,160 +1298,6 @@ public final boolean equals(Object other) { } - private enum EndpointAdjuster implements ClientConfigurator, ClientRequestFilter, Predicate { - - - /* - * Enum constants. - */ - - - // See - // https://docs.oracle.com/en-us/iaas/tools/java/latest/com/oracle/bmc/monitoring/MonitoringAsync.html#postMetricData-com.oracle.bmc.monitoring.requests.PostMetricDataRequest-com.oracle.bmc.responses.AsyncHandler-: - // - // The endpoints for this [particular POST] operation differ - // from other Monitoring operations. Replace the string - // telemetry with telemetry-ingestion in the endpoint, as in - // the following example: - // - // https://telemetry-ingestion.eu-frankfurt-1.oraclecloud.com - // - // Doing this in an application that uses a MonitoringClient - // or a MonitoringAsyncClient from several threads, not all of - // which are POSTing, is, of course, unsafe, since a thread - // performing a GET operation using the client might use the - // POSTing endpoint. This filter repairs this flaw and is - // installed by OCI-SDK-supported client customization - // facilities. - // - // The documented instructions above are imprecise. This filter - // implements what it seems was actually meant: - // - // The OCI hostname to which metrics should be POSTed must - // be a specific hostname that is derived from, but not - // equal to, the automatically computed hostname used for - // all other HTTP operations initiated by the Monitoring - // service client. This specific custom hostname must be - // derived as follows: - // - // If the automatically computed hostname begins with - // "telemetry.", replace only that occurrence of - // "telemetry." with "telemetry-ingestion.". The - // resulting hostname is the derived hostname to use for - // POSTing metrics and for no other purpose. - MONITORING(crc -> { - if ("POST".equalsIgnoreCase(crc.getMethod())) { - URI uri = crc.getUri(); - if (uri != null) { - String host = uri.getHost(); - if (host != null && host.startsWith("telemetry.")) { - String path = uri.getPath(); - return path != null && path.endsWith("/metrics"); - } - } - } - return false; - }, - h -> "telemetry-ingestion." + h.substring("telemetry.".length()) - ); - - - /* - * Static fields. - */ - - - private static final Map ENDPOINT_ADJUSTERS; - - static { - Map map = new HashMap<>(); - for (EndpointAdjuster ea : EnumSet.allOf(EndpointAdjuster.class)) { - map.put(ea.clientBuilderClassName, ea); - map.put(ea.asyncClientBuilderClassName, ea); - } - ENDPOINT_ADJUSTERS = Collections.unmodifiableMap(map); - } - - - /* - * Instance fields. - */ - - - private final String clientBuilderClassName; - - private final String asyncClientBuilderClassName; - - private final Predicate suitabilityTester; - - private final UnaryOperator adjuster; - - - /* - * Constructors. - */ - - - EndpointAdjuster(Predicate suitabilityTester, - UnaryOperator adjuster) { - String lowerCaseName = this.name().toLowerCase(); - String titleCaseName = Character.toUpperCase(lowerCaseName.charAt(0)) + lowerCaseName.substring(1); - String prefix = OCI_PACKAGE_PREFIX + lowerCaseName + "." + titleCaseName; - this.clientBuilderClassName = prefix + "Client$Builder"; - this.asyncClientBuilderClassName = prefix + "AsyncClient$Builder"; - this.suitabilityTester = suitabilityTester; - this.adjuster = adjuster; - } - - - /* - * Instance methods. - */ - - - @Override // ClientConfigurator - public void customizeBuilder(ClientBuilder builder) { - builder.register(this, Map.of(ClientRequestFilter.class, Integer.valueOf(Priorities.AUTHENTICATION - 500))); - } - - @Override // Predicate - public final boolean test(ClientRequestContext crc) { - return this.suitabilityTester.test(crc); - } - - @Override // ClientRequestFilter - public final void filter(ClientRequestContext crc) throws IOException { - if (this.test(crc)) { - URI uri = crc.getUri(); - if (uri != null) { - String hostname = uri.getHost(); - if (hostname != null) { - this.adjust(crc, hostname); - } - } - } - } - - private void adjust(ClientRequestContext crc, String hostname) { - crc.setUri(UriBuilder.fromUri(crc.getUri()).host(this.adjuster.apply(hostname)).build()); - } - - @Override // ClientConfigurator - public void customizeClient(Client client) { - } - - - /* - * Static methods. - */ - - - private static EndpointAdjuster of(String clientBuilderClassName) { - return ENDPOINT_ADJUSTERS.get(clientBuilderClassName); - } - - } - private static class SelectorShim implements AdpSelectionStrategy.Selector { diff --git a/integrations/oci/sdk/cdi/src/main/java/module-info.java b/integrations/oci/sdk/cdi/src/main/java/module-info.java index afd61b15651..e50c77c7bca 100644 --- a/integrations/oci/sdk/cdi/src/main/java/module-info.java +++ b/integrations/oci/sdk/cdi/src/main/java/module-info.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,9 +30,11 @@ requires transitive jakarta.cdi; requires jakarta.inject; requires jakarta.interceptor.api; + requires jakarta.ws.rs; requires microprofile.config.api; - requires oci.java.sdk.shaded.full; - + requires oci.java.sdk.common; + requires oci.java.sdk.common.httpclient; + exports io.helidon.integrations.oci.sdk.cdi; provides jakarta.enterprise.inject.spi.Extension diff --git a/integrations/oci/sdk/cdi/src/test/java/io/helidon/integrations/oci/sdk/cdi/TestSpike.java b/integrations/oci/sdk/cdi/src/test/java/io/helidon/integrations/oci/sdk/cdi/TestSpike.java index 0a345815097..3b93ed8bd2b 100644 --- a/integrations/oci/sdk/cdi/src/test/java/io/helidon/integrations/oci/sdk/cdi/TestSpike.java +++ b/integrations/oci/sdk/cdi/src/test/java/io/helidon/integrations/oci/sdk/cdi/TestSpike.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2022 Oracle and/or its affiliates. + * Copyright (c) 2022, 2023 Oracle and/or its affiliates. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -190,7 +190,7 @@ private ExampleBean(// The service* parameters below are // isn't; see the comments in the // constructor body below. It should be // unsatisfied. - Instance unresolvedJaxRsCircuitBreakerInstance, + Instance unresolvedJaxRsCircuitBreakerInstance, // Streaming turns out to be the only // convention-violating service in the // entire portfolio, and the violation is diff --git a/integrations/pom.xml b/integrations/pom.xml index 0b93ee26446..6801b09e315 100644 --- a/integrations/pom.xml +++ b/integrations/pom.xml @@ -1,7 +1,7 @@