├── Dockerfile ├── .mvn └── wrapper │ ├── maven-wrapper.jar │ ├── maven-wrapper.properties │ └── MavenWrapperDownloader.java ├── .openshiftio ├── description.adoc ├── index.html.flt ├── licenses.xsl ├── licenses-fix.xsl └── application.yaml ├── run_tests_with_dekorate_in_ocp.sh ├── src ├── main │ ├── resources │ │ ├── application.properties │ │ ├── application-openshift.properties │ │ └── static │ │ │ └── index.html │ └── java │ │ └── dev │ │ └── snowdrop │ │ └── example │ │ ├── service │ │ ├── Greeting.java │ │ └── GreetingEndpoint.java │ │ └── ExampleApplication.java └── test │ ├── resources │ └── logback-test.xml │ └── java │ └── dev │ └── snowdrop │ └── example │ ├── ManagedOpenShiftIT.java │ ├── LocalTest.java │ ├── UnmanagedOpenShiftIT.java │ ├── AbstractExampleApplicationTest.java │ ├── ManagedKubernetesIT.java │ └── UnmanagedKubernetesIT.java ├── helm ├── charts │ └── spring-boot-example-app-0.0.4.tgz ├── values.yaml ├── Chart.lock └── Chart.yaml ├── .gitignore ├── Jenkinsfile ├── run_tests_with_dekorate_in_k8s.sh ├── .editorconfig ├── run_tests_with_helm_in_ocp.sh ├── scripts └── waitFor.sh ├── .github ├── mvn-settings.xml └── workflows │ ├── push.yml │ └── pr.yml ├── run_tests_with_helm_in_k8s.sh ├── run_tests_with_generated_helm_in_k8s.sh ├── run_tests_with_s2i.sh ├── README.md ├── mvnw.cmd ├── pom.xml ├── mvnw ├── LICENSE └── guide.adoc /Dockerfile: -------------------------------------------------------------------------------- 1 | FROM openjdk:11 2 | COPY target/*.jar rest-http.jar 3 | CMD java ${JAVA_OPTS} -jar rest-http.jar 4 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.jar: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snowdrop/rest-http-example/HEAD/.mvn/wrapper/maven-wrapper.jar -------------------------------------------------------------------------------- /.openshiftio/description.adoc: -------------------------------------------------------------------------------- 1 | Quickstart to expose a HTTP Greeting endpoint using Spring Boot and Apache Tomcat in embedded mode 2 | -------------------------------------------------------------------------------- /run_tests_with_dekorate_in_ocp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Run Tests 3 | eval "./mvnw clean verify -Popenshift,openshift-it $@" 4 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | resteasy.jaxrs.defaultPath=/api 2 | management.endpoints.web.exposure.include=health,info 3 | -------------------------------------------------------------------------------- /.mvn/wrapper/maven-wrapper.properties: -------------------------------------------------------------------------------- 1 | distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.3.9/apache-maven-3.3.9-bin.zip -------------------------------------------------------------------------------- /helm/charts/spring-boot-example-app-0.0.4.tgz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/snowdrop/rest-http-example/HEAD/helm/charts/spring-boot-example-app-0.0.4.tgz -------------------------------------------------------------------------------- /helm/values.yaml: -------------------------------------------------------------------------------- 1 | app: 2 | name: rest-http 3 | version: 2.7-SNAPSHOT 4 | docker: 5 | image: quay.io/snowdrop/spring-boot-rest-http-example:2.7 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # IntelliJ 2 | .idea 3 | *.iml 4 | target 5 | 6 | # Eclipse 7 | .metadata 8 | .settings 9 | .classpath 10 | .project 11 | bin 12 | tmp 13 | 14 | # VSCodium 15 | .vscode 16 | 17 | # Misc 18 | *.versionsBackup 19 | -------------------------------------------------------------------------------- /Jenkinsfile: -------------------------------------------------------------------------------- 1 | node("launchpad-maven") { 2 | checkout scm 3 | stage("Test") { 4 | sh "mvn test" 5 | } 6 | stage("Deploy") { 7 | sh "mvn clean install -Popenshift -Ddekorate.deploy=true -DskipTests" 8 | } 9 | } 10 | -------------------------------------------------------------------------------- /helm/Chart.lock: -------------------------------------------------------------------------------- 1 | dependencies: 2 | - name: spring-boot-example-app 3 | repository: http://localhost:8080 4 | version: 0.0.4 5 | digest: sha256:e6423b099d4d1b426c5a1e7ee1ba3421e07a42cf80f8d9584ba9ce370b0a8204 6 | generated: "2022-02-08T13:56:40.411628683+01:00" 7 | -------------------------------------------------------------------------------- /src/main/resources/application-openshift.properties: -------------------------------------------------------------------------------- 1 | resteasy.jaxrs.defaultPath=/api 2 | management.endpoints.web.exposure.include=health,info 3 | 4 | dekorate.openshift.expose=true 5 | dekorate.s2i.builder-image=registry.access.redhat.com/ubi8/openjdk-11:1.14 6 | -------------------------------------------------------------------------------- /src/test/resources/logback-test.xml: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | -------------------------------------------------------------------------------- /run_tests_with_dekorate_in_k8s.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CONTAINER_REGISTRY=${1:-localhost:5000} 3 | K8S_NAMESPACE=${2:-k8s} 4 | MAVEN_OPTS=${3:-} 5 | 6 | source scripts/waitFor.sh 7 | 8 | kubectl config set-context --current --namespace=$K8S_NAMESPACE 9 | 10 | # deploy application and run tests 11 | ./mvnw -s .github/mvn-settings.xml clean verify -Pkubernetes,kubernetes-it -Ddekorate.docker.registry=$CONTAINER_REGISTRY -Dkubernetes.namespace=$K8S_NAMESPACE -Ddekorate.push=true $MAVEN_OPTS 12 | 13 | -------------------------------------------------------------------------------- /helm/Chart.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: v2 2 | name: spring-boot-example-rest-http 3 | version: 0.0.1-SNAPSHOT 4 | description: A Helm chart to build and deploy Spring Boot application with REST endpoints 5 | keywords: 6 | - runtimes 7 | - spring-boot 8 | icon: https://avatars.githubusercontent.com/u/558276?s=400&u=19efc68c74844b2e092698a8a7a752921edcdc19&v=4 9 | dependencies: 10 | - alias: app 11 | name: spring-boot-example-app 12 | version: 0.0.4 13 | repository: http://snowdrop.github.io/helm 14 | -------------------------------------------------------------------------------- /.editorconfig: -------------------------------------------------------------------------------- 1 | # Snowdrop editorconfig file 2 | # More info is available here : http://EditorConfig.org) 3 | 4 | # top-most EditorConfig file 5 | root = true 6 | 7 | # Unix-style newlines with a newline ending every file 8 | [*] 9 | end_of_line = lf 10 | insert_final_newline = true 11 | 12 | # Matches multiple files with brace expansion notation 13 | # Set default charset 14 | [*.{js,xml,yaml,yml,json}] 15 | charset = utf-8 16 | indent_style = space 17 | indent_size = 2 18 | 19 | # 4 space indentation 20 | [*.java] 21 | indent_style = space 22 | indent_size = 4 23 | continuation_indent_size = 8 -------------------------------------------------------------------------------- /run_tests_with_helm_in_ocp.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | SOURCE_REPOSITORY_URL=${1:-https://github.com/snowdrop/rest-http-example} 3 | SOURCE_REPOSITORY_REF=${2:-sb-2.7.x} 4 | 5 | source scripts/waitFor.sh 6 | 7 | helm install rest-http ./helm --set app.route.expose=true --set app.s2i.source.repo=$SOURCE_REPOSITORY_URL --set app.s2i.source.ref=$SOURCE_REPOSITORY_REF --set app.s2i.builderImage.repo=registry.access.redhat.com/ubi8/openjdk-11 --set app.s2i.builderImage.tag=1.14 8 | if [[ $(waitFor "rest-http" "app") -eq 1 ]] ; then 9 | echo "Application failed to deploy. Aborting" 10 | exit 1 11 | fi 12 | 13 | # Run Tests 14 | ./mvnw -s .github/mvn-settings.xml clean verify -Popenshift,openshift-it -Dunmanaged-test=true 15 | -------------------------------------------------------------------------------- /scripts/waitFor.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | waitFor() { 4 | NAME=$1 5 | POD_LABEL=$2 6 | READY_TIMEOUT=600s 7 | LOOP=2s 8 | RETRIES=300 9 | 10 | idx=0 11 | # Wait for pod to be created 12 | while ! [[ $(oc get pods -l $POD_LABEL=$NAME --ignore-not-found | wc -l) -ge 1 ]] ; 13 | do 14 | if [[ $idx -eq $RETRIES ]] ; then 15 | echo "$NAME pods failed to be created. Aborting..." 16 | return 1 17 | fi 18 | sleep $LOOP 19 | let "idx+=1" 20 | done 21 | # Wait for pod to be ready 22 | if [[ $(oc wait --for=condition=ready --timeout=$READY_TIMEOUT pod -l $POD_LABEL=$NAME | grep "condition met" | wc -l) -eq 0 ]] ; then 23 | echo "$NAME pods failed to be ready. Aborting..." 24 | return 1 25 | fi 26 | 27 | return 0 28 | } 29 | -------------------------------------------------------------------------------- /.github/mvn-settings.xml: -------------------------------------------------------------------------------- 1 | 4 | 5 | 6 | snapshots 7 | 8 | true 9 | 10 | 11 | 12 | ossrh-snapshots 13 | https://oss.sonatype.org/content/repositories/snapshots 14 | 15 | true 16 | 17 | 18 | 19 | 20 | 21 | 22 | -------------------------------------------------------------------------------- /run_tests_with_helm_in_k8s.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CONTAINER_REGISTRY=${1:-localhost:5000} 3 | K8S_NAMESPACE=${2:-helm} 4 | 5 | source scripts/waitFor.sh 6 | oc project $K8S_NAMESPACE 7 | 8 | # Build 9 | ./mvnw -s .github/mvn-settings.xml clean package 10 | 11 | # Create docker image and tag it in registry 12 | IMAGE=rest-http:latest 13 | docker build . -t $IMAGE 14 | docker tag $IMAGE $CONTAINER_REGISTRY/$IMAGE 15 | docker push $CONTAINER_REGISTRY/$IMAGE 16 | 17 | helm install rest-http ./helm --set app.docker.image=$CONTAINER_REGISTRY/$IMAGE -n $K8S_NAMESPACE 18 | if [[ $(waitFor "rest-http" "app") -eq 1 ]] ; then 19 | echo "Application failed to deploy. Aborting" 20 | exit 1 21 | fi 22 | 23 | # Run Tests 24 | ./mvnw -s .github/mvn-settings.xml clean verify -Pkubernetes-it -Dunmanaged-test=true -Dkubernetes.namespace=$K8S_NAMESPACE 25 | -------------------------------------------------------------------------------- /run_tests_with_generated_helm_in_k8s.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | CONTAINER_REGISTRY=${1:-localhost:5000} 3 | K8S_NAMESPACE=${2:-genhelm} 4 | MAVEN_OPTS=${3:-} 5 | 6 | source scripts/waitFor.sh 7 | oc project $K8S_NAMESPACE 8 | 9 | # Build 10 | ./mvnw -s .github/mvn-settings.xml clean package -Pkubernetes,helm -Ddekorate.helm.name=rest-http $MAVEN_OPTS 11 | 12 | # Create docker image and tag it in registry 13 | IMAGE=rest-http:latest 14 | docker build . -t $IMAGE 15 | docker tag $IMAGE $CONTAINER_REGISTRY/$IMAGE 16 | docker push $CONTAINER_REGISTRY/$IMAGE 17 | 18 | helm install rest-http ./target/classes/META-INF/dekorate/helm/rest-http --set app.image=$CONTAINER_REGISTRY/$IMAGE -n $K8S_NAMESPACE 19 | if [[ $(waitFor "rest-http" "app.kubernetes.io/name") -eq 1 ]] ; then 20 | echo "Application failed to deploy. Aborting" 21 | exit 1 22 | fi 23 | 24 | # Run Tests 25 | ./mvnw -s .github/mvn-settings.xml clean verify -Pkubernetes-it -Dunmanaged-test=true -Dkubernetes.namespace=$K8S_NAMESPACE $MAVEN_OPTS 26 | -------------------------------------------------------------------------------- /.github/workflows/push.yml: -------------------------------------------------------------------------------- 1 | name: "Push Images" 2 | on: 3 | workflow_dispatch: 4 | push: 5 | branches: 6 | - sb-2.7.x 7 | jobs: 8 | push: 9 | name: Push Images to Quay.io 10 | runs-on: ubuntu-latest 11 | strategy: 12 | matrix: 13 | java: [ 11 ] 14 | steps: 15 | - name: Checkout 16 | uses: actions/checkout@v2.3.4 17 | - name: Setup Java 18 | uses: actions/setup-java@v2.3.1 19 | with: 20 | java-version: ${{ matrix.java }} 21 | distribution: 'adopt' 22 | cache: 'maven' 23 | - name: Quay.io Login 24 | run: docker login quay.io -u="${{secrets.QUAY_USER}}" -p="${{secrets.QUAY_TOKEN}}" 25 | - name: Build 26 | run: ./mvnw -s .github/mvn-settings.xml clean package 27 | - name: Push Image to Quay.io 28 | run: | 29 | CONTAINER_REGISTRY=quay.io/snowdrop 30 | IMAGE=spring-boot-rest-http-example:2.7 31 | docker build . -t $IMAGE 32 | docker tag $IMAGE $CONTAINER_REGISTRY/$IMAGE 33 | docker push $CONTAINER_REGISTRY/$IMAGE 34 | -------------------------------------------------------------------------------- /src/main/java/dev/snowdrop/example/service/Greeting.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dev.snowdrop.example.service; 17 | 18 | // tag::snippet-greeting[] 19 | public class Greeting { 20 | 21 | public static final String FORMAT = "Hello, %s!"; 22 | 23 | private final String content; 24 | 25 | public Greeting() { 26 | this.content = null; 27 | } 28 | 29 | public Greeting(String content) { 30 | this.content = content; 31 | } 32 | 33 | public String getContent() { 34 | return content; 35 | } 36 | } 37 | // end::snippet-greeting[] 38 | -------------------------------------------------------------------------------- /src/main/java/dev/snowdrop/example/service/GreetingEndpoint.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dev.snowdrop.example.service; 17 | 18 | import javax.ws.rs.DefaultValue; 19 | import javax.ws.rs.GET; 20 | import javax.ws.rs.Path; 21 | import javax.ws.rs.Produces; 22 | import javax.ws.rs.QueryParam; 23 | 24 | import org.springframework.stereotype.Component; 25 | 26 | @Path("/greeting") 27 | @Component 28 | public class GreetingEndpoint { 29 | @GET 30 | @Produces("application/json") 31 | public Greeting greeting(@QueryParam("name") @DefaultValue("World") String name) { 32 | final String message = String.format(Greeting.FORMAT, name); 33 | return new Greeting(message); 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/ManagedOpenShiftIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.snowdrop.example; 18 | 19 | import java.net.URL; 20 | 21 | import org.junit.jupiter.api.condition.DisabledIfSystemProperty; 22 | 23 | import io.dekorate.testing.annotation.Inject; 24 | import io.dekorate.testing.openshift.annotation.OpenshiftIntegrationTest; 25 | 26 | @DisabledIfSystemProperty(named = "unmanaged-test", matches = "true") 27 | @OpenshiftIntegrationTest 28 | public class ManagedOpenShiftIT extends AbstractExampleApplicationTest { 29 | 30 | @Inject 31 | private URL appUrl; 32 | 33 | @Override 34 | public String baseURI() { 35 | return appUrl.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/dev/snowdrop/example/ExampleApplication.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | *

4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | *

8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | *

10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dev.snowdrop.example; 17 | 18 | import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; 19 | import org.springframework.boot.SpringApplication; 20 | import org.springframework.boot.autoconfigure.SpringBootApplication; 21 | import org.springframework.context.annotation.Bean; 22 | 23 | @SpringBootApplication 24 | public class ExampleApplication { 25 | 26 | public static void main(String[] args) { 27 | SpringApplication.run(ExampleApplication.class, args); 28 | } 29 | 30 | @Bean 31 | public JacksonJsonProvider jsonProvider() { 32 | return new JacksonJsonProvider(); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /run_tests_with_s2i.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | # Parameters allowed: 3 | # . --repository-url 4 | # . --branch-to-test 5 | # . --maven-settings 6 | # . --maven-mirror-url 7 | UNMANAGED_PARAMS="" 8 | SOURCE_REPOSITORY_URL="https://github.com/snowdrop/rest-http-example" 9 | SOURCE_REPOSITORY_REF="sb-2.7.x" 10 | MAVEN_SETTINGS_REF="" 11 | MAVEN_MIRROR_URL="" 12 | 13 | while [ $# -gt 0 ]; do 14 | if [[ $1 == *"--"* ]]; then 15 | param="${1/--/}" 16 | case $1 in 17 | --repository-url) SOURCE_REPOSITORY_URL="$2";; 18 | --branch-to-test) SOURCE_REPOSITORY_REF="$2";; 19 | --maven-settings) MAVEN_SETTINGS_REF="-s $2";; 20 | --maven-mirror-url) MAVEN_MIRROR_URL="$2";; 21 | esac; 22 | shift 23 | elif [[ $1 == "-D"* ]]; 24 | then 25 | UNMANAGED_PARAMS="${UNMANAGED_PARAMS} $1"; 26 | fi 27 | shift 28 | done 29 | 30 | source scripts/waitFor.sh 31 | 32 | oc create -f .openshiftio/application.yaml 33 | oc new-app --template=rest-http -p SOURCE_REPOSITORY_URL=$SOURCE_REPOSITORY_URL -p SOURCE_REPOSITORY_REF=$SOURCE_REPOSITORY_REF \ 34 | -p MAVEN_MIRROR_URL=$MAVEN_MIRROR_URL -p MAVEN_ARGS_APPEND="$UNMANAGED_PARAMS" 35 | if [[ $(waitFor "rest-http" "app") -eq 1 ]] ; then 36 | echo "Application failed to deploy. Aborting" 37 | exit 1 38 | fi 39 | 40 | # Run Tests 41 | eval "./mvnw ${MAVEN_SETTINGS_REF} clean verify -Popenshift,openshift-it -Dunmanaged-test=true ${UNMANAGED_PARAMS}" 42 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/LocalTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dev.snowdrop.example; 17 | 18 | import org.junit.jupiter.api.extension.ExtendWith; 19 | import org.springframework.beans.factory.annotation.Value; 20 | import org.springframework.boot.test.context.SpringBootTest; 21 | import org.springframework.test.context.junit.jupiter.SpringExtension; 22 | 23 | @ExtendWith(SpringExtension.class) 24 | @SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT) 25 | public class LocalTest extends AbstractExampleApplicationTest { 26 | 27 | @Value("${local.server.port}") 28 | private int port; 29 | 30 | @Override 31 | public String baseURI() { 32 | return String.format("http://localhost:%d", port); 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/UnmanagedOpenShiftIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.snowdrop.example; 18 | 19 | import java.net.URL; 20 | 21 | import org.junit.jupiter.api.condition.EnabledIfSystemProperty; 22 | 23 | import io.dekorate.testing.annotation.Inject; 24 | import io.dekorate.testing.openshift.annotation.OpenshiftIntegrationTest; 25 | 26 | @EnabledIfSystemProperty(named = "unmanaged-test", matches = "true") 27 | @OpenshiftIntegrationTest(deployEnabled = false, buildEnabled = false, pushEnabled = false) 28 | public class UnmanagedOpenShiftIT extends AbstractExampleApplicationTest { 29 | 30 | @Inject 31 | private URL appUrl; 32 | 33 | @Override 34 | public String baseURI() { 35 | return appUrl.toString(); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /.openshiftio/index.html.flt: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | API Level 0 Mission - Spring Boot 5 | 7 | 8 | 9 | 10 |

11 |
12 | ${html} 13 | 14 |
15 |
16 | 17 | 18 |
19 | 20 |
21 | 22 |

Result:

23 |
Invoke the service to see the result.
24 |
25 |
26 | 27 | 28 | 31 | 32 | 43 | 44 | 45 | 46 | 47 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/AbstractExampleApplicationTest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | package dev.snowdrop.example; 17 | 18 | import static io.restassured.RestAssured.given; 19 | import static org.hamcrest.core.Is.is; 20 | 21 | import org.junit.jupiter.api.Test; 22 | 23 | import dev.snowdrop.example.service.Greeting; 24 | 25 | public abstract class AbstractExampleApplicationTest { 26 | 27 | private static final String GREETING_PATH = "api/greeting"; 28 | 29 | @Test 30 | public void testGreetingEndpoint() { 31 | given() 32 | .baseUri(baseURI()) 33 | .get(GREETING_PATH) 34 | .then() 35 | .statusCode(200) 36 | .body("content", is(String.format(Greeting.FORMAT, "World"))); 37 | } 38 | 39 | @Test 40 | public void testGreetingEndpointWithNameParameter() { 41 | given() 42 | .baseUri(baseURI()) 43 | .param("name", "John") 44 | .when() 45 | .get(GREETING_PATH) 46 | .then() 47 | .statusCode(200) 48 | .body("content", is(String.format(Greeting.FORMAT, "John"))); 49 | } 50 | 51 | protected abstract String baseURI(); 52 | } 53 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/ManagedKubernetesIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2017 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.snowdrop.example; 18 | 19 | import java.io.IOException; 20 | 21 | import org.junit.jupiter.api.AfterEach; 22 | import org.junit.jupiter.api.BeforeEach; 23 | import org.junit.jupiter.api.condition.DisabledIfSystemProperty; 24 | 25 | import io.dekorate.testing.annotation.Inject; 26 | import io.dekorate.testing.annotation.KubernetesIntegrationTest; 27 | import io.fabric8.kubernetes.client.KubernetesClient; 28 | import io.fabric8.kubernetes.client.LocalPortForward; 29 | 30 | @DisabledIfSystemProperty(named = "unmanaged-test", matches = "true") 31 | @KubernetesIntegrationTest 32 | public class ManagedKubernetesIT extends AbstractExampleApplicationTest { 33 | 34 | @Inject 35 | KubernetesClient client; 36 | 37 | LocalPortForward appPort; 38 | 39 | @BeforeEach 40 | public void setup() { 41 | appPort = client.services().inNamespace(System.getProperty("kubernetes.namespace")) 42 | .withName("rest-http").portForward(8080); 43 | } 44 | 45 | @AfterEach 46 | public void tearDown() throws IOException { 47 | if (appPort != null) { 48 | appPort.close(); 49 | } 50 | } 51 | 52 | @Override 53 | public String baseURI() { 54 | return "http://localhost:" + appPort.getLocalPort() + "/"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/dev/snowdrop/example/UnmanagedKubernetesIT.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2016-2021 Red Hat, Inc, and individual contributors. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package dev.snowdrop.example; 18 | 19 | import java.io.IOException; 20 | 21 | import org.junit.jupiter.api.AfterEach; 22 | import org.junit.jupiter.api.BeforeEach; 23 | import org.junit.jupiter.api.condition.EnabledIfSystemProperty; 24 | 25 | import io.dekorate.testing.annotation.Inject; 26 | import io.dekorate.testing.annotation.KubernetesIntegrationTest; 27 | import io.fabric8.kubernetes.client.KubernetesClient; 28 | import io.fabric8.kubernetes.client.LocalPortForward; 29 | 30 | @EnabledIfSystemProperty(named = "unmanaged-test", matches = "true") 31 | @KubernetesIntegrationTest(deployEnabled = false, buildEnabled = false) 32 | public class UnmanagedKubernetesIT extends AbstractExampleApplicationTest { 33 | 34 | @Inject 35 | KubernetesClient client; 36 | 37 | LocalPortForward appPort; 38 | 39 | @BeforeEach 40 | public void setup() { 41 | appPort = client.services().inNamespace(System.getProperty("kubernetes.namespace")) 42 | .withName("rest-http").portForward(8080); 43 | } 44 | 45 | @AfterEach 46 | public void tearDown() throws IOException { 47 | if (appPort != null) { 48 | appPort.close(); 49 | } 50 | } 51 | 52 | @Override 53 | public String baseURI() { 54 | return "http://localhost:" + appPort.getLocalPort() + "/"; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/main/resources/static/index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | API Level 0 Mission - Spring Boot 5 | 7 | 8 | 9 | 10 |
11 |
12 |
13 |

HTTP Example

14 |
15 |
16 |

An example of simple mapping of a business operation to a remote endpoint. By taking this approach, clients use the HTTP protocol as a transport mechanism to call services. Application engineers define the APIs using a broad interpretation of the REST fundamentals, encouraging freedom in design and quick prototyping.

17 |
18 |
19 |

Using the greeting service

20 | 21 |
22 |
23 |
24 | 25 |
26 |
27 | 28 | 29 |
30 | 31 |
32 | 33 |

Result:

34 |
Invoke the service to see the result.
35 |
36 |
37 | 38 | 39 | 42 | 43 | 54 | 55 | 56 | 57 | 58 | -------------------------------------------------------------------------------- /.github/workflows/pr.yml: -------------------------------------------------------------------------------- 1 | name: "Pull Request Build" 2 | on: 3 | workflow_dispatch: 4 | pull_request: 5 | jobs: 6 | linux-build-local: 7 | name: PR - Linux - JVM ${{ matrix.java }} - Local 8 | runs-on: ubuntu-latest 9 | strategy: 10 | matrix: 11 | java: [ 11 ] 12 | steps: 13 | - name: Checkout 14 | uses: actions/checkout@v2.3.4 15 | - name: Setup Java 16 | uses: actions/setup-java@v2.3.1 17 | with: 18 | java-version: ${{ matrix.java }} 19 | distribution: 'adopt' 20 | cache: 'maven' 21 | - name: Build 22 | run: ./mvnw -s .github/mvn-settings.xml clean verify 23 | linux-build-ocp: 24 | name: PR - Linux - JVM ${{ matrix.java }} - OpenShift ${{ matrix.openshift }} 25 | needs: linux-build-local 26 | # the action "manusa/actions-setup-openshift@v1.1.4" only works in ubuntu-20.04 27 | runs-on: ubuntu-20.04 28 | strategy: 29 | matrix: 30 | java: [ 11 ] 31 | openshift: [ v3.11.0 ] 32 | steps: 33 | - name: Checkout 34 | uses: actions/checkout@v2.3.4 35 | - name: Setup Java 36 | uses: actions/setup-java@v2.3.1 37 | with: 38 | java-version: ${{ matrix.java }} 39 | distribution: 'adopt' 40 | cache: 'maven' 41 | - name: Setup OpenShift 42 | uses: manusa/actions-setup-openshift@v1.1.5 43 | with: 44 | oc version: ${{ matrix.openshift }} 45 | dns ip: 1.1.1.1 46 | github token: ${{ secrets.GITHUB_TOKEN }} 47 | - name: Build Project using Dekorate 48 | run: | 49 | oc new-project dekorate 50 | ./run_tests_with_dekorate_in_ocp.sh -s .github/mvn-settings.xml 51 | - name: Delete Project using Dekorate 52 | run: oc delete project dekorate 53 | - name: Clean folder 54 | run: ./mvnw -s .github/mvn-settings.xml clean 55 | - name: Build Project using S2i 56 | run: | 57 | oc new-project s2i 58 | ./run_tests_with_s2i.sh --repository-url "${{ github.event.pull_request.head.repo.owner.html_url }}/${{ github.event.pull_request.head.repo.name }}" --branch-to-test ${{ github.head_ref }} --maven-settings ".github/mvn-settings.xml" 59 | - name: Delete Project using S2i 60 | run: oc delete project s2i 61 | - name: Build Project using Helm 62 | run: | 63 | oc new-project helm 64 | ./run_tests_with_helm_in_ocp.sh "${{ github.event.pull_request.head.repo.owner.html_url }}/${{ github.event.pull_request.head.repo.name }}" ${{ github.head_ref }} 65 | - name: Delete Project using Helm 66 | run: oc delete project helm 67 | linux-build-kubernetes: 68 | name: PR - Linux - JVM ${{ matrix.java }} - Kubernetes 69 | needs: linux-build-local 70 | runs-on: ubuntu-latest 71 | strategy: 72 | matrix: 73 | java: [ 11 ] 74 | steps: 75 | - name: Checkout 76 | uses: actions/checkout@v2.3.4 77 | - name: Setup Java 78 | uses: actions/setup-java@v2.3.1 79 | with: 80 | java-version: ${{ matrix.java }} 81 | distribution: 'adopt' 82 | cache: 'maven' 83 | - name: Kubernetes KinD Cluster 84 | uses: container-tools/kind-action@v1 85 | with: 86 | version: v0.11.1 87 | registry: true 88 | - name: Build Project using Helm 89 | run: | 90 | kubectl create namespace helm 91 | ./run_tests_with_helm_in_k8s.sh $KIND_REGISTRY helm 92 | - name: Delete Project using Helm 93 | run: kubectl delete namespace helm 94 | - name: Build Project using Dekorate 95 | run: | 96 | kubectl create namespace k8s 97 | ./run_tests_with_dekorate_in_k8s.sh $KIND_REGISTRY k8s 98 | - name: Delete Project using K8s 99 | run: kubectl delete namespace k8s 100 | - name: Build Project using the generated Helm by Dekorate 101 | run: | 102 | kubectl create namespace genhelm 103 | ./run_tests_with_generated_helm_in_k8s.sh $KIND_REGISTRY genhelm 104 | - name: Delete Project using the generated Helm by Dekorate 105 | run: kubectl delete namespace genhelm 106 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # REST HTTP Spring Boot Example 2 | 3 | https://appdev.openshift.io/docs/spring-boot-runtime.html#mission-http-api-spring-boot 4 | 5 | ## Table of Contents 6 | 7 | * [REST HTTP Spring Boot Example](#rest-http-spring-boot-example) 8 | * [Prerequisites](#prerequisites) 9 | * [Deploying application on OpenShift using Dekorate](#deploying-application-on-openshift-using-dekorate) 10 | * [Deploying application on OpenShift using Helm](#deploying-application-on-openshift-using-helm) 11 | * [Deploying application on Kubernetes using Helm](#deploying-application-on-kubernetes-using-helm) 12 | * [Running Tests on OpenShift using Dekorate](#running-tests-on-openshift-using-dekorate) 13 | * [Running Tests on OpenShift using S2i from Source](#running-tests-on-openshift-using-s2i-from-source) 14 | * [Running Tests on OpenShift using Helm](#running-tests-on-openshift-using-helm) 15 | * [Running Tests on Kubernetes with External Registry](#running-tests-on-kubernetes-with-external-registry) 16 | * [Running Tests on Kubernetes with Helm](#running-tests-on-kubernetes-using-helm) 17 | 18 | ## Prerequisites 19 | 20 | - JDK 11+ installed with JAVA_HOME configured appropriately 21 | 22 | ## Deploying application on OpenShift using Dekorate 23 | 24 | ``` 25 | mvn clean verify -Popenshift -Ddekorate.deploy=true 26 | ``` 27 | 28 | ## Deploying application on OpenShift using Helm 29 | 30 | First, make sure you have installed [the Helm command line](https://helm.sh/docs/intro/install/) and connected/logged to a kubernetes cluster. 31 | 32 | Then, you need to install the example by doing: 33 | 34 | ``` 35 | helm install rest-http ./helm --set app.route.expose=true --set app.s2i.source.repo=https://github.com/snowdrop/rest-http-example --set app.s2i.source.ref= 36 | ``` 37 | 38 | **note**: Replace `` with one branch from `https://github.com/snowdrop/rest-http-example/branches/all`. 39 | 40 | And to uninstall the chart, execute: 41 | 42 | ``` 43 | helm uninstall rest-http 44 | ``` 45 | 46 | ## Deploying application on Kubernetes using Helm 47 | 48 | Requirements: 49 | - Have installed [the Helm command line](https://helm.sh/docs/intro/install/) 50 | - Have connected/logged to a kubernetes cluster 51 | 52 | You need to install the example by doing: 53 | 54 | ``` 55 | helm install rest-http ./helm --set app.ingress.host= 56 | ``` 57 | 58 | And to uninstall the chart, execute: 59 | 60 | ``` 61 | helm uninstall rest-http 62 | ``` 63 | 64 | ## Running Tests on OpenShift using Dekorate 65 | 66 | ``` 67 | ./run_tests_with_dekorate_in_ocp.sh 68 | ``` 69 | 70 | Alternativelly, tests can be executed against a specific Spring Boot or Dekorate version by passing the 71 | version as a `-D=value` parameter. For instance overriding both the Spring Boot and the Dekorate versions using their corresponding version properties is done the following way: 72 | 73 | ```bash 74 | ./run_tests_with_dekorate_in_ocp.sh -Dspring-boot.version=2.7.3 -Ddekorate.version=2.11.1 75 | ``` 76 | 77 | ## Running Tests on OpenShift using S2i from Source 78 | 79 | ``` 80 | ./run_tests_with_s2i.sh 81 | ``` 82 | 83 | This script can take up to 3 parameters which are: 84 | 85 | * `--repository-url`: repository to use to source the images from 86 | * `--branch-to-test`: branch to use to source the images from 87 | * `--maven-settings`: custom maven settings file 88 | 89 | ```bash 90 | ./run_tests_with_s2i.sh --repository-url "https://github.com/snowdrop/rest-http-example" --branch-to-test branch-to-test --maven-settings "${HOME}/.m2/my-custom-maven-settings.xml" 91 | ``` 92 | 93 | ## Running Tests on OpenShift using Helm 94 | 95 | ``` 96 | ./run_tests_with_helm_in_ocp.sh 97 | ``` 98 | 99 | This script can take 2 parameters referring to the repository and the branch to use to source the images from. 100 | 101 | ```bash 102 | ./run_tests_with_helm_in_ocp.sh "https://github.com/snowdrop/rest-http-example" branch-to-test 103 | ``` 104 | 105 | ## Running Tests on Kubernetes with External Registry 106 | 107 | ``` 108 | mvn clean verify -Pkubernetes,kubernetes-it -Ddekorate.docker.registry= -Ddekorate.push=true 109 | ``` 110 | 111 | ## Running Tests on Kubernetes using Helm 112 | 113 | First, you need to create the k8s namespace: 114 | 115 | ``` 116 | kubectl create namespace 117 | ``` 118 | 119 | Then, run the tests by specifying the container registry and the kubernetes namespace: 120 | ``` 121 | ./run_tests_with_helm_in_k8s.sh 122 | ``` 123 | 124 | For example: 125 | 126 | ``` 127 | ./run_tests_with_helm_in_k8s.sh "quay.io/user" "myNamespace" 128 | ``` 129 | -------------------------------------------------------------------------------- /.mvn/wrapper/MavenWrapperDownloader.java: -------------------------------------------------------------------------------- 1 | /* 2 | Licensed to the Apache Software Foundation (ASF) under one 3 | or more contributor license agreements. See the NOTICE file 4 | distributed with this work for additional information 5 | regarding copyright ownership. The ASF licenses this file 6 | to you under the Apache License, Version 2.0 (the 7 | "License"); you may not use this file except in compliance 8 | with the License. You may obtain a copy of the License at 9 | 10 | http://www.apache.org/licenses/LICENSE-2.0 11 | 12 | Unless required by applicable law or agreed to in writing, 13 | software distributed under the License is distributed on an 14 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | KIND, either express or implied. See the License for the 16 | specific language governing permissions and limitations 17 | under the License. 18 | */ 19 | 20 | import java.net.*; 21 | import java.io.*; 22 | import java.nio.channels.*; 23 | import java.util.Properties; 24 | 25 | public class MavenWrapperDownloader { 26 | 27 | /** 28 | * Default URL to download the maven-wrapper.jar from, if no 'downloadUrl' is provided. 29 | */ 30 | private static final String DEFAULT_DOWNLOAD_URL = 31 | "https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar"; 32 | 33 | /** 34 | * Path to the maven-wrapper.properties file, which might contain a downloadUrl property to 35 | * use instead of the default one. 36 | */ 37 | private static final String MAVEN_WRAPPER_PROPERTIES_PATH = 38 | ".mvn/wrapper/maven-wrapper.properties"; 39 | 40 | /** 41 | * Path where the maven-wrapper.jar will be saved to. 42 | */ 43 | private static final String MAVEN_WRAPPER_JAR_PATH = 44 | ".mvn/wrapper/maven-wrapper.jar"; 45 | 46 | /** 47 | * Name of the property which should be used to override the default download url for the wrapper. 48 | */ 49 | private static final String PROPERTY_NAME_WRAPPER_URL = "wrapperUrl"; 50 | 51 | public static void main(String args[]) { 52 | System.out.println("- Downloader started"); 53 | File baseDirectory = new File(args[0]); 54 | System.out.println("- Using base directory: " + baseDirectory.getAbsolutePath()); 55 | 56 | // If the maven-wrapper.properties exists, read it and check if it contains a custom 57 | // wrapperUrl parameter. 58 | File mavenWrapperPropertyFile = new File(baseDirectory, MAVEN_WRAPPER_PROPERTIES_PATH); 59 | String url = DEFAULT_DOWNLOAD_URL; 60 | if(mavenWrapperPropertyFile.exists()) { 61 | FileInputStream mavenWrapperPropertyFileInputStream = null; 62 | try { 63 | mavenWrapperPropertyFileInputStream = new FileInputStream(mavenWrapperPropertyFile); 64 | Properties mavenWrapperProperties = new Properties(); 65 | mavenWrapperProperties.load(mavenWrapperPropertyFileInputStream); 66 | url = mavenWrapperProperties.getProperty(PROPERTY_NAME_WRAPPER_URL, url); 67 | } catch (IOException e) { 68 | System.out.println("- ERROR loading '" + MAVEN_WRAPPER_PROPERTIES_PATH + "'"); 69 | } finally { 70 | try { 71 | if(mavenWrapperPropertyFileInputStream != null) { 72 | mavenWrapperPropertyFileInputStream.close(); 73 | } 74 | } catch (IOException e) { 75 | // Ignore ... 76 | } 77 | } 78 | } 79 | System.out.println("- Downloading from: : " + url); 80 | 81 | File outputFile = new File(baseDirectory.getAbsolutePath(), MAVEN_WRAPPER_JAR_PATH); 82 | if(!outputFile.getParentFile().exists()) { 83 | if(!outputFile.getParentFile().mkdirs()) { 84 | System.out.println( 85 | "- ERROR creating output direcrory '" + outputFile.getParentFile().getAbsolutePath() + "'"); 86 | } 87 | } 88 | System.out.println("- Downloading to: " + outputFile.getAbsolutePath()); 89 | try { 90 | downloadFileFromURL(url, outputFile); 91 | System.out.println("Done"); 92 | System.exit(0); 93 | } catch (Throwable e) { 94 | System.out.println("- Error downloading"); 95 | e.printStackTrace(); 96 | System.exit(1); 97 | } 98 | } 99 | 100 | private static void downloadFileFromURL(String urlString, File destination) throws Exception { 101 | URL website = new URL(urlString); 102 | ReadableByteChannel rbc; 103 | rbc = Channels.newChannel(website.openStream()); 104 | FileOutputStream fos = new FileOutputStream(destination); 105 | fos.getChannel().transferFrom(rbc, 0, Long.MAX_VALUE); 106 | fos.close(); 107 | rbc.close(); 108 | } 109 | 110 | } 111 | -------------------------------------------------------------------------------- /.openshiftio/licenses.xsl: -------------------------------------------------------------------------------- 1 | 2 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 33 | 34 | 35 |

36 |

The following material has been provided for informational purposes only, and should not be relied upon or construed as a legal opinion or legal advice.

37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 48 | 49 | 50 | 51 | 52 | 57 | 76 | 77 | 78 |
Package GroupPackage ArtifactPackage VersionRemote LicensesLocal Licenses
53 | 54 |
55 |
56 |
58 | 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 |
74 |
75 |
79 | 80 | 81 |
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 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 |
137 | -------------------------------------------------------------------------------- /mvnw.cmd: -------------------------------------------------------------------------------- 1 | @REM ---------------------------------------------------------------------------- 2 | @REM Licensed to the Apache Software Foundation (ASF) under one 3 | @REM or more contributor license agreements. See the NOTICE file 4 | @REM distributed with this work for additional information 5 | @REM regarding copyright ownership. The ASF licenses this file 6 | @REM to you under the Apache License, Version 2.0 (the 7 | @REM "License"); you may not use this file except in compliance 8 | @REM with the License. You may obtain a copy of the License at 9 | @REM 10 | @REM http://www.apache.org/licenses/LICENSE-2.0 11 | @REM 12 | @REM Unless required by applicable law or agreed to in writing, 13 | @REM software distributed under the License is distributed on an 14 | @REM "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 15 | @REM KIND, either express or implied. See the License for the 16 | @REM specific language governing permissions and limitations 17 | @REM under the License. 18 | @REM ---------------------------------------------------------------------------- 19 | 20 | @REM ---------------------------------------------------------------------------- 21 | @REM Maven2 Start Up Batch script 22 | @REM 23 | @REM Required ENV vars: 24 | @REM JAVA_HOME - location of a JDK home dir 25 | @REM 26 | @REM Optional ENV vars 27 | @REM M2_HOME - location of maven2's installed home dir 28 | @REM MAVEN_BATCH_ECHO - set to 'on' to enable the echoing of the batch commands 29 | @REM MAVEN_BATCH_PAUSE - set to 'on' to wait for a key stroke before ending 30 | @REM MAVEN_OPTS - parameters passed to the Java VM when running Maven 31 | @REM e.g. to debug Maven itself, use 32 | @REM set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 33 | @REM MAVEN_SKIP_RC - flag to disable loading of mavenrc files 34 | @REM ---------------------------------------------------------------------------- 35 | 36 | @REM Begin all REM lines with '@' in case MAVEN_BATCH_ECHO is 'on' 37 | @echo off 38 | @REM set title of command window 39 | title %0 40 | @REM enable echoing my setting MAVEN_BATCH_ECHO to 'on' 41 | @if "%MAVEN_BATCH_ECHO%" == "on" echo %MAVEN_BATCH_ECHO% 42 | 43 | @REM set %HOME% to equivalent of $HOME 44 | if "%HOME%" == "" (set "HOME=%HOMEDRIVE%%HOMEPATH%") 45 | 46 | @REM Execute a user defined script before this one 47 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPre 48 | @REM check for pre script, once with legacy .bat ending and once with .cmd ending 49 | if exist "%HOME%\mavenrc_pre.bat" call "%HOME%\mavenrc_pre.bat" 50 | if exist "%HOME%\mavenrc_pre.cmd" call "%HOME%\mavenrc_pre.cmd" 51 | :skipRcPre 52 | 53 | @setlocal 54 | 55 | set ERROR_CODE=0 56 | 57 | @REM To isolate internal variables from possible post scripts, we use another setlocal 58 | @setlocal 59 | 60 | @REM ==== START VALIDATION ==== 61 | if not "%JAVA_HOME%" == "" goto OkJHome 62 | 63 | echo. 64 | echo Error: JAVA_HOME not found in your environment. >&2 65 | echo Please set the JAVA_HOME variable in your environment to match the >&2 66 | echo location of your Java installation. >&2 67 | echo. 68 | goto error 69 | 70 | :OkJHome 71 | if exist "%JAVA_HOME%\bin\java.exe" goto init 72 | 73 | echo. 74 | echo Error: JAVA_HOME is set to an invalid directory. >&2 75 | echo JAVA_HOME = "%JAVA_HOME%" >&2 76 | echo Please set the JAVA_HOME variable in your environment to match the >&2 77 | echo location of your Java installation. >&2 78 | echo. 79 | goto error 80 | 81 | @REM ==== END VALIDATION ==== 82 | 83 | :init 84 | 85 | @REM Find the project base dir, i.e. the directory that contains the folder ".mvn". 86 | @REM Fallback to current working directory if not found. 87 | 88 | set MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR% 89 | IF NOT "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir 90 | 91 | set EXEC_DIR=%CD% 92 | set WDIR=%EXEC_DIR% 93 | :findBaseDir 94 | IF EXIST "%WDIR%"\.mvn goto baseDirFound 95 | cd .. 96 | IF "%WDIR%"=="%CD%" goto baseDirNotFound 97 | set WDIR=%CD% 98 | goto findBaseDir 99 | 100 | :baseDirFound 101 | set MAVEN_PROJECTBASEDIR=%WDIR% 102 | cd "%EXEC_DIR%" 103 | goto endDetectBaseDir 104 | 105 | :baseDirNotFound 106 | set MAVEN_PROJECTBASEDIR=%EXEC_DIR% 107 | cd "%EXEC_DIR%" 108 | 109 | :endDetectBaseDir 110 | 111 | IF NOT EXIST "%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config" goto endReadAdditionalConfig 112 | 113 | @setlocal EnableExtensions EnableDelayedExpansion 114 | for /F "usebackq delims=" %%a in ("%MAVEN_PROJECTBASEDIR%\.mvn\jvm.config") do set JVM_CONFIG_MAVEN_PROPS=!JVM_CONFIG_MAVEN_PROPS! %%a 115 | @endlocal & set JVM_CONFIG_MAVEN_PROPS=%JVM_CONFIG_MAVEN_PROPS% 116 | 117 | :endReadAdditionalConfig 118 | 119 | SET MAVEN_JAVA_EXE="%JAVA_HOME%\bin\java.exe" 120 | set WRAPPER_JAR="%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.jar" 121 | set WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 122 | 123 | set DOWNLOAD_URL="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" 124 | FOR /F "tokens=1,2 delims==" %%A IN (%MAVEN_PROJECTBASEDIR%\.mvn\wrapper\maven-wrapper.properties) DO ( 125 | IF "%%A"=="wrapperUrl" SET DOWNLOAD_URL=%%B 126 | ) 127 | 128 | @REM Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 129 | @REM This allows using the maven wrapper in projects that prohibit checking in binary data. 130 | if exist %WRAPPER_JAR% ( 131 | echo Found %WRAPPER_JAR% 132 | ) else ( 133 | echo Couldn't find %WRAPPER_JAR%, downloading it ... 134 | echo Downloading from: %DOWNLOAD_URL% 135 | powershell -Command "(New-Object Net.WebClient).DownloadFile('%DOWNLOAD_URL%', '%WRAPPER_JAR%')" 136 | echo Finished downloading %WRAPPER_JAR% 137 | ) 138 | @REM End of extension 139 | 140 | %MAVEN_JAVA_EXE% %JVM_CONFIG_MAVEN_PROPS% %MAVEN_OPTS% %MAVEN_DEBUG_OPTS% -classpath %WRAPPER_JAR% "-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" %WRAPPER_LAUNCHER% %MAVEN_CONFIG% %* 141 | if ERRORLEVEL 1 goto error 142 | goto end 143 | 144 | :error 145 | set ERROR_CODE=1 146 | 147 | :end 148 | @endlocal & set ERROR_CODE=%ERROR_CODE% 149 | 150 | if not "%MAVEN_SKIP_RC%" == "" goto skipRcPost 151 | @REM check for post script, once with legacy .bat ending and once with .cmd ending 152 | if exist "%HOME%\mavenrc_post.bat" call "%HOME%\mavenrc_post.bat" 153 | if exist "%HOME%\mavenrc_post.cmd" call "%HOME%\mavenrc_post.cmd" 154 | :skipRcPost 155 | 156 | @REM pause the script if MAVEN_BATCH_PAUSE is set to 'on' 157 | if "%MAVEN_BATCH_PAUSE%" == "on" pause 158 | 159 | if "%MAVEN_TERMINATE_CMD%" == "on" exit %ERROR_CODE% 160 | 161 | exit /B %ERROR_CODE% 162 | -------------------------------------------------------------------------------- /.openshiftio/licenses-fix.xsl: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 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 | 80 | 81 | 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 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | -------------------------------------------------------------------------------- /.openshiftio/application.yaml: -------------------------------------------------------------------------------- 1 | apiVersion: template.openshift.io/v1 2 | kind: Template 3 | metadata: 4 | name: rest-http 5 | labels: 6 | app.kubernetes.io/part-of: http-api-example 7 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 8 | app.openshift.io/runtime: rh-spring-boot 9 | app.kubernetes.io/name: http-api 10 | app.kubernetes.io/component: frontend 11 | annotations: 12 | iconClass: icon-spring 13 | tags: spring-boot, rest, java, microservice 14 | openshift.io/display-name: Spring Boot - REST Http Endpoint 15 | openshift.io/provider-display-name: "Red Hat, Inc." 16 | openshift.io/documentation-url: "https://appdev.prod-preview.openshift.io/docs/spring-boot-runtime.html#mission-http-api-spring-boot-tomcat" 17 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 18 | description: >- 19 | The REST API Level 0 Mission provides a basic example of mapping business operations to a remote procedure call endpoint over HTTP using a REST framework. 20 | parameters: 21 | - name: RUNTIME_VERSION 22 | displayName: OpenJDK 11 image version to use 23 | description: Specifies which version of the OpenShift OpenJDK 11 image to use 24 | value: "1.14" 25 | required: true 26 | - name: SOURCE_REPOSITORY_URL 27 | description: The source URL for the application 28 | displayName: Source URL 29 | required: true 30 | - name: SOURCE_REPOSITORY_REF 31 | description: The branch name for the application 32 | displayName: Source Branch 33 | value: master 34 | required: true 35 | - name: SOURCE_REPOSITORY_DIR 36 | description: The location within the source repo of the application 37 | displayName: Source Directory 38 | value: . 39 | required: true 40 | - name: ARTIFACT_COPY_ARGS 41 | description: Syntax to be used to copy uberjar files to the target directory 42 | displayName: Copy Args 43 | value: '*.jar' 44 | required: true 45 | - name: GITHUB_WEBHOOK_SECRET 46 | description: A secret string used to configure the GitHub webhook. 47 | displayName: GitHub Webhook Secret 48 | required: true 49 | from: '[a-zA-Z0-9]{40}' 50 | generate: expression 51 | - name: MAVEN_MIRROR_URL 52 | description: Maven Nexus Repository to be used during build phase 53 | displayName: 54 | required: false 55 | - name: MAVEN_ARGS_APPEND 56 | description: Extra arguments passed to mvn. 57 | displayName: 58 | required: false 59 | objects: 60 | - apiVersion: v1 61 | kind: ImageStream 62 | metadata: 63 | name: rest-http 64 | spec: {} 65 | - apiVersion: v1 66 | kind: ImageStream 67 | metadata: 68 | name: runtime 69 | spec: 70 | tags: 71 | - name: "${RUNTIME_VERSION}" 72 | from: 73 | kind: DockerImage 74 | name: registry.access.redhat.com/ubi8/openjdk-11:${RUNTIME_VERSION} 75 | - apiVersion: v1 76 | kind: BuildConfig 77 | metadata: 78 | name: rest-http 79 | labels: 80 | app.kubernetes.io/part-of: http-api-example 81 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 82 | app.openshift.io/runtime: rh-spring-boot 83 | app.kubernetes.io/name: http-api 84 | app.kubernetes.io/component: frontend 85 | annotations: 86 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 87 | spec: 88 | output: 89 | to: 90 | kind: ImageStreamTag 91 | name: rest-http:BOOSTER_VERSION 92 | postCommit: {} 93 | resources: {} 94 | source: 95 | git: 96 | uri: ${SOURCE_REPOSITORY_URL} 97 | ref: ${SOURCE_REPOSITORY_REF} 98 | type: Git 99 | strategy: 100 | sourceStrategy: 101 | from: 102 | kind: ImageStreamTag 103 | name: runtime:${RUNTIME_VERSION} 104 | incremental: true 105 | env: 106 | - name: MAVEN_ARGS_APPEND 107 | value: "-pl ${SOURCE_REPOSITORY_DIR}" 108 | - name: ARTIFACT_DIR 109 | value: "${SOURCE_REPOSITORY_DIR}/target" 110 | - name: MAVEN_MIRROR_URL 111 | value: "${MAVEN_MIRROR_URL}" 112 | - name: ARTIFACT_COPY_ARGS 113 | value: "${ARTIFACT_COPY_ARGS}" 114 | - name: MAVEN_ARGS_APPEND 115 | value: "${MAVEN_ARGS_APPEND}" 116 | type: Source 117 | triggers: 118 | - github: 119 | secret: ${GITHUB_WEBHOOK_SECRET} 120 | type: GitHub 121 | - type: ConfigChange 122 | - imageChange: {} 123 | type: ImageChange 124 | status: 125 | lastVersion: 0 126 | - apiVersion: v1 127 | kind: Service 128 | metadata: 129 | labels: 130 | app: rest-http 131 | provider: snowdrop 132 | version: "BOOSTER_VERSION" 133 | group: dev.snowdrop.example 134 | app.kubernetes.io/part-of: http-api-example 135 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 136 | app.openshift.io/runtime: rh-spring-boot 137 | app.kubernetes.io/name: http-api 138 | app.kubernetes.io/component: frontend 139 | annotations: 140 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 141 | name: rest-http 142 | spec: 143 | ports: 144 | - name: http 145 | port: 8080 146 | protocol: TCP 147 | targetPort: 8080 148 | selector: 149 | app: rest-http 150 | provider: snowdrop 151 | group: dev.snowdrop.example 152 | - apiVersion: v1 153 | kind: DeploymentConfig 154 | metadata: 155 | labels: 156 | app: rest-http 157 | provider: snowdrop 158 | version: "BOOSTER_VERSION" 159 | group: dev.snowdrop.example 160 | app.kubernetes.io/part-of: http-api-example 161 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 162 | app.openshift.io/runtime: rh-spring-boot 163 | app.kubernetes.io/name: http-api 164 | app.kubernetes.io/component: frontend 165 | annotations: 166 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 167 | name: rest-http 168 | spec: 169 | replicas: 1 170 | selector: 171 | app: rest-http 172 | provider: snowdrop 173 | group: dev.snowdrop.example 174 | strategy: 175 | rollingParams: 176 | timeoutSeconds: 3600 177 | type: Rolling 178 | template: 179 | metadata: 180 | labels: 181 | app: rest-http 182 | provider: snowdrop 183 | version: "BOOSTER_VERSION" 184 | group: dev.snowdrop.example 185 | app.kubernetes.io/part-of: http-api-example 186 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 187 | app.openshift.io/runtime: rh-spring-boot 188 | app.kubernetes.io/name: http-api 189 | app.kubernetes.io/component: frontend 190 | annotations: 191 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 192 | spec: 193 | containers: 194 | - env: 195 | - name: KUBERNETES_NAMESPACE 196 | valueFrom: 197 | fieldRef: 198 | fieldPath: metadata.namespace 199 | image: rest-http:BOOSTER_VERSION 200 | imagePullPolicy: IfNotPresent 201 | name: spring-boot 202 | ports: 203 | - containerPort: 8080 204 | name: http 205 | protocol: TCP 206 | - containerPort: 8778 207 | name: jolokia 208 | protocol: TCP 209 | readinessProbe: 210 | httpGet: 211 | path: /actuator/health 212 | port: 8080 213 | scheme: HTTP 214 | initialDelaySeconds: 10 215 | livenessProbe: 216 | httpGet: 217 | path: /actuator/health 218 | port: 8080 219 | scheme: HTTP 220 | initialDelaySeconds: 180 221 | securityContext: 222 | privileged: false 223 | triggers: 224 | - type: ConfigChange 225 | - imageChangeParams: 226 | automatic: true 227 | containerNames: 228 | - spring-boot 229 | from: 230 | kind: ImageStreamTag 231 | name: rest-http:BOOSTER_VERSION 232 | type: ImageChange 233 | - apiVersion: v1 234 | kind: Route 235 | metadata: 236 | labels: 237 | app: rest-http 238 | provider: snowdrop 239 | version: "BOOSTER_VERSION" 240 | group: dev.snowdrop.example 241 | app.kubernetes.io/part-of: http-api-example 242 | app.openshift.io/runtime-version: "SPRING_BOOT_VERSION" 243 | app.openshift.io/runtime: rh-spring-boot 244 | app.kubernetes.io/name: http-api 245 | app.kubernetes.io/component: frontend 246 | annotations: 247 | app.kubernetes.io/vcs-uri: git@github.com:snowdrop/rest-http-example.git 248 | name: rest-http 249 | spec: 250 | path: / 251 | port: 252 | targetPort: 8080 253 | to: 254 | kind: Service 255 | name: rest-http 256 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 17 | 4.0.0 18 | dev.snowdrop.example 19 | rest-http 20 | 2.7.18-2-SNAPSHOT 21 | Spring Boot - HTTP Example 22 | Spring Boot - HTTP Example 23 | 24 | 11 25 | 11 26 | 2.22.2 27 | 2.22.2 28 | 29 | 2.7.18 30 | 2.11.6 31 | 3.9.4.Final 32 | 33 | 34 | 35 | 36 | 37 | Apache License, Version 2.0 38 | https://www.apache.org/licenses/LICENSE-2.0.txt 39 | repo 40 | A business-friendly OSS license 41 | 42 | 43 | 44 | 45 | 46 | maven-central 47 | Public Maven Central Repository 48 | https://repo.maven.apache.org/maven2/ 49 | 50 | 51 | redhat-ga 52 | Red Hat GA Repository 53 | https://maven.repository.redhat.com/ga/ 54 | 55 | 56 | redhat-early-access 57 | Red Hat Early Access Repository 58 | https://maven.repository.redhat.com/earlyaccess/all/ 59 | 60 | 61 | 62 | 63 | 64 | maven-central 65 | Public Maven Central Repository 66 | https://repo.maven.apache.org/maven2/ 67 | 68 | 69 | redhat-ga 70 | Red Hat GA Repository 71 | https://maven.repository.redhat.com/ga/ 72 | 73 | 74 | redhat-early-access 75 | Red Hat Early Access Repository 76 | https://maven.repository.redhat.com/earlyaccess/all/ 77 | 78 | 79 | 80 | 81 | 82 | 83 | io.dekorate 84 | dekorate-spring-bom 85 | ${dekorate.version} 86 | pom 87 | import 88 | 89 | 90 | org.springframework.boot 91 | spring-boot-dependencies 92 | ${spring-boot.version} 93 | pom 94 | import 95 | 96 | 97 | 98 | 99 | 100 | 101 | org.springframework.boot 102 | spring-boot-starter-actuator 103 | 104 | 105 | org.jboss.resteasy 106 | resteasy-spring-boot-starter 107 | ${resteasy-spring-boot-starter.version} 108 | 109 | 110 | org.springframework.boot 111 | spring-boot-devtools 112 | true 113 | 114 | 115 | org.springframework.boot 116 | spring-boot-starter-test 117 | test 118 | 119 | 120 | io.rest-assured 121 | rest-assured 122 | test 123 | 124 | 125 | io.dekorate 126 | openshift-junit 127 | test 128 | 129 | 130 | io.dekorate 131 | kubernetes-junit 132 | test 133 | 134 | 135 | 136 | 137 | 138 | src/main/resources 139 | true 140 | 141 | 142 | 143 | 144 | org.springframework.boot 145 | spring-boot-maven-plugin 146 | ${spring-boot.version} 147 | 148 | 149 | 150 | 151 | repackage 152 | 153 | 154 | 155 | 156 | 157 | org.apache.maven.plugins 158 | maven-surefire-plugin 159 | ${maven-surefire-plugin.version} 160 | 161 | 162 | 163 | 164 | 165 | openshift-it 166 | 167 | 168 | 169 | org.apache.maven.plugins 170 | maven-failsafe-plugin 171 | ${maven-failsafe-plugin.version} 172 | 173 | 174 | ${project.artifactId} 175 | 176 | 177 | **/*OpenShiftIT.class 178 | 179 | 180 | 181 | 182 | 183 | integration-test 184 | verify 185 | 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | kubernetes-it 194 | 195 | 196 | 197 | org.apache.maven.plugins 198 | maven-failsafe-plugin 199 | ${maven-failsafe-plugin.version} 200 | 201 | 202 | ${project.artifactId} 203 | 204 | 205 | **/*KubernetesIT.class 206 | 207 | 208 | 209 | 210 | 211 | integration-test 212 | verify 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | openshift 222 | 223 | 224 | io.dekorate 225 | openshift-spring-starter 226 | 227 | 228 | 229 | 230 | kubernetes 231 | 232 | 233 | io.dekorate 234 | kubernetes-spring-starter 235 | 236 | 237 | 238 | 239 | helm 240 | 241 | 242 | io.dekorate 243 | helm-annotations 244 | 245 | 246 | 247 | 248 | -------------------------------------------------------------------------------- /mvnw: -------------------------------------------------------------------------------- 1 | #!/bin/sh 2 | # ---------------------------------------------------------------------------- 3 | # Licensed to the Apache Software Foundation (ASF) under one 4 | # or more contributor license agreements. See the NOTICE file 5 | # distributed with this work for additional information 6 | # regarding copyright ownership. The ASF licenses this file 7 | # to you under the Apache License, Version 2.0 (the 8 | # "License"); you may not use this file except in compliance 9 | # with the License. You may obtain a copy of the License at 10 | # 11 | # http://www.apache.org/licenses/LICENSE-2.0 12 | # 13 | # Unless required by applicable law or agreed to in writing, 14 | # software distributed under the License is distributed on an 15 | # "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 | # KIND, either express or implied. See the License for the 17 | # specific language governing permissions and limitations 18 | # under the License. 19 | # ---------------------------------------------------------------------------- 20 | 21 | # ---------------------------------------------------------------------------- 22 | # Maven2 Start Up Batch script 23 | # 24 | # Required ENV vars: 25 | # ------------------ 26 | # JAVA_HOME - location of a JDK home dir 27 | # 28 | # Optional ENV vars 29 | # ----------------- 30 | # M2_HOME - location of maven2's installed home dir 31 | # MAVEN_OPTS - parameters passed to the Java VM when running Maven 32 | # e.g. to debug Maven itself, use 33 | # set MAVEN_OPTS=-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 34 | # MAVEN_SKIP_RC - flag to disable loading of mavenrc files 35 | # ---------------------------------------------------------------------------- 36 | 37 | if [ -z "$MAVEN_SKIP_RC" ] ; then 38 | 39 | if [ -f /etc/mavenrc ] ; then 40 | . /etc/mavenrc 41 | fi 42 | 43 | if [ -f "$HOME/.mavenrc" ] ; then 44 | . "$HOME/.mavenrc" 45 | fi 46 | 47 | fi 48 | 49 | # OS specific support. $var _must_ be set to either true or false. 50 | cygwin=false; 51 | darwin=false; 52 | mingw=false 53 | case "`uname`" in 54 | CYGWIN*) cygwin=true ;; 55 | MINGW*) mingw=true;; 56 | Darwin*) darwin=true 57 | # Use /usr/libexec/java_home if available, otherwise fall back to /Library/Java/Home 58 | # See https://developer.apple.com/library/mac/qa/qa1170/_index.html 59 | if [ -z "$JAVA_HOME" ]; then 60 | if [ -x "/usr/libexec/java_home" ]; then 61 | export JAVA_HOME="`/usr/libexec/java_home`" 62 | else 63 | export JAVA_HOME="/Library/Java/Home" 64 | fi 65 | fi 66 | ;; 67 | esac 68 | 69 | if [ -z "$JAVA_HOME" ] ; then 70 | if [ -r /etc/gentoo-release ] ; then 71 | JAVA_HOME=`java-config --jre-home` 72 | fi 73 | fi 74 | 75 | if [ -z "$M2_HOME" ] ; then 76 | ## resolve links - $0 may be a link to maven's home 77 | PRG="$0" 78 | 79 | # need this for relative symlinks 80 | while [ -h "$PRG" ] ; do 81 | ls=`ls -ld "$PRG"` 82 | link=`expr "$ls" : '.*-> \(.*\)$'` 83 | if expr "$link" : '/.*' > /dev/null; then 84 | PRG="$link" 85 | else 86 | PRG="`dirname "$PRG"`/$link" 87 | fi 88 | done 89 | 90 | saveddir=`pwd` 91 | 92 | M2_HOME=`dirname "$PRG"`/.. 93 | 94 | # make it fully qualified 95 | M2_HOME=`cd "$M2_HOME" && pwd` 96 | 97 | cd "$saveddir" 98 | # echo Using m2 at $M2_HOME 99 | fi 100 | 101 | # For Cygwin, ensure paths are in UNIX format before anything is touched 102 | if $cygwin ; then 103 | [ -n "$M2_HOME" ] && 104 | M2_HOME=`cygpath --unix "$M2_HOME"` 105 | [ -n "$JAVA_HOME" ] && 106 | JAVA_HOME=`cygpath --unix "$JAVA_HOME"` 107 | [ -n "$CLASSPATH" ] && 108 | CLASSPATH=`cygpath --path --unix "$CLASSPATH"` 109 | fi 110 | 111 | # For Mingw, ensure paths are in UNIX format before anything is touched 112 | if $mingw ; then 113 | [ -n "$M2_HOME" ] && 114 | M2_HOME="`(cd "$M2_HOME"; pwd)`" 115 | [ -n "$JAVA_HOME" ] && 116 | JAVA_HOME="`(cd "$JAVA_HOME"; pwd)`" 117 | # TODO classpath? 118 | fi 119 | 120 | if [ -z "$JAVA_HOME" ]; then 121 | javaExecutable="`which javac`" 122 | if [ -n "$javaExecutable" ] && ! [ "`expr \"$javaExecutable\" : '\([^ ]*\)'`" = "no" ]; then 123 | # readlink(1) is not available as standard on Solaris 10. 124 | readLink=`which readlink` 125 | if [ ! `expr "$readLink" : '\([^ ]*\)'` = "no" ]; then 126 | if $darwin ; then 127 | javaHome="`dirname \"$javaExecutable\"`" 128 | javaExecutable="`cd \"$javaHome\" && pwd -P`/javac" 129 | else 130 | javaExecutable="`readlink -f \"$javaExecutable\"`" 131 | fi 132 | javaHome="`dirname \"$javaExecutable\"`" 133 | javaHome=`expr "$javaHome" : '\(.*\)/bin'` 134 | JAVA_HOME="$javaHome" 135 | export JAVA_HOME 136 | fi 137 | fi 138 | fi 139 | 140 | if [ -z "$JAVACMD" ] ; then 141 | if [ -n "$JAVA_HOME" ] ; then 142 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 143 | # IBM's JDK on AIX uses strange locations for the executables 144 | JAVACMD="$JAVA_HOME/jre/sh/java" 145 | else 146 | JAVACMD="$JAVA_HOME/bin/java" 147 | fi 148 | else 149 | JAVACMD="`which java`" 150 | fi 151 | fi 152 | 153 | if [ ! -x "$JAVACMD" ] ; then 154 | echo "Error: JAVA_HOME is not defined correctly." >&2 155 | echo " We cannot execute $JAVACMD" >&2 156 | exit 1 157 | fi 158 | 159 | if [ -z "$JAVA_HOME" ] ; then 160 | echo "Warning: JAVA_HOME environment variable is not set." 161 | fi 162 | 163 | CLASSWORLDS_LAUNCHER=org.codehaus.plexus.classworlds.launcher.Launcher 164 | 165 | # traverses directory structure from process work directory to filesystem root 166 | # first directory with .mvn subdirectory is considered project base directory 167 | find_maven_basedir() { 168 | 169 | if [ -z "$1" ] 170 | then 171 | echo "Path not specified to find_maven_basedir" 172 | return 1 173 | fi 174 | 175 | basedir="$1" 176 | wdir="$1" 177 | while [ "$wdir" != '/' ] ; do 178 | if [ -d "$wdir"/.mvn ] ; then 179 | basedir=$wdir 180 | break 181 | fi 182 | # workaround for JBEAP-8937 (on Solaris 10/Sparc) 183 | if [ -d "${wdir}" ]; then 184 | wdir=`cd "$wdir/.."; pwd` 185 | fi 186 | # end of workaround 187 | done 188 | echo "${basedir}" 189 | } 190 | 191 | # concatenates all lines of a file 192 | concat_lines() { 193 | if [ -f "$1" ]; then 194 | echo "$(tr -s '\n' ' ' < "$1")" 195 | fi 196 | } 197 | 198 | BASE_DIR=`find_maven_basedir "$(pwd)"` 199 | if [ -z "$BASE_DIR" ]; then 200 | exit 1; 201 | fi 202 | 203 | ########################################################################################## 204 | # Extension to allow automatically downloading the maven-wrapper.jar from Maven-central 205 | # This allows using the maven wrapper in projects that prohibit checking in binary data. 206 | ########################################################################################## 207 | if [ -r "$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" ]; then 208 | if [ "$MVNW_VERBOSE" = true ]; then 209 | echo "Found .mvn/wrapper/maven-wrapper.jar" 210 | fi 211 | else 212 | if [ "$MVNW_VERBOSE" = true ]; then 213 | echo "Couldn't find .mvn/wrapper/maven-wrapper.jar, downloading it ..." 214 | fi 215 | jarUrl="https://repo.maven.apache.org/maven2/io/takari/maven-wrapper/0.4.0/maven-wrapper-0.4.0.jar" 216 | while IFS="=" read key value; do 217 | case "$key" in (wrapperUrl) jarUrl="$value"; break ;; 218 | esac 219 | done < "$BASE_DIR/.mvn/wrapper/maven-wrapper.properties" 220 | if [ "$MVNW_VERBOSE" = true ]; then 221 | echo "Downloading from: $jarUrl" 222 | fi 223 | wrapperJarPath="$BASE_DIR/.mvn/wrapper/maven-wrapper.jar" 224 | 225 | if command -v wget > /dev/null; then 226 | if [ "$MVNW_VERBOSE" = true ]; then 227 | echo "Found wget ... using wget" 228 | fi 229 | wget "$jarUrl" -O "$wrapperJarPath" 230 | elif command -v curl > /dev/null; then 231 | if [ "$MVNW_VERBOSE" = true ]; then 232 | echo "Found curl ... using curl" 233 | fi 234 | curl -o "$wrapperJarPath" "$jarUrl" 235 | else 236 | if [ "$MVNW_VERBOSE" = true ]; then 237 | echo "Falling back to using Java to download" 238 | fi 239 | javaClass="$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.java" 240 | if [ -e "$javaClass" ]; then 241 | if [ ! -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 242 | if [ "$MVNW_VERBOSE" = true ]; then 243 | echo " - Compiling MavenWrapperDownloader.java ..." 244 | fi 245 | # Compiling the Java class 246 | ("$JAVA_HOME/bin/javac" "$javaClass") 247 | fi 248 | if [ -e "$BASE_DIR/.mvn/wrapper/MavenWrapperDownloader.class" ]; then 249 | # Running the downloader 250 | if [ "$MVNW_VERBOSE" = true ]; then 251 | echo " - Running MavenWrapperDownloader.java ..." 252 | fi 253 | ("$JAVA_HOME/bin/java" -cp .mvn/wrapper MavenWrapperDownloader "$MAVEN_PROJECTBASEDIR") 254 | fi 255 | fi 256 | fi 257 | fi 258 | ########################################################################################## 259 | # End of extension 260 | ########################################################################################## 261 | 262 | export MAVEN_PROJECTBASEDIR=${MAVEN_BASEDIR:-"$BASE_DIR"} 263 | if [ "$MVNW_VERBOSE" = true ]; then 264 | echo $MAVEN_PROJECTBASEDIR 265 | fi 266 | MAVEN_OPTS="$(concat_lines "$MAVEN_PROJECTBASEDIR/.mvn/jvm.config") $MAVEN_OPTS" 267 | 268 | # For Cygwin, switch paths to Windows format before running java 269 | if $cygwin; then 270 | [ -n "$M2_HOME" ] && 271 | M2_HOME=`cygpath --path --windows "$M2_HOME"` 272 | [ -n "$JAVA_HOME" ] && 273 | JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"` 274 | [ -n "$CLASSPATH" ] && 275 | CLASSPATH=`cygpath --path --windows "$CLASSPATH"` 276 | [ -n "$MAVEN_PROJECTBASEDIR" ] && 277 | MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` 278 | fi 279 | 280 | WRAPPER_LAUNCHER=org.apache.maven.wrapper.MavenWrapperMain 281 | 282 | exec "$JAVACMD" \ 283 | $MAVEN_OPTS \ 284 | -classpath "$MAVEN_PROJECTBASEDIR/.mvn/wrapper/maven-wrapper.jar" \ 285 | "-Dmaven.home=${M2_HOME}" "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ 286 | ${WRAPPER_LAUNCHER} $MAVEN_CONFIG "$@" 287 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | 2 | Apache License 3 | Version 2.0, January 2004 4 | http://www.apache.org/licenses/ 5 | 6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 7 | 8 | 1. Definitions. 9 | 10 | "License" shall mean the terms and conditions for use, reproduction, 11 | and distribution as defined by Sections 1 through 9 of this document. 12 | 13 | "Licensor" shall mean the copyright owner or entity authorized by 14 | the copyright owner that is granting the License. 15 | 16 | "Legal Entity" shall mean the union of the acting entity and all 17 | other entities that control, are controlled by, or are under common 18 | control with that entity. For the purposes of this definition, 19 | "control" means (i) the power, direct or indirect, to cause the 20 | direction or management of such entity, whether by contract or 21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 22 | outstanding shares, or (iii) beneficial ownership of such entity. 23 | 24 | "You" (or "Your") shall mean an individual or Legal Entity 25 | exercising permissions granted by this License. 26 | 27 | "Source" form shall mean the preferred form for making modifications, 28 | including but not limited to software source code, documentation 29 | source, and configuration files. 30 | 31 | "Object" form shall mean any form resulting from mechanical 32 | transformation or translation of a Source form, including but 33 | not limited to compiled object code, generated documentation, 34 | and conversions to other media types. 35 | 36 | "Work" shall mean the work of authorship, whether in Source or 37 | Object form, made available under the License, as indicated by a 38 | copyright notice that is included in or attached to the work 39 | (an example is provided in the Appendix below). 40 | 41 | "Derivative Works" shall mean any work, whether in Source or Object 42 | form, that is based on (or derived from) the Work and for which the 43 | editorial revisions, annotations, elaborations, or other modifications 44 | represent, as a whole, an original work of authorship. For the purposes 45 | of this License, Derivative Works shall not include works that remain 46 | separable from, or merely link (or bind by name) to the interfaces of, 47 | the Work and Derivative Works thereof. 48 | 49 | "Contribution" shall mean any work of authorship, including 50 | the original version of the Work and any modifications or additions 51 | to that Work or Derivative Works thereof, that is intentionally 52 | submitted to Licensor for inclusion in the Work by the copyright owner 53 | or by an individual or Legal Entity authorized to submit on behalf of 54 | the copyright owner. For the purposes of this definition, "submitted" 55 | means any form of electronic, verbal, or written communication sent 56 | to the Licensor or its representatives, including but not limited to 57 | communication on electronic mailing lists, source code control systems, 58 | and issue tracking systems that are managed by, or on behalf of, the 59 | Licensor for the purpose of discussing and improving the Work, but 60 | excluding communication that is conspicuously marked or otherwise 61 | designated in writing by the copyright owner as "Not a Contribution." 62 | 63 | "Contributor" shall mean Licensor and any individual or Legal Entity 64 | on behalf of whom a Contribution has been received by Licensor and 65 | subsequently incorporated within the Work. 66 | 67 | 2. Grant of Copyright License. Subject to the terms and conditions of 68 | this License, each Contributor hereby grants to You a perpetual, 69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 70 | copyright license to reproduce, prepare Derivative Works of, 71 | publicly display, publicly perform, sublicense, and distribute the 72 | Work and such Derivative Works in Source or Object form. 73 | 74 | 3. Grant of Patent License. Subject to the terms and conditions of 75 | this License, each Contributor hereby grants to You a perpetual, 76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 77 | (except as stated in this section) patent license to make, have made, 78 | use, offer to sell, sell, import, and otherwise transfer the Work, 79 | where such license applies only to those patent claims licensable 80 | by such Contributor that are necessarily infringed by their 81 | Contribution(s) alone or by combination of their Contribution(s) 82 | with the Work to which such Contribution(s) was submitted. If You 83 | institute patent litigation against any entity (including a 84 | cross-claim or counterclaim in a lawsuit) alleging that the Work 85 | or a Contribution incorporated within the Work constitutes direct 86 | or contributory patent infringement, then any patent licenses 87 | granted to You under this License for that Work shall terminate 88 | as of the date such litigation is filed. 89 | 90 | 4. Redistribution. You may reproduce and distribute copies of the 91 | Work or Derivative Works thereof in any medium, with or without 92 | modifications, and in Source or Object form, provided that You 93 | meet the following conditions: 94 | 95 | (a) You must give any other recipients of the Work or 96 | Derivative Works a copy of this License; and 97 | 98 | (b) You must cause any modified files to carry prominent notices 99 | stating that You changed the files; and 100 | 101 | (c) You must retain, in the Source form of any Derivative Works 102 | that You distribute, all copyright, patent, trademark, and 103 | attribution notices from the Source form of the Work, 104 | excluding those notices that do not pertain to any part of 105 | the Derivative Works; and 106 | 107 | (d) If the Work includes a "NOTICE" text file as part of its 108 | distribution, then any Derivative Works that You distribute must 109 | include a readable copy of the attribution notices contained 110 | within such NOTICE file, excluding those notices that do not 111 | pertain to any part of the Derivative Works, in at least one 112 | of the following places: within a NOTICE text file distributed 113 | as part of the Derivative Works; within the Source form or 114 | documentation, if provided along with the Derivative Works; or, 115 | within a display generated by the Derivative Works, if and 116 | wherever such third-party notices normally appear. The contents 117 | of the NOTICE file are for informational purposes only and 118 | do not modify the License. You may add Your own attribution 119 | notices within Derivative Works that You distribute, alongside 120 | or as an addendum to the NOTICE text from the Work, provided 121 | that such additional attribution notices cannot be construed 122 | as modifying the License. 123 | 124 | You may add Your own copyright statement to Your modifications and 125 | may provide additional or different license terms and conditions 126 | for use, reproduction, or distribution of Your modifications, or 127 | for any such Derivative Works as a whole, provided Your use, 128 | reproduction, and distribution of the Work otherwise complies with 129 | the conditions stated in this License. 130 | 131 | 5. Submission of Contributions. Unless You explicitly state otherwise, 132 | any Contribution intentionally submitted for inclusion in the Work 133 | by You to the Licensor shall be under the terms and conditions of 134 | this License, without any additional terms or conditions. 135 | Notwithstanding the above, nothing herein shall supersede or modify 136 | the terms of any separate license agreement you may have executed 137 | with Licensor regarding such Contributions. 138 | 139 | 6. Trademarks. This License does not grant permission to use the trade 140 | names, trademarks, service marks, or product names of the Licensor, 141 | except as required for reasonable and customary use in describing the 142 | origin of the Work and reproducing the content of the NOTICE file. 143 | 144 | 7. Disclaimer of Warranty. Unless required by applicable law or 145 | agreed to in writing, Licensor provides the Work (and each 146 | Contributor provides its Contributions) on an "AS IS" BASIS, 147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 148 | implied, including, without limitation, any warranties or conditions 149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 150 | PARTICULAR PURPOSE. You are solely responsible for determining the 151 | appropriateness of using or redistributing the Work and assume any 152 | risks associated with Your exercise of permissions under this License. 153 | 154 | 8. Limitation of Liability. In no event and under no legal theory, 155 | whether in tort (including negligence), contract, or otherwise, 156 | unless required by applicable law (such as deliberate and grossly 157 | negligent acts) or agreed to in writing, shall any Contributor be 158 | liable to You for damages, including any direct, indirect, special, 159 | incidental, or consequential damages of any character arising as a 160 | result of this License or out of the use or inability to use the 161 | Work (including but not limited to damages for loss of goodwill, 162 | work stoppage, computer failure or malfunction, or any and all 163 | other commercial damages or losses), even if such Contributor 164 | has been advised of the possibility of such damages. 165 | 166 | 9. Accepting Warranty or Additional Liability. While redistributing 167 | the Work or Derivative Works thereof, You may choose to offer, 168 | and charge a fee for, acceptance of support, warranty, indemnity, 169 | or other liability obligations and/or rights consistent with this 170 | License. However, in accepting such obligations, You may act only 171 | on Your own behalf and on Your sole responsibility, not on behalf 172 | of any other Contributor, and only if You agree to indemnify, 173 | defend, and hold each Contributor harmless for any liability 174 | incurred by, or claims asserted against, such Contributor by reason 175 | of your accepting any such warranty or additional liability. 176 | 177 | END OF TERMS AND CONDITIONS 178 | 179 | APPENDIX: How to apply the Apache License to your work. 180 | 181 | To apply the Apache License to your work, attach the following 182 | boilerplate notice, with the fields enclosed by brackets "[]" 183 | replaced with your own identifying information. (Don't include 184 | the brackets!) The text should be enclosed in the appropriate 185 | comment syntax for the file format. We also recommend that a 186 | file or class name and description of purpose be included on the 187 | same "printed page" as the copyright notice for easier 188 | identification within third-party archives. 189 | 190 | Copyright [yyyy] [name of copyright owner] 191 | 192 | Licensed under the Apache License, Version 2.0 (the "License"); 193 | you may not use this file except in compliance with the License. 194 | You may obtain a copy of the License at 195 | 196 | http://www.apache.org/licenses/LICENSE-2.0 197 | 198 | Unless required by applicable law or agreed to in writing, software 199 | distributed under the License is distributed on an "AS IS" BASIS, 200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 201 | See the License for the specific language governing permissions and 202 | limitations under the License. 203 | -------------------------------------------------------------------------------- /guide.adoc: -------------------------------------------------------------------------------- 1 | = Understanding how to deploy a simple RESTful service and front-end on OpenShift using Spring Boot and Apache CXF 2 | 3 | This document will guide you through the steps to create a simple "Hello World" https://jcp.org/en/jsr/detail?id=370[JAX-RS] 4 | based, RESTful web service using http://cxf.apache.org/[Apache CXF] and https://spring.io/projects/spring-boot[Spring Boot]. 5 | While learning how to use JAX-RS with Spring Boot is interesting in itself, we will detail the steps and mechanisms involved in 6 | deploying the application on an OpenShift cluster in an effort to develop a truly cloud-native application with a workflow 7 | focused on making things natural to Java developers. 8 | 9 | Conceptually, the application is similar to the one developed in 10 | https://spring.io/guides/gs/rest-service/[Spring Boot's guide on building RESTful services]. However, where the Spring 11 | Boot guide uses Spring-specific annotations to define the endpoint and its method, we will use standard annotations, making it 12 | easier to reuse endpoints implementations across servers, should you want to target a different platform than Spring Boot at some point. 13 | 14 | == What you'll build 15 | 16 | The application you will be building exposes a very simple greeting web service accepting `GET` HTTP requests to 17 | `/api/greeting`, responding with a JSON message in the form `{"content":"Hello, World!"}`. The 18 | message can be customized by passing the `name` query parameter to the request as in 19 | `http://localhost:8080/api/greeting?name=John` which would result in the following response: `{"content":"Hello, 20 | John!"}`. 21 | Additionally, a very simple front-end is provided using HTML and jQuery to interact with the greeting endpoint 22 | from a more user-friendly interface than query the service using https://curl.haxx.se/[`cURL`]. 23 | 24 | NOTE: While we will go over the implementation, we will focus mostly on the specifics needed to get your application running on 25 | OpenShift as opposed to detailing all the Spring Boot-specific implementation. 26 | 27 | == What you'll need 28 | 29 | * Java 11 30 | * Access to an OpenShift cluster whether locally via https://www.openshift.org/minishift/[minishift] or using the different 31 | flavors of https://www.openshift.com/products[OpenShift products] 32 | 33 | 34 | == Endpoint 35 | 36 | The application is composed of a RESTful service. Its code can be found in the `src/main/java/dev/snowdrop/example/service` 37 | directory. It is split in two classes: `GreetingEndpoint`, which implements the endpoint itself, and `Greeting` which is a 38 | simple class representing the payload sent back to users of the endpoint. 39 | 40 | Let's look at the `Greeting` class first, which is pretty simple: 41 | ```java 42 | public class Greeting { 43 | 44 | public static final String FORMAT = "Hello, %s!"; #<1> 45 | 46 | private final String content; #<2> 47 | 48 | public Greeting() { 49 | this.content = null; 50 | } 51 | 52 | public Greeting(String content) { 53 | this.content = content; 54 | } 55 | 56 | public String getContent() { 57 | return content; 58 | } 59 | } 60 | ``` 61 | <1> `FORMAT` constant that can be used by clients of the class to create greeting messages in the expected format 62 | <2> `content` field which will be used to populate our JSON payload 63 | This `Greeting` class will be automatically marshalled by Jackson using the accessor. 64 | 65 | Let's now look at the `GreetingEndpoint` class, short and sweet but packing quite a punch, thanks to annotations: 66 | ```java 67 | import javax.ws.rs.DefaultValue; # <1> 68 | import javax.ws.rs.GET; 69 | import javax.ws.rs.Path; 70 | import javax.ws.rs.Produces; 71 | import javax.ws.rs.QueryParam; 72 | 73 | import org.springframework.stereotype.Component; 74 | 75 | @Path("/greeting") # <2> 76 | @Component # <3> 77 | public class GreetingEndpoint { 78 | @GET # <4> 79 | @Produces("application/json") # <5> 80 | public Greeting greeting(@QueryParam("name") @DefaultValue("World") String name) { #<6> 81 | final String message = String.format(Greeting.FORMAT, name); #<7> 82 | return new Greeting(message); #<8> 83 | } 84 | } 85 | ``` 86 | <1> Standard JAX-RS annotation imports 87 | <2> Specify that this class is a JAX-RS root resource and that the endpoint will answer requests on `/greeting` 88 | <3> Mark the endpoint as a Spring component to be managed by Spring Boot. In conjunction with the `cxf.jaxrs.component-scan` property set to `true` in `application.properties`, this allows CXF to create a JAX-RS endpoint from the auto-discovered JAX-RS root resources. 89 | <4> Mark the `greeting` method as answering HTTP `GET` requests 90 | <5> Specify that the method returns JSON content (`application/json` content type) 91 | <6> The `name` method parameter is annotated with `@QueryParam("name")` to specify that it is passed as a query parameter in the URL when the service is invoked and that its default value is `World` if none is provided (thanks to the `@DefaultValue("World")` annotation) 92 | <7> We format the message using the `Greeting.FORMAT` constant… 93 | <8> and return a `Greeting` instance with the proper message. This object will be automatically serialized to JSON using https://github.com/FasterXML/jackson[Jackson] as we will see later. 94 | 95 | As you can see, there isn't much to it as far as code goes. 96 | 97 | We still need to configure CXF and Spring Boot properly for everything to work well. 98 | 99 | On the Spring Boot side, we need an entry point to our service in the form a class annotated with `@SpringBootApplication`, also giving us the opportunity to further configure our stack: 100 | ```java 101 | import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider; 102 | import org.springframework.boot.SpringApplication; 103 | import org.springframework.boot.autoconfigure.SpringBootApplication; 104 | import org.springframework.context.annotation.Bean; 105 | 106 | @SpringBootApplication #<1> 107 | public class ExampleApplication { 108 | 109 | public static void main(String[] args) { 110 | SpringApplication.run(BoosterApplication.class, args); 111 | } 112 | 113 | @Bean 114 | public JacksonJsonProvider jsonProvider() { #<2> 115 | return new JacksonJsonProvider(); 116 | } 117 | } 118 | ``` 119 | <1> Activates auto-configuration, component scan and marks the class as providing configuration using the https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-using-springbootapplication-annotation.html[`@SpringBootApplication` annotation]. This also allows to package the application as a jar that can be run as a typical application. Spring Boot will then start the embedded Tomcat server. 120 | <2> Specifies that the JSON provider to be used by CXF (which uses http://cxf.apache.org/docs/configuration.html[Spring as basis of its configuration]) should be Jackson. 121 | 122 | NOTE: You'll notice that, contrary to https://docs.spring.io/spring/docs/4.3.18.RELEASE/spring-framework-reference/htmlsingle/#mvc[Spring MVC] where Jackson only needs to be present on the classpath for it to be used, Apache CXF requires Jackson to be explicitly configured. This could be done via XML but we might as well leverage the `@SpringBootApplication` configuration capability. 123 | 124 | Let's now look at the content of `application.properties` which we need to further configure CXF: 125 | ```properties 126 | cxf.path:/api #<1> 127 | cxf.jaxrs.component-scan:true #<2> 128 | ``` 129 | <1> Specify that CXF will answer to requests sent to the `/api` context. Our endpoint root resource is annotated with `@Path("/greeting")` which means that the full context for our endpoint will be `/api/greeting`. 130 | <2> As mentioned above when we looked at the `GreetingEndpoint` class, we need to set that property to `true` to activate automatic creation of endpoint based on resource detection. 131 | 132 | == Frontend 133 | 134 | Let's take a quick look at our frontend. It's implemented as a static HTML `src/resources/static/index.html` file served from the root of the embedded Tomcat server. The basic idea is similar to what is explained in the https://spring.io/guides/gs/consuming-rest-jquery/[consuming a RESTful Web Service with jQuery] Spring Boot guide so we will only focus on the salient parts for our purpose. 135 | 136 | In our case, our service is running on the same server so we don't need to worry about https://spring.io/understanding/CORS[CORS]. Moreover, for the same reason, we don't need any extra code for Spring Boot to start Tomcat. 137 | 138 | The simple UI consists in a form to specify which name to pass to the greeting service and then invoke it: 139 | ```html 140 |
141 |
142 | 143 | #<1> 144 |
145 | #<2> 146 |
147 |

Result:

148 |
Invoke the service to see the result.
#<3> 149 | ``` 150 | <1> Text input to enter the name to pass to the greeting service 151 | <2> Button to trigger the call to the greeting service 152 | <3> Placeholder text that will be replaced by the result of the service call 153 | 154 | and the embedded jQuery script: 155 | ```js 156 | $(document).ready(function () { 157 | $("#invoke").click(function (e) { #<1> 158 | var n = $("#name").val() || "World"; #<2> 159 | $.getJSON("/api/greeting?name=" + n, function (res) { #<3> 160 | $("#greeting-result").text(JSON.stringify(res)); #<4> 161 | }); 162 | e.preventDefault(); 163 | }); 164 | }); 165 | ``` 166 | <1> Add a `click` event handler to the button with the `invoke` id 167 | <2> Retrieve the value of the `name` input to pass to the greeting server 168 | <3> Invoke the RESTful endpoint and retrieve the JSON response 169 | <4> Replace the content of the element with the `greeting-result` id with the result of the invocation 170 | 171 | == Building and testing the application locally 172 | 173 | You can run the application using `./mvnw spring-boot:run`, using the `run` goal of the https://docs.spring.io/spring-boot/docs/1.5.x/maven-plugin//index.html[Maven Spring Boot plugin]. 174 | It's also possible to build the JAR file with `./mvnw clean package` and run it like a traditional Java application: 175 | 176 | java -jar target/rest-http-.jar 177 | 178 | where `` corresponds to the current version of the project. 179 | Once the application is started, you can visit http://localhost:8080/index.html to see the frontend of the application and interact with the greeting service. 180 | 181 | Let's look at the important parts of the Maven project to properly build and run the application locally. 182 | 183 | First, we need to tell Maven that we're using Spring Boot and more specifically that we want to use the http://snowdrop.me/[Snowdrop] supported set of Spring Boot starters. This is accomplished by using 2 properties and importing the https://github.com/snowdrop/spring-boot-bom/tree/sb-1.5.x[Snowdrop Bill Of Materials (BOM)] and any dependencies we need for our application: 184 | ```xml 185 | ... 186 | 187 | 1.5.14.Final #<1> 188 | 1.5.14.RELEASE #<2> 189 | .... 190 | 191 | ... 192 | 193 | 194 | 195 | me.snowdrop 196 | spring-boot-bom 197 | ${spring-boot-bom.version} #<3> 198 | pom 199 | import 200 | 201 | ... 202 | 203 | 204 | #<4> 205 | 206 | org.springframework.boot 207 | spring-boot-starter-tomcat #<5> 208 | 209 | 210 | org.springframework.boot 211 | spring-boot-starter-actuator 212 | 213 | 214 | org.apache.cxf 215 | cxf-spring-boot-starter-jaxrs #<6> 216 | 217 | 218 | com.fasterxml.jackson.jaxrs 219 | jackson-jaxrs-json-provider #<7> 220 | 221 | ... 222 | 223 | ... 224 | ``` 225 | <1> Specify the BOM version we want to use. More details on the 226 | https://github.com/snowdrop/spring-boot-bom/tree/sb-1.5.x[BOM content] and its 227 | https://github.com/snowdrop/spring-boot-bom/tree/sb-1.5.x#versioning-scheme[versioning scheme] are available. 228 | <2> Associated Spring Boot version 229 | <3> The BOM version is imported in the `dependencyManagement` section of the POM file 230 | <4> Since the BOM defines supported versions, we can then import supported dependencies without having to worry about their respective versions 231 | <5> Specify that we want to use Spring Boot with an embedded Tomcat server 232 | <6> Needed to be able to use Apache CXF integration with Spring Boot 233 | <7> Needed so that Apache CXF can use Jackson as JSON marshaller as seen above when we defined a `jsonProvider` bean provider method in our application entry point 234 | 235 | Let's now look at the build configuration: 236 | 237 | ```xml 238 | ... 239 | 240 | 241 | 242 | src/main/resources 243 | true #<3> 244 | 245 | 246 | 247 | 248 | src/test/resources 249 | true #<4> 250 | 251 | 252 | 253 | 254 | 255 | org.springframework.boot 256 | spring-boot-maven-plugin 257 | ${spring-boot.version} #<1> 258 | 259 | 260 | 261 | 262 | 263 | org.springframework.boot 264 | spring-boot-maven-plugin 265 | 266 | 267 | 268 | 269 | repackage #<2> 270 | 271 | 272 | 273 | 274 | 275 | 276 | ... 277 | ``` 278 | <1> Add the https://docs.spring.io/spring-boot/docs/1.5.x/maven-plugin/[Spring Boot Maven plugin] to the build using the previously defined `spring-boot.version` property. 279 | <2> Specify that the `repackage` goal of the Spring Boot plugin should be executed during the `package` phase of the Maven build. This leads to the creation of new jar file repackaged to create a self-contained, executable application. The originally generated jar file is kept but renamed with the `.original` suffix appended to its name. 280 | <3> Activate https://maven.apache.org/shared/maven-filtering/index.html[Maven filtering] on files put in `src/main/resources` where Spring Boot configuration files live so that properties in the `${property.name}` can be interpolated and replaced during the build 281 | <4> Also perform Maven filtering on `src/test/resources` test resource files 282 | 283 | == Deploying the application on OpenShift 284 | 285 | Now that we've seen the gist of the application and how to run it locally, let's look at what's needed to deploy it on OpenShift. This is accomplished using Dekorate. Dekorate brings your Java applications to OpenShift. Tightly integrated with Maven, it leverages the existing build configuration to focus on two tasks: building Docker images and creating OpenShift (or plain Kubernetes) resource descriptors. Since our application is built using Maven, it makes sense to continue to leverage that tool to generate whatever is necessary to deploy and run our application on OpenShift. 286 | 287 | NOTE: The following steps assume that you are currently connected to a running OpenShift cluster via `oc login`. By doing so, FMP will be able to determine that you are targeting an OpenShift deployment automatically and take additional steps to generate OpenShift-specific descriptors (as opposed to generic Kubernetes ones). 288 | 289 | First, we need to tell Maven that we want to use this dependency. This is accomplished in the parent POM of our example, which is declared as: 290 | ```xml 291 | 292 | io.openshift 293 | booster-parent 294 | 23 295 | 296 | ``` 297 | NOTE: We're considering removing the need for a parent and including the FMP (Fabric8 Maven Plugin) configuration directly in our boosters. 298 | 299 | Let's look at the parts that deal with configuring the Fabric8 Maven Plugin: 300 | ```xml 301 | ... 302 | 303 | 304 | 305 | io.dekorate 306 | openshift-spring-starter 307 | 308 | ... 309 | 310 | ... 311 | ``` 312 | 313 | And specify the Docker base image to use in the `application.properties`: 314 | 315 | ``` 316 | dekorate.openshift.expose=true 317 | dekorate.s2i.builder-image=registry.access.redhat.com/ubi8/openjdk-11:1.14 318 | ``` 319 | 320 | Specify which Docker base image to use when generating the images for our application. The base image will serve as the foundation on top of which Dekorate adds our application to create a container ready to be deployed on a Kubernetes cluster. In this case, the base image is the 321 | https://access.redhat.com/containers/?tab=overview&platform=openshift#/registry.access.redhat.com/ubi8/openjdk-11[Red Hat supported OpenJDK 11 image] since our application is, at its code, a Java application. 322 | 323 | NOTE: You can see and explore the list of Red Hat supported images that can serve as base images for you applications at: https://access.redhat.com/containers/. 324 | 325 | We then need to generate the resources and deploy to the Openshift cluster we're connected to. This is accomplished by running: 326 | 327 | ```bash 328 | ./mvnw clean verify -Popenshift -Ddekorate.deploy=true 329 | ``` 330 | 331 | The more interesting directory when it comes to files generated by `Dekorate` is the `target/classes/META-INF/dekorate` directory. This is where FMP puts the final version of the generated files once they have prepared. Looking at it, we notice it has the following structure: 332 | 333 | ``` 334 | - openshift.json 335 | - openshift.yml 336 | ``` 337 | 338 | Next, you can access your application by running 339 | 340 | ```bash 341 | oc get route rest-http -o jsonpath='{"http://"}{.spec.host}{"\n"}' 342 | ``` 343 | 344 | and pasting that URL in your favorite browser. 345 | 346 | == See Also 347 | 348 | * https://spring.io/guides/gs/rest-service/[Spring Boot's guide on building RESTful services] 349 | * https://docs.spring.io/spring-boot/docs/1.5.x/reference/html/[Spring Boot 1.5.x reference documentation] 350 | * https://docs.spring.io/spring-boot/docs/1.5.x/maven-plugin/[Spring Boot 1.5.x Maven plugin] 351 | * http://cxf.apache.org/docs/springboot.html[Apache CXF Spring Boot configuration] 352 | * http://cxf.apache.org/docs/configuration.html[Apache CXF configuration] 353 | * http://www.baeldung.com/spring-boot-devtools[Introduction to Spring Boot devtools] 354 | * https://docs.spring.io/spring-boot/docs/current/reference/html/using-boot-devtools.html[Spring Boot devtools documentation] 355 | * https://github.com/dekorateio/dekorate[Dekorate] 356 | * https://docs.openshift.org/latest/welcome/index.html[OpenShift Origin documentation] 357 | --------------------------------------------------------------------------------