Chapter 4. Implementing, building, and deploying a Fuse application based on a REST API You can use Red Hat Fuse API Designer to generate a Camel Fuse project based on a REST API definition. In your Fuse development environment, you can complete the Camel routes and Rest DSL API. Finally, you can build the project and deploy the resulting application to Fuse on OpenShift. Prerequisites You have an existing API definition, which complies with the OpenAPI 3 (or 2) specification. For example, an openapi-spec.json file that you created with API Designer. API Designer is installed and running on your local OpenShift cluster. You have an existing OpenShift project with API Designer added as a service. You have installed Maven and Red Hat Fuse. The following topics describe how to implement, build, and deploy a Fuse application based on a REST API: Section 4.1, "Uploading an API definition to API Designer" Section 4.2, "Generating a Fuse Camel project from API Designer" Section 4.3, "Completing the API Designer-generated Camel project" Section 4.4, "Building and deploying a REST service" 4.1. Uploading an API definition to API Designer You can upload an existing API definition to API Designer. Prerequisites You have an existing API definition, which complies with the OpenAPI 3 (or 2) specification. For example, an openapi.json file that you created with API Designer. API Designer is installed and running on your local OpenShift cluster. You have an existing OpenShift project with API Designer added as an application. Procedure In your OpenShift web console, open the project that contains API Designer. Open the API Designer console. In the list of applications for the project, click the URL under apidesigner. For example: https://apidesigner-myproject.192.168.64.38.nip.io The API Designer console opens in a separate web browser tab or window. Click Open API . A file manager window opens. In the file manager window: Navigate to the folder that contains the existing OpenAPI definition file, for example, openapi.json . Select the OpenAPI definition file and then click Open . The OpenAPI definition opens in the API Designer console. 4.2. Generating a Fuse Camel project from API Designer You can use API Designer to generate a Fuse Camel project based on an API definition. Prerequisites API Designer is installed and running on your local OpenShift cluster. You have an existing OpenShift project with API Designer added as an application. You have created or opened an API definition file in the API Designer console. Procedure In the API Designer console: Click Generate . Select Fuse Camel Project from the drop-down list. API Designer generates a camel-project.zip file and downloads it to your local default download folder. The zip file contains a Fuse Camel project that provides a default skeleton implementation of the API definition using Camel's Rest DSL and includes all resource operations. The project also includes the original OpenAPI definition file that you used to generate the project. 4.3. Completing the API Designer-generated Camel project API Designer generates a Fuse project that provides a default skeleton implementation of the API definition using Camel's Rest DSL and covering all resource operations. In your Fuse development environment, you complete the project. Prerequisites You have a camel-project.zip file generated by API Designer. (Optional) You have installed Red Hat Developer Studio with Fuse Tooling. Procedure Unzip the API Designer-generated camel-project.zip file to a temporary folder. Open Red Hat Developer Studio. In Developer Studio, select File Import . In the Import dialog, select Maven Existing Maven Projects . Open the project's camel-context.xml file in the editor view. Click the REST tab to edit the Rest DSL components. For information on defining REST services, see the "Defining REST services" section of the Apache Camel Development Guide . For information on extending JAX-RS endpoints with Swagger support, see the Apache CXF Development Guide . For information on using the Fuse Tooling REST editor, see the "Viewing and editing Rest DSL components" section of the Tooling User Guide . In the Design tab, edit the Camel routes. For information on editing Camel routes, see the "Editing a routing context in the route editor" section of the Tooling User Guide . 4.4. Building and deploying a REST service After you complete the Fuse project, you can build and deploy the project in OpenShift. Prerequisites You have a complete, error-free Fuse project that defines a REST service. You have installed Java 8 JDK (or later) and Maven 3.3.x (or later). Procedure If you have a single-node OpenShift cluster, such as Minishift or the Red Hat Container Development Kit, installed and running , you can deploy your project there. To deploy this project to a running single-node OpenShift cluster: Log in to your OpenShift cluster: USD oc login -u developer -p developer Create a new OpenShift project for the project. For example, the following command creates a new project named test-deploy . Change the directory to the folder that contains your Fuse Camel project (for example, myworkspace/camel-project ) : Build and deploy the project to the OpenShift cluster: USD mvn clean fabric8:deploy -Popenshift In your browser, open the OpenShift console and navigate to the project (for example, test-deploy ). Wait until you can see that the pod for the camel-project application has started. On the project's Overview page, locate the URL for the camel-project application. The URL uses this form: http://camel-project-MY_PROJECT_NAME.OPENSHIFT_IP_ADDR.nip.io . Click the URL to access the service.

Commands:
oc login -u developer -p developer
oc new-project test-deploy
cd myworkspace/camel-project
mvn clean fabric8:deploy -Popenshift