Skip to content

Latest commit

 

History

History

camel-quarkus-xmlvalidation-api

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Camel-Quarkus-XmlValidation-Api project

This project leverages Quarkus version 1.9.x, the Supersonic Subatomic Java Framework.

It exposes the following RESTful service endpoints using the Apache Camel Quarkus Platform extension:

  • /validateMembershipXML : validates a sample Membership XML instance through the POST HTTP method.
  • /health : returns the Camel Quarkus MicroProfile health checks
  • /metrics : the Camel Quarkus MicroProfile metrics

Prerequisites

  • JDK 11 installed with JAVA_HOME configured appropriately
  • Apache Maven 3.6.2+

Running the application in dev mode

You can run your application in dev mode that enables live coding using:

./mvnw quarkus:dev

Packaging and running the application locally

The application can be packaged using ./mvnw package. It produces the camel-quarkus-xmlvalidation-api-1.0.0-SNAPSHOT-runner.jar file in the /target directory. Be aware that it’s not an über-jar as the dependencies are copied into the target/lib directory.

The application is now runnable using java -jar target/camel-quarkus-xmlvalidation-api-1.0.0-SNAPSHOT-runner.jar.

Packaging and running the application on Red Hat OpenShift

Pre-requisites

  • Access to a Red Hat OpenShift cluster v3 or v4
  • User has self-provisioner privilege or has access to a working OpenShift project
  1. Login to the OpenShift cluster
    oc login ...
  2. Create an OpenShift project or use your existing OpenShift project. For instance, to create camel-quarkus
    oc new-project camel-quarkus-jvm --display-name="Apache Camel Quarkus Apps - JVM Mode"
  3. Use either the S2I binary workflow or S2I source workflow to deploy the Camel-Quarkus-XmlValidation-Api.postman_collection app as described below.

OpenShift S2I binary workflow

This leverages the Quarkus OpenShift extension and is only recommended for development and testing purposes.

./mvnw clean package -Dquarkus.kubernetes.deploy=true
[...]
[INFO] [io.quarkus.deployment.pkg.steps.JarResultBuildStep] Building thin jar: /Users/jeannyil/Workdata/myGit/Quarkus/upstream-quarkus-camel-demos/camel-quarkus-xmlvalidation-api/target/camel-quarkus-xmlvalidation-api-1.0.0-SNAPSHOT-runner.jar
[INFO] [io.quarkus.kubernetes.deployment.KubernetesDeploy] Kubernetes API Server at 'https://api.cluster-f7d5.sandbox81.opentlc.com:6443/' successfully contacted.
[...]
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Performing s2i binary build with jar on server: https://api.cluster-f7d5.sandbox81.opentlc.com:6443/ in namespace:camel-quarkus.
[...]
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Successfully pushed image-registry.openshift-image-registry.svc:5000/camel-quarkus/camel-quarkus-xmlvalidation-api@sha256:3d3d8060f906acb8d942fb28283cbbc344377ab20d982cd1eec2041a8f20f521
[INFO] [io.quarkus.container.image.s2i.deployment.S2iProcessor] Push successful
[INFO] [io.quarkus.kubernetes.deployment.KubernetesDeployer] Deploying to openshift server: https://api.cluster-f7d5.sandbox81.opentlc.com:6443/ in namespace: camel-quarkus.
[...]

OpenShift S2I source workflow (recommended for PRODUCTION use)

  1. Make sure the latest supported OpenJDK 11 image is imported in OpenShift
    oc import-image --confirm openjdk-11-ubi8 \
    --from=registry.access.redhat.com/ubi8/openjdk-11 \
    -n openshift
  2. Create the Camel-Quarkus-XmlValidation-Api.postman_collection OpenShift application from the git repository
    oc new-app https://github.com/jeanNyil/upstream-quarkus-camel-demos.git \
    --context-dir=camel-quarkus-xmlvalidation-api \
    --name=camel-quarkus-xmlvalidation-api \
    --image-stream="openshift/openjdk-11-ubi8"
  3. Follow the log of the S2I build
    oc logs bc/camel-quarkus-xmlvalidation-api -f
    Cloning "https://github.com/jeanNyil/upstream-quarkus-camel-demos.git" ...
            Commit: 33b40b3149e109557b8587c14d4aaa88cca5a590 (Updated README)
            Author: Jean Armand Nyilimbibi <jean.nyilimbibi@gmail.com>
            Date:   Mon Sep 7 21:14:41 2020 +0200
    [...]
    Successfully pushed image-registry.openshift-image-registry.svc:5000/camel-quarkus/camel-quarkus-xmlvalidation-api-s2i@sha256:024fcbaf80ec49e5f044f9af96e176e5fb16ba3325e7d6cee5d70c4884289a69
    Push successful
  4. Create a non-secure route to expose the Camel-Quarkus-XmlValidation-Api.postman_collection service outside the OpenShift cluster
    oc expose svc/camel-quarkus-xmlvalidation-api

Testing the application on OpenShift

  1. Get the OpenShift route hostname

    URL="http://$(oc get route camel-quarkus-xmlvalidation-api -o jsonpath='{.spec.host}')"
  2. Test the /validateMembershipJSON endpoint

    curl -w '\n' -X POST -H 'Content-Type: text/xml' \
    -d '<?xml version="1.0" encoding="UTF-8"?><p:membership xmlns:p="http://www.github.com/jeanNyil/schemas/membership/v1.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><p:requestType>API</p:requestType><p:requestID>5948</p:requestID><p:memberID>85623617</p:memberID><p:status>A</p:status><p:enrolmentDate>2020-09-05</p:enrolmentDate><p:changedBy>JaLiLa</p:changedBy><p:forcedLevelCode>69</p:forcedLevelCode><p:vipOnInvitation>Y</p:vipOnInvitation><p:startDate>2020-09-05</p:startDate><p:endDate>2100-09-05</p:endDate></p:membership>' \
    $URL/validateMembershipXML
    {
        "validationResult" : {
            "status" : "OK"
        }
    }
  3. Test the /health endpoint

    curl -w '\n' $URL/health
    {
        "status": "UP",
        "checks": [
            {
                "name": "camel-liveness-checks",
                "status": "UP"
            },
            {
                "name": "camel-context-check",
                "status": "UP",
                "data": {
                    "contextStatus": "Started",
                    "name": "camel-1"
                }
            },
            {
                "name": "camel-readiness-checks",
                "status": "UP"
            }
        ]
    }
  4. Test the /health/live endpoint

    curl -w '\n' $URL/health/live
    {
        "status": "UP",
        "checks": [
            {
                "name": "camel-liveness-checks",
                "status": "UP"
            }
        ]
    }
  5. Test the /health/ready endpoint

    curl -w '\n' $URL/health/ready
    {
        "status": "UP",
        "checks": [
            {
                "name": "camel-readiness-checks",
                "status": "UP"
            },
            {
                "name": "camel-context-check",
                "status": "UP",
                "data": {
                    "contextStatus": "Started",
                    "name": "camel-1"
                }
            }
        ]
    }
  6. Test the /metrics endpoint

    curl -w '\n' $URL/metrics
    [...]
    # HELP application_camel_context_exchanges_total The total number of exchanges for a route or Camel Context
    # TYPE application_camel_context_exchanges_total counter
    application_camel_context_exchanges_total{camelContext="camel-1"} 30.0
    [...]
    # HELP application_camel_route_exchanges_total The total number of exchanges for a route or Camel Context
    # TYPE application_camel_route_exchanges_total counter
    application_camel_route_exchanges_total{camelContext="camel-1",routeId="api-doc-route"} 0.0
    application_camel_route_exchanges_total{camelContext="camel-1",routeId="common-500-http-code-route"} 0.0
    application_camel_route_exchanges_total{camelContext="camel-1",routeId="custom-http-error-route"} 0.0
    application_camel_route_exchanges_total{camelContext="camel-1",routeId="validate-membership-xml-route"} 30.0
    application_camel_route_exchanges_total{camelContext="camel-1",routeId="xml-validation-api-route"} 30.0
    [...]

Testing using Postman

Import the provided Postman Collection for testing: tests/Camel-Quarkus-XmlValidation-Api.postman_collection.json Camel-Quarkus-XmlValidation-Api.postman_collection.png

Creating a native executable

Running locally

You can create a native executable using: ./mvnw package -Pnative.

Or, if you don't have GraalVM installed, you can run the native executable build in a container using: ./mvnw package -Pnative -Dquarkus.native.container-build=true.

You can then execute your native executable with: ./target/camel-quarkus-xmlvalidation-api-1.0.0-SNAPSHOT-runner

If you want to learn more about building native executables, please consult https://quarkus.io/guides/building-native-image.