Skip to content

Commit

Permalink
[resolves wildfly-extras#395] Provide camel-swagger support - WIP
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Diesler committed May 4, 2015
1 parent d386efc commit a9b60e6
Show file tree
Hide file tree
Showing 36 changed files with 450 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,9 @@
/**
* @author <a href="mailto:cdewolf@redhat.com">Carlo de Wolf</a>
*/
public class HttpRequest {
public final class HttpRequest {

// Hide ctor
private HttpRequest(){
}

Expand Down Expand Up @@ -181,10 +182,12 @@ private HttpResponse processResponse(HttpURLConnection conn) throws IOException

if (throwExceptionOnFailure && responseCode != HttpURLConnection.HTTP_OK) {
final InputStream err = conn.getErrorStream();
try {
throw new IOException(read(err));
} finally {
err.close();
if (err != null) {
try {
throw new IOException(read(err));
} finally {
err.close();
}
}
}
final InputStream in = conn.getInputStream();
Expand All @@ -198,4 +201,29 @@ private HttpResponse processResponse(HttpURLConnection conn) throws IOException
}
}
}

public static class HttpResponse {
private int statusCode;
private String body;

public int getStatusCode() {
return statusCode;
}

public void setStatusCode(int statusCode) {
this.statusCode = statusCode;
}

public String getBody() {
return body;
}

public void setBody(String body) {
this.body = body;
}

public String toString() {
return "HttpResponse{status=" + statusCode + "}";
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,10 @@
*/
package org.wildfly.camel.test.docker.domain;

import java.io.File;
import java.io.FilenameFilter;
import java.util.concurrent.TimeUnit;

import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ContainerResource;
Expand All @@ -27,14 +31,10 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.common.HttpRequest;
import org.wildfly.camel.test.common.HttpResponse;
import org.wildfly.camel.test.common.HttpRequest.HttpResponse;
import org.wildfly.camel.test.common.docker.DeployCommand;
import org.wildfly.camel.test.common.docker.DockerCommand.Result;

import java.io.File;
import java.io.FilenameFilter;
import java.util.concurrent.TimeUnit;


@RunAsClient
@RunWith(Arquillian.class)
Expand Down
16 changes: 7 additions & 9 deletions itests/standalone/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@
-->


<!--
Set these VM properties in your IDE debugger
-Djava.util.logging.manager=org.jboss.logmanager.LogManager
-Dwildfly.camel.home=${workspace_loc:wildfly-camel-build}/target/wildfly-camel-1.0.0-SNAPSHOT
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -141,20 +135,24 @@
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<artifactId>camel-restlet</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-restlet</artifactId>
<artifactId>camel-rss</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rss</artifactId>
<artifactId>camel-script</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-soap</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-swagger</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-xmlsecurity</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.common.HttpRequest;
import org.wildfly.camel.test.common.HttpResponse;
import org.wildfly.camel.test.common.HttpRequest.HttpResponse;

@RunWith(Arquillian.class)
public class RestDslIntegrationTest {
Expand All @@ -40,7 +40,7 @@ public class RestDslIntegrationTest {
public static WebArchive createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel.war");
archive.addAsWebInfResource("rest/web.xml", "web.xml");
archive.addClasses(HttpRequest.class, HttpResponse.class);
archive.addClasses(HttpRequest.class);
return archive;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.common.HttpRequest;
import org.wildfly.camel.test.common.HttpResponse;
import org.wildfly.camel.test.common.HttpRequest.HttpResponse;

@RunWith(Arquillian.class)
public class ServletIntegrationTest {
Expand All @@ -42,7 +42,7 @@ public class ServletIntegrationTest {
public static WebArchive createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "camel.war");
archive.addAsWebInfResource("servlet/web.xml", "web.xml");
archive.addClasses(HttpRequest.class, HttpResponse.class);
archive.addClasses(HttpRequest.class);
return archive;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
/*
* #%L
* Wildfly Camel :: Testsuite
* %%
* Copyright (C) 2013 - 2015 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.swagger;

import org.apache.camel.CamelContext;
import org.apache.camel.builder.RouteBuilder;
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.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.wildfly.camel.test.common.HttpRequest;
import org.wildfly.camel.test.common.HttpRequest.HttpResponse;

@RunWith(Arquillian.class)
public class SwaggerIntegrationTest {

@Deployment
public static WebArchive createDeployment() {
final WebArchive archive = ShrinkWrap.create(WebArchive.class, "swagger-tests.war");
archive.addAsWebInfResource("swagger/web.xml", "web.xml");
archive.addClasses(HttpRequest.class);
return archive;
}

@Test
public void testRestDsl() throws Exception {
CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
restConfiguration().component("servlet").contextPath("swagger-tests/rest").port(8080);
rest("/hello").get("/{name}").to("direct:hello");
from("direct:hello").transform(simple("Hello ${header.name}"));
}
});

camelctx.start();
try {
HttpResponse result = HttpRequest.get("http://localhost:8080/swagger-tests/rest/hello/Kermit").getResponse();
Assert.assertEquals("Hello Kermit", result.getBody());

result = HttpRequest.get("http://localhost:8080/swagger-tests/api-docs").getResponse();
System.out.println(result);
System.out.println(result.getBody());
} finally {
camelctx.stop();
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
[includes]
^ca/uhn/hl7v2(.*)
^com/google/protobuf
^com/wordnik/swagger(.*)
^org/apache/abdera(.*)
^org/apache/activemq
^org/apache/activemq/camel(.*)
Expand Down
43 changes: 43 additions & 0 deletions itests/standalone/src/test/resources/swagger/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<web-app>

<servlet>
<servlet-name>CamelServlet</servlet-name>
<servlet-class>org.apache.camel.component.servlet.CamelHttpTransportServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>

<servlet>
<servlet-name>ApiDeclarationServlet</servlet-name>
<servlet-class>org.apache.camel.component.swagger.DefaultCamelSwaggerServlet</servlet-class>
<init-param>
<param-name>base.path</param-name>
<param-value>rest</param-value>
</init-param>
<init-param>
<param-name>api.path</param-name>
<param-value>api-docs</param-value>
</init-param>
<init-param>
<param-name>api.version</param-name>
<param-value>1.2.3</param-value>
</init-param>
<init-param>
<param-name>api.title</param-name>
<param-value>User Services</param-value>
</init-param>
<init-param>
<param-name>api.description</param-name>
<param-value>Camel Rest Example with Swagger that provides an User REST service</param-value>
</init-param>
<load-on-startup>2</load-on-startup>
</servlet>

<servlet-mapping>
<servlet-name>CamelServlet</servlet-name>
<url-pattern>/rest/*</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>ApiDeclarationServlet</servlet-name>
<url-pattern>/api-docs/*</url-pattern>
</servlet-mapping>
</web-app>
19 changes: 19 additions & 0 deletions modules/etc/baseline/exported-paths.txt
Original file line number Diff line number Diff line change
Expand Up @@ -236,6 +236,24 @@ ca/uhn/hl7v2/validation/builder/support
ca/uhn/hl7v2/validation/impl
ca/uhn/hl7v2/view
com/google/protobuf
com/wordnik/swagger
com/wordnik/swagger/annotations
com/wordnik/swagger/config
com/wordnik/swagger/converter
com/wordnik/swagger/core
com/wordnik/swagger/core/filter
com/wordnik/swagger/core/util
com/wordnik/swagger/jaxrs
com/wordnik/swagger/jaxrs/config
com/wordnik/swagger/jaxrs/filter
com/wordnik/swagger/jaxrs/json
com/wordnik/swagger/jaxrs/listing
com/wordnik/swagger/jaxrs/reader
com/wordnik/swagger/model
com/wordnik/swagger/reader
com/wordnik/swagger/servlet
com/wordnik/swagger/servlet/config
com/wordnik/swagger/servlet/listing
org/apache/abdera
org/apache/abdera/factory
org/apache/abdera/filter
Expand Down Expand Up @@ -309,6 +327,7 @@ org/apache/camel/component/rss
org/apache/camel/component/servlet
org/apache/camel/component/servlet/osgi
org/apache/camel/component/sql
org/apache/camel/component/swagger
org/apache/camel/component/velocity
org/apache/camel/component/weather
org/apache/camel/component/xmlsecurity
Expand Down
Loading

0 comments on commit a9b60e6

Please sign in to comment.