This project exposes a simple HTTP endpoint exposing a greeting service. The service is available at this address: http://hostname:port/api/greeting and returns a JSON response containing the greeting message.
{
"content": "Hello, World!"
}
To get started with this quickstart you'll need the following prerequisites:
Name | Description | Version |
---|---|---|
java | Java JDK | 8 |
maven | Apache Maven | 3.3.x |
oc | OpenShift Client | v1.4.x |
git | Git version management | 2.x |
In order to build and deploy this project on OpenShift, you need either:
- a local OpenShift instance such as Minishift,
- account on an OpenShift Online (OSO) instance, such as https://console.dev-preview-int.openshift.com/ instance.
To build and deploy this quickstart you can:
- run it locally (non in OpenShift),
- deploy it to OpenShift using Apache Maven,
- deploy it to OpenShift using a pipeline.
For the approach 2 and 3 you need to be logged in to your OpenShift instance.
If you are using Minishift
- Login to your OpenShift instance using:
oc login https://192.168.64.12:8443 -u developer -p developer
-
Open your browser to https://192.168.64.12:8443/console/, and log in using developer/developer.
-
Check that you have a project. If
oc project
returns an error, create a project with:
oc new-project myproject
If your are using OpenShift Online
- Go to OpenShift Online to get the token used
by the
oc
client for authentication and project access. - On the oc client, execute the following command to replace $MYTOKEN with the one from the Web Console:
oc login https://api.dev-preview-int.openshift.com --token=$MYTOKEN
- Check that you have a project. If
oc project
returns an error, create a project with:
oc new-project myproject
To run this quickstart locally:
- Execute the following Apache Maven command:
mvn clean package
The application is packaged as a fat-jar, i.e. a jar containing all the required dependencies to run the application. So the resulting artifact is a standalone application.
- Run the application using:
java -jar target/vertx-http-1.0.0-SNAPSHOT.jar
Alternatively, you can run it in dev mode using mvn compile vertx:run
.
- Access the application using a browser: http://localhost:8080.
Alternatively, you can invoke the greeting service directly using curl or httpie:
curl http://localhost:8080/api/greeting
curl http://localhost:8080/api/greeting?name=Bruno
http http://localhost:8080/api/greeting
http http://localhost:8080/api/greeting name==Charles
To deploy the application using Maven, launch:
mvn fabric8:deploy -Popenshift
This command builds and deploys the application to the OpenShift instance on which you are logged in.
Once deployed, you can access the application using the application URL. Retrieve it using:
$ oc get route vertx-http -o jsonpath={$.spec.host}
vertx-http-myproject.192.168.64.12.nip.io
Then, open your browser to the displayed url: http://vertx-http-myproject.192.168.64.12.nip.io.
Alternatively, you can invoke the greeting service directly using curl or httpie:
curl http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting
curl http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting?name=Bruno
http http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting
http http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting name==Charles
If you get a 503
response, it means that the application is not ready yet.
When deployed with a pipeline the application is built from the sources (from a git repository) by a continuous integration server (Jenkins) running in OpenShift.
To trigger this built:
- Apply the OpenShift template:
oc new-app -f src/openshift/openshift-pipeline-template.yml
- Trigger the pipeline build:
oc start-build vertx-http
With the sequence of command, you have deployed a Jenkins instance in your OpenShift project, define the build pipeline of the application and trigger a first build of the application.
Once the build is complete, you can access the application using the application URL. Retrieve this url using:
oc get route vertx-http -o jsonpath={$.spec.host}
Then, open your browser to the displayed url. For instance, http://vertx-http-myproject.192.168.64.12.nip.io.
Alternatively, you can invoke the greeting service directly using curl or httpie:
curl http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting
curl http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting?name=Bruno
http http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting
http http://vertx-http-myproject.192.168.64.12.nip.io/api/greeting name==Charles
If you get a 503
response, it means that the application is not ready yet.
The quickstart also contains a set of integration tests. You need to be connected to an OpenShift instance (Openshift Online or Minishift) to run them. You also need to select an existing project.
Then, run integration tests using:
mvn clean verify -Popenshift -Popenshift-it