Skip to content

Commit

Permalink
Add REST OpenApi native support
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed May 18, 2020
1 parent 692e5bf commit 4b729c6
Show file tree
Hide file tree
Showing 18 changed files with 235 additions and 63 deletions.
1 change: 1 addition & 0 deletions .github/test-categories.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ platform:
- platform-http
- platform-http-engine
- reactive-streams
- rest-openapi
saas:
- box
- github
Expand Down
4 changes: 2 additions & 2 deletions docs/modules/ROOT/pages/list-of-camel-quarkus-extensions.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -526,8 +526,8 @@ Level | Since | Description
Stable | 0.2.0 | Expose OpenAPI Specification of the REST services defined using Camel REST DSL.

| link:https://camel.apache.org/components/latest/rest-openapi-component.html[REST OpenApi] (camel-quarkus-rest-openapi) +
`rest-openapi:specificationUri#operationId` | JVM +
Preview | 1.0.0-M6 | Configure REST producers based on an OpenAPI specification document delegating to a component implementing the RestProducerFactory interface.
`rest-openapi:specificationUri#operationId` | Native +
Stable | 1.0.0-M6 | Configure REST producers based on an OpenAPI specification document delegating to a component implementing the RestProducerFactory interface.

| link:https://camel.apache.org/components/latest/salesforce-component.html[Salesforce] (camel-quarkus-salesforce) +
`salesforce:operationName:topicName` | Native +
Expand Down
1 change: 0 additions & 1 deletion extensions-jvm/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,6 @@
<module>protobuf</module>
<module>pubnub</module>
<module>rabbitmq</module>
<module>rest-openapi</module>
</modules>

</project>
1 change: 1 addition & 0 deletions extensions/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@
<module>reactive-streams</module>
<module>ref</module>
<module>rest</module>
<module>rest-openapi</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>scheduler</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-rest-deployment</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-rest-openapi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,15 @@
package org.apache.camel.quarkus.component.rest.openapi.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.deployment.pkg.steps.NativeBuild;
import org.apache.camel.quarkus.core.JvmOnlyRecorder;
import org.jboss.logging.Logger;

class RestOpenapiProcessor {

private static final Logger LOG = Logger.getLogger(RestOpenapiProcessor.class);
private static final String FEATURE = "camel-rest-openapi";

@BuildStep
FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

/**
* Remove this once this extension starts supporting the native mode.
*/
@BuildStep(onlyIf = NativeBuild.class)
@Record(value = ExecutionTime.RUNTIME_INIT)
void warnJvmInNative(JvmOnlyRecorder recorder) {
JvmOnlyRecorder.warnJvmInNative(LOG, FEATURE); // warn at build time
recorder.warnJvmInNative(FEATURE); // warn at runtime
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,5 @@
<modules>
<module>deployment</module>
<module>runtime</module>
<module>integration-test</module>
</modules>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-rest</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rest-openapi</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@
name: "Camel REST OpenApi"
description: "Configure REST producers based on an OpenAPI specification document delegating to a component implementing the RestProducerFactory interface"
metadata:
unlisted: true
guide: "https://camel.apache.org/components/latest/rest-openapi-component.html"
categories:
- "integration"
status: "preview"
1 change: 1 addition & 0 deletions integration-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@
<module>reactive-streams</module>
<module>ref</module>
<module>rest-binding-mode-xml</module>
<module>rest-openapi</module>
<module>salesforce</module>
<module>sap-netweaver</module>
<module>scheduler</module>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-build-parent-it</artifactId>
<artifactId>camel-quarkus-integration-tests</artifactId>
<version>1.1.0-SNAPSHOT</version>
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
</parent>

<artifactId>camel-quarkus-rest-openapi-integration-test</artifactId>
<name>Camel Quarkus :: REST OpenApi :: Integration Test</name>
<artifactId>camel-quarkus-integration-test-rest-openapi</artifactId>
<name>Camel Quarkus :: Integration Tests :: REST OpenApi</name>
<description>Integration tests for Camel Quarkus REST OpenApi extension</description>

<properties>
Expand All @@ -37,10 +36,18 @@
<!-- explicit dependencies of this module in the Maven sense, although they are required by the Quarkus Maven plugin. -->
<!-- Please update rule whenever you change the dependencies of this module by running -->
<!-- mvn process-resources -Pformat from the root directory -->
<mvnd.builder.rule>camel-quarkus-rest-openapi-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
<mvnd.builder.rule>camel-quarkus-direct-deployment,camel-quarkus-netty-http-deployment,camel-quarkus-rest-openapi-deployment,camel-quarkus-support-policy-deployment</mvnd.builder.rule>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-direct</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-netty-http</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-rest-openapi</artifactId>
Expand All @@ -49,6 +56,14 @@
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-resteasy-jsonb</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
</dependency>

<!-- test dependencies -->
<dependency>
Expand Down Expand Up @@ -78,4 +93,34 @@
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<properties>
<quarkus.package.type>native</quarkus.package.type>
</properties>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-failsafe-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>integration-test</goal>
<goal>verify</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.rest.openapi.it;

import java.util.Collections;
import java.util.LinkedHashMap;
import java.util.Set;

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;

import org.apache.camel.quarkus.component.rest.openapi.it.model.Fruit;
import org.eclipse.microprofile.openapi.annotations.Operation;

@Path("/fruits")
@Produces(MediaType.APPLICATION_JSON)
public class FruitResource {

private Set<Fruit> fruits = Collections.newSetFromMap(Collections.synchronizedMap(new LinkedHashMap<>()));

public FruitResource() {
fruits.add(new Fruit("Apple", "Winter fruit"));
fruits.add(new Fruit("Pineapple", "Tropical fruit"));
}

@Operation(operationId = "list")
@GET
public Set<Fruit> list() {
return fruits;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,13 @@
*/
package org.apache.camel.quarkus.component.rest.openapi.it;

import io.quarkus.test.junit.QuarkusTest;
import io.restassured.RestAssured;
import org.junit.jupiter.api.Test;
import org.apache.camel.builder.RouteBuilder;

@QuarkusTest
class RestOpenapiTest {
public class RestOpenApiRoutes extends RouteBuilder {

@Test
public void loadComponentRestOpenapi() {
/* A simple autogenerated test */
RestAssured.get("/rest-openapi/load/component/rest-openapi")
.then()
.statusCode(200);
@Override
public void configure() throws Exception {
from("direct:start")
.toD("rest-openapi:#list?specificationUri=RAW(http://localhost:${header.test-port}/openapi?format=JSON)");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -16,36 +16,38 @@
*/
package org.apache.camel.quarkus.component.rest.openapi.it;

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.inject.Named;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.camel.CamelContext;
import org.jboss.logging.Logger;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.netty.http.NettyHttpComponent;

@Path("/rest-openapi")
@ApplicationScoped
public class RestOpenapiResource {

private static final Logger LOG = Logger.getLogger(RestOpenapiResource.class);

private static final String COMPONENT_REST_OPENAPI = "rest-openapi";
@Inject
CamelContext context;
ProducerTemplate producerTemplate;

@Path("/load/component/rest-openapi")
@Path("/fruits/list")
@Produces(MediaType.APPLICATION_JSON)
@GET
@Produces(MediaType.TEXT_PLAIN)
public Response loadComponentRestOpenapi() throws Exception {
/* This is an autogenerated test */
if (context.getComponent(COMPONENT_REST_OPENAPI) != null) {
return Response.ok().build();
}
LOG.warnf("Could not load [%s] from the Camel context", COMPONENT_REST_OPENAPI);
return Response.status(500, COMPONENT_REST_OPENAPI + " could not be loaded from the Camel context").build();
public Response invokeListFruitsOperation(@QueryParam("port") int port) {
String response = producerTemplate.requestBodyAndHeader("direct:start", null, "test-port", port, String.class);
return Response.ok().entity(response).build();
}

// TODO: Remove this for Camel 3.4.0. See https://issues.apache.org/jira/browse/CAMEL-15076
@javax.enterprise.inject.Produces
@Named("netty-http")
public NettyHttpComponent createNettyHttpComponent(CamelContext context) {
NettyHttpComponent nettyHttpComponent = new NettyHttpComponent();
nettyHttpComponent.setCamelContext(context);
return nettyHttpComponent;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.rest.openapi.it.model;

public class Fruit {

public String name;
public String description;

public Fruit(String name, String description) {
this.name = name;
this.description = description;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You under the Apache License, Version 2.0
* (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.camel.quarkus.component.rest.openapi.it;

import io.quarkus.test.junit.NativeImageTest;

@NativeImageTest
class RestOpenapiIT extends RestOpenapiTest {
}

0 comments on commit 4b729c6

Please sign in to comment.