├── .gitignore ├── 3RD-PARTY-LICENSE.txt ├── LICENSE.txt ├── README.adoc ├── docs └── Usage.adoc ├── examples └── domain-xml │ └── domain.xml ├── launcher-dist ├── pom.xml └── src │ └── main │ └── resources │ ├── LICENSE.txt │ ├── META-INF │ └── 3RD-PARTY-LICENSE.txt │ └── config │ └── branding │ └── glassfish-version.properties ├── launcher-impl ├── bootstrap │ ├── pom.xml │ └── src │ │ ├── main │ │ ├── java │ │ │ └── com │ │ │ │ └── fujitsu │ │ │ │ └── launcher │ │ │ │ ├── DeployProperties.java │ │ │ │ ├── ExceptionUtil.java │ │ │ │ ├── LauncherConfig.java │ │ │ │ ├── LauncherMain.java │ │ │ │ ├── Operation.java │ │ │ │ ├── cli │ │ │ │ ├── ArgumentList.java │ │ │ │ ├── ArgumentToken.java │ │ │ │ ├── BooleanOption.java │ │ │ │ ├── CommandLineException.java │ │ │ │ ├── IntOption.java │ │ │ │ ├── LauncherCommandLine.java │ │ │ │ ├── Option.java │ │ │ │ ├── OptionMap.java │ │ │ │ ├── OptionNameToken.java │ │ │ │ ├── OptionSpec.java │ │ │ │ ├── OptionValueToken.java │ │ │ │ ├── Parser.java │ │ │ │ ├── ParsingResult.java │ │ │ │ ├── StringOption.java │ │ │ │ └── Token.java │ │ │ │ └── uberjar │ │ │ │ └── Launcher.java │ │ └── resources │ │ │ └── com │ │ │ └── fujitsu │ │ │ └── launcher │ │ │ └── uber-jar_MANIFEST.MF │ │ └── test │ │ └── java │ │ └── com │ │ └── fujitsu │ │ └── launcher │ │ └── cli │ │ ├── LauncherCommandLineTest.java │ │ └── ParserTest.java ├── glassfish │ ├── pom.xml │ └── src │ │ └── main │ │ ├── java │ │ ├── com │ │ │ └── sun │ │ │ │ ├── appserv │ │ │ │ └── connectors │ │ │ │ │ └── internal │ │ │ │ │ └── api │ │ │ │ │ └── ConnectorsClassLoaderUtil.java │ │ │ │ ├── enterprise │ │ │ │ ├── admin │ │ │ │ │ └── cli │ │ │ │ │ │ ├── embeddable │ │ │ │ │ │ └── DeployerImpl.java │ │ │ │ │ │ └── schemadoc │ │ │ │ │ │ ├── AttributeMethodVisitor.java │ │ │ │ │ │ └── DocClassVisitor.java │ │ │ │ ├── glassfish │ │ │ │ │ └── bootstrap │ │ │ │ │ │ └── StaticGlassFishRuntime.java │ │ │ │ ├── security │ │ │ │ │ ├── cli │ │ │ │ │ │ ├── CreateFileUser.java │ │ │ │ │ │ └── LocalStrings.properties │ │ │ │ │ ├── ssl │ │ │ │ │ │ └── impl │ │ │ │ │ │ │ └── SecuritySupportImpl.java │ │ │ │ │ └── web │ │ │ │ │ │ └── integration │ │ │ │ │ │ └── GlassFishToExousiaConverter.java │ │ │ │ ├── server │ │ │ │ │ └── logging │ │ │ │ │ │ └── ServerLogFileService.java │ │ │ │ ├── v3 │ │ │ │ │ ├── admin │ │ │ │ │ │ └── CommandRunnerImpl.java │ │ │ │ │ ├── common │ │ │ │ │ │ └── PlainTextActionReporter.java │ │ │ │ │ ├── server │ │ │ │ │ │ ├── AppServerStartup.java │ │ │ │ │ │ └── ApplicationLifecycle.java │ │ │ │ │ └── services │ │ │ │ │ │ └── impl │ │ │ │ │ │ ├── GlassfishErrorPageGenerator.java │ │ │ │ │ │ ├── GlassfishNetworkListener.java │ │ │ │ │ │ └── HttpUtils.java │ │ │ │ └── web │ │ │ │ │ └── PEAccessLogValve.java │ │ │ │ └── web │ │ │ │ └── security │ │ │ │ └── RealmAdapter.java │ │ └── org │ │ │ └── glassfish │ │ │ ├── deployment │ │ │ ├── admin │ │ │ │ └── DeployCommand.java │ │ │ └── common │ │ │ │ ├── GenericAnnotationDetector.java │ │ │ │ └── NodeInfo.java │ │ │ ├── flashlight │ │ │ └── impl │ │ │ │ ├── client │ │ │ │ └── ProbeProviderClassFileTransformer.java │ │ │ │ └── core │ │ │ │ └── ProviderSubClassImplGenerator.java │ │ │ ├── grizzly │ │ │ ├── http │ │ │ │ ├── HttpServerFilter.java │ │ │ │ ├── server │ │ │ │ │ ├── DefaultErrorPageGenerator.java │ │ │ │ │ ├── Request.java │ │ │ │ │ └── util │ │ │ │ │ │ └── HtmlHelper.java │ │ │ │ └── util │ │ │ │ │ ├── MimeHeaders.java │ │ │ │ │ └── Parameters.java │ │ │ ├── http2 │ │ │ │ ├── Http2ServerFilter.java │ │ │ │ ├── Http2Session.java │ │ │ │ ├── Http2State.java │ │ │ │ └── Http2Stream.java │ │ │ └── utils │ │ │ │ └── IdleTimeoutFilter.java │ │ │ ├── hk2 │ │ │ └── classmodel │ │ │ │ └── reflect │ │ │ │ ├── Parser.java │ │ │ │ └── impl │ │ │ │ ├── AnnotatedElementImpl.java │ │ │ │ ├── FieldSignatureVisitorImpl.java │ │ │ │ ├── MethodSignatureVisitorImpl.java │ │ │ │ ├── ModelClassVisitor.java │ │ │ │ └── SignatureVisitorImpl.java │ │ │ ├── internal │ │ │ └── data │ │ │ │ └── ApplicationInfo.java │ │ │ ├── jersey │ │ │ └── server │ │ │ │ ├── ApplicationHandler.java │ │ │ │ └── ResourceBagConfigurator.java │ │ │ ├── pfl │ │ │ ├── dynamic │ │ │ │ └── codegen │ │ │ │ │ └── impl │ │ │ │ │ └── ASMUtil.java │ │ │ └── tf │ │ │ │ └── tools │ │ │ │ └── enhancer │ │ │ │ ├── AnnotationScannerAction.java │ │ │ │ ├── ClassTracer.java │ │ │ │ ├── SimpleMethodTracer.java │ │ │ │ └── TFEnhanceAdapter.java │ │ │ ├── rmic │ │ │ └── asm │ │ │ │ └── AsmClassFactory.java │ │ │ ├── web │ │ │ ├── embed │ │ │ │ └── impl │ │ │ │ │ └── ScatteredWebArchivist.java │ │ │ └── loader │ │ │ │ └── WebappClassLoader.java │ │ │ └── weld │ │ │ ├── DeploymentImpl.java │ │ │ └── ParamLibrariesResolver.java │ │ └── resources │ │ ├── config │ │ ├── cacerts.jks │ │ └── keystore.jks │ │ └── org │ │ └── glassfish │ │ ├── embed │ │ └── domain.xml │ │ └── web │ │ └── embed │ │ └── default-web.xml ├── microprofile │ ├── config │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── io │ │ │ └── smallrye │ │ │ └── config │ │ │ └── SmallRyeConfigBuilder.java │ ├── fault-tolerance │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ ├── com │ │ │ │ └── fujitsu │ │ │ │ │ └── launcher │ │ │ │ │ └── microprofile │ │ │ │ │ └── faulttolerance │ │ │ │ │ ├── IntegrateAsyncExecutorProvider.java │ │ │ │ │ ├── ProviderExtension.java │ │ │ │ │ └── ThreadFactoryProvider.java │ │ │ └── io │ │ │ │ └── smallrye │ │ │ │ └── faulttolerance │ │ │ │ ├── ExecutorHolder.java │ │ │ │ └── core │ │ │ │ └── timer │ │ │ │ └── ThreadTimer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── jakarta.enterprise.inject.spi.Extension │ ├── health │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ └── com │ │ │ │ └── fujitsu │ │ │ │ └── launcher │ │ │ │ └── microprofile │ │ │ │ └── health │ │ │ │ ├── HealthExtension.java │ │ │ │ ├── HealthReporterProducer.java │ │ │ │ ├── HealthServlet.java │ │ │ │ └── HealthServletContainerInitializer.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ ├── jakarta.enterprise.inject.spi.Extension │ │ │ └── jakarta.servlet.ServletContainerInitializer │ ├── jwt-auth │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ ├── com │ │ │ │ └── fujitsu │ │ │ │ │ └── launcher │ │ │ │ │ └── microprofile │ │ │ │ │ └── jwt │ │ │ │ │ └── auth │ │ │ │ │ ├── JwtAuthService.java │ │ │ │ │ ├── cdi │ │ │ │ │ ├── JwtAuthExtension.java │ │ │ │ │ └── VerboseJwtAuthContextInfoProvider.java │ │ │ │ │ └── rs │ │ │ │ │ └── JwtAuthAutoDiscoverable.java │ │ │ └── org │ │ │ │ └── glassfish │ │ │ │ └── web │ │ │ │ └── deployment │ │ │ │ └── annotation │ │ │ │ └── handlers │ │ │ │ └── LoginConfigHandler.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ ├── jakarta.enterprise.inject.spi.Extension │ │ │ └── org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable │ ├── metrics │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ ├── java │ │ │ ├── com │ │ │ │ └── fujitsu │ │ │ │ │ └── launcher │ │ │ │ │ └── microprofile │ │ │ │ │ └── metrics │ │ │ │ │ ├── MetricsServlet.java │ │ │ │ │ └── MetricsServletContainerInitializer.java │ │ │ └── io │ │ │ │ └── smallrye │ │ │ │ └── metrics │ │ │ │ └── base │ │ │ │ └── LegacyBaseMetrics.java │ │ │ └── resources │ │ │ └── META-INF │ │ │ └── services │ │ │ └── jakarta.servlet.ServletContainerInitializer │ ├── openapi │ │ ├── pom.xml │ │ └── src │ │ │ ├── main │ │ │ ├── java │ │ │ │ └── com │ │ │ │ │ └── fujitsu │ │ │ │ │ └── launcher │ │ │ │ │ └── microprofile │ │ │ │ │ └── openapi │ │ │ │ │ ├── OpenApiService.java │ │ │ │ │ ├── OpenApiServlet.java │ │ │ │ │ └── OpenApiServletContainerInitializer.java │ │ │ └── resources │ │ │ │ └── META-INF │ │ │ │ └── services │ │ │ │ └── jakarta.servlet.ServletContainerInitializer │ │ │ └── test │ │ │ └── java │ │ │ └── com │ │ │ └── fujitsu │ │ │ └── launcher │ │ │ └── microprofile │ │ │ └── openapi │ │ │ ├── OpenApiServiceTest.java │ │ │ └── OpenApiServletTest.java │ ├── pom.xml │ ├── rest-client │ │ ├── pom.xml │ │ └── src │ │ │ └── main │ │ │ └── java │ │ │ └── org │ │ │ └── glassfish │ │ │ └── jersey │ │ │ └── microprofile │ │ │ └── restclient │ │ │ └── RestClientBuilderImpl.java │ └── telemetry-tracing │ │ ├── pom.xml │ │ └── src │ │ └── main │ │ ├── java │ │ └── com │ │ │ └── fujitsu │ │ │ └── launcher │ │ │ └── microprofile │ │ │ └── telemetry │ │ │ └── tracing │ │ │ ├── cdi │ │ │ ├── MethodRequest.java │ │ │ ├── OpenTelemetryConfigProducer.java │ │ │ ├── OpenTelemetryExtension.java │ │ │ ├── OpenTelemetryProducer.java │ │ │ ├── WithSpanInterceptor.java │ │ │ └── WithSpanInterceptorBean.java │ │ │ ├── config │ │ │ └── OpenTelemetryConfig.java │ │ │ └── rest │ │ │ ├── client │ │ │ ├── OpenTelemetryClientAutoDiscoverable.java │ │ │ ├── OpenTelemetryClientFeature.java │ │ │ ├── OpenTelemetryClientFilter.java │ │ │ └── OpenTelemetryPreInvocationInterceptor.java │ │ │ └── server │ │ │ ├── OpenTelemetryServerAutoDiscoverable.java │ │ │ ├── OpenTelemetryServerDynamicFeature.java │ │ │ └── OpenTelemetryServerFilter.java │ │ └── resources │ │ └── META-INF │ │ └── services │ │ ├── jakarta.enterprise.inject.spi.Extension │ │ └── org.glassfish.jersey.internal.spi.AutoDiscoverable └── pom.xml └── pom.xml /.gitignore: -------------------------------------------------------------------------------- 1 | *.orig 2 | *.rej 3 | .classpath 4 | .factorypath 5 | .project 6 | .idea 7 | .settings/ 8 | dependency-reduced-pom.xml 9 | target/ 10 | -------------------------------------------------------------------------------- /README.adoc: -------------------------------------------------------------------------------- 1 | = Launcher 2 | 3 | 4 | == Overview 5 | Launcher is an implementation of https://microprofile.io/[MicroProfile]. 6 | 7 | Launcher 5.1 supports MicroProfile 6.0 and some APIs from Jakarta EE 10. 8 | Currently supported APIs are as follows: 9 | 10 | * MicroProfile Config 3.0 11 | * MicroProfile Fault Tolerance 4.0 12 | * MicroProfile Health 4.0 13 | * MicroProfile JWT Authentication 2.1 14 | * MicroProfile Metrics 5.0 15 | * MicroProfile OpenAPI 3.1 16 | * MicroProfile Telemetry 1.0 17 | * MicroProfile Rest Client 3.0 18 | * Jakarta EE 10 Core Profile 19 | * Jakarta Expression Language 5.0 20 | * Jakarta Server Pages 3.1 21 | * Jakarta Servlet 6.0 22 | * Jakarta Standard Tag Library 3.0 23 | 24 | Launcher provides features to run MicroProfile applications and create portable uber (fat) JARs. 25 | For more details, please refer to link:docs/Usage.adoc[]. 26 | 27 | == Build instructions 28 | ---- 29 | $ mvn clean install 30 | ---- 31 | 32 | == Usage 33 | Refer to link:docs/Usage.adoc[]. 34 | 35 | == Downloads 36 | Binary distributions can be obtained from link:https://github.com/fujitsu/launcher/releases[]. 37 | 38 | == Configuration file example 39 | 40 | An example of configuration file which can be used with `--config-file` option is available from link:examples/domain-xml[]. 41 | -------------------------------------------------------------------------------- /docs/Usage.adoc: -------------------------------------------------------------------------------- 1 | = Launcher 2 | 3 | == Usage 4 | ---- 5 | java -jar launcher-.jar 6 | [--config-file file-path] 7 | [--contextroot context-root] 8 | [--http-listener port-number] 9 | [--https-listener port-number] 10 | [--libraries jar-filepath[,jar-filepath]*] 11 | [--precompilejsp[=true|=false]] 12 | --deploy war-file 13 | [--generate uber-jar-filepath] 14 | ---- 15 | 16 | ---- 17 | java -jar launcher-.jar 18 | [--config-file file-path] 19 | --execute subcommand 20 | subcommand-args... 21 | ---- 22 | 23 | === Options 24 | [options="autowidth, header"] 25 | |=== 26 | | Name | Description | Default Value 27 | | `--config-file` | Specify the path to configuration file (domain.xml). Do not use `--http-listener` or `--https-listener` when using this option. | 28 | | `--contextroot` | Specify the context-root. | `/` 29 | | `--deploy` | Specify the path to WAR file to deploy. This option is mandatory. | 30 | | `--execute` | Specify the subcommand to execute. | 31 | | `--generate` | Specify the path to uber JAR to generate. When this option is not specified, the application will run automatically. | 32 | | `--http-listener` | Specify HTTP port number. Do not use `--config-file` when using this option. | `8080` 33 | | `--https-listener` |Specify HTTPS port number. Do not use `--config-file` when using this option. | `8181` 34 | | `--libraries` | Specify the paths to JAR files referred from the application. To specify more than one files, use comma (`,`) as a separator. Files specified in this option will not be included in the generated uber JAR. | 35 | | `--precompilejsp` | Specify `true` to enable JSP precompilation; `false` to disable. | `false` 36 | |=== 37 | 38 | === Operands 39 | [options="autowidth, header"] 40 | |=== 41 | | Name | Description 42 | | `subcommand-args` | Specify options and operands for the subcommand. 43 | |=== 44 | 45 | == Examples 46 | * Example 1: Run an application `my-app.war` without creating an uber JAR. 47 | ---- 48 | $ java -jar launcher-.jar --deploy my-app.war 49 | ---- 50 | 51 | * Example 2: Create an uber JAR `my-uber.jar` and run it. 52 | ---- 53 | $ java -jar launcher-.jar --deploy my-app.war --generate my-uber.jar 54 | $ java -jar my-uber.jar 55 | ---- 56 | 57 | * Example 3: Execute the `create-file-user` subcommand. 58 | ---- 59 | $ java -jar launcher-.jar --config-file domain.xml --execute create-file-user --passwordfile password.txt user1 60 | ---- 61 | -------------------------------------------------------------------------------- /examples/domain-xml/domain.xml: -------------------------------------------------------------------------------- 1 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | -Djavax.net.ssl.keyStore=${com.sun.aas.instanceRoot}/config/keystore.jks 80 | -Djavax.net.ssl.trustStore=${com.sun.aas.instanceRoot}/config/cacerts.jks 81 | -Djdk.tls.rejectClientInitiatedRenegotiation=true 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 114 | 115 | 116 | 117 | -------------------------------------------------------------------------------- /launcher-dist/src/main/resources/config/branding/glassfish-version.properties: -------------------------------------------------------------------------------- 1 | # 2 | # Copyright (c) 2019-2024 Fujitsu Limited and/or its affiliates. All rights 3 | # reserved. 4 | # 5 | # This program and the accompanying materials are made available under the 6 | # terms of the Eclipse Public License v. 2.0, which is available at 7 | # http://www.eclipse.org/legal/epl-2.0. 8 | # 9 | # SPDX-License-Identifier: EPL-2.0 10 | # 11 | 12 | product_name=Launcher 13 | brief_product_name=Launcher 14 | abbrev_product_name=launcher 15 | major_version=5 16 | minor_version=1 17 | update_version= 18 | build_id= 19 | version_prefix= 20 | version_suffix= 21 | default_domain_template=appserver-domain.jar 22 | admin_client_command_name=asadmin 23 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 14 | 4.0.0 15 | 16 | 17 | com.fujitsu.launcher 18 | launcher-impl 19 | 5.1-SNAPSHOT 20 | 21 | bootstrap 22 | jar 23 | 24 | 25 | 26 | com.fujitsu.launcher 27 | patched-glassfish 28 | 29 | 30 | 31 | args4j 32 | args4j 33 | 34 | 35 | 36 | 37 | org.junit.jupiter 38 | junit-jupiter-api 39 | 5.8.1 40 | test 41 | 42 | 43 | org.junit.jupiter 44 | junit-jupiter-engine 45 | 5.8.1 46 | test 47 | 48 | 49 | org.junit.jupiter 50 | junit-jupiter-params 51 | 5.8.1 52 | test 53 | 54 | 55 | org.mockito 56 | mockito-core 57 | 4.0.0 58 | test 59 | 60 | 61 | 62 | 63 | 64 | 65 | org.apache.maven.plugins 66 | maven-surefire-plugin 67 | 3.0.0-M5 68 | 69 | 70 | 71 | 72 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/DeployProperties.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher; 12 | 13 | import java.io.File; 14 | import java.util.ArrayList; 15 | import java.util.List; 16 | import java.util.Properties; 17 | 18 | /** 19 | * 20 | * @author Tsuyoshi Yoshitomi 21 | */ 22 | public class DeployProperties extends Properties { 23 | 24 | private static boolean relativeToApplibsDirectory = Boolean 25 | .getBoolean("com.fujitsu.launcher.deploy.libraries.relativeToApplibsDirectory"); 26 | 27 | public void setContextRoot(String contextroot) { 28 | setProperty("--contextroot", contextroot); 29 | } 30 | 31 | public void setLibraries(String libraries) { 32 | setProperty("--libraries", libraries); 33 | } 34 | 35 | public void setPrecompilejsp(boolean precompilejsp) { 36 | setProperty("--precompilejsp", Boolean.toString(precompilejsp)); 37 | } 38 | 39 | public String[] getDeployOptions() { 40 | List deployOptions = new ArrayList<>(); 41 | deployOptions.add("--name=launcher_application"); 42 | 43 | if (this.getProperty("--contextroot") != null) { 44 | deployOptions.add("--contextroot=" + getProperty("--contextroot")); 45 | } else { 46 | deployOptions.add("--contextroot="); 47 | } 48 | 49 | if (this.getProperty("--libraries") != null) { 50 | String libraries = getProperty("--libraries"); 51 | 52 | // Convert relative paths to absolute ones by taking them to be 53 | // relative to the current working directory. 54 | // By default GlassFish regards relative paths as relative to 55 | // instance-root/lib/applibs. 56 | if (!relativeToApplibsDirectory) { 57 | libraries = absolutizeDeployParamLibraries(libraries); 58 | } 59 | 60 | deployOptions.add("--libraries=" + libraries); 61 | } 62 | 63 | if (this.getProperty("--precompilejsp") != null) { 64 | deployOptions.add("--precompilejsp=" + getProperty("--precompilejsp")); 65 | } 66 | 67 | return deployOptions.toArray(new String[deployOptions.size()]); 68 | } 69 | 70 | private static String absolutizeDeployParamLibraries(String libraries) { 71 | String[] split = libraries.split(","); 72 | 73 | for (int i = 0; i < split.length; i++) { 74 | File f = new File(split[i]); 75 | split[i] = f.getAbsolutePath(); 76 | } 77 | 78 | return String.join(",", split); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/ExceptionUtil.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher; 12 | 13 | import java.io.IOException; 14 | import java.io.PrintWriter; 15 | import java.io.StringWriter; 16 | 17 | public class ExceptionUtil { 18 | public static String toStackStaceString(Throwable throwable) { 19 | try (StringWriter sw = new StringWriter(); 20 | PrintWriter pw = new PrintWriter(sw)) { 21 | throwable.printStackTrace(pw); 22 | return sw.toString(); 23 | } catch (IOException e) { 24 | throw new RuntimeException("Error while processing stack trace: " + e); 25 | } 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/LauncherConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher; 12 | 13 | import java.util.List; 14 | 15 | public class LauncherConfig { 16 | 17 | private Operation operation; 18 | private String configFile; 19 | private String contextRoot = "/"; 20 | private String deploy; 21 | private String execute; 22 | private boolean force; 23 | private String generate; 24 | private int httpListener = 8080; 25 | private int httpsListener = 8181; 26 | private String libraries; 27 | private boolean precompilejsp; 28 | private List subcommandArguments; 29 | 30 | public void setOperation(Operation operation) { 31 | this.operation = operation; 32 | } 33 | 34 | public Operation getOperation() { 35 | return operation; 36 | } 37 | 38 | public String getConfigFile() { 39 | return configFile; 40 | } 41 | 42 | public void setConfigFile(String configFile) { 43 | this.configFile = configFile; 44 | } 45 | 46 | public String getContextRoot() { 47 | return contextRoot; 48 | } 49 | 50 | public void setContextRoot(String contextRoot) { 51 | this.contextRoot = contextRoot; 52 | } 53 | 54 | public String getDeploy() { 55 | return deploy; 56 | } 57 | 58 | public void setDeploy(String deploy) { 59 | this.deploy = deploy; 60 | } 61 | 62 | public String getExecute() { 63 | return execute; 64 | } 65 | 66 | public void setExecute(String execute) { 67 | this.execute = execute; 68 | } 69 | 70 | public boolean isForce() { 71 | return force; 72 | } 73 | 74 | public void setForce(boolean force) { 75 | this.force = force; 76 | } 77 | 78 | public String getGenerate() { 79 | return generate; 80 | } 81 | 82 | public void setGenerate(String generate) { 83 | this.generate = generate; 84 | } 85 | 86 | public int getHttpListener() { 87 | return httpListener; 88 | } 89 | 90 | public void setHttpListener(int httpListener) { 91 | this.httpListener = httpListener; 92 | } 93 | 94 | public int getHttpsListener() { 95 | return httpsListener; 96 | } 97 | 98 | public void setHttpsListener(int httpsListener) { 99 | this.httpsListener = httpsListener; 100 | } 101 | 102 | public String getLibraries() { 103 | return libraries; 104 | } 105 | 106 | public void setLibraries(String libraries) { 107 | this.libraries = libraries; 108 | } 109 | 110 | public boolean isPrecompilejsp() { 111 | return precompilejsp; 112 | } 113 | 114 | public void setPrecompilejsp(boolean precompilejsp) { 115 | this.precompilejsp = precompilejsp; 116 | } 117 | 118 | public List getSubcommandArguments() { 119 | return subcommandArguments; 120 | } 121 | 122 | public void setSubcommandArguments(List subcommandArguments) { 123 | this.subcommandArguments = subcommandArguments; 124 | } 125 | } 126 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/Operation.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher; 12 | 13 | public enum Operation { 14 | DEPLOY, 15 | GENERATE, 16 | EXECUTE 17 | } 18 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/ArgumentList.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class ArgumentList { 17 | private List arguments = new ArrayList<>(); 18 | 19 | public void add(String token) { 20 | arguments.add(token); 21 | } 22 | 23 | public List getList() { 24 | return arguments; 25 | } 26 | 27 | @Override 28 | public String toString() { 29 | return "ArgumentList[" + arguments.toString() + "]"; 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/ArgumentToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class ArgumentToken extends Token { 14 | public ArgumentToken(String value) { 15 | super(value); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "ArgumentToken[" + get() + "]"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/BooleanOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class BooleanOption implements Option { 14 | private String name; 15 | private boolean value; 16 | 17 | public BooleanOption(String name, boolean value) { 18 | this.name = name; 19 | this.value = value; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | @Override 28 | public Boolean getValue() { 29 | return value; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "BooleanOption[" + name + "=" + value + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/CommandLineException.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class CommandLineException extends Exception { 14 | 15 | public CommandLineException(String message) { 16 | super(message); 17 | } 18 | 19 | public CommandLineException(String message, Throwable cause) { 20 | super(message, cause); 21 | } 22 | 23 | public CommandLineException(Throwable cause) { 24 | super(cause); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/IntOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class IntOption implements Option { 14 | private String name; 15 | private int value; 16 | 17 | public IntOption(String name, int value) { 18 | this.name = name; 19 | this.value = value; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | @Override 28 | public Integer getValue() { 29 | return value; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "IntOption[" + name + "=" + value + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/LauncherCommandLine.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import java.util.function.Consumer; 14 | 15 | import com.fujitsu.launcher.LauncherConfig; 16 | import com.fujitsu.launcher.Operation; 17 | 18 | public class LauncherCommandLine { 19 | public static final String CONFIG_FILE_OPTION = "--config-file"; 20 | public static final String CONTEXT_ROOT_OPTION = "--contextroot"; 21 | public static final String DEPLOY_OPTION = "--deploy"; 22 | public static final String EXECUTE_OPTION = "--execute"; 23 | public static final String FORCE_OPTION = "--force"; 24 | public static final String GENERATE_OPTION = "--generate"; 25 | public static final String HTTP_LISTENER_OPTION = "--http-listener"; 26 | public static final String HTTPS_LISTENER_OPTION = "--https-listener"; 27 | public static final String LIBRARIES_OPTION = "--libraries"; 28 | public static final String PRECOMPILEJSP_OPTION = "--precompilejsp"; 29 | 30 | private static final String[] FORBIDDEN_OPTIONS_FOR_EXECUTE = new String[] { 31 | CONTEXT_ROOT_OPTION, 32 | FORCE_OPTION, 33 | GENERATE_OPTION, 34 | LIBRARIES_OPTION, 35 | PRECOMPILEJSP_OPTION, 36 | }; 37 | 38 | public LauncherConfig parseCommandLine(String[] args) throws CommandLineException { 39 | OptionSpec optionSpec = new OptionSpec(); 40 | initOptionMap(optionSpec); 41 | 42 | Parser parser = new Parser(optionSpec); 43 | ParsingResult result = parser.parse(args); 44 | OptionMap optionMap = result.getOptionMap(); 45 | ArgumentList argumentList = result.getArgumentList(); 46 | Operation operation = detectOperation(optionMap); 47 | 48 | validateCommandLine(operation, optionMap, argumentList); 49 | 50 | return createConfigFromParsingResult(operation, optionMap, argumentList); 51 | } 52 | 53 | private void initOptionMap(OptionSpec optionSpec) { 54 | optionSpec.define(CONFIG_FILE_OPTION, StringOption.class); 55 | optionSpec.define(CONTEXT_ROOT_OPTION, StringOption.class); 56 | optionSpec.define(DEPLOY_OPTION, StringOption.class); 57 | optionSpec.define(EXECUTE_OPTION, StringOption.class); 58 | optionSpec.define(FORCE_OPTION, BooleanOption.class); 59 | optionSpec.define(GENERATE_OPTION, StringOption.class); 60 | optionSpec.define(HTTP_LISTENER_OPTION, IntOption.class); 61 | optionSpec.define(HTTPS_LISTENER_OPTION, IntOption.class); 62 | optionSpec.define(LIBRARIES_OPTION, StringOption.class); 63 | optionSpec.define(PRECOMPILEJSP_OPTION, BooleanOption.class); 64 | } 65 | 66 | private static LauncherConfig createConfigFromParsingResult(Operation operation, OptionMap optionMap, ArgumentList argumentList) { 67 | LauncherConfig config = new LauncherConfig(); 68 | 69 | config.setOperation(operation); 70 | 71 | setConfigIfPresent(config::setConfigFile, optionMap.get(CONFIG_FILE_OPTION, StringOption.class)); 72 | setConfigIfPresent(config::setHttpListener, optionMap.get(HTTP_LISTENER_OPTION, StringOption.class)); 73 | setConfigIfPresent(config::setHttpsListener, optionMap.get(HTTPS_LISTENER_OPTION, StringOption.class)); 74 | setConfigIfPresent(config::setContextRoot, optionMap.get(CONTEXT_ROOT_OPTION, StringOption.class)); 75 | setConfigIfPresent(config::setLibraries, optionMap.get(LIBRARIES_OPTION, StringOption.class)); 76 | setConfigIfPresent(config::setPrecompilejsp, optionMap.get(PRECOMPILEJSP_OPTION, StringOption.class)); 77 | setConfigIfPresent(config::setDeploy, optionMap.get(DEPLOY_OPTION, StringOption.class)); 78 | setConfigIfPresent(config::setGenerate, optionMap.get(GENERATE_OPTION, StringOption.class)); 79 | setConfigIfPresent(config::setForce, optionMap.get(FORCE_OPTION, StringOption.class)); 80 | setConfigIfPresent(config::setExecute, optionMap.get(EXECUTE_OPTION, StringOption.class)); 81 | 82 | config.setSubcommandArguments(argumentList.getList()); 83 | 84 | return config; 85 | } 86 | 87 | @SuppressWarnings("unchecked") 88 | private static void setConfigIfPresent(Consumer setter, Option option) { 89 | if (option != null) { 90 | setter.accept((T) option.getValue()); 91 | } 92 | } 93 | 94 | private static Operation detectOperation(OptionMap optionMap) throws CommandLineException { 95 | boolean deployOptionIsSet = optionMap.get(DEPLOY_OPTION) != null; 96 | boolean executeOptionIsSet = optionMap.get(EXECUTE_OPTION) != null; 97 | boolean generateOptionIsSet = optionMap.get(GENERATE_OPTION) != null; 98 | 99 | if (deployOptionIsSet && executeOptionIsSet) { 100 | throw new CommandLineException("Options '--deploy' and '--execute' are conflicting."); 101 | } else if (deployOptionIsSet && !executeOptionIsSet) { 102 | if (generateOptionIsSet) { 103 | return Operation.GENERATE; 104 | } else { 105 | return Operation.DEPLOY; 106 | } 107 | } else if (!deployOptionIsSet && executeOptionIsSet) { 108 | return Operation.EXECUTE; 109 | } else { 110 | throw new CommandLineException("Neither option '--deploy' nor '--execute' is specified."); 111 | } 112 | } 113 | 114 | private static void validateCommandLine(Operation operation, OptionMap optionMap, ArgumentList argumentList) throws CommandLineException { 115 | // test emptiness of argument list 116 | if (operation == Operation.DEPLOY || operation == Operation.GENERATE) { 117 | if (!argumentList.getList().isEmpty()) { 118 | throw new CommandLineException("Unexpected argument: " + argumentList.getList().get(0)); 119 | } 120 | } 121 | 122 | // test forbidden options 123 | if (operation == Operation.DEPLOY) { 124 | if (optionMap.get(FORCE_OPTION) != null) { 125 | throw new CommandLineException("Option '--force' must be used with option '--generate'."); 126 | } 127 | } else if (operation == Operation.EXECUTE) { 128 | for (String forbidden : FORBIDDEN_OPTIONS_FOR_EXECUTE) { 129 | if (optionMap.get(forbidden) != null) { 130 | throw new CommandLineException("Option '" + forbidden + "' cannot be used with option '--execute'."); 131 | } 132 | } 133 | } 134 | } 135 | } 136 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/Option.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public interface Option { 14 | String getName(); 15 | 16 | T getValue(); 17 | } 18 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/OptionMap.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class OptionMap { 17 | 18 | private Map> map = new HashMap<>(); 19 | 20 | public void put(Option option) { 21 | map.put(option.getName(), option); 22 | } 23 | 24 | public Option get(String name) { 25 | return map.get(name); 26 | } 27 | 28 | @SuppressWarnings("unchecked") 29 | public > T get(String name, Class clazz) { 30 | return (T) map.get(name); 31 | } 32 | 33 | public Map> getMap() { 34 | return map; 35 | } 36 | 37 | @Override 38 | public String toString() { 39 | return "OptionMap[" + map.toString() + "]"; 40 | } 41 | } -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/OptionNameToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class OptionNameToken extends Token { 14 | public OptionNameToken(String value) { 15 | super(value); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "OptionNameToken[" + get() + "]"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/OptionSpec.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import java.util.HashMap; 14 | import java.util.Map; 15 | 16 | public class OptionSpec { 17 | 18 | private Map>> map = new HashMap<>(); 19 | 20 | public void define(String name, Class> type) { 21 | map.put(name, type); 22 | } 23 | 24 | public Class> getType(String name) { 25 | return map.get(name); 26 | } 27 | 28 | public boolean isDefined(String name) { 29 | return map.containsKey(name); 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return map.toString(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/OptionValueToken.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class OptionValueToken extends Token { 14 | public OptionValueToken(String value) { 15 | super(value); 16 | } 17 | 18 | @Override 19 | public String toString() { 20 | return "OptionValueToken[" + get() + "]"; 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/Parser.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import java.util.ArrayList; 14 | import java.util.List; 15 | 16 | public class Parser { 17 | 18 | private OptionSpec optionSpec; 19 | 20 | public Parser(OptionSpec optionSpec) { 21 | this.optionSpec = optionSpec; 22 | } 23 | 24 | public ParsingResult parse(String[] args) throws CommandLineException { 25 | return parse(tokenize(args)); 26 | } 27 | 28 | public ParsingResult parse(List tokens) throws CommandLineException { 29 | OptionMap optionMap = new OptionMap(); 30 | ArgumentList argumentList = new ArgumentList(); 31 | 32 | for (int i = 0; i < tokens.size(); i++) { 33 | Token token = tokens.get(i); 34 | 35 | if (token instanceof OptionNameToken) { 36 | Token nextToken = i + 1 < tokens.size() ? tokens.get(i + 1) : null; 37 | 38 | if (nextToken != null && nextToken instanceof OptionValueToken) { 39 | String optionName = token.get(); 40 | String optionValue = nextToken.get(); 41 | Class> optionType = optionSpec.getType(optionName); 42 | if (optionType == StringOption.class) { 43 | optionMap.put(new StringOption(optionName, optionValue)); 44 | } else if (optionType == IntOption.class) { 45 | int intValue = Integer.parseInt(optionValue); 46 | optionMap.put(new IntOption(optionName, intValue)); 47 | } else if (optionType == BooleanOption.class) { 48 | boolean boolValue = Boolean.parseBoolean(optionValue); 49 | optionMap.put(new BooleanOption(optionName, boolValue)); 50 | } else { 51 | throw new CommandLineException( 52 | "Unsupported type '" + optionType + "' for option '" + optionName + "'"); 53 | } 54 | i++; 55 | } else { 56 | String optionName = token.get(); 57 | Class> optionType = optionSpec.getType(optionName); 58 | 59 | if (optionType == BooleanOption.class) { 60 | optionMap.put(new BooleanOption(optionName, true)); 61 | } else { 62 | throw new CommandLineException("Operand missing for option: " + optionName); 63 | } 64 | } 65 | } else if (token instanceof ArgumentToken) { 66 | argumentList.add(token.get()); 67 | } else { 68 | throw new CommandLineException("Unexpected token: " + token); 69 | } 70 | } 71 | 72 | return new ParsingResult(optionMap, argumentList); 73 | } 74 | 75 | public List tokenize(String[] args) { 76 | List tokens = new ArrayList<>(); 77 | for (int i = 0; i < args.length; i++) { 78 | String arg = args[i]; 79 | 80 | if (arg.startsWith("--")) { 81 | int equalIndex = arg.indexOf("="); 82 | 83 | String optionName; 84 | String optionValue; 85 | 86 | if (equalIndex != -1) { 87 | optionName = arg.substring(0, equalIndex); 88 | optionValue = arg.substring(equalIndex + 1); 89 | } else { 90 | optionName = arg; 91 | optionValue = null; 92 | } 93 | 94 | Class optionType = optionSpec.getType(optionName); 95 | if (optionType != null) { 96 | if (optionValue != null) { 97 | tokens.add(new OptionNameToken(optionName)); 98 | tokens.add(new OptionValueToken(optionValue)); 99 | } else { 100 | if (i + 1 < args.length) { 101 | String nextArg = args[i + 1]; 102 | if (optionType == BooleanOption.class && 103 | !nextArg.equalsIgnoreCase("true") && 104 | !nextArg.equalsIgnoreCase("false")) { 105 | // if the option is boolean and the next token is not a boolean literal, 106 | // we should not consume the next token 107 | tokens.add(new OptionNameToken(optionName)); 108 | } else { 109 | tokens.add(new OptionNameToken(optionName)); 110 | tokens.add(new OptionValueToken(nextArg)); 111 | i++; 112 | } 113 | } else { 114 | tokens.add(new OptionNameToken(optionName)); 115 | } 116 | } 117 | } else { 118 | // we regard unknown tokens as arguments even if it starts with "--" 119 | tokens.add(new ArgumentToken(arg)); 120 | } 121 | } else { 122 | tokens.add(new ArgumentToken(arg)); 123 | } 124 | } 125 | return tokens; 126 | } 127 | } 128 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/ParsingResult.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class ParsingResult { 14 | 15 | private OptionMap optionMap; 16 | private ArgumentList argumentList; 17 | 18 | public ParsingResult(OptionMap optionMap, ArgumentList argumentList) { 19 | this.optionMap = optionMap; 20 | this.argumentList = argumentList; 21 | } 22 | 23 | public OptionMap getOptionMap() { 24 | return optionMap; 25 | } 26 | 27 | public void setOptionMap(OptionMap optionMap) { 28 | this.optionMap = optionMap; 29 | } 30 | 31 | public ArgumentList getArgumentList() { 32 | return argumentList; 33 | } 34 | 35 | public void setArgumentList(ArgumentList argumentList) { 36 | this.argumentList = argumentList; 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "ParseResult[" + optionMap + ", " + argumentList + "]"; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/StringOption.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public class StringOption implements Option { 14 | private String name; 15 | private String value; 16 | 17 | public StringOption(String name, String value) { 18 | this.name = name; 19 | this.value = value; 20 | } 21 | 22 | @Override 23 | public String getName() { 24 | return name; 25 | } 26 | 27 | @Override 28 | public String getValue() { 29 | return value; 30 | } 31 | 32 | @Override 33 | public String toString() { 34 | return "StringOption[" + name + "=" + value + "]"; 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/cli/Token.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | public abstract class Token { 14 | 15 | private String value; 16 | 17 | protected Token(String value) { 18 | this.value = value; 19 | } 20 | 21 | public String get() { 22 | return value; 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/java/com/fujitsu/launcher/uberjar/Launcher.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.uberjar; 12 | 13 | import com.fujitsu.launcher.DeployProperties; 14 | import com.fujitsu.launcher.LauncherMain; 15 | 16 | import java.io.InputStream; 17 | import java.net.URL; 18 | import java.util.logging.Level; 19 | import java.util.logging.Logger; 20 | import org.glassfish.embeddable.GlassFish; 21 | import org.glassfish.embeddable.GlassFishProperties; 22 | import org.glassfish.embeddable.GlassFishRuntime; 23 | 24 | /** 25 | * 26 | * @author Tsuyoshi Yoshitomi 27 | */ 28 | public class Launcher { 29 | 30 | public static void main(String[] args) { 31 | new Launcher().start(); 32 | } 33 | 34 | private void start() { 35 | try ( 36 | InputStream gpis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_glassfish.properties"); 37 | InputStream dpis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_deploy.properties"); 38 | InputStream wis = this.getClass().getClassLoader().getResourceAsStream("uber-jar_application.war")) { 39 | 40 | GlassFishProperties glassfishProperties = new GlassFishProperties(); 41 | glassfishProperties.getProperties().load(gpis); 42 | URL url = this.getClass().getClassLoader().getResource("uber-jar_domain.xml"); 43 | if (url != null) { 44 | glassfishProperties.setConfigFileURI(url.toURI().toString()); 45 | } 46 | 47 | DeployProperties deployProperties = new DeployProperties(); 48 | deployProperties.load(dpis); 49 | 50 | LauncherMain.initProductName(); 51 | 52 | Thread preInitShutdownHook = LauncherMain.createPreInitShutdownHook(); 53 | Runtime.getRuntime().addShutdownHook(preInitShutdownHook); 54 | 55 | GlassFish glassfish = GlassFishRuntime.bootstrap().newGlassFish(glassfishProperties); 56 | 57 | Thread postInitShutdownHook = LauncherMain.createPostInitShutdownHook(glassfish); 58 | Runtime.getRuntime().addShutdownHook(postInitShutdownHook); 59 | Runtime.getRuntime().removeShutdownHook(preInitShutdownHook); 60 | 61 | glassfish.start(); 62 | glassfish.getDeployer().deploy(wis, deployProperties.getDeployOptions()); 63 | } catch (Throwable th) { 64 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, "Server was stopped.", th); 65 | LauncherMain.cleanInstanceRoot(); 66 | System.exit(1); 67 | } 68 | } 69 | } 70 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/main/resources/com/fujitsu/launcher/uber-jar_MANIFEST.MF: -------------------------------------------------------------------------------- 1 | Manifest-Version: 1.0 2 | Bundle-SymbolicName: org.glassfish.main.embedded.web 3 | Main-Class: com.fujitsu.launcher.uberjar.Launcher 4 | Add-Opens: java.base/java.lang java.base/java.lang.invoke java.base/java.util java.base/jdk.internal.loader java.base/sun.net.www.protocol.jar java.naming/javax.naming.spi java.rmi/sun.rmi.transport java.xml/com.sun.org.apache.bcel.internal.classfile 5 | Multi-Release: true 6 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/test/java/com/fujitsu/launcher/cli/LauncherCommandLineTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | import static org.junit.jupiter.api.Assertions.assertThrows; 15 | 16 | import java.util.Arrays; 17 | 18 | import org.junit.jupiter.api.Test; 19 | 20 | import com.fujitsu.launcher.LauncherConfig; 21 | import com.fujitsu.launcher.Operation; 22 | 23 | public class LauncherCommandLineTest { 24 | 25 | @Test 26 | public void testDeploy() throws CommandLineException { 27 | LauncherCommandLine commandLine = new LauncherCommandLine(); 28 | LauncherConfig config = commandLine.parseCommandLine(new String[] { 29 | "--config-file", "mydomain.xml", 30 | "--contextroot", "/mycontextroot", 31 | "--deploy", "myapp.war", 32 | "--http-listener", "28080", 33 | "--https-listener", "28181", 34 | "--libraries", "mylib1.jar,mylib2.jar", 35 | "--precompilejsp", "true" 36 | }); 37 | 38 | assertEquals(Operation.DEPLOY, config.getOperation()); 39 | assertEquals("mydomain.xml", config.getConfigFile()); 40 | assertEquals("/mycontextroot", config.getContextRoot()); 41 | assertEquals("myapp.war", config.getDeploy()); 42 | assertEquals(28080, config.getHttpListener()); 43 | assertEquals(28181, config.getHttpsListener()); 44 | assertEquals("mylib1.jar,mylib2.jar", config.getLibraries()); 45 | assertEquals(true, config.isPrecompilejsp()); 46 | } 47 | 48 | @Test 49 | public void testGenerate() throws CommandLineException { 50 | LauncherCommandLine commandLine = new LauncherCommandLine(); 51 | LauncherConfig config = commandLine.parseCommandLine(new String[] { 52 | "--deploy", "myapp.war", 53 | "--force", "true", 54 | "--generate", "myuber.jar" 55 | }); 56 | 57 | assertEquals(Operation.GENERATE, config.getOperation()); 58 | assertEquals("myapp.war", config.getDeploy()); 59 | assertEquals(true, config.isForce()); 60 | assertEquals("myuber.jar", config.getGenerate()); 61 | } 62 | 63 | @Test 64 | public void testExecute() throws CommandLineException { 65 | LauncherCommandLine commandLine = new LauncherCommandLine(); 66 | LauncherConfig config = commandLine.parseCommandLine(new String[] { 67 | "--execute", "create-file-user", "--passwordfile", "password.txt", "user1" 68 | }); 69 | 70 | assertEquals(Operation.EXECUTE, config.getOperation()); 71 | assertEquals("create-file-user", config.getExecute()); 72 | assertEquals(Arrays.asList("--passwordfile", "password.txt", "user1"), config.getSubcommandArguments()); 73 | } 74 | 75 | @Test 76 | public void testConflictingOptions() { 77 | LauncherCommandLine commandLine = new LauncherCommandLine(); 78 | 79 | Exception exception = assertThrows( 80 | CommandLineException.class, () -> { 81 | commandLine.parseCommandLine(new String[] { "--deploy", "myapp.war", "--execute", "create-file-user" }); 82 | }); 83 | 84 | assertEquals("Options '--deploy' and '--execute' are conflicting.", exception.getMessage()); 85 | } 86 | 87 | @Test 88 | public void testMandatoryOptionNotFound() { 89 | LauncherCommandLine commandLine = new LauncherCommandLine(); 90 | 91 | Exception exception = assertThrows( 92 | CommandLineException.class, () -> { 93 | commandLine.parseCommandLine(new String[] { "--config-file", "mydomain.xml" }); 94 | }); 95 | 96 | assertEquals("Neither option '--deploy' nor '--execute' is specified.", exception.getMessage()); 97 | } 98 | 99 | @Test 100 | public void testUnexpectedArgument() { 101 | LauncherCommandLine commandLine = new LauncherCommandLine(); 102 | 103 | Exception exception = assertThrows( 104 | CommandLineException.class, () -> { 105 | commandLine.parseCommandLine(new String[] { "--deploy", "myapp.war", "foo" }); 106 | }); 107 | 108 | assertEquals("Unexpected argument: foo", exception.getMessage()); 109 | } 110 | 111 | @Test 112 | public void testForbiddenOptionForDeploy() { 113 | LauncherCommandLine commandLine = new LauncherCommandLine(); 114 | 115 | Exception exception = assertThrows( 116 | CommandLineException.class, () -> { 117 | commandLine.parseCommandLine(new String[] { "--deploy", "myapp.war", "--force" }); 118 | }); 119 | 120 | assertEquals("Option '--force' must be used with option '--generate'.", exception.getMessage()); 121 | } 122 | 123 | @Test 124 | public void testForbiddenOptionForExecute() { 125 | LauncherCommandLine commandLine = new LauncherCommandLine(); 126 | 127 | Exception exception = assertThrows( 128 | CommandLineException.class, () -> { 129 | commandLine.parseCommandLine(new String[] { "--execute", "create-file-user", "--contextroot", "/mycontextroot" }); 130 | }); 131 | 132 | assertEquals("Option '--contextroot' cannot be used with option '--execute'.", exception.getMessage()); 133 | } 134 | 135 | } 136 | -------------------------------------------------------------------------------- /launcher-impl/bootstrap/src/test/java/com/fujitsu/launcher/cli/ParserTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.cli; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | import static org.junit.jupiter.api.Assertions.assertThrows; 15 | 16 | import java.util.Arrays; 17 | import java.util.Collections; 18 | import java.util.List; 19 | import java.util.stream.Stream; 20 | 21 | import org.junit.jupiter.api.Test; 22 | import org.junit.jupiter.params.ParameterizedTest; 23 | import org.junit.jupiter.params.provider.MethodSource; 24 | 25 | public class ParserTest { 26 | private OptionSpec optionSpec = new OptionSpec() { 27 | { 28 | define("--iopt", IntOption.class); 29 | define("--sopt", StringOption.class); 30 | define("--bopt", BooleanOption.class); 31 | } 32 | }; 33 | 34 | static Stream parserTestSpecProvider() { 35 | return Stream.of( 36 | new ParserTestSpec( 37 | new String[] { "--iopt", "123", "--sopt", "abc", "--bopt", "true", "--foo", "bar" }, 38 | Arrays.asList( 39 | new ExpectedOption("--iopt", 123, IntOption.class), 40 | new ExpectedOption("--sopt", "abc", StringOption.class), 41 | new ExpectedOption("--bopt", true, BooleanOption.class)), 42 | Arrays.asList("--foo", "bar")), 43 | new ParserTestSpec( 44 | new String[] { "--iopt=123", "--sopt=abc", "--bopt=true", "--foo=bar" }, 45 | Arrays.asList( 46 | new ExpectedOption("--iopt", 123, IntOption.class), 47 | new ExpectedOption("--sopt", "abc", StringOption.class), 48 | new ExpectedOption("--bopt", true, BooleanOption.class)), 49 | Arrays.asList("--foo=bar")), 50 | new ParserTestSpec( 51 | new String[] { "--bopt", "false" }, 52 | Arrays.asList( 53 | new ExpectedOption("--bopt", false, BooleanOption.class)), 54 | Collections.emptyList()), 55 | new ParserTestSpec( 56 | new String[] { "--bopt", "bar" }, 57 | Arrays.asList( 58 | new ExpectedOption("--bopt", true, BooleanOption.class)), 59 | Arrays.asList("bar")), 60 | new ParserTestSpec( 61 | new String[] { "--bopt" }, 62 | Arrays.asList( 63 | new ExpectedOption("--bopt", true, BooleanOption.class)), 64 | Collections.emptyList())); 65 | } 66 | 67 | @ParameterizedTest 68 | @MethodSource("parserTestSpecProvider") 69 | public void testParser(ParserTestSpec testSpec) throws CommandLineException { 70 | Parser parser = new Parser(optionSpec); 71 | 72 | ParsingResult parsingResult = parser.parse(testSpec.getCommandLine()); 73 | OptionMap optionMap = parsingResult.getOptionMap(); 74 | ArgumentList argumentList = parsingResult.getArgumentList(); 75 | 76 | assertEquals(testSpec.getExpectedOptions().size(), optionMap.getMap().size()); 77 | 78 | for (ExpectedOption expectedOption : testSpec.getExpectedOptions()) { 79 | assertEquals(expectedOption.getExpected(), 80 | optionMap.get(expectedOption.getOptionName(), expectedOption.getOptionType()).getValue()); 81 | } 82 | 83 | assertEquals(testSpec.getExpectedArguments(), argumentList.getList()); 84 | } 85 | 86 | @Test 87 | public void testMissingOperand() { 88 | Parser parser = new Parser(optionSpec); 89 | 90 | Exception exception = assertThrows( 91 | CommandLineException.class, () -> { 92 | parser.parse(new String[] { "--sopt" }); 93 | }); 94 | 95 | assertEquals("Operand missing for option: --sopt", exception.getMessage()); 96 | } 97 | 98 | public static class ParserTestSpec { 99 | private String[] commandLine; 100 | private List expectedOptions; 101 | private List expectedArguments; 102 | 103 | public ParserTestSpec(String[] commandLine, List expectedOptions, List expectedArguments) { 104 | this.commandLine = commandLine; 105 | this.expectedOptions = expectedOptions; 106 | this.expectedArguments = expectedArguments; 107 | } 108 | 109 | public String[] getCommandLine() { 110 | return commandLine; 111 | } 112 | 113 | public List getExpectedOptions() { 114 | return expectedOptions; 115 | } 116 | 117 | public List getExpectedArguments() { 118 | return expectedArguments; 119 | } 120 | } 121 | 122 | public static class ExpectedOption { 123 | private String optionName; 124 | private Object expected; 125 | private Class> optionType; 126 | 127 | public ExpectedOption(String optionName, Object expected, Class> optionType) { 128 | this.optionName = optionName; 129 | this.expected = expected; 130 | this.optionType = optionType; 131 | } 132 | 133 | public String getOptionName() { 134 | return optionName; 135 | } 136 | 137 | public Object getExpected() { 138 | return expected; 139 | } 140 | 141 | public Class> getOptionType() { 142 | return optionType; 143 | } 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/admin/cli/schemadoc/AttributeMethodVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | 17 | package com.sun.enterprise.admin.cli.schemadoc; 18 | 19 | import org.objectweb.asm.AnnotationVisitor; 20 | import org.glassfish.api.admin.config.PropertiesDesc; 21 | import org.glassfish.api.admin.config.PropertyDesc; 22 | import org.jvnet.hk2.config.Attribute; 23 | import org.objectweb.asm.Opcodes; 24 | 25 | public class AttributeMethodVisitor extends EmptyVisitor { 26 | private ClassDef def; 27 | private String name; 28 | private String type; 29 | private boolean duckTyped; 30 | 31 | public AttributeMethodVisitor(ClassDef classDef, String method, String aggType) { 32 | super(Opcodes.ASM9); 33 | def = classDef; 34 | name = method; 35 | type = aggType; 36 | def.addAttribute(name, null); 37 | } 38 | 39 | @Override 40 | public String toString() { 41 | return "AttributeMethodVisitor{" + "def=" + def + ", name='" + name + '\'' + ", type='" + type + '\'' + ", duckTyped=" + duckTyped 42 | + '}'; 43 | } 44 | 45 | /** 46 | * Visits an annotation of this method. 47 | * 48 | * @param desc the class descriptor of the annotation class. 49 | * @param visible true if the annotation is visible at runtime. 50 | * 51 | * @return a visitor to visit the annotation values, or null if this visitor is not interested in visiting this 52 | * annotation. 53 | */ 54 | @Override 55 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 56 | duckTyped |= "Lorg/jvnet/hk2/config/DuckTyped;".equals(desc); 57 | AnnotationVisitor visitor = null; 58 | if ("Lorg/jvnet/hk2/config/Attribute;".equals(desc) || "Lorg/jvnet/hk2/config/Element;".equals(desc)) { 59 | try { 60 | final Class configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef()); 61 | final Attribute annotation = configurable.getMethod(name).getAnnotation(Attribute.class); 62 | def.addAttribute(name, annotation); 63 | } catch (Exception e) { 64 | throw new RuntimeException(e.getMessage(), e); 65 | } 66 | 67 | } else if ("Lorg/glassfish/api/admin/config/PropertiesDesc;".equals(desc)) { 68 | try { 69 | final Class configurable = Thread.currentThread().getContextClassLoader().loadClass(def.getDef()); 70 | final PropertiesDesc annotation = configurable.getMethod(name).getAnnotation(PropertiesDesc.class); 71 | final PropertyDesc[] propertyDescs = annotation.props(); 72 | for (PropertyDesc prop : propertyDescs) { 73 | def.addProperty(prop); 74 | } 75 | } catch (Exception e) { 76 | throw new RuntimeException(e.getMessage(), e); 77 | } 78 | } 79 | return visitor; 80 | } 81 | 82 | @Override 83 | public void visitEnd() { 84 | if (!duckTyped) { 85 | if (!isSimpleType(type)) { 86 | def.addAggregatedType(name, type); 87 | def.removeAttribute(name); 88 | } 89 | } else { 90 | def.removeAttribute(name); 91 | } 92 | } 93 | 94 | private boolean isSimpleType(String type) { 95 | return type.startsWith("java"); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/admin/cli/schemadoc/DocClassVisitor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | 17 | package com.sun.enterprise.admin.cli.schemadoc; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import org.objectweb.asm.*; 22 | 23 | public class DocClassVisitor extends ClassVisitor { 24 | private boolean hasConfiguredAnnotation = false; 25 | private String className; 26 | private List interfaces; 27 | private ClassDef classDef; 28 | private boolean showDeprecated; 29 | 30 | public DocClassVisitor(final boolean showDep) { 31 | super(Opcodes.ASM9); 32 | showDeprecated = showDep; 33 | } 34 | 35 | @Override 36 | public void visit(int version, int access, String name, String signature, String superName, String[] intfs) { 37 | className = GenerateDomainSchema.toClassName(name); 38 | interfaces = new ArrayList(); 39 | for (String intf : intfs) { 40 | interfaces.add(GenerateDomainSchema.toClassName(intf)); 41 | } 42 | classDef = new ClassDef(className, interfaces); 43 | } 44 | 45 | public List getInterfaces() { 46 | return interfaces; 47 | } 48 | 49 | @Override 50 | public void visitSource(String source, String debug) { 51 | } 52 | 53 | @Override 54 | public void visitOuterClass(String owner, String name, String desc) { 55 | } 56 | 57 | @Override 58 | public AnnotationVisitor visitAnnotation(String desc, boolean visible) { 59 | hasConfiguredAnnotation |= "Lorg/jvnet/hk2/config/Configured;".equals(desc); 60 | if ("Ljava/lang/Deprecated;".equals(desc) && classDef != null) { 61 | classDef.setDeprecated(true); 62 | } 63 | return null; 64 | } 65 | 66 | @Override 67 | public void visitAttribute(Attribute attr) { 68 | } 69 | 70 | @Override 71 | public void visitInnerClass(String name, String outerName, String innerName, int access) { 72 | } 73 | 74 | @Override 75 | public FieldVisitor visitField(int access, String name, String desc, String signature, Object value) { 76 | return null; 77 | } 78 | 79 | @Override 80 | public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { 81 | String type = null; 82 | try { 83 | if (showDeprecated || ((access & Opcodes.ACC_DEPRECATED) != Opcodes.ACC_DEPRECATED)) { 84 | if (hasConfiguredAnnotation) { 85 | if (signature != null) { 86 | type = GenerateDomainSchema 87 | .toClassName(signature.substring(signature.indexOf("<") + 1, signature.lastIndexOf(">") - 1)); 88 | } else { 89 | type = GenerateDomainSchema.toClassName(desc); 90 | } 91 | } 92 | } 93 | } catch (StringIndexOutOfBoundsException e) { 94 | throw new RuntimeException(e.getMessage()); 95 | } 96 | return name.startsWith("get") && type != null ? new AttributeMethodVisitor(classDef, name, type) : null; 97 | } 98 | 99 | /** 100 | * Visits the end of the class. This method, which is the last one to be called, is used to inform the visitor that all 101 | * the fields and methods of the class have been visited. 102 | */ 103 | @Override 104 | public void visitEnd() { 105 | } 106 | 107 | public ModuleVisitor visitModule() { 108 | return null; 109 | } 110 | 111 | public boolean isConfigured() { 112 | return hasConfiguredAnnotation; 113 | } 114 | 115 | public ClassDef getClassDef() { 116 | return hasConfiguredAnnotation ? classDef : null; 117 | } 118 | 119 | @Override 120 | public String toString() { 121 | return "DocClassVisitor{" + "className='" + className + '\'' + ", hasConfiguredAnnotation=" + hasConfiguredAnnotation + '}'; 122 | } 123 | } 124 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/security/web/integration/GlassFishToExousiaConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021 Contributors to the Eclipse Foundation 3 | * Copyright (c) 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package com.sun.enterprise.security.web.integration; 19 | 20 | import static jakarta.servlet.annotation.ServletSecurity.TransportGuarantee.CONFIDENTIAL; 21 | import static jakarta.servlet.annotation.ServletSecurity.TransportGuarantee.NONE; 22 | import static java.util.Collections.list; 23 | import static java.util.stream.Collectors.toSet; 24 | 25 | import java.util.ArrayList; 26 | import java.util.HashMap; 27 | import java.util.List; 28 | import java.util.Map; 29 | import java.util.Set; 30 | 31 | import org.glassfish.exousia.constraints.SecurityConstraint; 32 | import org.glassfish.exousia.constraints.WebResourceCollection; 33 | import org.glassfish.exousia.mapping.SecurityRoleRef; 34 | 35 | import com.sun.enterprise.deployment.WebBundleDescriptor; 36 | import com.sun.enterprise.deployment.WebComponentDescriptor; 37 | import com.sun.enterprise.deployment.web.SecurityRoleReference; 38 | import com.sun.enterprise.deployment.web.UserDataConstraint; 39 | 40 | import jakarta.servlet.annotation.ServletSecurity.TransportGuarantee; 41 | 42 | /** 43 | * This class converts from GlassFish security types to Exousia security types. 44 | * 45 | * @author arjan 46 | * 47 | */ 48 | public class GlassFishToExousiaConverter { 49 | 50 | 51 | /** 52 | * Get the security constraints from the WebBundleDescriptor. 53 | * 54 | * @param webBundleDescriptor the WebBundleDescriptor. 55 | * @return the security constraints. 56 | */ 57 | public static List getConstraintsFromBundle(WebBundleDescriptor webBundleDescriptor) { 58 | List constraints = new ArrayList<>(); 59 | 60 | for (com.sun.enterprise.deployment.web.SecurityConstraint glassFishSecurityConstraint : list(webBundleDescriptor.getSecurityConstraints())) { 61 | 62 | List webResourceCollections = new ArrayList<>(); 63 | for (com.sun.enterprise.deployment.web.WebResourceCollection glassFishCollection : glassFishSecurityConstraint.getWebResourceCollections()) { 64 | webResourceCollections.add(new WebResourceCollection( 65 | glassFishCollection.getUrlPatterns(), 66 | glassFishCollection.getHttpMethods(), 67 | glassFishCollection.getHttpMethodOmissions())); 68 | } 69 | 70 | constraints.add(new SecurityConstraint( 71 | webResourceCollections, 72 | securityRoles(glassFishSecurityConstraint), 73 | transportGuarantee(glassFishSecurityConstraint))); 74 | 75 | } 76 | 77 | return constraints; 78 | } 79 | 80 | static Set securityRoles(com.sun.enterprise.deployment.web.SecurityConstraint glassFishSecurityConstraint) { 81 | if (glassFishSecurityConstraint.getAuthorizationConstraint() == null) { 82 | return null; 83 | } 84 | 85 | return 86 | list(glassFishSecurityConstraint.getAuthorizationConstraint().getSecurityRoles()) 87 | .stream() 88 | .map(role -> role.getName()) 89 | .collect(toSet()); 90 | } 91 | 92 | 93 | static TransportGuarantee transportGuarantee(com.sun.enterprise.deployment.web.SecurityConstraint glassFishSecurityConstraint) { 94 | UserDataConstraint userDataConstraint = glassFishSecurityConstraint.getUserDataConstraint(); 95 | if (userDataConstraint == null) { 96 | return NONE; 97 | } 98 | String transportGuarantee = userDataConstraint.getTransportGuarantee(); 99 | if ("confidential".equalsIgnoreCase(transportGuarantee) || "integral".equalsIgnoreCase(transportGuarantee)) { 100 | return CONFIDENTIAL; 101 | } else { 102 | return NONE; 103 | } 104 | } 105 | 106 | /** 107 | * Get the security role refs from the WebBundleDescriptor. 108 | * 109 | * @param servletNames the servlet names. 110 | * @param webBundleDescriptor the WebBundleDescriptor. 111 | * @return the security role refs. 112 | */ 113 | public static Map> getSecurityRoleRefsFromBundle(WebBundleDescriptor webBundleDescriptor) { 114 | Map> exousiaRoleRefsPerServlet = new HashMap<>(); 115 | 116 | for (WebComponentDescriptor webComponent : webBundleDescriptor.getWebComponentDescriptors()) { 117 | 118 | List exousiaSecurityRoleRefs = new ArrayList<>(); 119 | 120 | for (SecurityRoleReference glassFishSecurityRoleRef : webComponent.getSecurityRoleReferenceSet()) { 121 | exousiaSecurityRoleRefs.add(new SecurityRoleRef( 122 | glassFishSecurityRoleRef.getRoleName(), 123 | glassFishSecurityRoleRef.getSecurityRoleLink().getName())); 124 | } 125 | 126 | exousiaRoleRefsPerServlet.put(webComponent.getCanonicalName(), exousiaSecurityRoleRefs); 127 | } 128 | 129 | return exousiaRoleRefsPerServlet; 130 | } 131 | 132 | } -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/server/logging/ServerLogFileService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited. 3 | * Copyright (c) 2022 Contributors to the Eclipse Foundation 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package com.sun.enterprise.server.logging; 19 | 20 | import jakarta.inject.Singleton; 21 | 22 | import java.io.File; 23 | import java.lang.System.Logger.Level; 24 | 25 | import org.glassfish.main.jul.JULHelperFactory; 26 | import org.glassfish.main.jul.JULHelperFactory.JULHelper; 27 | import org.glassfish.main.jul.handler.GlassFishLogHandler; 28 | import org.jvnet.hk2.annotations.ContractsProvided; 29 | import org.jvnet.hk2.annotations.Service; 30 | 31 | /** 32 | * This service is used to rotate the server.log file (if it is configured). 33 | * 34 | * @author Jerome Dochez 35 | * @author Carla Mott 36 | * @author David Matejcek 37 | */ 38 | @Service 39 | @Singleton 40 | @ContractsProvided(ServerLogFileManager.class) 41 | public class ServerLogFileService implements ServerLogFileManager { 42 | 43 | private final JULHelper julHelper = JULHelperFactory.getHelper(); 44 | 45 | 46 | @Override 47 | public File getCurrentLogFile() { 48 | final GlassFishLogHandler logHandler = julHelper.findGlassFishLogHandler(); 49 | if (logHandler == null) { 50 | return null; 51 | } 52 | return logHandler.getConfiguration().getLogFile(); 53 | } 54 | 55 | 56 | /** 57 | * Renames the server.log file and starts logging to a new file. 58 | */ 59 | @Override 60 | public void roll() { 61 | final GlassFishLogHandler logHandler = julHelper.findGlassFishLogHandler(); 62 | if (logHandler == null) { 63 | throw new IllegalStateException("The GlassFishLogHandler was not found, rolling the output file failed."); 64 | } 65 | logHandler.roll(); 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/v3/services/impl/GlassfishErrorPageGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2021, 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package com.sun.enterprise.v3.services.impl; 19 | 20 | import com.sun.appserv.server.util.Version; 21 | import org.glassfish.grizzly.http.server.ErrorPageGenerator; 22 | import org.glassfish.grizzly.http.server.Request; 23 | 24 | /** 25 | * Glassfish default {@link ErrorPageGenerator}. 26 | */ 27 | public class GlassfishErrorPageGenerator implements ErrorPageGenerator { 28 | 29 | @Override 30 | public String generate(final Request request, final int status, 31 | final String reasonPhrase, final String description, 32 | final Throwable exception) { 33 | 34 | String serverInfo = System.getProperty("product.name"); 35 | String serverVersion = serverInfo != null ? serverInfo : Version.getVersion(); 36 | 37 | if (status == 404) { 38 | return HttpUtils.getErrorPage(serverVersion, 39 | "The requested resource is not available.", "404"); 40 | } else { 41 | return HttpUtils.getErrorPage(serverVersion, 42 | "The server encountered an internal error that prevented it from fulfilling this request.", String.valueOf(status)); 43 | } 44 | } 45 | } 46 | 47 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/com/sun/enterprise/v3/services/impl/HttpUtils.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2007, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2021, 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package com.sun.enterprise.v3.services.impl; 19 | 20 | import java.nio.ByteBuffer; 21 | 22 | import org.glassfish.grizzly.http.util.Ascii; 23 | 24 | /** 25 | * Utility class for parsing ByteBuffer 26 | * @author Jeanfrancois 27 | */ 28 | public class HttpUtils { 29 | 30 | 31 | private final static String CSS = 32 | "H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} " + 33 | "H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} " + 34 | "H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} " + 35 | "BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} " + 36 | "B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} " + 37 | "P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}" + 38 | "A {color : black;}" + 39 | "HR {color : #525D76;}"; 40 | 41 | /** 42 | * Specialized utility method: find a sequence of lower case bytes inside 43 | * a {@link ByteBuffer}. 44 | */ 45 | public static int findBytes(ByteBuffer byteBuffer, byte[] b) { 46 | int curPosition = byteBuffer.position(); 47 | int curLimit = byteBuffer.limit(); 48 | 49 | if (byteBuffer.position() == 0){ 50 | throw new IllegalStateException("Invalid state"); 51 | } 52 | 53 | byteBuffer.position(0); 54 | byteBuffer.limit(curPosition); 55 | try { 56 | byte first = b[0]; 57 | int start = 0; 58 | int end = curPosition; 59 | 60 | // Look for first char 61 | int srcEnd = b.length; 62 | 63 | for (int i = start; i <= (end - srcEnd); i++) { 64 | if (Ascii.toLower(byteBuffer.get(i)) != first) continue; 65 | // found first char, now look for a match 66 | int myPos = i+1; 67 | for (int srcPos = 1; srcPos < srcEnd; ) { 68 | if (Ascii.toLower(byteBuffer.get(myPos++)) != b[srcPos++]) 69 | break; 70 | if (srcPos == srcEnd) return i - start; // found it 71 | } 72 | } 73 | return -1; 74 | } finally { 75 | byteBuffer.limit(curLimit); 76 | byteBuffer.position(curPosition); 77 | } 78 | } 79 | 80 | public static String getErrorPage(String serverName, String message, String errorCode) { 81 | StringBuilder sb = new StringBuilder(); 82 | sb.append(""); 84 | sb.append(""); 85 | if (null != serverName && !serverName.isEmpty()) { 86 | sb.append(serverName).append(" - "); 87 | } 88 | sb.append("Error report

HTTP Status "); 96 | sb.append(errorCode).append(" - "); 97 | sb.append("


type Status report

message

description"); 98 | sb.append(message).append("


"); 99 | if (null != serverName && !serverName.isEmpty()) { 100 | sb.append(serverName); 101 | } 102 | sb.append("

"); 103 | return sb.toString(); 104 | } 105 | 106 | } 107 | 108 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/grizzly/http/server/DefaultErrorPageGenerator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2013, 2020 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2021, 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package org.glassfish.grizzly.http.server; 19 | 20 | import org.glassfish.grizzly.http.server.util.HtmlHelper; 21 | import org.glassfish.grizzly.http.util.HttpStatus; 22 | import org.glassfish.grizzly.http.util.HttpUtils; 23 | 24 | /** 25 | * Default Grizzly {@link ErrorPageGenerator}. 26 | */ 27 | public class DefaultErrorPageGenerator implements ErrorPageGenerator { 28 | 29 | /** 30 | * {@inheritDoc} 31 | */ 32 | @Override 33 | public String generate(final Request request, final int status, final String reasonPhrase, final String description, final Throwable exception) { 34 | if (status == 404) { 35 | return HtmlHelper.getErrorPage(HttpStatus.NOT_FOUND_404.getReasonPhrase(), 36 | "Resource identified by path '" + HttpUtils.filter(request.getRequestURI()) + "', does not exist.", 37 | System.getProperty("product.name")); 38 | } 39 | 40 | return HtmlHelper.getExceptionErrorPage(reasonPhrase, description, System.getProperty("product.name"), exception); 41 | } 42 | } 43 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/grizzly/http2/Http2State.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2015, 2020 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package org.glassfish.grizzly.http2; 19 | 20 | import java.util.ArrayList; 21 | import java.util.List; 22 | import java.util.concurrent.atomic.AtomicReference; 23 | 24 | import org.glassfish.grizzly.Connection; 25 | import org.glassfish.grizzly.attributes.Attribute; 26 | import org.glassfish.grizzly.attributes.AttributeBuilder; 27 | import org.glassfish.grizzly.http2.Http2FrameCodec.FrameParsingState; 28 | 29 | /** 30 | * 31 | * @author oleksiys 32 | */ 33 | class Http2State { 34 | private static final Attribute http2State = AttributeBuilder.DEFAULT_ATTRIBUTE_BUILDER.createAttribute(Http2State.class.getName() + ".state"); 35 | 36 | private List listeners; 37 | 38 | static Http2State get(final Connection connection) { 39 | return http2State.get(connection); 40 | } 41 | 42 | static boolean isHttp2(final Connection connection) { 43 | final Http2State state = http2State.get(connection); 44 | 45 | return state != null && state.isHttp2(); 46 | } 47 | 48 | static Http2State obtain(final Connection connection) { 49 | Http2State state = http2State.get(connection); 50 | if (state == null) { 51 | state = create(connection); 52 | } 53 | 54 | return state; 55 | } 56 | 57 | static Http2State create(final Connection connection) { 58 | final Http2State state = new Http2State(); 59 | http2State.set(connection, state); 60 | 61 | return state; 62 | } 63 | 64 | static void remove(final Connection connection) { 65 | http2State.remove(connection); 66 | } 67 | 68 | private final AtomicReference status = new AtomicReference<>(); 69 | private final FrameParsingState frameParsingState = new FrameParsingState(); 70 | 71 | private Http2Session http2Session; 72 | 73 | private volatile boolean isPriReceived; 74 | 75 | private boolean isClientHttpUpgradeRequestFinished; 76 | private boolean isClientPrefaceSent; 77 | 78 | public enum Status { 79 | NEVER_HTTP2, HTTP_UPGRADE, DIRECT_UPGRADE, OPEN 80 | } 81 | 82 | public Http2State() { 83 | status.set(Status.HTTP_UPGRADE); 84 | } 85 | 86 | public Status getStatus() { 87 | return status.get(); 88 | } 89 | 90 | /** 91 | * @return true if this connection is not HTTP2 and never will be in future, or false otherwise 92 | */ 93 | boolean isNeverHttp2() { 94 | return status.get() == Status.NEVER_HTTP2; 95 | } 96 | 97 | /** 98 | * Marks the connection as never be used for HTTP2. 99 | */ 100 | void setNeverHttp2() { 101 | status.set(Status.NEVER_HTTP2); 102 | } 103 | 104 | boolean isHttp2() { 105 | return !isNeverHttp2(); 106 | } 107 | 108 | /** 109 | * @return true if HTTP2 connection received preface from the peer, or false otherwise 110 | */ 111 | public boolean isReady() { 112 | return status.get() == Status.OPEN; 113 | } 114 | 115 | public synchronized void addReadyListener(final ReadyListener... readyListeners) { 116 | if (readyListeners == null) { 117 | return; 118 | } 119 | if (isReady()) { 120 | for (int i = 0, len = readyListeners.length; i < len; i++) { 121 | readyListeners[i].ready(http2Session); 122 | } 123 | } else { 124 | if (listeners == null) { 125 | listeners = new ArrayList<>(readyListeners.length + 2); 126 | } 127 | for (int i = 0, len = readyListeners.length; i < len; i++) { 128 | listeners.add(readyListeners[i]); 129 | } 130 | } 131 | } 132 | 133 | /** 134 | * Confirms that HTTP2 connection received preface from the peer. 135 | */ 136 | void setOpen() { 137 | status.set(Status.OPEN); 138 | notifyReadyListeners(); 139 | } 140 | 141 | boolean isHttpUpgradePhase() { 142 | return status.get() == Status.HTTP_UPGRADE; 143 | } 144 | 145 | void finishHttpUpgradePhase() { 146 | status.compareAndSet(Status.HTTP_UPGRADE, Status.DIRECT_UPGRADE); 147 | } 148 | 149 | void setDirectUpgradePhase() { 150 | status.set(Status.DIRECT_UPGRADE); 151 | } 152 | 153 | FrameParsingState getFrameParsingState() { 154 | return frameParsingState; 155 | } 156 | 157 | Http2Session getHttp2Session() { 158 | return http2Session; 159 | } 160 | 161 | void setHttp2Session(final Http2Session http2Session) { 162 | this.http2Session = http2Session; 163 | this.http2Session.http2State = this; 164 | } 165 | 166 | boolean isPriReceived() { 167 | return isPriReceived; 168 | } 169 | 170 | void setPriReceived(boolean isPriReceived) { 171 | this.isPriReceived = isPriReceived; 172 | } 173 | 174 | /** 175 | * Client-side only. Invoked, when a client finishes sending plain HTTP/1.x request containing HTTP2 upgrade headers. 176 | */ 177 | void onClientHttpUpgradeRequestFinished() { 178 | isClientHttpUpgradeRequestFinished = true; 179 | } 180 | 181 | synchronized boolean tryLockClientPreface() { 182 | final Status s = status.get(); 183 | if (!isClientPrefaceSent && isClientHttpUpgradeRequestFinished && (s == Status.DIRECT_UPGRADE || s == Status.OPEN)) { 184 | isClientPrefaceSent = true; 185 | return true; 186 | } 187 | 188 | return false; 189 | } 190 | 191 | private synchronized void notifyReadyListeners() { 192 | if (listeners != null && !listeners.isEmpty()) { 193 | for (ReadyListener listener : listeners) { 194 | listener.ready(http2Session); 195 | } 196 | listeners.clear(); 197 | listeners = null; 198 | } 199 | } 200 | 201 | interface ReadyListener { 202 | void ready(Http2Session http2Session); 203 | } 204 | } 205 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/AnnotatedElementImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2010, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2022 Fujitsu Limited. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package org.glassfish.hk2.classmodel.reflect.impl; 19 | 20 | import org.glassfish.hk2.classmodel.reflect.*; 21 | 22 | import java.util.*; 23 | 24 | /** 25 | * Implementation of an annotated element 26 | * 27 | * @author Jerome Dochez 28 | */ 29 | public class AnnotatedElementImpl implements AnnotatedElement { 30 | 31 | private final String name; 32 | 33 | private final List annotations = new ArrayList(); 34 | 35 | private boolean isApplicationClass; 36 | 37 | public AnnotatedElementImpl(String name) { 38 | this.name = name; 39 | } 40 | 41 | @Override 42 | public String getName() { 43 | return name; 44 | } 45 | 46 | synchronized void addAnnotation(AnnotationModel annotation) { 47 | annotations.add(annotation); 48 | } 49 | 50 | @Override 51 | public synchronized Collection getAnnotations() { 52 | return new ArrayList(annotations); 53 | } 54 | 55 | @Override 56 | public synchronized AnnotationModel getAnnotation(String name) { 57 | for (AnnotationModel am : annotations) { 58 | if (am.getType().getName().equals(name)) { 59 | return am; 60 | } 61 | } 62 | return null; 63 | } 64 | 65 | public boolean isApplicationClass() { 66 | return isApplicationClass; 67 | } 68 | 69 | public void setApplicationClass(boolean applicationClass) { 70 | isApplicationClass = applicationClass; 71 | } 72 | 73 | @Override 74 | public String toString() { 75 | 76 | StringBuffer sb = new StringBuffer(); 77 | sb.append(getClass().getSimpleName()).append("{"); 78 | print(sb); 79 | sb.append("}"); 80 | return sb.toString(); 81 | } 82 | 83 | @Override 84 | public String shortDesc() { 85 | StringBuffer sb = new StringBuffer(); 86 | sb.append(getClass().getSimpleName()).append("{"); 87 | sb.append(getName()); 88 | sb.append("}"); 89 | return sb.toString(); 90 | } 91 | 92 | protected void print(StringBuffer sb) { 93 | sb.append("name='").append(name).append("\', annotations="); 94 | sb.append("["); 95 | for (AnnotationModel am : this.getAnnotations()) { 96 | sb.append(" ").append(am.getType().getName()); 97 | } 98 | sb.append("]"); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/FieldSignatureVisitorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | package org.glassfish.hk2.classmodel.reflect.impl; 17 | 18 | import java.util.ArrayDeque; 19 | import org.glassfish.hk2.classmodel.reflect.FieldModel; 20 | import org.objectweb.asm.Opcodes; 21 | import org.objectweb.asm.signature.SignatureVisitor; 22 | import org.glassfish.hk2.classmodel.reflect.ParameterizedType; 23 | 24 | /** 25 | * Signature visitor to visit field and respective generic types 26 | * 27 | * @author gaurav.gupta@payara.fish 28 | */ 29 | public class FieldSignatureVisitorImpl extends SignatureVisitor { 30 | 31 | private final TypeBuilder typeBuilder; 32 | private final ArrayDeque parentType = new ArrayDeque<>(); 33 | 34 | public FieldSignatureVisitorImpl(TypeBuilder typeBuilder, FieldModel fieldModel) { 35 | super(Opcodes.ASM9); 36 | 37 | this.typeBuilder = typeBuilder; 38 | parentType.add(fieldModel); 39 | } 40 | 41 | @Override 42 | public void visitTypeVariable(String typeVariable) { 43 | if (!parentType.isEmpty()) { 44 | ParameterizedType current = parentType.peekLast(); 45 | if (current instanceof FieldModelImpl 46 | && ((FieldModelImpl) current).getTypeProxy() == null 47 | && ((FieldModelImpl) current).getFormalType() == null) { 48 | ((FieldModelImpl) current).setFormalType(typeVariable); 49 | } else { 50 | ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl(typeVariable); 51 | current.getParameterizedTypes().add(parameterizedType); 52 | } 53 | } 54 | } 55 | 56 | @Override 57 | public void visitClassType(String name) { 58 | String className = org.objectweb.asm.Type.getObjectType(name).getClassName(); 59 | TypeProxy typeProxy = typeBuilder.getHolder(className); 60 | if (typeProxy != null) { 61 | if (!parentType.isEmpty()) { 62 | ParameterizedType current = parentType.peekLast(); 63 | if (current instanceof FieldModelImpl 64 | && ((FieldModelImpl) current).getTypeProxy() == null) { 65 | ((FieldModelImpl) current).setTypeProxy(typeProxy); 66 | } else { 67 | ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl(typeProxy); 68 | current.getParameterizedTypes().add(parameterizedType); 69 | parentType.add(parameterizedType); 70 | } 71 | } 72 | } 73 | } 74 | 75 | @Override 76 | public void visitEnd() { 77 | parentType.pollLast(); 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/MethodSignatureVisitorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2020 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | package org.glassfish.hk2.classmodel.reflect.impl; 17 | 18 | import org.objectweb.asm.Opcodes; 19 | import org.objectweb.asm.signature.SignatureVisitor; 20 | 21 | import java.util.*; 22 | import org.glassfish.hk2.classmodel.reflect.MethodModel; 23 | import org.glassfish.hk2.classmodel.reflect.Parameter; 24 | import org.glassfish.hk2.classmodel.reflect.ParameterizedType; 25 | 26 | /** 27 | * Signature visitor to visit method parameters, return type and respective 28 | * generic types 29 | * 30 | * @author gaurav.gupta@payara.fish 31 | */ 32 | public class MethodSignatureVisitorImpl extends SignatureVisitor { 33 | 34 | private final TypeBuilder typeBuilder; 35 | private final MethodModel methodModel; 36 | 37 | private final List parameters = new ArrayList<>(); 38 | private final ParameterizedType returnType = new ParameterizedTypeImpl(); 39 | private final ArrayDeque parentType = new ArrayDeque<>(); 40 | 41 | public MethodSignatureVisitorImpl(TypeBuilder typeBuilder, MethodModel methodModel) { 42 | super(Opcodes.ASM9); 43 | 44 | this.typeBuilder = typeBuilder; 45 | this.methodModel = methodModel; 46 | } 47 | 48 | public List getParameters() { 49 | return parameters; 50 | } 51 | 52 | public ParameterizedType getReturnType() { 53 | return returnType; 54 | } 55 | 56 | @Override 57 | public SignatureVisitor visitParameterType() { 58 | ParameterImpl parameter = new ParameterImpl(parameters.size(), null, methodModel); 59 | parameters.add(parameter); 60 | parentType.add(parameter); 61 | return this; 62 | } 63 | 64 | @Override 65 | public SignatureVisitor visitReturnType() { 66 | parentType.add(returnType); 67 | return this; 68 | } 69 | 70 | @Override 71 | public void visitTypeVariable(String typeVariable) { 72 | if (!parentType.isEmpty()) { 73 | ParameterizedType current = parentType.peekLast(); 74 | if (current instanceof ParameterImpl 75 | && ((ParameterImpl) current).getTypeProxy() == null 76 | && ((ParameterImpl) current).getFormalType() == null) { 77 | ((ParameterImpl) current).setFormalType(typeVariable); 78 | } else if (current instanceof ParameterizedTypeImpl 79 | && ((ParameterizedTypeImpl) current).getTypeProxy() == null 80 | && ((ParameterizedTypeImpl) current).getFormalType() == null) { 81 | ((ParameterizedTypeImpl) current).setFormalType(typeVariable); 82 | } else { 83 | ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl(typeVariable); 84 | current.getParameterizedTypes().add(parameterizedType); 85 | } 86 | } 87 | } 88 | 89 | @Override 90 | public void visitClassType(String name) { 91 | String className = org.objectweb.asm.Type.getObjectType(name).getClassName(); 92 | TypeProxy typeProxy = typeBuilder.getHolder(className); 93 | if (typeProxy != null) { 94 | if (!parentType.isEmpty()) { 95 | ParameterizedType current = parentType.peekLast(); 96 | if (current instanceof ParameterImpl 97 | && ((ParameterImpl) current).getTypeProxy() == null) { 98 | ((ParameterImpl) current).setTypeProxy(typeProxy); 99 | } else if (current instanceof ParameterizedTypeImpl 100 | && ((ParameterizedTypeImpl) current).getTypeProxy() == null) { 101 | ((ParameterizedTypeImpl) current).setTypeProxy(typeProxy); 102 | } else { 103 | ParameterizedTypeImpl parameterizedType = new ParameterizedTypeImpl(typeProxy); 104 | current.getParameterizedTypes().add(parameterizedType); 105 | parentType.add(parameterizedType); 106 | } 107 | } 108 | } 109 | } 110 | 111 | @Override 112 | public SignatureVisitor visitTypeArgument(char c) { 113 | return this; 114 | } 115 | 116 | @Override 117 | public void visitEnd() { 118 | parentType.pollLast(); 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/hk2/classmodel/reflect/impl/SignatureVisitorImpl.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2011, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | 17 | package org.glassfish.hk2.classmodel.reflect.impl; 18 | 19 | import org.objectweb.asm.Opcodes; 20 | import org.objectweb.asm.signature.SignatureVisitor; 21 | 22 | import java.util.*; 23 | 24 | /** 25 | * Signature visitor to visit parameterized declarations 26 | * 27 | * @author Jerome Dochez 28 | */ 29 | public class SignatureVisitorImpl extends SignatureVisitor { 30 | 31 | private final TypeBuilder typeBuilder; 32 | private final Stack stack = new Stack<>(); 33 | private final Stack formalTypesNames = new Stack<>(); 34 | 35 | private final Map formalTypes = new LinkedHashMap<>(); 36 | private final List parameterizedIntf = new ArrayList<>(); 37 | 38 | public SignatureVisitorImpl(TypeBuilder typeBuilder) { 39 | super(Opcodes.ASM9); 40 | this.typeBuilder = typeBuilder; 41 | } 42 | 43 | Collection getImplementedInterfaces() { 44 | return Collections.unmodifiableCollection(parameterizedIntf); 45 | } 46 | 47 | @Override 48 | public void visitFormalTypeParameter(String s) { 49 | formalTypesNames.push(s); 50 | } 51 | 52 | public Map getFormalTypeParameters() { 53 | return formalTypes; 54 | } 55 | 56 | @Override 57 | public SignatureVisitor visitClassBound() { 58 | return this; //To change body of implemented methods use File | Settings | File Templates. 59 | } 60 | 61 | @Override 62 | public SignatureVisitor visitInterfaceBound() { 63 | return this; 64 | } 65 | 66 | @Override 67 | public SignatureVisitor visitSuperclass() { 68 | return this; //To change body of implemented methods use File | Settings | File Templates. 69 | } 70 | 71 | @Override 72 | public SignatureVisitor visitInterface() { 73 | return this; //To change body of implemented methods use File | Settings | File Templates. 74 | } 75 | 76 | @Override 77 | public SignatureVisitor visitParameterType() { 78 | return this; //To change body of implemented methods use File | Settings | File Templates. 79 | } 80 | 81 | @Override 82 | public SignatureVisitor visitReturnType() { 83 | return this; //To change body of implemented methods use File | Settings | File Templates. 84 | } 85 | 86 | @Override 87 | public SignatureVisitor visitExceptionType() { 88 | return this; //To change body of implemented methods use File | Settings | File Templates. 89 | } 90 | 91 | @Override 92 | public void visitBaseType(char c) { 93 | //To change body of implemented methods use File | Settings | File Templates. 94 | } 95 | 96 | @Override 97 | public void visitTypeVariable(String s) { 98 | if (formalTypes.get(s) != null) { 99 | String interfaceName = formalTypes.get(s).getName(); 100 | TypeProxy typeProxy = typeBuilder.getHolder(interfaceName); 101 | if (typeProxy!=null) { 102 | ParameterizedInterfaceModelImpl childParameterized = new ParameterizedInterfaceModelImpl(typeProxy); 103 | if (!stack.empty()) { 104 | stack.peek().addParameterizedType(childParameterized); 105 | } 106 | } 107 | } 108 | } 109 | 110 | @Override 111 | public SignatureVisitor visitArrayType() { 112 | return this; //To change body of implemented methods use File | Settings | File Templates. 113 | } 114 | 115 | @Override 116 | public void visitClassType(String s) { 117 | String interfaceName = org.objectweb.asm.Type.getObjectType(s).getClassName(); 118 | TypeProxy interfaceTypeProxy = typeBuilder.getHolder(interfaceName); 119 | if (interfaceTypeProxy!=null) { 120 | ParameterizedInterfaceModelImpl childParameterized = new ParameterizedInterfaceModelImpl(interfaceTypeProxy); 121 | if (!s.equals("java/lang/Object")) { 122 | if (formalTypesNames.empty()) { 123 | if (!stack.empty()) { 124 | stack.peek().addParameterizedType(childParameterized); 125 | } 126 | } else { 127 | formalTypes.put(formalTypesNames.pop(), childParameterized); 128 | } 129 | } 130 | stack.push(childParameterized); 131 | } else if (!formalTypesNames.empty()) { 132 | formalTypes.put(formalTypesNames.pop(), null); 133 | } 134 | } 135 | 136 | @Override 137 | public void visitInnerClassType(String s) { 138 | //To change body of implemented methods use File | Settings | File Templates. 139 | } 140 | 141 | @Override 142 | public void visitTypeArgument() { 143 | //To change body of implemented methods use File | Settings | File Templates. 144 | } 145 | 146 | @Override 147 | public SignatureVisitor visitTypeArgument(char c) { 148 | return this; //To change body of implemented methods use File | Settings | File Templates. 149 | } 150 | 151 | @Override 152 | public void visitEnd() { 153 | if (stack.empty()) return; 154 | ParameterizedInterfaceModelImpl lastElement = stack.pop(); 155 | if (stack.isEmpty()) { 156 | parameterizedIntf.add(lastElement); 157 | } 158 | } 159 | } 160 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/jersey/server/ResourceBagConfigurator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2017, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * This Source Code may also be made available under the following Secondary 9 | * Licenses when the conditions for such availability set forth in the 10 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 11 | * version 2 with the GNU Classpath Exception, which is available at 12 | * https://www.gnu.org/software/classpath/license.html. 13 | * 14 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 15 | */ 16 | 17 | package org.glassfish.jersey.server; 18 | 19 | import java.util.Comparator; 20 | import java.util.logging.Logger; 21 | 22 | import org.glassfish.jersey.internal.BootstrapBag; 23 | import org.glassfish.jersey.internal.BootstrapConfigurator; 24 | import org.glassfish.jersey.internal.inject.InjectionManager; 25 | import org.glassfish.jersey.server.model.Resource; 26 | 27 | /** 28 | * Configurator which initializes and register {@link ResourceBag} instance into {@link BootstrapBag}. 29 | * 30 | * @author Petr Bouda 31 | */ 32 | class ResourceBagConfigurator implements BootstrapConfigurator { 33 | 34 | private static final Logger LOGGER = Logger.getLogger(ResourceBagConfigurator.class.getName()); 35 | 36 | @Override 37 | public void init(InjectionManager injectionManager, BootstrapBag bootstrapBag) { 38 | ServerBootstrapBag serverBag = (ServerBootstrapBag) bootstrapBag; 39 | ResourceConfig runtimeConfig = serverBag.getRuntimeConfig(); 40 | 41 | final boolean disableValidation = ServerProperties.getValue(runtimeConfig.getProperties(), 42 | ServerProperties.RESOURCE_VALIDATION_DISABLE, 43 | Boolean.FALSE, 44 | Boolean.class); 45 | 46 | final ResourceBag.Builder resourceBagBuilder = new ResourceBag.Builder(); 47 | 48 | // Adding programmatic resource models 49 | for (final Resource programmaticResource : runtimeConfig.getResources()) { 50 | resourceBagBuilder.registerProgrammaticResource(programmaticResource); 51 | } 52 | 53 | // Introspecting classes & instances 54 | if (Boolean.getBoolean(ServerProperties.RESOURCE_VALIDATION_IGNORE_ERRORS)) { 55 | runtimeConfig.getClasses().stream().sorted(new Comparator>() { 56 | @Override 57 | public int compare(Class o1, Class o2) { 58 | if (o1.isInterface() && !o2.isInterface()) { 59 | return 1; 60 | } else if (!o1.isInterface() && o2.isInterface()) { 61 | return -1; 62 | } else { 63 | return 0; 64 | } 65 | } 66 | }).forEach( c -> { 67 | try { 68 | final Resource resource = Resource.from(c, disableValidation); 69 | if (resource != null) { 70 | resourceBagBuilder.registerResource(c, resource); 71 | } 72 | } catch (final IllegalArgumentException ex) { 73 | LOGGER.warning(ex.getMessage()); 74 | } 75 | }); 76 | } else { 77 | for (final Class c : runtimeConfig.getClasses()) { 78 | try { 79 | final Resource resource = Resource.from(c, disableValidation); 80 | if (resource != null) { 81 | resourceBagBuilder.registerResource(c, resource); 82 | } 83 | } catch (final IllegalArgumentException ex) { 84 | LOGGER.warning(ex.getMessage()); 85 | } 86 | } 87 | } 88 | 89 | for (final Object o : runtimeConfig.getSingletons()) { 90 | try { 91 | final Resource resource = Resource.from(o.getClass(), disableValidation); 92 | if (resource != null) { 93 | resourceBagBuilder.registerResource(o, resource); 94 | } 95 | } catch (final IllegalArgumentException ex) { 96 | LOGGER.warning(ex.getMessage()); 97 | } 98 | } 99 | 100 | serverBag.setResourceBag(resourceBagBuilder.build()); 101 | } 102 | } 103 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/pfl/tf/tools/enhancer/TFEnhanceAdapter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 1997, 2018 Oracle and/or its affiliates. All rights reserved. 3 | * Copyright (c) 2020 Payara Services Ltd. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Distribution License v. 1.0, which is available at 7 | * http://www.eclipse.org/org/documents/edl-v10.php. 8 | * 9 | * SPDX-License-Identifier: BSD-3-Clause 10 | */ 11 | 12 | package org.glassfish.pfl.tf.tools.enhancer; 13 | 14 | import org.glassfish.pfl.tf.spi.EnhancedClassData; 15 | import org.glassfish.pfl.tf.spi.TraceEnhancementException; 16 | import org.glassfish.pfl.tf.spi.annotation.TFEnhanced; 17 | import org.glassfish.pfl.tf.spi.annotation.TraceEnhanceLevel; 18 | import org.objectweb.asm.AnnotationVisitor; 19 | import org.objectweb.asm.ClassVisitor; 20 | import org.objectweb.asm.FieldVisitor; 21 | import org.objectweb.asm.MethodVisitor; 22 | import org.objectweb.asm.Opcodes; 23 | import org.objectweb.asm.Type; 24 | 25 | /** 26 | * 27 | * @author ken 28 | */ 29 | public class TFEnhanceAdapter extends ClassVisitor { 30 | private static final String TFENHANCED_ANNO_DESC = 31 | Type.getDescriptor( TFEnhanced.class ) ; 32 | private static final String TRACE_ENHANCE_LEVEL_DESC = 33 | Type.getDescriptor( TraceEnhanceLevel.class ) ; 34 | 35 | private boolean firstCall = true ; 36 | 37 | 38 | // Holder for actual value of TFEnhanced annotation (NONE if no 39 | // annotation present. 40 | private final TraceEnhanceLevel[] present = new TraceEnhanceLevel[1] ; 41 | 42 | private final TraceEnhanceLevel required ; // required for next phase to run 43 | private final TraceEnhanceLevel result ; // if at required level, resulting level 44 | 45 | private final EnhancedClassData ecd ; 46 | 47 | public TFEnhanceAdapter( ClassVisitor cv, TraceEnhanceLevel required, 48 | TraceEnhanceLevel result, EnhancedClassData ecd ) { 49 | super(Opcodes.ASM9, cv); 50 | this.required = required ; 51 | this.result = result ; 52 | this.ecd = ecd ; 53 | present[0] = TraceEnhanceLevel.NONE ; 54 | } 55 | 56 | private void checkForTFEnhanceAnnotation() { 57 | if (firstCall) { 58 | firstCall = false ; 59 | if (present[0] != required) { 60 | throw new TraceEnhancementException( 61 | "Class " + ecd.getClassName() 62 | + " has trace enhancement level " + present[0] 63 | + " but " + required + " is required.") ; 64 | } 65 | 66 | // Write out annotation with result level. 67 | AnnotationVisitor av = super.visitAnnotation( TFENHANCED_ANNO_DESC, 68 | true ) ; 69 | av.visitEnum( "stage", TRACE_ENHANCE_LEVEL_DESC, result.name() ) ; 70 | av.visitEnd() ; 71 | } 72 | } 73 | 74 | @Override 75 | public void visitInnerClass( String name, 76 | String outerName, String innerName, int access ) { 77 | 78 | checkForTFEnhanceAnnotation(); 79 | super.visitInnerClass( name, outerName, innerName, access ) ; 80 | } 81 | 82 | @Override 83 | public FieldVisitor visitField( int access, String name, String desc, 84 | String signature, Object value ) { 85 | 86 | checkForTFEnhanceAnnotation(); 87 | return super.visitField(access, name, desc, signature, value) ; 88 | } 89 | 90 | @Override 91 | public MethodVisitor visitMethod( int access, String name, String desc, 92 | String signature, String[] exceptions ) { 93 | 94 | checkForTFEnhanceAnnotation(); 95 | return super.visitMethod(access, name, desc, signature, exceptions) ; 96 | } 97 | 98 | @Override 99 | public AnnotationVisitor visitAnnotation( String desc, boolean isVisible ) { 100 | if (desc.equals( TFENHANCED_ANNO_DESC )) { 101 | // Consume the TFEnhanced annotation here. We'll write out a new 102 | // one above. 103 | return new AnnotationVisitor(Opcodes.ASM9) { 104 | public void visit(String name, Object value) { 105 | } 106 | 107 | public void visitEnum(String name, String desc, String value) { 108 | if (name.equals( "stage")) { 109 | present[0] = Enum.valueOf( TraceEnhanceLevel.class, 110 | value ) ; 111 | } 112 | } 113 | 114 | public AnnotationVisitor visitAnnotation(String name, 115 | String desc) { 116 | 117 | return null ; 118 | } 119 | 120 | public AnnotationVisitor visitArray(String name) { 121 | return null ; 122 | } 123 | 124 | public void visitEnd() { 125 | } 126 | } ; 127 | } else { 128 | final AnnotationVisitor av = super.visitAnnotation( desc, isVisible ) ; 129 | return av ; 130 | } 131 | } 132 | } 133 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/web/embed/impl/ScatteredWebArchivist.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited. 3 | * Copyright (c) 2022 Eclipse Foundation and/or its affiliates. All rights reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * This Source Code may also be made available under the following Secondary 10 | * Licenses when the conditions for such availability set forth in the 11 | * Eclipse Public License v. 2.0 are satisfied: GNU General Public License, 12 | * version 2 with the GNU Classpath Exception, which is available at 13 | * https://www.gnu.org/software/classpath/license.html. 14 | * 15 | * SPDX-License-Identifier: EPL-2.0 OR GPL-2.0 WITH Classpath-exception-2.0 16 | */ 17 | 18 | package org.glassfish.web.embed.impl; 19 | 20 | import com.sun.enterprise.deployment.ScatteredWarType; 21 | import com.sun.enterprise.deployment.annotation.impl.ModuleScanner; 22 | import com.sun.enterprise.deployment.archivist.ArchivistFor; 23 | 24 | import java.io.File; 25 | import java.io.IOException; 26 | import java.net.URL; 27 | import java.util.Enumeration; 28 | import java.util.HashSet; 29 | import java.util.Set; 30 | import java.util.logging.Level; 31 | import java.util.logging.Logger; 32 | 33 | import org.glassfish.api.deployment.archive.ArchiveType; 34 | import org.glassfish.api.deployment.archive.ReadableArchive; 35 | import org.glassfish.hk2.api.PerLookup; 36 | import org.glassfish.hk2.classmodel.reflect.Parser; 37 | import org.glassfish.internal.api.Globals; 38 | import org.glassfish.web.LogFacade; 39 | import org.glassfish.web.deployment.archivist.WebArchivist; 40 | import org.glassfish.web.deployment.descriptor.WebBundleDescriptorImpl; 41 | import org.jvnet.hk2.annotations.Service; 42 | 43 | 44 | /** 45 | * @author Jerome Dochez 46 | * @author David Matejcek 47 | */ 48 | @Service 49 | @PerLookup 50 | @ArchivistFor(ScatteredWarType.ARCHIVE_TYPE) 51 | public class ScatteredWebArchivist extends WebArchivist { 52 | 53 | private static final Logger LOG = LogFacade.getLogger(); 54 | private static URL defaultWebXmlLocation; 55 | 56 | private final EmbeddedWebScanner embeddedScanner = new EmbeddedWebScanner(); 57 | 58 | static void setDefaultWebXml(URL defaultWebXml) { 59 | defaultWebXmlLocation = defaultWebXml; 60 | } 61 | 62 | 63 | @Override 64 | public URL getDefaultWebXML() throws IOException { 65 | if (defaultWebXmlLocation != null) { 66 | return defaultWebXmlLocation; 67 | } 68 | URL defaultWebXml = super.getDefaultWebXML(); 69 | return defaultWebXml == null 70 | ? getClass().getClassLoader().getResource("org/glassfish/web/embed/default-web.xml") 71 | : defaultWebXml; 72 | } 73 | 74 | 75 | @Override 76 | public ArchiveType getModuleType() { 77 | return Globals.getDefaultHabitat().getService(ArchiveType.class, ScatteredWarType.ARCHIVE_TYPE); 78 | } 79 | 80 | 81 | /** 82 | * @return the scanner for this archivist, usually it is the scanner regitered 83 | * with the same module type as this archivist, but subclasses can return 84 | * a different version 85 | */ 86 | @Override 87 | public EmbeddedWebScanner getScanner() { 88 | return this.embeddedScanner; 89 | } 90 | 91 | private static class EmbeddedWebScanner extends ModuleScanner { 92 | 93 | private final Set> elements = new HashSet<>(); 94 | private ClassLoader classLoader; 95 | 96 | @Override 97 | public void process(ReadableArchive archiveFile, WebBundleDescriptorImpl descriptor, ClassLoader classLoader, 98 | Parser parser) throws IOException { 99 | this.classLoader = classLoader; 100 | // in embedded mode, we don't scan archive, we just process all classes. 101 | Enumeration fileEntries = archiveFile.entries(); 102 | while (fileEntries.hasMoreElements()) { 103 | String entry = fileEntries.nextElement(); 104 | if (entry.endsWith(".class")) { 105 | try { 106 | elements.add(classLoader.loadClass(toClassName(entry))); 107 | } catch (ClassNotFoundException | NoClassDefFoundError e) { 108 | LOG.log(Level.WARNING, "Cannot load class " + entry, e); 109 | } 110 | } 111 | } 112 | } 113 | 114 | 115 | @Override 116 | protected void process(File archiveFile, WebBundleDescriptorImpl descriptor, ClassLoader classLoader) 117 | throws IOException { 118 | } 119 | 120 | 121 | private String toClassName(String entryName) { 122 | String name = entryName.substring("WEB-INF/classes/".length(), entryName.length() - ".class".length()); 123 | return name.replaceAll("/", "."); 124 | } 125 | 126 | 127 | @Override 128 | public Set> getElements() { 129 | return elements; 130 | } 131 | 132 | 133 | @Override 134 | public ClassLoader getClassLoader() { 135 | return classLoader; 136 | } 137 | } 138 | } -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/java/org/glassfish/weld/ParamLibrariesResolver.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019 Fujitsu Limited and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | */ 10 | package org.glassfish.weld; 11 | 12 | import java.io.IOException; 13 | import java.util.HashSet; 14 | import java.util.Optional; 15 | import java.util.Set; 16 | import java.util.jar.Attributes; 17 | import java.util.jar.Attributes.Name; 18 | import java.util.jar.JarFile; 19 | 20 | import org.glassfish.api.deployment.DeployCommandParameters; 21 | import org.glassfish.api.deployment.DeploymentContext; 22 | import org.glassfish.api.deployment.archive.ReadableArchive; 23 | 24 | /** 25 | * 26 | * @author Katsuhiro Kunisada 27 | */ 28 | public class ParamLibrariesResolver { 29 | 30 | /** 31 | * Checks jars specified by '--libraries' option and returns them if they are 32 | * required by 'Extension-List' of the given archive. 33 | * 34 | * @throws IOException 35 | */ 36 | public static Set getLibraries(DeploymentContext context, ReadableArchive archive) throws IOException { 37 | Set libs = new HashSet(); 38 | DeployCommandParameters params = context.getCommandParameters(DeployCommandParameters.class); 39 | String librariesOption = Optional.ofNullable(params.libraries()).orElse(""); 40 | if (archive.getManifest() == null || librariesOption.isEmpty()) { 41 | return libs; 42 | } 43 | 44 | Attributes archiveAttrs = archive.getManifest().getMainAttributes(); 45 | String archiveExtList = getAttributeString(archiveAttrs, Name.EXTENSION_LIST); 46 | for (String file : librariesOption.split(",")) { 47 | try (JarFile jar = new JarFile(file)) { 48 | if (jar.getManifest() == null) { 49 | continue; 50 | } 51 | Attributes jarAttrs = jar.getManifest().getMainAttributes(); 52 | String jarExtName = getAttributeString(jarAttrs, Name.EXTENSION_NAME); 53 | String jarExtVer = getAttributeString(jarAttrs, Name.SPECIFICATION_VERSION); 54 | if (jarExtName.isEmpty() || jarExtVer.isEmpty()) { 55 | continue; 56 | } 57 | for (String s : archiveExtList.split("\\p{javaWhitespace}+")) { 58 | if (s.isEmpty()) { 59 | continue; 60 | } 61 | String name = getAttributeString(archiveAttrs, s + "-" + Name.EXTENSION_NAME); 62 | String version = getAttributeString(archiveAttrs, s + "-" + Name.SPECIFICATION_VERSION); 63 | if (jarExtName.equals(name) && jarExtVer.equals(version)) { 64 | libs.add(jar.getName()); 65 | } 66 | } 67 | } 68 | } 69 | return libs; 70 | } 71 | 72 | private static String getAttributeString(Attributes attr, String name) { 73 | return Optional.ofNullable(attr.getValue(name)).orElse("").trim(); 74 | } 75 | 76 | private static String getAttributeString(Attributes attr, Name name) { 77 | return getAttributeString(attr, name.toString()); 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/resources/config/cacerts.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujitsu/launcher/7e2c856be01c74e313f51d26463c211e8318cf9d/launcher-impl/glassfish/src/main/resources/config/cacerts.jks -------------------------------------------------------------------------------- /launcher-impl/glassfish/src/main/resources/config/keystore.jks: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/fujitsu/launcher/7e2c856be01c74e313f51d26463c211e8318cf9d/launcher-impl/glassfish/src/main/resources/config/keystore.jks -------------------------------------------------------------------------------- /launcher-impl/microprofile/config/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | microprofile 18 | 5.1-SNAPSHOT 19 | 20 | microprofile-config 21 | jar 22 | 23 | 24 | 25 | org.eclipse.microprofile.config 26 | microprofile-config-api 27 | 28 | 29 | 30 | com.fujitsu.launcher 31 | patched-glassfish 32 | 33 | 34 | 35 | io.smallrye.config 36 | smallrye-config 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | microprofile 18 | 5.1-SNAPSHOT 19 | 20 | microprofile-fault-tolerance 21 | jar 22 | 23 | 24 | 25 | org.eclipse.microprofile.fault-tolerance 26 | microprofile-fault-tolerance-api 27 | 28 | 29 | com.fujitsu.launcher 30 | patched-glassfish 31 | 32 | 33 | io.smallrye 34 | smallrye-fault-tolerance 35 | 36 | 37 | 38 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/src/main/java/com/fujitsu/launcher/microprofile/faulttolerance/IntegrateAsyncExecutorProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.faulttolerance; 12 | 13 | import java.util.concurrent.ExecutorService; 14 | 15 | import javax.naming.InitialContext; 16 | import javax.naming.NamingException; 17 | 18 | import org.eclipse.microprofile.config.inject.ConfigProperty; 19 | 20 | import io.smallrye.faulttolerance.AsyncExecutorProvider; 21 | import jakarta.annotation.Priority; 22 | import jakarta.enterprise.concurrent.ManagedExecutorService; 23 | import jakarta.enterprise.inject.Alternative; 24 | import jakarta.inject.Inject; 25 | import jakarta.inject.Singleton; 26 | 27 | @Singleton 28 | @Alternative 29 | @Priority(1) 30 | public class IntegrateAsyncExecutorProvider implements AsyncExecutorProvider { 31 | private ManagedExecutorService executor; 32 | 33 | @Inject 34 | public IntegrateAsyncExecutorProvider( 35 | @ConfigProperty(name = "com.fujitsu.launcher.microprofile.faulttolerance.managedExecutorService", defaultValue="java:comp/DefaultManagedExecutorService") String executorName 36 | ){ 37 | try{ 38 | InitialContext ic = new InitialContext(); 39 | executor = (ManagedExecutorService) ic.lookup(executorName); 40 | } catch (NamingException e){ 41 | throw new RuntimeException(e); 42 | } 43 | } 44 | 45 | @Override 46 | public ExecutorService get() { 47 | return executor; 48 | } 49 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/src/main/java/com/fujitsu/launcher/microprofile/faulttolerance/ProviderExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.faulttolerance; 12 | 13 | import jakarta.enterprise.event.Observes; 14 | import jakarta.enterprise.inject.spi.BeanManager; 15 | import jakarta.enterprise.inject.spi.BeforeBeanDiscovery; 16 | import jakarta.enterprise.inject.spi.Extension; 17 | 18 | public class ProviderExtension implements Extension { 19 | 20 | public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) { 21 | if (!Boolean.getBoolean("com.fujitsu.launcher.microprofile.faulttolerance.useDefaultAsyncExecutorProvider")) { 22 | bbd.addAnnotatedType(bm.createAnnotatedType(IntegrateAsyncExecutorProvider.class), 23 | IntegrateAsyncExecutorProvider.class.getName()); 24 | } 25 | bbd.addAnnotatedType(bm.createAnnotatedType(ThreadFactoryProvider.class), 26 | ThreadFactoryProvider.class.getName()); 27 | } 28 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/src/main/java/com/fujitsu/launcher/microprofile/faulttolerance/ThreadFactoryProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.faulttolerance; 12 | 13 | import java.util.concurrent.ThreadFactory; 14 | 15 | import javax.naming.InitialContext; 16 | import javax.naming.NamingException; 17 | 18 | import org.eclipse.microprofile.config.inject.ConfigProperty; 19 | 20 | import jakarta.enterprise.concurrent.ManagedThreadFactory; 21 | import jakarta.inject.Inject; 22 | import jakarta.inject.Singleton; 23 | 24 | @Singleton 25 | public class ThreadFactoryProvider { 26 | private ManagedThreadFactory factory; 27 | 28 | @Inject 29 | public ThreadFactoryProvider( 30 | @ConfigProperty(name = "com.fujitsu.launcher.microprofile.faulttolerance.managedThreadFactory", defaultValue="java:comp/DefaultManagedThreadFactory") String factoryName 31 | ){ 32 | try{ 33 | InitialContext ic = new InitialContext(); 34 | factory = (ManagedThreadFactory) ic.lookup(factoryName); 35 | } catch (NamingException e){ 36 | throw new RuntimeException(e); 37 | } 38 | } 39 | 40 | public ThreadFactory get(){ 41 | return factory; 42 | } 43 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/src/main/java/io/smallrye/faulttolerance/ExecutorHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2017 Red Hat, Inc. 3 | * Copyright 2021-2023 Fujitsu Limited. 4 | * 5 | * Licensed under the Apache License, Version 2.0 (the "License"); 6 | * you may not use this file except in compliance with the License. 7 | * You may obtain a copy of the License at 8 | * 9 | * http://www.apache.org/licenses/LICENSE-2.0 10 | * 11 | * Unless required by applicable law or agreed to in writing, software 12 | * distributed under the License is distributed on an "AS IS" BASIS, 13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | * See the License for the specific language governing permissions and 15 | * limitations under the License. 16 | */ 17 | package io.smallrye.faulttolerance; 18 | 19 | import java.util.concurrent.ExecutorService; 20 | import java.util.concurrent.TimeUnit; 21 | 22 | import jakarta.annotation.PreDestroy; 23 | import jakarta.inject.Inject; 24 | import jakarta.inject.Singleton; 25 | 26 | import io.smallrye.faulttolerance.core.event.loop.EventLoop; 27 | import io.smallrye.faulttolerance.core.timer.ThreadTimer; 28 | import io.smallrye.faulttolerance.core.timer.Timer; 29 | 30 | import com.fujitsu.launcher.microprofile.faulttolerance.ThreadFactoryProvider; 31 | 32 | @Singleton 33 | public class ExecutorHolder { 34 | private final ExecutorService asyncExecutor; 35 | 36 | private final EventLoop eventLoop; 37 | 38 | private final Timer timer; 39 | 40 | private final boolean shouldShutdownAsyncExecutor; 41 | 42 | @Inject 43 | public ExecutorHolder(AsyncExecutorProvider asyncExecutorProvider, ThreadFactoryProvider threadFactoryProvider) { 44 | this.asyncExecutor = asyncExecutorProvider.get(); 45 | this.eventLoop = EventLoop.get(); 46 | this.timer = new ThreadTimer(asyncExecutor, threadFactoryProvider.get()); 47 | this.shouldShutdownAsyncExecutor = asyncExecutorProvider instanceof DefaultAsyncExecutorProvider; 48 | } 49 | 50 | @PreDestroy 51 | public void tearDown() { 52 | try { 53 | timer.shutdown(); 54 | } catch (InterruptedException e) { 55 | // no need to do anything, we're shutting down anyway 56 | // just set the interruption flag to be a good citizen 57 | Thread.currentThread().interrupt(); 58 | } 59 | 60 | if (shouldShutdownAsyncExecutor) { 61 | asyncExecutor.shutdownNow(); 62 | try { 63 | asyncExecutor.awaitTermination(1, TimeUnit.SECONDS); 64 | } catch (InterruptedException e) { 65 | // no need to do anything, we're shutting down anyway 66 | // just set the interruption flag to be a good citizen 67 | Thread.currentThread().interrupt(); 68 | } 69 | } 70 | } 71 | 72 | public ExecutorService getAsyncExecutor() { 73 | return asyncExecutor; 74 | } 75 | 76 | public EventLoop getEventLoop() { 77 | return eventLoop; 78 | } 79 | 80 | public Timer getTimer() { 81 | return timer; 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/fault-tolerance/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | io.smallrye.faulttolerance.FaultToleranceExtension 2 | com.fujitsu.launcher.microprofile.faulttolerance.ProviderExtension 3 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 4.0.0 13 | 14 | 15 | com.fujitsu.launcher 16 | microprofile 17 | 5.1-SNAPSHOT 18 | 19 | microprofile-health 20 | jar 21 | 22 | 23 | 24 | org.eclipse.microprofile.health 25 | microprofile-health-api 26 | 27 | 28 | com.fujitsu.launcher 29 | patched-glassfish 30 | 31 | 32 | io.smallrye 33 | smallrye-health 34 | 35 | 36 | 37 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/java/com/fujitsu/launcher/microprofile/health/HealthExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.health; 12 | 13 | import io.smallrye.health.AsyncHealthCheckFactory; 14 | import io.smallrye.health.registry.HealthRegistries; 15 | import jakarta.enterprise.event.Observes; 16 | import jakarta.enterprise.inject.spi.BeanManager; 17 | import jakarta.enterprise.inject.spi.BeforeBeanDiscovery; 18 | import jakarta.enterprise.inject.spi.Extension; 19 | 20 | /** 21 | * Enables {@link HealthReporterProducer}. 22 | * 23 | * @author Takahiro Nagao 24 | */ 25 | public class HealthExtension implements Extension { 26 | 27 | public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) { 28 | bbd.addAnnotatedType(bm.createAnnotatedType(AsyncHealthCheckFactory.class), AsyncHealthCheckFactory.class.getName()); 29 | bbd.addAnnotatedType(bm.createAnnotatedType(HealthRegistries.class), HealthRegistries.class.getName()); 30 | bbd.addAnnotatedType(bm.createAnnotatedType(HealthReporterProducer.class), HealthReporterProducer.class.getName()); 31 | } 32 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/java/com/fujitsu/launcher/microprofile/health/HealthReporterProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.health; 12 | 13 | import jakarta.enterprise.context.ApplicationScoped; 14 | import jakarta.enterprise.inject.Disposes; 15 | import jakarta.enterprise.inject.Produces; 16 | import jakarta.enterprise.inject.spi.BeanManager; 17 | import jakarta.enterprise.inject.spi.CDI; 18 | import jakarta.enterprise.inject.spi.Unmanaged; 19 | 20 | import io.smallrye.health.SmallRyeHealthReporter; 21 | 22 | /** 23 | * Produces an instance of {@link SmallRyeHealthReporter}. 24 | * 25 | * @author Takahiro Nagao 26 | */ 27 | @ApplicationScoped 28 | public class HealthReporterProducer { 29 | 30 | private SmallRyeHealthReporter reporter; 31 | private Unmanaged.UnmanagedInstance reporterInstance; 32 | 33 | @Produces 34 | @ApplicationScoped 35 | public SmallRyeHealthReporter getReporter() { 36 | if (reporter == null) { 37 | BeanManager bm = CDI.current().getBeanManager(); 38 | Unmanaged unmanagedReporter = new Unmanaged<>(bm, SmallRyeHealthReporter.class); 39 | reporterInstance = unmanagedReporter.newInstance(); 40 | reporter = reporterInstance.produce().inject().postConstruct().get(); 41 | } 42 | return reporter; 43 | } 44 | 45 | public void disposeReporter(@Disposes SmallRyeHealthReporter reporter) { 46 | if (reporterInstance != null) { 47 | reporterInstance.preDestroy().dispose(); 48 | reporterInstance = null; 49 | } 50 | } 51 | } 52 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/java/com/fujitsu/launcher/microprofile/health/HealthServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.health; 12 | 13 | import java.io.IOException; 14 | import java.util.logging.Level; 15 | import java.util.logging.Logger; 16 | 17 | import jakarta.inject.Inject; 18 | import jakarta.servlet.ServletException; 19 | import jakarta.servlet.annotation.WebServlet; 20 | import jakarta.servlet.http.HttpServlet; 21 | import jakarta.servlet.http.HttpServletRequest; 22 | import jakarta.servlet.http.HttpServletResponse; 23 | 24 | import io.smallrye.health.SmallRyeHealth; 25 | import io.smallrye.health.SmallRyeHealthReporter; 26 | 27 | /** 28 | * Provides the health check endpoints. 29 | * 30 | * @author Takahiro Nagao 31 | */ 32 | @WebServlet 33 | public class HealthServlet extends HttpServlet { 34 | 35 | public static final String HEALTH = "/health"; 36 | public static final String HEALTH_LIVE = "/health/live"; 37 | public static final String HEALTH_READY = "/health/ready"; 38 | public static final String HEALTH_STARTED = "/health/started"; 39 | 40 | @Inject 41 | private SmallRyeHealthReporter reporter; 42 | 43 | @Override 44 | protected void doGet(HttpServletRequest request, HttpServletResponse response) 45 | throws ServletException, IOException { 46 | processRequest(request, response); 47 | } 48 | 49 | private void processRequest(HttpServletRequest request, HttpServletResponse response) 50 | throws ServletException, IOException { 51 | 52 | if (reporter == null) { 53 | Logger.getLogger(this.getClass().getName()).log(Level.INFO, "Health reporter has not been prepared"); 54 | response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); 55 | return; 56 | } 57 | 58 | String path = request.getRequestURI(); 59 | 60 | if (HEALTH.equals(path)) { 61 | report(response, reporter.getHealth()); 62 | } else if (HEALTH_LIVE.equals(path)) { 63 | report(response, reporter.getLiveness()); 64 | } else if (HEALTH_READY.equals(path)) { 65 | report(response, reporter.getReadiness()); 66 | } else if (HEALTH_STARTED.equals(path)) { 67 | report(response, reporter.getStartup()); 68 | } else { 69 | response.setStatus(HttpServletResponse.SC_NOT_FOUND); 70 | response.getWriter().write("Endpoint " + path + " not found"); 71 | } 72 | } 73 | 74 | private void report(HttpServletResponse response, SmallRyeHealth health) throws ServletException, IOException { 75 | if (health.isDown()) { 76 | response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE); 77 | } 78 | reporter.reportHealth(response.getOutputStream(), health); 79 | } 80 | } 81 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/java/com/fujitsu/launcher/microprofile/health/HealthServletContainerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.health; 12 | 13 | import java.util.Set; 14 | 15 | import jakarta.servlet.ServletContainerInitializer; 16 | import jakarta.servlet.ServletContext; 17 | import jakarta.servlet.ServletException; 18 | import jakarta.servlet.ServletRegistration; 19 | 20 | /** 21 | * Adds health check servlets to the context. 22 | * 23 | * @author Takahiro Nagao 24 | */ 25 | public class HealthServletContainerInitializer implements ServletContainerInitializer { 26 | 27 | @Override 28 | public void onStartup(Set> classes, ServletContext context) throws ServletException { 29 | ServletRegistration.Dynamic dynamic = context.addServlet("health-servlet", HealthServlet.class); 30 | dynamic.addMapping("/health/*"); 31 | } 32 | } 33 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.health.HealthExtension -------------------------------------------------------------------------------- /launcher-impl/microprofile/health/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.health.HealthServletContainerInitializer 2 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 4.0.0 13 | 14 | com.fujitsu.launcher 15 | microprofile 16 | 5.1-SNAPSHOT 17 | 18 | microprofile-jwt-auth 19 | jar 20 | 21 | 22 | 23 | org.eclipse.microprofile.jwt 24 | microprofile-jwt-auth-api 25 | 26 | 27 | com.fujitsu.launcher 28 | patched-glassfish 29 | 30 | 31 | io.smallrye 32 | smallrye-jwt-jaxrs 33 | 34 | 35 | org.slf4j 36 | slf4j-jdk14 37 | 38 | 39 | 40 | 41 | 42 | 43 | org.glassfish.hk2 44 | hk2-inhabitant-generator 45 | 46 | 47 | 48 | generate-inhabitants 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/java/com/fujitsu/launcher/microprofile/jwt/auth/JwtAuthService.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.jwt.auth; 12 | 13 | import jakarta.inject.Inject; 14 | 15 | import org.glassfish.api.StartupRunLevel; 16 | import org.glassfish.hk2.runlevel.RunLevel; 17 | import org.glassfish.web.deployment.annotation.handlers.LoginConfigHandler; 18 | import org.jvnet.hk2.annotations.Service; 19 | 20 | @Service(name = "jwt-auth-service") 21 | @RunLevel(StartupRunLevel.VAL) 22 | public class JwtAuthService { 23 | 24 | @Inject 25 | LoginConfigHandler loginConfigHandler; 26 | 27 | public boolean isJwtAuthEnabled() { 28 | return loginConfigHandler.isAnnotationPresent() && "MP-JWT".equals(loginConfigHandler.getAuthMethod()); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/java/com/fujitsu/launcher/microprofile/jwt/auth/cdi/JwtAuthExtension.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.jwt.auth.cdi; 12 | 13 | import java.lang.reflect.Type; 14 | import java.util.Arrays; 15 | import java.util.HashSet; 16 | import java.util.Optional; 17 | import java.util.Set; 18 | 19 | import jakarta.enterprise.event.Observes; 20 | import jakarta.enterprise.inject.spi.BeanManager; 21 | import jakarta.enterprise.inject.spi.BeforeBeanDiscovery; 22 | import jakarta.enterprise.inject.spi.Extension; 23 | import jakarta.enterprise.inject.spi.ProcessBeanAttributes; 24 | 25 | import org.eclipse.microprofile.jwt.Claim; 26 | import org.eclipse.microprofile.jwt.Claims; 27 | import org.glassfish.hk2.utilities.reflection.ParameterizedTypeImpl; 28 | import org.glassfish.internal.api.Globals; 29 | 30 | import com.fujitsu.launcher.microprofile.jwt.auth.JwtAuthService; 31 | 32 | import io.smallrye.jwt.auth.cdi.ClaimValueProducer; 33 | import io.smallrye.jwt.auth.cdi.CommonJwtProducer; 34 | import io.smallrye.jwt.auth.cdi.JWTCallerPrincipalFactoryProducer; 35 | import io.smallrye.jwt.auth.cdi.JsonValueProducer; 36 | import io.smallrye.jwt.auth.cdi.PrincipalProducer; 37 | import io.smallrye.jwt.auth.cdi.RawClaimTypeProducer; 38 | import io.smallrye.jwt.auth.jaxrs.JWTAuthenticationFilter; 39 | import io.smallrye.jwt.auth.principal.DefaultJWTParser; 40 | 41 | public class JwtAuthExtension implements Extension { 42 | 43 | private static final Type[] OPTIONAL_RAW_CLAIM_TYPES = new Type[] { 44 | new ParameterizedTypeImpl(Optional.class, String.class), 45 | new ParameterizedTypeImpl(Optional.class, new ParameterizedTypeImpl(Set.class, String.class)), 46 | new ParameterizedTypeImpl(Optional.class, Long.class), 47 | new ParameterizedTypeImpl(Optional.class, Boolean.class), 48 | }; 49 | 50 | public void beforeBeanDiscovery(@Observes BeforeBeanDiscovery bbd, BeanManager bm) { 51 | if (Globals.getDefaultHabitat().getService(JwtAuthService.class).isJwtAuthEnabled()) { 52 | bbd.addAnnotatedType(bm.createAnnotatedType(ClaimValueProducer.class), ClaimValueProducer.class.getName()); 53 | bbd.addAnnotatedType(bm.createAnnotatedType(CommonJwtProducer.class), CommonJwtProducer.class.getName()); 54 | bbd.addAnnotatedType(bm.createAnnotatedType(JsonValueProducer.class), JsonValueProducer.class.getName()); 55 | bbd.addAnnotatedType(bm.createAnnotatedType(VerboseJwtAuthContextInfoProvider.class), VerboseJwtAuthContextInfoProvider.class.getName()); 56 | bbd.addAnnotatedType(bm.createAnnotatedType(JWTAuthenticationFilter.class), JWTAuthenticationFilter.class.getName()); 57 | bbd.addAnnotatedType(bm.createAnnotatedType(PrincipalProducer.class), PrincipalProducer.class.getName()); 58 | bbd.addAnnotatedType(bm.createAnnotatedType(RawClaimTypeProducer.class), RawClaimTypeProducer.class.getName()); 59 | bbd.addAnnotatedType(bm.createAnnotatedType(DefaultJWTParser.class), DefaultJWTParser.class.getName()); 60 | bbd.addAnnotatedType(bm.createAnnotatedType(JWTCallerPrincipalFactoryProducer.class), JWTCallerPrincipalFactoryProducer.class.getName()); 61 | } 62 | } 63 | 64 | public void processBeanAttributes(@Observes ProcessBeanAttributes pba, BeanManager bm) { 65 | Claim claim = pba.getAnnotated().getAnnotation(Claim.class); 66 | if (claim != null && isClaimUnknown(claim)) { 67 | if (pba.getBeanAttributes().getTypes().contains(Optional.class)) { 68 | // let RawClaimTypeProducer#getOptionalValue handle each optional type 69 | pba.configureBeanAttributes().addTypes(new HashSet<>(Arrays.asList(OPTIONAL_RAW_CLAIM_TYPES))); 70 | } 71 | } 72 | } 73 | 74 | private boolean isClaimUnknown(Claim claim) { 75 | return (claim.value() == null || claim.value().isEmpty()) && claim.standard() == Claims.UNKNOWN; 76 | } 77 | } 78 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/java/com/fujitsu/launcher/microprofile/jwt/auth/cdi/VerboseJwtAuthContextInfoProvider.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.jwt.auth.cdi; 12 | 13 | import java.util.logging.Level; 14 | import java.util.logging.Logger; 15 | 16 | import jakarta.enterprise.context.ApplicationScoped; 17 | import jakarta.enterprise.context.Dependent; 18 | import jakarta.enterprise.inject.Produces; 19 | 20 | import io.smallrye.jwt.auth.principal.JWTAuthContextInfo; 21 | import io.smallrye.jwt.config.JWTAuthContextInfoProvider; 22 | 23 | // Just put additional log message if mandatory property is set incorrectly. 24 | @Dependent 25 | public class VerboseJwtAuthContextInfoProvider extends JWTAuthContextInfoProvider { 26 | @Produces 27 | @ApplicationScoped 28 | @Override 29 | public JWTAuthContextInfo getContextInfo() { 30 | try { 31 | return super.getContextInfo(); 32 | } catch (IllegalStateException e) { 33 | Logger.getLogger(this.getClass().getName()).log(Level.SEVERE, e.toString()); 34 | throw e; 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/java/com/fujitsu/launcher/microprofile/jwt/auth/rs/JwtAuthAutoDiscoverable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.jwt.auth.rs; 12 | 13 | import jakarta.annotation.Priority; 14 | import jakarta.ws.rs.core.FeatureContext; 15 | 16 | import org.glassfish.internal.api.Globals; 17 | import org.glassfish.jersey.internal.spi.AutoDiscoverable; 18 | import org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable; 19 | 20 | import com.fujitsu.launcher.microprofile.jwt.auth.JwtAuthService; 21 | 22 | import io.smallrye.jwt.auth.jaxrs.JWTAuthenticationFilter; 23 | import io.smallrye.jwt.auth.jaxrs.JWTAuthorizationFilterRegistrar; 24 | 25 | @Priority(AutoDiscoverable.DEFAULT_PRIORITY) 26 | public class JwtAuthAutoDiscoverable implements ForcedAutoDiscoverable { 27 | 28 | @Override 29 | public void configure(FeatureContext context) { 30 | if (Globals.getDefaultHabitat().getService(JwtAuthService.class).isJwtAuthEnabled()) { 31 | if (!context.getConfiguration().isRegistered(JWTAuthorizationFilterRegistrar.class)) { 32 | context.register(JWTAuthorizationFilterRegistrar.class); 33 | } 34 | if (!context.getConfiguration().isRegistered(JWTAuthenticationFilter.class)) { 35 | context.register(JWTAuthenticationFilter.class); 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/java/org/glassfish/web/deployment/annotation/handlers/LoginConfigHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package org.glassfish.web.deployment.annotation.handlers; 12 | 13 | import java.util.logging.Level; 14 | 15 | import org.eclipse.microprofile.auth.LoginConfig; 16 | import org.glassfish.apf.AnnotationHandlerFor; 17 | import org.glassfish.apf.AnnotationInfo; 18 | import org.glassfish.apf.AnnotationProcessorException; 19 | import org.glassfish.apf.HandlerProcessingResult; 20 | import org.jvnet.hk2.annotations.Service; 21 | 22 | import com.sun.enterprise.deployment.WebBundleDescriptor; 23 | import com.sun.enterprise.deployment.annotation.context.WebBundleContext; 24 | import com.sun.enterprise.deployment.annotation.context.WebComponentContext; 25 | 26 | @Service 27 | @AnnotationHandlerFor(LoginConfig.class) 28 | public class LoginConfigHandler extends AbstractWebHandler { 29 | 30 | public static final String MP_JWT_AUTHENTICATION = "MP-JWT"; 31 | 32 | private boolean annotationPresent = false; 33 | private String authMethod; 34 | private String realmName; 35 | 36 | @Override 37 | protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebComponentContext[] webCompContexts) 38 | throws AnnotationProcessorException { 39 | return processAnnotation(ainfo, webCompContexts[0].getDescriptor().getWebBundleDescriptor()); 40 | } 41 | 42 | @Override 43 | protected HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebBundleContext webBundleContext) 44 | throws AnnotationProcessorException { 45 | return processAnnotation(ainfo, webBundleContext.getDescriptor()); 46 | } 47 | 48 | private HandlerProcessingResult processAnnotation(AnnotationInfo ainfo, WebBundleDescriptor webBundleDesc) 49 | throws AnnotationProcessorException { 50 | Class annotated = (Class) ainfo.getAnnotatedElement(); 51 | LoginConfig annotation = ainfo.getAnnotatedElement().getAnnotation(LoginConfig.class); 52 | 53 | if (!jakarta.ws.rs.core.Application.class.isAssignableFrom(annotated)) { 54 | log(Level.SEVERE, ainfo, 55 | I18N.getLocalString( 56 | "web.deployment.annotation.handlers.needtoimpl", 57 | "The Class {0} having annotation {1} need to implement the interface {2}.", 58 | new Object[] { annotated.getName(), LoginConfig.class.getName(), jakarta.ws.rs.core.Application.class.getName() })); 59 | return getDefaultFailedResult(); 60 | } 61 | 62 | if (!MP_JWT_AUTHENTICATION.equals(annotation.authMethod())) { 63 | log(Level.SEVERE, ainfo, String.format("Unsupported authentication method '%s' is specified in %s at %s.", 64 | annotation.authMethod(), LoginConfig.class.getName(), annotated.getName())); 65 | return getDefaultFailedResult(); 66 | } 67 | 68 | annotationPresent = true; 69 | authMethod = annotation.authMethod(); 70 | realmName = annotation.realmName(); 71 | 72 | // TODO support MP-JWT login-config in dd and adopt the code below: 73 | // LoginConfiguration loginConfig= new LoginConfigurationImpl(); 74 | // loginConfig.setAuthenticationMethod(annotation.authMethod()); 75 | // loginConfig.setRealmName(annotation.realmName()); 76 | // webBundleDesc.setLoginConfiguration(loginConfig); 77 | 78 | return getDefaultProcessedResult(); 79 | } 80 | 81 | public boolean isAnnotationPresent() { 82 | return annotationPresent; 83 | } 84 | 85 | public String getAuthMethod() { 86 | return authMethod; 87 | } 88 | 89 | public String getRealmName() { 90 | return realmName; 91 | } 92 | } 93 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.jwt.auth.cdi.JwtAuthExtension 2 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/jwt-auth/src/main/resources/META-INF/services/org.glassfish.jersey.internal.spi.ForcedAutoDiscoverable: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.jwt.auth.rs.JwtAuthAutoDiscoverable 2 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/metrics/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | microprofile 18 | 5.1-SNAPSHOT 19 | 20 | microprofile-metrics 21 | jar 22 | 23 | 24 | 25 | org.eclipse.microprofile.metrics 26 | microprofile-metrics-api 27 | 28 | 29 | com.fujitsu.launcher 30 | patched-glassfish 31 | 32 | 33 | io.smallrye 34 | smallrye-metrics 35 | 36 | 37 | io.micrometer 38 | micrometer-registry-prometheus 39 | 40 | 41 | 42 | 43 | 44 | 45 | org.glassfish.hk2 46 | hk2-inhabitant-generator 47 | 48 | 49 | 50 | generate-inhabitants 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/metrics/src/main/java/com/fujitsu/launcher/microprofile/metrics/MetricsServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.metrics; 12 | 13 | import java.io.IOException; 14 | import java.util.Collections; 15 | import java.util.Map; 16 | import java.util.logging.Level; 17 | import java.util.logging.Logger; 18 | import java.util.stream.Stream; 19 | 20 | import jakarta.inject.Inject; 21 | import jakarta.servlet.annotation.WebServlet; 22 | import jakarta.servlet.http.HttpServlet; 23 | import jakarta.servlet.http.HttpServletRequest; 24 | import jakarta.servlet.http.HttpServletResponse; 25 | 26 | import io.smallrye.metrics.MetricsRequestHandler; 27 | import io.smallrye.metrics.MetricsRequestHandler.Responder; 28 | 29 | @WebServlet 30 | public class MetricsServlet extends HttpServlet { 31 | 32 | @Inject 33 | private MetricsRequestHandler handler; 34 | 35 | @Override 36 | protected void doOptions(HttpServletRequest request, HttpServletResponse response) throws IOException { 37 | processRequest(request, response); 38 | } 39 | 40 | @Override 41 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 42 | processRequest(request, response); 43 | } 44 | 45 | private void processRequest(HttpServletRequest request, HttpServletResponse response) throws IOException { 46 | if (handler == null) { 47 | Logger.getLogger(this.getClass().getName()).log(Level.INFO, "No metrics request handler is installed."); 48 | return; 49 | } 50 | 51 | Stream acceptHeaders = Collections.list(request.getHeaders("Accept")).stream(); 52 | 53 | Responder responder = new Responder() { 54 | public void respondWith(int status, String message, Map headers) throws IOException { 55 | headers.forEach(response::addHeader); 56 | response.getWriter().write(message); 57 | response.setStatus(status); 58 | } 59 | }; 60 | 61 | handler.handleRequest(request.getRequestURI(), request.getMethod(), acceptHeaders, request.getParameterMap(), responder); 62 | } 63 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/metrics/src/main/java/com/fujitsu/launcher/microprofile/metrics/MetricsServletContainerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.metrics; 12 | 13 | import java.util.Set; 14 | 15 | import jakarta.servlet.ServletContainerInitializer; 16 | import jakarta.servlet.ServletContext; 17 | import jakarta.servlet.ServletException; 18 | import jakarta.servlet.ServletRegistration; 19 | 20 | public class MetricsServletContainerInitializer implements ServletContainerInitializer { 21 | 22 | @Override 23 | public void onStartup(Set> classes, ServletContext context) throws ServletException { 24 | ServletRegistration.Dynamic dynamic = context.addServlet("metrics-servlet", MetricsServlet.class); 25 | dynamic.addMapping("/metrics/*"); 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/metrics/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.metrics.MetricsServletContainerInitializer 2 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/openapi/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 11 | 12 | 4.0.0 13 | 14 | 15 | com.fujitsu.launcher 16 | microprofile 17 | 5.1-SNAPSHOT 18 | 19 | microprofile-open-api 20 | jar 21 | 22 | 23 | 24 | org.eclipse.microprofile.openapi 25 | microprofile-openapi-api 26 | 27 | 28 | com.fujitsu.launcher 29 | patched-glassfish 30 | 31 | 32 | io.smallrye 33 | smallrye-open-api-core 34 | 35 | 36 | io.smallrye 37 | smallrye-open-api-jaxrs 38 | 39 | 40 | 41 | org.junit.jupiter 42 | junit-jupiter-api 43 | 5.8.1 44 | test 45 | 46 | 47 | org.junit.jupiter 48 | junit-jupiter-engine 49 | 5.8.1 50 | test 51 | 52 | 53 | org.junit.jupiter 54 | junit-jupiter-params 55 | 5.8.1 56 | test 57 | 58 | 59 | org.mockito 60 | mockito-core 61 | 4.0.0 62 | test 63 | 64 | 65 | 66 | 67 | 68 | 69 | org.glassfish.hk2 70 | hk2-inhabitant-generator 71 | 72 | 73 | 74 | generate-inhabitants 75 | 76 | 77 | 78 | 79 | 80 | org.apache.maven.plugins 81 | maven-surefire-plugin 82 | 3.0.0-M5 83 | 84 | 85 | 86 | 87 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/openapi/src/main/java/com/fujitsu/launcher/microprofile/openapi/OpenApiServlet.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | */ 10 | package com.fujitsu.launcher.microprofile.openapi; 11 | 12 | import java.io.IOException; 13 | import java.util.HashMap; 14 | import java.util.List; 15 | import java.util.Map; 16 | 17 | import jakarta.servlet.annotation.WebServlet; 18 | import jakarta.servlet.http.HttpServlet; 19 | import jakarta.servlet.http.HttpServletRequest; 20 | import jakarta.servlet.http.HttpServletResponse; 21 | 22 | import io.smallrye.openapi.api.OpenApiDocument; 23 | import io.smallrye.openapi.runtime.io.Format; 24 | import io.smallrye.openapi.runtime.io.OpenApiSerializer; 25 | 26 | import org.glassfish.jersey.message.internal.AcceptableMediaType; 27 | import org.glassfish.jersey.message.internal.HttpHeaderReader; 28 | 29 | import java.text.ParseException; 30 | 31 | import jakarta.ws.rs.core.MediaType; 32 | 33 | /** 34 | * 35 | * @author Takahiro Nagao 36 | * @author Katsuhiro Kunisada 37 | * @author Koki Kosaka 38 | */ 39 | @SuppressWarnings("serial") 40 | @WebServlet 41 | public class OpenApiServlet extends HttpServlet { 42 | public static final Map ACCEPTED_TYPES = new HashMap<>(); 43 | 44 | static { 45 | ACCEPTED_TYPES.put(Format.YAML, MediaType.TEXT_PLAIN); 46 | ACCEPTED_TYPES.put(Format.JSON, MediaType.APPLICATION_JSON); 47 | } 48 | 49 | @Override 50 | protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException { 51 | Format format = getResponseFormat(request); 52 | if (format != null) { 53 | String oai = OpenApiSerializer.serialize(OpenApiDocument.INSTANCE.get(), format); 54 | response.setContentType(ACCEPTED_TYPES.get(format)); 55 | response.getWriter().write(oai); 56 | response.setStatus(HttpServletResponse.SC_OK); 57 | } else { 58 | response.sendError(HttpServletResponse.SC_NOT_ACCEPTABLE); 59 | } 60 | } 61 | 62 | protected Format getResponseFormat(HttpServletRequest request) { 63 | try { 64 | Format format = parseFormatQueryParameter(request); 65 | if (format != null) return format; 66 | return parseAcceptHeader(request); 67 | } catch (ParseException e) { 68 | throw new RuntimeException(e); 69 | } 70 | } 71 | 72 | private Format parseFormatQueryParameter(HttpServletRequest request) { 73 | String formatParam = request.getParameter("format"); 74 | if (formatParam != null) { 75 | for (Format f : Format.values()) { 76 | if (f.name().equalsIgnoreCase(formatParam)) return f; 77 | } 78 | } 79 | return null; 80 | } 81 | 82 | private Format parseAcceptHeader(HttpServletRequest request) throws ParseException { 83 | String acceptHeader = request.getHeader("Accept"); 84 | // sorted by quality value 85 | List mediaTypes = HttpHeaderReader.readAcceptMediaType(acceptHeader); 86 | if (mediaTypes.isEmpty()) { 87 | mediaTypes.add(AcceptableMediaType.valueOf(MediaType.WILDCARD_TYPE)); 88 | } 89 | 90 | for (AcceptableMediaType mediaType : mediaTypes) { 91 | if (mediaType.isCompatible(MediaType.TEXT_PLAIN_TYPE)) { 92 | return Format.YAML; 93 | } 94 | if (mediaType.isCompatible(MediaType.APPLICATION_JSON_TYPE)) { 95 | return Format.JSON; 96 | } 97 | } 98 | return null; 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/openapi/src/main/java/com/fujitsu/launcher/microprofile/openapi/OpenApiServletContainerInitializer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2019-2022 Fujitsu Limited and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | */ 10 | package com.fujitsu.launcher.microprofile.openapi; 11 | 12 | import java.util.Set; 13 | 14 | import jakarta.servlet.ServletContainerInitializer; 15 | import jakarta.servlet.ServletContext; 16 | import jakarta.servlet.ServletException; 17 | import jakarta.servlet.ServletRegistration; 18 | 19 | /** 20 | * 21 | * @author Takahiro Nagao 22 | */ 23 | public class OpenApiServletContainerInitializer implements ServletContainerInitializer { 24 | @Override 25 | public void onStartup(Set> classes, ServletContext context) throws ServletException { 26 | ServletRegistration.Dynamic dynamic = context.addServlet("openapi-servlet", OpenApiServlet.class); 27 | dynamic.addMapping("/openapi"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/openapi/src/main/resources/META-INF/services/jakarta.servlet.ServletContainerInitializer: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.openapi.OpenApiServletContainerInitializer 2 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/openapi/src/test/java/com/fujitsu/launcher/microprofile/openapi/OpenApiServletTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2021-2022 Fujitsu Limited and/or its affiliates. All rights reserved. 3 | * 4 | * This program and the accompanying materials are made available under the 5 | * terms of the Eclipse Public License v. 2.0, which is available at 6 | * http://www.eclipse.org/legal/epl-2.0. 7 | * 8 | * SPDX-License-Identifier: EPL-2.0 9 | */ 10 | 11 | package com.fujitsu.launcher.microprofile.openapi; 12 | 13 | import static org.junit.jupiter.api.Assertions.assertEquals; 14 | import static org.junit.jupiter.api.Assertions.assertThrows; 15 | import static org.mockito.Mockito.doReturn; 16 | import static org.mockito.Mockito.mock; 17 | import static org.mockito.Mockito.spy; 18 | import static org.mockito.Mockito.times; 19 | import static org.mockito.Mockito.verify; 20 | import static org.mockito.Mockito.when; 21 | 22 | import java.io.IOException; 23 | import java.util.stream.Stream; 24 | 25 | import jakarta.servlet.http.HttpServletRequest; 26 | import jakarta.servlet.http.HttpServletResponse; 27 | 28 | import io.smallrye.openapi.runtime.io.Format; 29 | import org.junit.jupiter.api.Test; 30 | import org.junit.jupiter.params.ParameterizedTest; 31 | import org.junit.jupiter.params.provider.Arguments; 32 | import org.junit.jupiter.params.provider.MethodSource; 33 | 34 | public class OpenApiServletTest { 35 | 36 | HttpServletRequest mockRequest = mock(HttpServletRequest.class); 37 | HttpServletResponse mockResponse = mock(HttpServletResponse.class); 38 | 39 | OpenApiServlet servlet = spy(new OpenApiServlet()); 40 | 41 | @ParameterizedTest 42 | @MethodSource({"provideOnlyAcceptHeader", "provideOnlyFormatQuery", "provideFormatQueryAndAcceptHeader"}) 43 | public void testGetResponseFormat(String format, String acceptHeader, Format expected) { 44 | when(mockRequest.getParameter("format")).thenReturn(format); 45 | when(mockRequest.getHeader("Accept")).thenReturn(acceptHeader); 46 | Format result = servlet.getResponseFormat(mockRequest); 47 | assertEquals(result, expected); 48 | } 49 | 50 | private static Stream provideOnlyAcceptHeader() { 51 | return Stream.of( 52 | // one value 53 | Arguments.of(null, "", Format.YAML), 54 | Arguments.of(null, "text/plain", Format.YAML), 55 | Arguments.of(null, "application/json", Format.JSON), 56 | Arguments.of(null, "*/*", Format.YAML), 57 | Arguments.of(null, "text/*", Format.YAML), 58 | Arguments.of(null, "application/*", Format.JSON), 59 | Arguments.of(null, "hoge/hoge", null), 60 | 61 | // two value 62 | Arguments.of(null, "text/plain, application/json", Format.YAML), 63 | Arguments.of(null, "application/json, text/plain", Format.JSON), 64 | Arguments.of(null, "text/plain;q=0.9, application/json", Format.JSON), 65 | Arguments.of(null, "application/json;q=0.9, text/plain", Format.YAML), 66 | 67 | Arguments.of(null, "*/*, application/json", Format.JSON), 68 | Arguments.of(null, "text/*, application/json", Format.JSON), 69 | Arguments.of(null, "application/*, text/plain", Format.YAML), 70 | Arguments.of(null, "text/*, application/json;q=0.9", Format.YAML), 71 | Arguments.of(null, "application/*, text/plain;q=0.9", Format.JSON), 72 | 73 | // three value 74 | Arguments.of(null, "*/*, application/*, text/plain", Format.YAML), 75 | Arguments.of(null, "*/*, application/*, text/plain;q=0.9", Format.JSON), 76 | Arguments.of(null, "*/*, application/*;q=0.9, text/plain;q=0.8", Format.YAML) 77 | ); 78 | } 79 | 80 | private static Stream provideOnlyFormatQuery() { 81 | return Stream.of( 82 | // one value 83 | Arguments.of("YAML", null, Format.YAML), 84 | Arguments.of("JSON", null, Format.JSON), 85 | Arguments.of("yaml", null, Format.YAML), 86 | Arguments.of("json", null, Format.JSON), 87 | Arguments.of("hoge", null, Format.YAML), 88 | Arguments.of(null, null, Format.YAML) 89 | ); 90 | } 91 | 92 | private static Stream provideFormatQueryAndAcceptHeader() { 93 | return Stream.of( 94 | Arguments.of("YAML", "application/json", Format.YAML), 95 | Arguments.of("JSON", "text/plain", Format.JSON), 96 | Arguments.of("hoge", "application/json", Format.JSON) 97 | ); 98 | } 99 | 100 | @Test 101 | public void testSendError406() throws IOException { 102 | doReturn(null).when(servlet).getResponseFormat(mockRequest); 103 | servlet.doGet(mockRequest, mockResponse); 104 | verify(mockResponse, times(1)).sendError(406); 105 | } 106 | 107 | @Test 108 | public void testThrowRuntimeException() { 109 | when(mockRequest.getParameter("format")).thenReturn(null); 110 | when(mockRequest.getHeader("Accept")).thenReturn("application/json:q=0.4"); //colon 111 | assertThrows(RuntimeException.class, () -> servlet.getResponseFormat(mockRequest)); 112 | } 113 | 114 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | launcher-impl 18 | 5.1-SNAPSHOT 19 | 20 | microprofile 21 | pom 22 | 23 | 24 | config 25 | fault-tolerance 26 | health 27 | jwt-auth 28 | metrics 29 | openapi 30 | rest-client 31 | telemetry-tracing 32 | 33 | 34 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/rest-client/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | microprofile 18 | 5.1-SNAPSHOT 19 | 20 | microprofile-rest-client 21 | jar 22 | 23 | 24 | 25 | org.eclipse.microprofile.rest.client 26 | microprofile-rest-client-api 27 | 28 | 29 | 30 | com.fujitsu.launcher 31 | patched-glassfish 32 | 33 | 34 | 35 | org.glassfish.jersey.ext.microprofile 36 | jersey-mp-rest-client 37 | 38 | 39 | org.glassfish.jersey.ext.cdi 40 | jersey-weld2-se 41 | 42 | 43 | 44 | 45 | org.glassfish.jersey.connectors 46 | jersey-apache-connector 47 | 48 | 49 | 50 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | microprofile 18 | 5.1-SNAPSHOT 19 | 20 | microprofile-telemetry-tracing 21 | jar 22 | 23 | 24 | 25 | com.fujitsu.launcher 26 | patched-glassfish 27 | 28 | 29 | io.opentelemetry 30 | opentelemetry-exporter-otlp 31 | 32 | 33 | io.opentelemetry 34 | opentelemetry-sdk 35 | 36 | 37 | io.opentelemetry 38 | opentelemetry-sdk-extension-autoconfigure 39 | 40 | 41 | io.opentelemetry.instrumentation 42 | opentelemetry-instrumentation-api 43 | 44 | 45 | io.opentelemetry.instrumentation 46 | opentelemetry-instrumentation-api-semconv 47 | 48 | 49 | io.opentelemetry.instrumentation 50 | opentelemetry-instrumentation-annotations 51 | 52 | 53 | io.opentelemetry.instrumentation 54 | opentelemetry-instrumentation-annotations-support 55 | 56 | 57 | org.eclipse.microprofile.config 58 | microprofile-config-api 59 | 60 | 61 | 62 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/cdi/MethodRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.cdi; 16 | 17 | import java.lang.reflect.Method; 18 | 19 | final class MethodRequest { 20 | private final Method method; 21 | private final Object[] args; 22 | 23 | public MethodRequest(final Method method, final Object[] args) { 24 | this.method = method; 25 | this.args = args; 26 | } 27 | 28 | public Method getMethod() { 29 | return method; 30 | } 31 | 32 | public Object[] getArgs() { 33 | return args; 34 | } 35 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/cdi/OpenTelemetryConfigProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.cdi; 16 | 17 | import java.util.HashMap; 18 | import java.util.Map; 19 | 20 | import jakarta.enterprise.inject.Produces; 21 | import jakarta.inject.Inject; 22 | import jakarta.inject.Singleton; 23 | 24 | import org.eclipse.microprofile.config.Config; 25 | 26 | import com.fujitsu.launcher.microprofile.telemetry.tracing.config.OpenTelemetryConfig; 27 | 28 | @Singleton 29 | public class OpenTelemetryConfigProducer { 30 | @Inject 31 | Config config; 32 | 33 | static final Map defaultProperties = Map.of( 34 | "otel.sdk.disabled", "true", 35 | "otel.metrics.exporter", "none"); 36 | 37 | @Produces 38 | @Singleton 39 | public OpenTelemetryConfig produces() { 40 | return new OpenTelemetryConfig() { 41 | @Override 42 | public Map properties() { 43 | Map properties = new HashMap<>(defaultProperties); 44 | for (String propertyName : config.getPropertyNames()) { 45 | if (propertyName.startsWith("otel.") || propertyName.startsWith("OTEL_")) { 46 | config.getOptionalValue(propertyName, String.class).ifPresent( 47 | value -> properties.put(propertyName, value)); 48 | } 49 | } 50 | return properties; 51 | } 52 | }; 53 | } 54 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/cdi/OpenTelemetryProducer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.cdi; 16 | 17 | import static com.fujitsu.launcher.microprofile.telemetry.tracing.config.OpenTelemetryConfig.INSTRUMENTATION_NAME; 18 | 19 | import java.util.ArrayList; 20 | import java.util.List; 21 | import java.util.concurrent.TimeUnit; 22 | 23 | import com.fujitsu.launcher.microprofile.telemetry.tracing.config.OpenTelemetryConfig; 24 | import jakarta.enterprise.context.RequestScoped; 25 | import jakarta.enterprise.inject.Disposes; 26 | import jakarta.enterprise.inject.Produces; 27 | import jakarta.enterprise.inject.spi.CDI; 28 | import jakarta.inject.Inject; 29 | import jakarta.inject.Singleton; 30 | 31 | import io.opentelemetry.api.OpenTelemetry; 32 | import io.opentelemetry.api.baggage.Baggage; 33 | import io.opentelemetry.api.trace.Span; 34 | import io.opentelemetry.api.trace.Tracer; 35 | import io.opentelemetry.sdk.OpenTelemetrySdk; 36 | import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdk; 37 | import io.opentelemetry.sdk.autoconfigure.AutoConfiguredOpenTelemetrySdkBuilder; 38 | import io.opentelemetry.sdk.common.CompletableResultCode; 39 | 40 | @Singleton 41 | public class OpenTelemetryProducer { 42 | @Inject 43 | OpenTelemetryConfig config; 44 | 45 | @Produces 46 | @Singleton 47 | public OpenTelemetry getOpenTelemetry() { 48 | AutoConfiguredOpenTelemetrySdkBuilder builder = AutoConfiguredOpenTelemetrySdk.builder(); 49 | 50 | ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); 51 | if (contextClassLoader != null) { 52 | builder.setServiceClassLoader(contextClassLoader); 53 | } 54 | 55 | return builder 56 | .setResultAsGlobal(false) 57 | .registerShutdownHook(false) 58 | .addPropertiesSupplier(() -> config.properties()) 59 | .build() 60 | .getOpenTelemetrySdk(); 61 | } 62 | 63 | @Produces 64 | @Singleton 65 | public Tracer getTracer() { 66 | return CDI.current().select(OpenTelemetry.class).get().getTracer(INSTRUMENTATION_NAME); 67 | } 68 | 69 | @Produces 70 | @RequestScoped 71 | public Span getSpan() { 72 | return Span.current(); 73 | } 74 | 75 | @Produces 76 | @RequestScoped 77 | public Baggage getBaggage() { 78 | return Baggage.current(); 79 | } 80 | 81 | void close(@Disposes final OpenTelemetry openTelemetry) { 82 | OpenTelemetrySdk openTelemetrySdk = (OpenTelemetrySdk) openTelemetry; 83 | List shutdown = new ArrayList<>(); 84 | shutdown.add(openTelemetrySdk.getSdkTracerProvider().shutdown()); 85 | shutdown.add(openTelemetrySdk.getSdkMeterProvider().shutdown()); 86 | shutdown.add(openTelemetrySdk.getSdkLoggerProvider().shutdown()); 87 | CompletableResultCode.ofAll(shutdown).join(10, TimeUnit.SECONDS); 88 | } 89 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/cdi/WithSpanInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.cdi; 16 | 17 | import static com.fujitsu.launcher.microprofile.telemetry.tracing.config.OpenTelemetryConfig.INSTRUMENTATION_NAME; 18 | import static com.fujitsu.launcher.microprofile.telemetry.tracing.config.OpenTelemetryConfig.INSTRUMENTATION_VERSION; 19 | 20 | import java.lang.reflect.Method; 21 | import java.lang.reflect.Parameter; 22 | 23 | import jakarta.interceptor.AroundInvoke; 24 | import jakarta.interceptor.InvocationContext; 25 | 26 | import io.opentelemetry.api.OpenTelemetry; 27 | import io.opentelemetry.api.trace.SpanKind; 28 | import io.opentelemetry.context.Context; 29 | import io.opentelemetry.context.Scope; 30 | import io.opentelemetry.instrumentation.annotations.SpanAttribute; 31 | import io.opentelemetry.instrumentation.annotations.WithSpan; 32 | import io.opentelemetry.instrumentation.api.annotation.support.MethodSpanAttributesExtractor; 33 | import io.opentelemetry.instrumentation.api.annotation.support.ParameterAttributeNamesExtractor; 34 | import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter; 35 | import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder; 36 | import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor; 37 | import io.opentelemetry.instrumentation.api.instrumenter.util.SpanNames; 38 | 39 | public class WithSpanInterceptor { 40 | private final Instrumenter instrumenter; 41 | 42 | public WithSpanInterceptor(final OpenTelemetry openTelemetry) { 43 | InstrumenterBuilder builder = Instrumenter.builder(openTelemetry, INSTRUMENTATION_NAME, 44 | new MethodRequestSpanNameExtractor()); 45 | builder.setInstrumentationVersion(INSTRUMENTATION_VERSION); 46 | 47 | MethodSpanAttributesExtractor attributesExtractor = MethodSpanAttributesExtractor.newInstance( 48 | MethodRequest::getMethod, 49 | new WithSpanParameterAttributeNamesExtractor(), 50 | MethodRequest::getArgs); 51 | 52 | this.instrumenter = builder.addAttributesExtractor(attributesExtractor) 53 | .buildInstrumenter(methodRequest -> spanKindFromMethod(methodRequest.getMethod())); 54 | } 55 | 56 | private static SpanKind spanKindFromMethod(Method method) { 57 | WithSpan annotation = method.getDeclaredAnnotation(WithSpan.class); 58 | if (annotation == null) { 59 | return SpanKind.INTERNAL; 60 | } 61 | return annotation.kind(); 62 | } 63 | 64 | @AroundInvoke 65 | public Object span(final InvocationContext invocationContext) throws Exception { 66 | MethodRequest methodRequest = new MethodRequest(invocationContext.getMethod(), invocationContext.getParameters()); 67 | 68 | Context parentContext = Context.current(); 69 | Context spanContext = null; 70 | Scope scope = null; 71 | boolean shouldStart = instrumenter.shouldStart(parentContext, methodRequest); 72 | if (shouldStart) { 73 | spanContext = instrumenter.start(parentContext, methodRequest); 74 | scope = spanContext.makeCurrent(); 75 | } 76 | 77 | try { 78 | Object result = invocationContext.proceed(); 79 | 80 | if (shouldStart) { 81 | instrumenter.end(spanContext, methodRequest, null, null); 82 | } 83 | 84 | return result; 85 | } finally { 86 | if (scope != null) { 87 | scope.close(); 88 | } 89 | } 90 | } 91 | 92 | private static final class MethodRequestSpanNameExtractor implements SpanNameExtractor { 93 | @Override 94 | public String extract(final MethodRequest methodRequest) { 95 | WithSpan annotation = methodRequest.getMethod().getDeclaredAnnotation(WithSpan.class); 96 | String spanName = annotation.value(); 97 | if (spanName.isEmpty()) { 98 | spanName = SpanNames.fromMethod(methodRequest.getMethod()); 99 | } 100 | return spanName; 101 | } 102 | } 103 | 104 | private static final class WithSpanParameterAttributeNamesExtractor implements ParameterAttributeNamesExtractor { 105 | private static String attributeName(Parameter parameter) { 106 | SpanAttribute spanAttribute = parameter.getDeclaredAnnotation(SpanAttribute.class); 107 | if (spanAttribute == null) { 108 | return null; 109 | } 110 | String value = spanAttribute.value(); 111 | if (!value.isEmpty()) { 112 | return value; 113 | } else if (parameter.isNamePresent()) { 114 | return parameter.getName(); 115 | } else { 116 | return null; 117 | } 118 | } 119 | 120 | @Override 121 | public String[] extract(final Method method, final Parameter[] parameters) { 122 | String[] attributeNames = new String[parameters.length]; 123 | for (int i = 0; i < parameters.length; i++) { 124 | attributeNames[i] = attributeName(parameters[i]); 125 | } 126 | return attributeNames; 127 | } 128 | } 129 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/cdi/WithSpanInterceptorBean.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.cdi; 16 | 17 | import java.lang.annotation.Annotation; 18 | import java.lang.reflect.Type; 19 | import java.util.Collections; 20 | import java.util.Set; 21 | 22 | import jakarta.enterprise.context.Dependent; 23 | import jakarta.enterprise.context.spi.CreationalContext; 24 | import jakarta.enterprise.inject.spi.Bean; 25 | import jakarta.enterprise.inject.spi.BeanManager; 26 | import jakarta.enterprise.inject.spi.InjectionPoint; 27 | import jakarta.enterprise.inject.spi.InterceptionType; 28 | import jakarta.enterprise.inject.spi.Interceptor; 29 | import jakarta.enterprise.inject.spi.Prioritized; 30 | import jakarta.enterprise.util.AnnotationLiteral; 31 | import jakarta.interceptor.InvocationContext; 32 | 33 | import io.opentelemetry.api.OpenTelemetry; 34 | import io.opentelemetry.api.trace.SpanKind; 35 | import io.opentelemetry.instrumentation.annotations.WithSpan; 36 | 37 | public class WithSpanInterceptorBean implements Interceptor, Prioritized { 38 | private final BeanManager beanManager; 39 | 40 | public WithSpanInterceptorBean(final BeanManager beanManager) { 41 | this.beanManager = beanManager; 42 | } 43 | 44 | @Override 45 | public Set getInterceptorBindings() { 46 | return Collections.singleton(WithSpanLiteral.INSTANCE); 47 | } 48 | 49 | @Override 50 | public boolean intercepts(final InterceptionType type) { 51 | return InterceptionType.AROUND_INVOKE.equals(type); 52 | } 53 | 54 | @Override 55 | public Object intercept( 56 | final InterceptionType type, 57 | final WithSpanInterceptor instance, 58 | final InvocationContext invocationContext) 59 | throws Exception { 60 | 61 | return instance.span(invocationContext); 62 | } 63 | 64 | @Override 65 | public Class getBeanClass() { 66 | return WithSpanInterceptorBean.class; 67 | } 68 | 69 | @Override 70 | public Set getInjectionPoints() { 71 | return Collections.emptySet(); 72 | } 73 | 74 | @Override 75 | public WithSpanInterceptor create(final CreationalContext creationalContext) { 76 | Bean bean = beanManager.resolve(beanManager.getBeans(OpenTelemetry.class)); 77 | OpenTelemetry openTelemetry = (OpenTelemetry) beanManager.getReference(bean, OpenTelemetry.class, creationalContext); 78 | return new WithSpanInterceptor(openTelemetry); 79 | } 80 | 81 | @Override 82 | public void destroy( 83 | final WithSpanInterceptor instance, 84 | final CreationalContext creationalContext) { 85 | 86 | } 87 | 88 | @Override 89 | public Set getTypes() { 90 | return Collections.singleton(this.getBeanClass()); 91 | } 92 | 93 | @Override 94 | public Set getQualifiers() { 95 | return Collections.emptySet(); 96 | } 97 | 98 | @Override 99 | public Class getScope() { 100 | return Dependent.class; 101 | } 102 | 103 | @Override 104 | public String getName() { 105 | return getBeanClass().getName(); 106 | } 107 | 108 | @Override 109 | public Set> getStereotypes() { 110 | return Collections.emptySet(); 111 | } 112 | 113 | @Override 114 | public boolean isAlternative() { 115 | return false; 116 | } 117 | 118 | @Override 119 | public int getPriority() { 120 | return 100; 121 | } 122 | 123 | public static class WithSpanLiteral extends AnnotationLiteral implements WithSpan { 124 | public static final WithSpanLiteral INSTANCE = new WithSpanLiteral(); 125 | 126 | @Override 127 | public String value() { 128 | return null; 129 | } 130 | 131 | @Override 132 | public SpanKind kind() { 133 | return null; 134 | } 135 | } 136 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/config/OpenTelemetryConfig.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023-2024 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | * 11 | * This file incorporates work authored by SmallRye OpenTelemetry, 12 | * licensed under the Apache License, Version 2.0, which is available at 13 | * http://www.apache.org/licenses/LICENSE-2.0. 14 | */ 15 | package com.fujitsu.launcher.microprofile.telemetry.tracing.config; 16 | 17 | import java.util.Map; 18 | import java.util.Optional; 19 | 20 | public interface OpenTelemetryConfig { 21 | // TODO Get from glassfish-version.properties 22 | static String INSTRUMENTATION_NAME = "Launcher"; 23 | 24 | String INSTRUMENTATION_VERSION = Optional.of("5.1").orElse("SNAPSHOT"); 25 | 26 | Map properties(); 27 | } -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/rest/client/OpenTelemetryClientAutoDiscoverable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.telemetry.tracing.rest.client; 12 | 13 | import jakarta.ws.rs.ConstrainedTo; 14 | import jakarta.ws.rs.RuntimeType; 15 | import jakarta.ws.rs.core.FeatureContext; 16 | import org.glassfish.jersey.internal.spi.AutoDiscoverable; 17 | 18 | @ConstrainedTo(RuntimeType.CLIENT) 19 | public class OpenTelemetryClientAutoDiscoverable implements AutoDiscoverable { 20 | @Override 21 | public void configure(FeatureContext featureContext) { 22 | if (!featureContext.getConfiguration().isRegistered(OpenTelemetryPreInvocationInterceptor.class)) { 23 | featureContext.register(OpenTelemetryPreInvocationInterceptor.class); 24 | } 25 | if(!featureContext.getConfiguration().isRegistered(OpenTelemetryClientFeature.class)) { 26 | featureContext.register(OpenTelemetryClientFeature.class); 27 | } 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/rest/client/OpenTelemetryClientFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.telemetry.tracing.rest.client; 12 | 13 | import jakarta.enterprise.inject.spi.CDI; 14 | import jakarta.ws.rs.core.Feature; 15 | import jakarta.ws.rs.core.FeatureContext; 16 | 17 | public class OpenTelemetryClientFeature implements Feature { 18 | @Override 19 | public boolean configure(FeatureContext featureContext) { 20 | if (featureContext.getConfiguration().isRegistered(OpenTelemetryClientFilter.class)) { 21 | return false; 22 | } 23 | try { 24 | var clientFilter = CDI.current().select(OpenTelemetryClientFilter.class).get(); 25 | if (clientFilter != null) { 26 | featureContext.register(clientFilter); 27 | return true; 28 | } 29 | return false; 30 | } catch (IllegalStateException e) { 31 | return false; 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/rest/client/OpenTelemetryPreInvocationInterceptor.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.telemetry.tracing.rest.client; 12 | 13 | import io.opentelemetry.context.Context; 14 | import jakarta.ws.rs.client.ClientRequestContext; 15 | import org.glassfish.jersey.client.spi.PreInvocationInterceptor; 16 | 17 | public class OpenTelemetryPreInvocationInterceptor implements PreInvocationInterceptor { 18 | @Override 19 | public void beforeRequest(ClientRequestContext clientRequestContext) { 20 | clientRequestContext.setProperty("otel.span.client.parentContext", Context.current()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/rest/server/OpenTelemetryServerAutoDiscoverable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.telemetry.tracing.rest.server; 12 | 13 | import jakarta.annotation.Priority; 14 | import jakarta.ws.rs.ConstrainedTo; 15 | import jakarta.ws.rs.RuntimeType; 16 | import jakarta.ws.rs.core.FeatureContext; 17 | import org.glassfish.jersey.internal.spi.AutoDiscoverable; 18 | 19 | @Priority(AutoDiscoverable.DEFAULT_PRIORITY) 20 | @ConstrainedTo(RuntimeType.SERVER) 21 | public class OpenTelemetryServerAutoDiscoverable implements AutoDiscoverable { 22 | @Override 23 | public void configure(final FeatureContext context) { 24 | if (!context.getConfiguration().isRegistered(OpenTelemetryServerDynamicFeature.class)) { 25 | context.register(OpenTelemetryServerDynamicFeature.class); 26 | } 27 | } 28 | } 29 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/java/com/fujitsu/launcher/microprofile/telemetry/tracing/rest/server/OpenTelemetryServerDynamicFeature.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (c) 2023 Fujitsu Limited and/or its affiliates. All rights 3 | * reserved. 4 | * 5 | * This program and the accompanying materials are made available under the 6 | * terms of the Eclipse Public License v. 2.0, which is available at 7 | * http://www.eclipse.org/legal/epl-2.0. 8 | * 9 | * SPDX-License-Identifier: EPL-2.0 10 | */ 11 | package com.fujitsu.launcher.microprofile.telemetry.tracing.rest.server; 12 | 13 | import jakarta.enterprise.inject.spi.CDI; 14 | import jakarta.ws.rs.container.DynamicFeature; 15 | import jakarta.ws.rs.container.ResourceInfo; 16 | import jakarta.ws.rs.core.FeatureContext; 17 | import jakarta.ws.rs.ext.Provider; 18 | 19 | @Provider 20 | public class OpenTelemetryServerDynamicFeature implements DynamicFeature { 21 | 22 | @Override 23 | public void configure(ResourceInfo resourceInfo, FeatureContext featureContext) { 24 | if (featureContext.getConfiguration().isRegistered(OpenTelemetryServerFilter.class)) { 25 | return; 26 | } 27 | 28 | try { 29 | var serverFilter = CDI.current().select(OpenTelemetryServerFilter.class).get(); 30 | if (serverFilter != null) { 31 | featureContext.register(serverFilter); 32 | } 33 | } catch (IllegalStateException e) { 34 | // noop 35 | } 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/resources/META-INF/services/jakarta.enterprise.inject.spi.Extension: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.telemetry.tracing.cdi.OpenTelemetryExtension -------------------------------------------------------------------------------- /launcher-impl/microprofile/telemetry-tracing/src/main/resources/META-INF/services/org.glassfish.jersey.internal.spi.AutoDiscoverable: -------------------------------------------------------------------------------- 1 | com.fujitsu.launcher.microprofile.telemetry.tracing.rest.server.OpenTelemetryServerAutoDiscoverable 2 | com.fujitsu.launcher.microprofile.telemetry.tracing.rest.client.OpenTelemetryClientAutoDiscoverable 3 | -------------------------------------------------------------------------------- /launcher-impl/pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 12 | 13 | 4.0.0 14 | 15 | 16 | com.fujitsu.launcher 17 | launcher-parent 18 | 5.1-SNAPSHOT 19 | 20 | launcher-impl 21 | pom 22 | 23 | 24 | glassfish 25 | microprofile 26 | bootstrap 27 | 28 | 29 | --------------------------------------------------------------------------------