搜索

此内容没有您所选择的语言版本。

Chapter 3. Implement, build, and deploy a Fuse application based on a REST API

download PDF

You can use Red Hat Fuse Apicurito 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 2.0 specification. For example, an openapi-spec.json file that you created with Apicurito.
  • Apicurito is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with Apicurito 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:

3.1. Uploading an API definition to Apicurito

You can upload an existing API definition to Apicurito.

Prerequisites

  • You have an existing API definition, which complies with the OpenAPI 2.0 specification. For example, an openapi.json file that you created with Apicurito.
  • Apicurito is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with Apicurito added as an application.

Procedure

  1. In your OpenShift web console, open the project that contains Apicurito.
  2. Open the Apicurito console. In the list of applications for the project, click the URL under apicurito. For example: https://apicurito-myproject.192.168.64.38.nip.io

    apicurito url

    The Apicurito console opens in a separate web browser tab or window:

    apicurito welcome
  3. Click Open API.

    A file manager window opens.

  4. In the file manager window:

    1. Navigate to the folder that contains the existing OpenAPI definition file, for example, openapi.json.
    2. Select the OpenAPI definition file and then click Open.

      The OpenAPI definition opens in the Apicurito console. For example:

      apicurito open

3.2. Generating a Fuse Camel project from Apicurito

You can use Apicurito to generate a Fuse Camel project based on an API definition.

Prerequisites

  • Apicurito is installed and running on your local OpenShift cluster.
  • You have an existing OpenShift project with Apicurito added as an application.
  • You have created or opened an API definition file in the Apicurito console.

Procedure

In the Apicurito console:

  1. Click Generate.
  2. Select Fuse Camel Project from the drop-down list.

Apicurito 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.

3.3. Completing the Apicurito-generated Camel project

Apicurito 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 Apicurito.
  • (Optional) You have installed Red Hat Developer Studio with Fuse Tooling.

Procedure

  1. Unzip the Apicurito-generated camel-project.zip file to a temporary folder.
  2. Open Red Hat Developer Studio.
  3. In Developer Studio, select File Import.
  4. In the Import dialog, select Maven Existing Maven Projects.
  5. Open the project’s camel-context.xml file in the editor view.
  6. 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.

  7. 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.

3.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:

  1. Log in to your OpenShift cluster:

    $ oc login -u developer -p developer
  2. Create a new OpenShift project for the project. For example, the following command creates a new project named test-deploy.

    $ oc new-project test-deploy
  3. Change the directory to the folder that contains your Fuse Camel project (for example, myworkspace/camel-project) :

    $ cd myworkspace/camel-project
  4. Build and deploy the project to the OpenShift cluster:

    $ mvn clean fabric8:deploy -Popenshift
  5. 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.
  6. 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.
  7. Click the URL to access the service.
Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.