Skip to content
This repository has been archived by the owner on Jun 7, 2021. It is now read-only.

Commit

Permalink
Fixes SWARM-208: Add a camel-war example.
Browse files Browse the repository at this point in the history
  • Loading branch information
bobmcwhirter committed Dec 16, 2015
1 parent deb3284 commit fe046c2
Show file tree
Hide file tree
Showing 13 changed files with 705 additions and 0 deletions.
57 changes: 57 additions & 0 deletions camel/camel-war/README.adoc
@@ -0,0 +1,57 @@
= Camel in a `.war`

> Please raise any issues found with this example in this repo:
> https://github.com/wildfly-swarm/wildfly-swarm-examples/issues
>
> Issues related to *WildFly Swarm* core should be raised in our JIRA:
> https://issues.jboss.org/browse/SWARM

This example demonstrates how to use the default Camel `.war` demo
with WildFly Swarm.

== Project `pomx.xml`

The project is a normal maven project with `war` packaging.

[source,xml]
----
<packaging>war</packaging>
----

The project adds a `<plugin>` to configure `wildfly-swarm-plugin` to
create the runnable `.jar`.

[source,xml]
----
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
....
</plugin>
----

As with the other examples, this one inherits a few standard executions
from the parent `pom.xml`, particularly the `package` execution.

To define the needed parts of WildFly Swarm, a few dependencies are added
to support the `.war` deployment:

[source,xml]
----
<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-undertow</artifactId>
</dependency>
----

== Run

You can run it many ways:

* mvn package && java -jar ./target/example-camel-war-swarm.jar
* mvn wildfly-swarm:run
* In your IDE run the `org.wildfly.swarm.Swarm` class

== Use

http://localhost:8080/
92 changes: 92 additions & 0 deletions camel/camel-war/pom.xml
@@ -0,0 +1,92 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<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>

<parent>
<groupId>org.wildfly.swarm.examples</groupId>
<artifactId>examples-camel</artifactId>
<version>1.0.0.Alpha6-SNAPSHOT</version>
<relativePath>../</relativePath>
</parent>

<artifactId>example-camel-war</artifactId>
<name>WildFly Swarm Examples: Camel .war</name>
<description>WildFly Swarm Examples: Camel .war</description>
<packaging>war</packaging>

<properties>
<version.camel>2.16.1</version.camel>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-core</artifactId>
<version>${version.camel}</version>
</dependency>
<!-- we need servletlistener to bootstrap Camel -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servletlistener</artifactId>
<version>${version.camel}</version>
</dependency>
<!-- we use the servlet component in the Camel application -->
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-servlet</artifactId>
<version>${version.camel}</version>
</dependency>

<dependency>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-undertow</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>org.wildfly.swarm.examples</groupId>
<artifactId>examples-base</artifactId>
<version>${project.version}</version>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.wildfly.swarm</groupId>
<artifactId>wildfly-swarm-plugin</artifactId>
<version>${project.version}</version>
<executions>
<execution>
<id>package</id>
</execution>
<execution>
<id>start</id>
</execution>
<execution>
<id>stop</id>
</execution>
</executions>
</plugin>
</plugins>
</build>

</project>
@@ -0,0 +1,40 @@
package org.wildfly.swarm.it.camel;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.jboss.arquillian.drone.api.annotation.Drone;
import org.jboss.arquillian.junit.Arquillian;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.wildfly.swarm.it.AbstractIntegrationTest;

import static org.fest.assertions.Assertions.assertThat;

/**
* @author Bob McWhirter
*/
@RunWith(Arquillian.class)
public class CamelApplicationIT extends AbstractIntegrationTest {

private static Pattern REGEXP = Pattern.compile("Hello bob, how are you\\? You are from: [A-Z]+");

@Drone
WebDriver browser;

@Test
public void testIt() {
browser.navigate().to("http://localhost:8080/camel/hello");
assertThat(browser.getPageSource()).contains("Add a name parameter to uri, eg ?name=foo");

browser.navigate().to("http://localhost:8080/camel/hello?name=bob");

WebElement pre = browser.findElement(By.cssSelector("pre"));

Matcher matcher = REGEXP.matcher(pre.getText());
assertThat( matcher.matches() ).isTrue();
}
}
@@ -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.example.servletlistener;

import org.apache.camel.Header;
import org.apache.camel.language.Simple;

public class HelloBean {

public String sayHello(@Header("name") String name, @Simple("${sys.user.country}") String country) {
return "Hello " + name + ", how are you? You are from: " + country;
}

}
@@ -0,0 +1,55 @@
/**
* 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.example.servletlistener;

import org.apache.camel.component.servletlistener.CamelContextLifecycle;
import org.apache.camel.component.servletlistener.ServletCamelContext;
import org.apache.camel.impl.JndiRegistry;

public class MyLifecycle implements CamelContextLifecycle<JndiRegistry> {

@Override
public void beforeStart(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// enlist our bean(s) in the registry
registry.bind("myBean", new HelloBean());
}

@Override
public void beforeStop(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// noop
}

@Override
public void afterStop(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// noop
}

@Override
public void beforeAddRoutes(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// noop
}

@Override
public void afterAddRoutes(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// noop
}

@Override
public void afterStart(ServletCamelContext camelContext, JndiRegistry registry) throws Exception {
// noop
}
}

0 comments on commit fe046c2

Please sign in to comment.