forked from wildfly-extras/wildfly-camel
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[resolves wildfly-extras#1848] Add support for component rest-swagger
- Loading branch information
1 parent
da90c2c
commit a6b4b23
Showing
22 changed files
with
451 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
...ources/modules/system/layers/fuse/org/apache/camel/component/rest/swagger/main/module.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
121 changes: 121 additions & 0 deletions
121
...e/basic/src/test/java/org/wildfly/camel/test/rest/swagger/RestSwaggerIntegrationTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
itests/standalone/basic/src/test/java/org/wildfly/camel/test/rest/swagger/subA/Category.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
Oops, something went wrong.