Skip to content

Commit

Permalink
[resolves wildfly-extras#1848] Add support for component rest-swagger
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesnetherton committed May 23, 2017
1 parent da90c2c commit a6b4b23
Show file tree
Hide file tree
Showing 22 changed files with 451 additions and 2 deletions.
2 changes: 1 addition & 1 deletion catalog/src/main/resources/component.roadmap
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,7 @@ rabbitmq
ref
rest
rest-api
rest-swagger
rss
salesforce
sap-netweaver
Expand Down Expand Up @@ -176,7 +177,6 @@ openstack-nova
openstack-swift
pubnub
reactive-streams
rest-swagger
sjms2
tika
websocket
Expand Down
9 changes: 9 additions & 0 deletions docs/guide/components/camel-rest-swagger.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
### camel-rest-swagger

The https://github.com/apache/camel/blob/master/components/camel-rest-swagger/src/main/docs/rest-swagger-component.adoc[rest-swagger,window=_blank]
component can configure REST producers from a http://swagger.io/[Swagger,window=_blank] document and
delegate to a component implementing the `RestProducerFactory` interface such as:
* link:index.html#_camel_http4[camel-http4]
* link:index.html#_camel_undertow[camel-undertow]
2 changes: 2 additions & 0 deletions docs/guide/components/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,8 @@ include::camel-rabbitmq.adoc[]

include::camel-rest.adoc[]

include::camel-rest-swagger.adoc[]

include::camel-rss.adoc[]

include::camel-salesforce.adoc[]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<module name="org.apache.camel.component.protobuf" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.quartz2" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rabbitmq" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rest.swagger" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rss" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.salesforce" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.sap.netweaver" export="true" services="export" optional="true" />
Expand Down
17 changes: 17 additions & 0 deletions feature/etc/smartics/camel-modules.xml
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,8 @@
<include module="org.springframework.boot" />
</apply-to-dependencies>
<dependencies>
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="javax.api"/>
<module name="org.slf4j"/>
</dependencies>
Expand Down Expand Up @@ -1381,6 +1383,21 @@
</dependencies>
</module>

<module name="org.apache.camel.component.rest.swagger">
<include artifact="org.apache.camel:camel-rest-swagger" />
<apply-to-dependencies skip="true">
<include module="org.apache.camel.apt" />
<include module="org.springframework.boot" />
</apply-to-dependencies>
<dependencies>
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="javax.api"/>
<module name="org.slf4j"/>
</dependencies>
</module>

<module name="org.apache.camel.component.rss">
<include artifact="org.apache.camel:camel-rss" />
<apply-to-dependencies skip="true">
Expand Down
5 changes: 5 additions & 0 deletions feature/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,11 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-rabbitmq</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rest-swagger</artifactId>
<version>${version.apache.camel}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rss</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
<artifact name="${org.apache.camel:camel-jackson}" />
</resources>
<dependencies>
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="javax.api" />
<module name="org.slf4j" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@
<module name="org.apache.camel.component.protobuf" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.quartz2" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rabbitmq" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rest.swagger" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.rss" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.salesforce" export="true" services="export" optional="true" />
<module name="org.apache.camel.component.sap.netweaver" export="true" services="export" optional="true" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<module xmlns="urn:jboss:module:1.1" name="org.apache.camel.component.rest.swagger">
<resources>
<artifact name="${org.apache.camel:camel-rest-swagger}" />
</resources>
<dependencies>
<module name="com.fasterxml.jackson.core.jackson-annotations" />
<module name="com.fasterxml.jackson.core.jackson-core" />
<module name="com.fasterxml.jackson.core.jackson-databind" />
<module name="javax.api" />
<module name="org.slf4j" />
<module name="javax.xml.bind.api" />
<module name="org.apache.camel.component.swagger" />
<module name="org.apache.camel.core" />
</dependencies>
</module>
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
<module name="org.apache.commons.io" />
<module name="org.apache.commons.lang3" />
<module name="org.reflections" />
<module name="org.slf4j.ext" />
</dependencies>
<exports>
<exclude path="io/swagger" />
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2017 RedHat
* %%
* Licensed 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.
* #L%
*/
package org.wildfly.camel.test.rest.swagger;

import java.net.URI;

import javax.ws.rs.core.MediaType;
import javax.xml.bind.JAXBContext;

import org.apache.camel.ProducerTemplate;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.component.jackson.JacksonDataFormat;
import org.apache.camel.component.rest.swagger.RestSwaggerComponent;
import org.apache.camel.converter.jaxb.JaxbDataFormat;
import org.apache.camel.impl.DefaultCamelContext;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.rest.swagger.subA.Pet;
import org.wildfly.extension.camel.CamelAware;

@CamelAware
@RunWith(Arquillian.class)
public class RestSwaggerIntegrationTest {

@Deployment
public static JavaArchive createDeployment() {
return ShrinkWrap.create(JavaArchive.class, "camel-rest-swagger-tests.jar")
.addPackage(Pet.class.getPackage());
}

@Test
public void testRestSwaggerXML() throws Exception {
JAXBContext jaxbContext = JAXBContext.newInstance(Pet.class);
JaxbDataFormat jaxb = new JaxbDataFormat(jaxbContext);

DefaultCamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:getPetById")
.to("petstore:getPetById")
.unmarshal(jaxb);
}
});

RestSwaggerComponent petStoreComponent = new RestSwaggerComponent();
petStoreComponent.setSpecificationUri(new URI("http://petstore.swagger.io/v2/swagger.json"));
petStoreComponent.setComponentName("undertow");
petStoreComponent.setConsumes(MediaType.APPLICATION_XML);
petStoreComponent.setProduces(MediaType.APPLICATION_XML);

camelctx.addComponent("petstore", petStoreComponent);

camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
Pet pet = template.requestBodyAndHeader("direct:getPetById", null, "petId", "1", Pet.class);
Assert.assertNotNull(pet);
Assert.assertEquals(1, pet.getId().intValue());
} finally {
camelctx.stop();
}
}

@Test
public void testRestSwaggerJSON() throws Exception {
JacksonDataFormat jacksonDataFormat = new JacksonDataFormat();
jacksonDataFormat.setUnmarshalType(Pet.class);

DefaultCamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
from("direct:getPetById")
.to("petstore:getPetById")
.convertBodyTo(String.class)
.unmarshal(jacksonDataFormat);
}
});

RestSwaggerComponent petStoreComponent = new RestSwaggerComponent();
petStoreComponent.setSpecificationUri(new URI("http://petstore.swagger.io/v2/swagger.json"));
petStoreComponent.setComponentName("undertow");
petStoreComponent.setConsumes(MediaType.APPLICATION_JSON);
petStoreComponent.setProduces(MediaType.APPLICATION_JSON);

camelctx.addComponent("petstore", petStoreComponent);

camelctx.start();
try {
ProducerTemplate template = camelctx.createProducerTemplate();
Pet pet = template.requestBodyAndHeader("direct:getPetById", null, "petId", "1", Pet.class);
Assert.assertNotNull(pet);
Assert.assertEquals(1, pet.getId().intValue());
} finally {
camelctx.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2017 RedHat
* %%
* Licensed 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.
* #L%
*/
package org.wildfly.camel.test.rest.swagger.subA;

import com.fasterxml.jackson.annotation.JsonProperty;

public class Category {

@JsonProperty("id")
private Long id = null;

@JsonProperty("name")
private String name = null;

public Category id(Long id) {
this.id = id;
return this;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public Category name(String name) {
this.name = name;
return this;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
Loading

0 comments on commit a6b4b23

Please sign in to comment.