You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2015/11/16 18:10:19 UTC
[2/2] camel git commit: [CAMEL-9278] camel-undertow REST DSL support
[CAMEL-9278] camel-undertow REST DSL support
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/2d0c1428
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/2d0c1428
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/2d0c1428
Branch: refs/heads/master
Commit: 2d0c142844896ae00d1de52087fba224e25717ce
Parents: 8aab177
Author: James Netherton <ja...@gmail.com>
Authored: Fri Nov 13 11:27:55 2015 +0000
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 16 18:02:03 2015 +0100
----------------------------------------------------------------------
components/camel-undertow/pom.xml | 17 ++-
.../undertow/DefaultUndertowHttpBinding.java | 24 ++++-
.../component/undertow/UndertowComponent.java | 106 +++++++++++++------
.../component/undertow/UndertowConsumer.java | 5 +-
.../undertow/UndertowConsumerResolver.java | 66 ++++++++++++
.../component/undertow/UndertowRegistry.java | 26 ++---
.../undertow/handlers/HttpCamelHandler.java | 33 +++---
.../component/undertow/UndertowHeaderTest.java | 19 +++-
.../component/undertow/rest/CountryPojo.java | 40 +++++++
.../undertow/rest/RestApiUndertowTest.java | 67 ++++++++++++
.../component/undertow/rest/RestGetTest.java | 51 +++++++++
...UndertowHttpBindingModeAutoWithJsonTest.java | 59 +++++++++++
...tUndertowHttpBindingModeAutoWithXmlTest.java | 59 +++++++++++
.../RestUndertowHttpBindingModeJsonTest.java | 77 ++++++++++++++
.../RestUndertowHttpBindingModeXmlTest.java | 77 ++++++++++++++
...ndertowHttpContextPathConfigurationTest.java | 68 ++++++++++++
...RestUndertowHttpContextPathMatchGetTest.java | 68 ++++++++++++
.../undertow/rest/RestUndertowHttpGetTest.java | 66 ++++++++++++
.../rest/RestUndertowHttpGetWildcardsTest.java | 82 ++++++++++++++
.../rest/RestUndertowHttpPojoInOutTest.java | 70 ++++++++++++
.../RestUndertowHttpPostJsonJaxbPojoTest.java | 61 +++++++++++
.../RestUndertowHttpPostJsonPojoListTest.java | 68 ++++++++++++
.../rest/RestUndertowHttpPostJsonPojoTest.java | 61 +++++++++++
.../RestUndertowHttpPostXmlJaxbPojoTest.java | 79 ++++++++++++++
.../component/undertow/rest/UserJaxbPojo.java | 48 +++++++++
.../camel/component/undertow/rest/UserPojo.java | 40 +++++++
.../component/undertow/rest/UserService.java | 33 ++++++
.../src/test/resources/log4j.properties | 2 +-
28 files changed, 1410 insertions(+), 62 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/pom.xml
----------------------------------------------------------------------
diff --git a/components/camel-undertow/pom.xml b/components/camel-undertow/pom.xml
index 95acbca..7b00e49 100644
--- a/components/camel-undertow/pom.xml
+++ b/components/camel-undertow/pom.xml
@@ -62,6 +62,21 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jackson</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jaxb</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-swagger-java</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
@@ -73,4 +88,4 @@
</dependency>
</dependencies>
-</project>
\ No newline at end of file
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
index 7daa598..481d29a 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/DefaultUndertowHttpBinding.java
@@ -30,6 +30,7 @@ import io.undertow.client.ClientRequest;
import io.undertow.client.ClientResponse;
import io.undertow.connector.ByteBufferPool;
import io.undertow.connector.PooledByteBuffer;
+import io.undertow.predicate.Predicate;
import io.undertow.server.HttpServerExchange;
import io.undertow.util.Headers;
import io.undertow.util.HttpString;
@@ -116,8 +117,17 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding {
headersMap.put(Exchange.HTTP_QUERY, httpExchange.getQueryString());
headersMap.put(Exchange.HTTP_RAW_QUERY, httpExchange.getQueryString());
-
String path = httpExchange.getRequestPath();
+ UndertowEndpoint endpoint = (UndertowEndpoint) exchange.getFromEndpoint();
+ if (endpoint.getHttpURI() != null) {
+ // need to match by lower case as we want to ignore case on context-path
+ String endpointPath = endpoint.getHttpURI().getPath();
+ String matchPath = path.toLowerCase(Locale.US);
+ String match = endpointPath.toLowerCase(Locale.US);
+ if (match != null && matchPath.startsWith(match)) {
+ path = path.substring(endpointPath.length());
+ }
+ }
headersMap.put(Exchange.HTTP_PATH, path);
if (LOG.isTraceEnabled()) {
@@ -174,6 +184,18 @@ public class DefaultUndertowHttpBinding implements UndertowHttpBinding {
}
}
}
+
+ // Create headers for REST path placeholder variables
+ Map<String, Object> predicateContextParams = httpExchange.getAttachment(Predicate.PREDICATE_CONTEXT);
+ if (predicateContextParams != null) {
+ // Remove this as it's an unwanted artifact of our Undertow predicate chain
+ predicateContextParams.remove("remaining");
+
+ for (String paramName : predicateContextParams.keySet()) {
+ LOG.trace("REST Template Variable {}: {})", paramName, predicateContextParams.get(paramName));
+ headersMap.put(paramName, predicateContextParams.get(paramName));
+ }
+ }
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
index 695e376..28c4a2d 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowComponent.java
@@ -16,14 +16,23 @@
*/
package org.apache.camel.component.undertow;
+import io.undertow.Handlers;
+import io.undertow.Undertow;
+import io.undertow.attribute.ExchangeAttributes;
+import io.undertow.predicate.PathTemplatePredicate;
+import io.undertow.predicate.Predicate;
+import io.undertow.predicate.Predicates;
+import io.undertow.server.handlers.PathHandler;
+import io.undertow.server.handlers.PredicateHandler;
+
import java.net.URI;
import java.net.URISyntaxException;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
+import java.util.Locale;
import java.util.Map;
-import io.undertow.Handlers;
-import io.undertow.Undertow;
-import io.undertow.server.handlers.PathHandler;
import org.apache.camel.CamelContext;
import org.apache.camel.Consumer;
import org.apache.camel.Endpoint;
@@ -36,6 +45,7 @@ import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RestConsumerFactory;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.slf4j.Logger;
@@ -64,7 +74,14 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
// create the endpoint first
UndertowEndpoint endpoint = createEndpointInstance(endpointUri, this);
- endpoint.setUndertowHttpBinding(undertowHttpBinding);
+
+ UndertowHttpBinding binding = resolveAndRemoveReferenceParameter(parameters, "undertowHttpBinding", UndertowHttpBinding.class);
+ if (binding != null) {
+ endpoint.setUndertowHttpBinding(binding);
+ } else {
+ endpoint.setUndertowHttpBinding(undertowHttpBinding);
+ }
+
setProperties(endpoint, parameters);
if (options != null) {
endpoint.setOptions(options);
@@ -72,14 +89,14 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
// then re-create the http uri with the remaining parameters which the endpoint did not use
URI httpUri = URISupport.createRemainingURI(
- new URI(uriHttpUriAddress.getScheme(),
- uriHttpUriAddress.getUserInfo(),
- uriHttpUriAddress.getHost(),
- uriHttpUriAddress.getPort(),
- uriHttpUriAddress.getPath(),
- uriHttpUriAddress.getQuery(),
- uriHttpUriAddress.getFragment()),
- parameters);
+ new URI(uriHttpUriAddress.getScheme(),
+ uriHttpUriAddress.getUserInfo(),
+ uriHttpUriAddress.getHost(),
+ uriHttpUriAddress.getPort(),
+ uriHttpUriAddress.getPath(),
+ uriHttpUriAddress.getQuery(),
+ uriHttpUriAddress.getFragment()),
+ parameters);
endpoint.setHttpURI(httpUri);
return endpoint;
@@ -133,6 +150,16 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
port = num;
}
+ // prefix path with context-path if configured in rest-dsl configuration
+ String contextPath = config.getContextPath();
+ if (ObjectHelper.isNotEmpty(contextPath)) {
+ contextPath = FileUtil.stripTrailingSeparator(contextPath);
+ contextPath = FileUtil.stripLeadingSeparator(contextPath);
+ if (ObjectHelper.isNotEmpty(contextPath)) {
+ path = contextPath + "/" + path;
+ }
+ }
+
Map<String, Object> map = new HashMap<String, Object>();
// build query string, and append any endpoint configuration properties
if (config.getComponent() == null || config.getComponent().equals("undertow")) {
@@ -146,12 +173,14 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
String url;
if (api) {
- url = "undertow:%s://%s:%s/%s?matchOnUriPrefix=true";
+ url = "undertow:%s://%s:%s/%s?matchOnUriPrefix=true&httpMethodRestrict=%s";
} else {
- url = "undertow:%s://%s:%s/%s";
+ url = "undertow:%s://%s:%s/%s?httpMethodRestrict=%s";
}
- url = String.format(url, scheme, host, port, path);
+ String restrict = verb.toUpperCase(Locale.US);
+
+ url = String.format(url, scheme, host, port, path, restrict);
if (!query.isEmpty()) {
url = url + "&" + query;
@@ -218,26 +247,42 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
undertowRegistry.setServer(newServer);
}
- protected Undertow rebuildServer(UndertowRegistry registy) {
+ protected Undertow rebuildServer(UndertowRegistry registry) {
Undertow.Builder result = Undertow.builder();
- if (registy.getSslContext() != null) {
- result = result.addHttpsListener(registy.getPort(), registy.getHost(), registy.getSslContext());
+ if (registry.getSslContext() != null) {
+ result = result.addHttpsListener(registry.getPort(), registry.getHost(), registry.getSslContext());
} else {
- result = result.addHttpListener(registy.getPort(), registy.getHost());
- }
- PathHandler path = Handlers.path(new NotFoundHandler());
- for (URI key : registy.getConsumersRegistry().keySet()) {
- UndertowConsumer consumer = registy.getConsumersRegistry().get(key);
- URI httpUri = consumer.getEndpoint().getHttpURI();
- HttpCamelHandler handler = new HttpCamelHandler(consumer);
- if (consumer.getEndpoint().getMatchOnUriPrefix()) {
- path.addPrefixPath(httpUri.getPath(), handler);
+ result = result.addHttpListener(registry.getPort(), registry.getHost());
+ }
+
+ PathHandler pathHandler = Handlers.path(new NotFoundHandler());
+ HttpCamelHandler handler = new HttpCamelHandler();
+ List<Predicate> predicates = new ArrayList<Predicate>();
+ for (String key : registry.getConsumersRegistry().keySet()) {
+ UndertowConsumer consumer = registry.getConsumersRegistry().get(key);
+ UndertowEndpoint endpoint = consumer.getEndpoint();
+ String path = endpoint.getHttpURI().getPath();
+
+ // Assume URI contains REST variables
+ if (path.contains("{")) {
+ predicates.add(new PathTemplatePredicate(path, ExchangeAttributes.relativePath()));
} else {
- path.addExactPath(httpUri.getPath(), handler);
+ if (endpoint.getMatchOnUriPrefix()) {
+ predicates.add(Predicates.prefix(path));
+ } else {
+ predicates.add(Predicates.path(path));
+ }
}
- LOG.debug("Rebuild for path: {}", httpUri.getPath());
+
+ handler.connectConsumer(consumer);
+
+ LOG.debug("Rebuild for pathHandler: {}", path);
}
- result = result.setHandler(path);
+
+ Predicate combinedPathPredicate = Predicates.or(predicates.toArray(new Predicate[0]));
+ pathHandler.addPrefixPath("/", new PredicateHandler(combinedPathPredicate, handler, new NotFoundHandler()));
+
+ result = result.setHandler(pathHandler);
return result.build();
}
@@ -251,4 +296,5 @@ public class UndertowComponent extends UriEndpointComponent implements RestConsu
public void setUndertowHttpBinding(UndertowHttpBinding undertowHttpBinding) {
this.undertowHttpBinding = undertowHttpBinding;
}
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
index ae6ce7a..9eca7a3 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumer.java
@@ -64,8 +64,11 @@ public class UndertowConsumer extends DefaultConsumer {
URI httpUri = getEndpoint().getHttpURI();
UndertowHost host = getUndertowHost();
+ HttpCamelHandler httpCamelHandler = new HttpCamelHandler();
+ httpCamelHandler.connectConsumer(this);
+
host.validateEndpointURI(httpUri);
- host.registerHandler(httpUri.getPath(), new HttpCamelHandler(this));
+ host.registerHandler(httpUri.getPath(), httpCamelHandler) ;
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumerResolver.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumerResolver.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumerResolver.java
new file mode 100644
index 0000000..f8f4ec3
--- /dev/null
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowConsumerResolver.java
@@ -0,0 +1,66 @@
+package org.apache.camel.component.undertow;
+
+import io.undertow.server.HttpServerExchange;
+import io.undertow.util.HttpString;
+
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+
+import org.apache.camel.support.RestConsumerContextPathMatcher;
+
+public class UndertowConsumerResolver {
+
+ public UndertowConsumer resolve(HttpServerExchange exchange, Map<String, UndertowConsumer> consumers) {
+ UndertowConsumer answer = null;
+
+ String path = exchange.getRequestPath();
+ if (path == null) {
+ return null;
+ }
+ HttpString method = exchange.getRequestMethod();
+ if (method == null) {
+ return null;
+ }
+
+ List<RestConsumerContextPathMatcher.ConsumerPath> paths = new ArrayList<RestConsumerContextPathMatcher.ConsumerPath>();
+ for (final Map.Entry<String, UndertowConsumer> entry : consumers.entrySet()) {
+ paths.add(new RestConsumerContextPathMatcher.ConsumerPath<UndertowConsumer>() {
+ @Override
+ public String getRestrictMethod() {
+ return entry.getValue().getEndpoint().getHttpMethodRestrict();
+ }
+
+ @Override
+ public String getConsumerPath() {
+ return entry.getValue().getEndpoint().getHttpURI().getPath();
+ }
+
+ @Override
+ public UndertowConsumer getConsumer() {
+ return entry.getValue();
+ }
+ });
+ }
+
+ RestConsumerContextPathMatcher.ConsumerPath<UndertowConsumer> best = RestConsumerContextPathMatcher.matchBestPath(method.toString(), path, paths);
+ if (best != null) {
+ answer = best.getConsumer();
+ }
+
+ if (answer == null) {
+ for (String key : consumers.keySet()) {
+ String consumerPath = consumers.get(key).getEndpoint().getHttpURI().getPath();
+ UndertowConsumer consumer = consumers.get(key);
+ boolean matchOnUriPrefix = consumer.getEndpoint().getMatchOnUriPrefix();
+ if (RestConsumerContextPathMatcher.matchPath(path, consumerPath, matchOnUriPrefix)) {
+ answer = consumers.get(key);
+ break;
+ }
+ }
+ }
+
+ return answer;
+ }
+}
+
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowRegistry.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowRegistry.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowRegistry.java
index 195946a..6d7e434 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowRegistry.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowRegistry.java
@@ -33,11 +33,11 @@ public class UndertowRegistry {
private static final Logger LOG = LoggerFactory.getLogger(UndertowRegistry.class);
- int port;
- SSLContext sslContext;
- String host;
- Undertow server;
- Map<URI, UndertowConsumer> consumersRegistry = new HashMap<URI, UndertowConsumer>();
+ private int port;
+ private SSLContext sslContext;
+ private String host;
+ private Undertow server;
+ private Map<String, UndertowConsumer> consumersRegistry = new HashMap<String, UndertowConsumer>();
public UndertowRegistry(UndertowConsumer consumer, int port) {
registerConsumer(consumer);
@@ -56,24 +56,26 @@ public class UndertowRegistry {
}
public void registerConsumer(UndertowConsumer consumer) {
- URI httpUri = consumer.getEndpoint().getHttpURI();
+ UndertowEndpoint endpoint = consumer.getEndpoint();
+ URI httpUri = endpoint.getHttpURI();
if (host != null && !host.equals(httpUri.getHost())) {
throw new IllegalArgumentException("Cannot register UndertowConsumer on different host and same port: {}" + host + " " + httpUri.getHost());
} else {
host = httpUri.getHost();
}
LOG.info("Adding consumer to consumerRegistry: {}", httpUri);
- consumersRegistry.put(httpUri, consumer);
- if (sslContext != null && consumer.getEndpoint().getSslContext() != null) {
+ consumersRegistry.put(endpoint.getEndpointUri(), consumer);
+ if (sslContext != null && endpoint.getSslContext() != null) {
throw new IllegalArgumentException("Cannot register UndertowConsumer with different SSL config");
}
}
public void unregisterConsumer(UndertowConsumer consumer) {
- URI httpUri = consumer.getEndpoint().getHttpURI();
- if (consumersRegistry.containsKey(httpUri)) {
- consumersRegistry.remove(httpUri);
+ UndertowEndpoint endpoint = consumer.getEndpoint();
+ String endpointUri = endpoint.getEndpointUri();
+ if (consumersRegistry.containsKey(endpointUri)) {
+ consumersRegistry.remove(endpointUri);
} else {
LOG.debug("Cannot unregister consumer {} as it was not registered", consumer);
}
@@ -91,7 +93,7 @@ public class UndertowRegistry {
this.server = server;
}
- public Map<URI, UndertowConsumer> getConsumersRegistry() {
+ public Map<String, UndertowConsumer> getConsumersRegistry() {
return consumersRegistry;
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/HttpCamelHandler.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/HttpCamelHandler.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/HttpCamelHandler.java
index 0229b78..5061312 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/HttpCamelHandler.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/handlers/HttpCamelHandler.java
@@ -17,6 +17,8 @@
package org.apache.camel.component.undertow.handlers;
import java.nio.ByteBuffer;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
import io.undertow.server.HttpHandler;
import io.undertow.server.HttpServerExchange;
@@ -29,6 +31,7 @@ import org.apache.camel.Exchange;
import org.apache.camel.TypeConverter;
import org.apache.camel.component.undertow.ExchangeHeaders;
import org.apache.camel.component.undertow.UndertowConsumer;
+import org.apache.camel.component.undertow.UndertowConsumerResolver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -39,20 +42,20 @@ import org.slf4j.LoggerFactory;
* This class can be considered part of UndertowConsumer implementation.
*/
public class HttpCamelHandler implements HttpHandler {
- private static final Logger LOG = LoggerFactory.getLogger(UndertowConsumer.class);
-
- private UndertowConsumer consumer;
-
- public HttpCamelHandler(UndertowConsumer consumer) {
- this.consumer = consumer;
- }
-
- public UndertowConsumer getConsumer() {
- return consumer;
- }
+ private static final Logger LOG = LoggerFactory.getLogger(HttpCamelHandler.class);
+ private UndertowConsumerResolver resolver = new UndertowConsumerResolver();
+ private ConcurrentMap<String, UndertowConsumer> consumers = new ConcurrentHashMap<String, UndertowConsumer>();
@Override
public void handleRequest(HttpServerExchange httpExchange) throws Exception {
+ UndertowConsumer consumer = resolver.resolve(httpExchange, consumers);
+
+ if (consumer == null) {
+ LOG.debug("Unable to resolve consumer matching path {}", httpExchange.getRequestPath());
+ new NotFoundHandler().handleRequest(httpExchange);
+ return;
+ }
+
HttpString requestMethod = httpExchange.getRequestMethod();
if (Methods.OPTIONS.equals(requestMethod)) {
@@ -101,7 +104,7 @@ public class HttpCamelHandler implements HttpHandler {
consumer.doneUoW(camelExchange);
}
- Object body = getResponseBody(httpExchange, camelExchange);
+ Object body = getResponseBody(httpExchange, camelExchange, consumer);
TypeConverter tc = consumer.getEndpoint().getCamelContext().getTypeConverter();
if (body == null) {
@@ -115,8 +118,7 @@ public class HttpCamelHandler implements HttpHandler {
httpExchange.getResponseSender().close();
}
-
- private Object getResponseBody(HttpServerExchange httpExchange, Exchange camelExchange) {
+ private Object getResponseBody(HttpServerExchange httpExchange, Exchange camelExchange, UndertowConsumer consumer) {
Object result;
if (camelExchange.hasOut()) {
result = consumer.getEndpoint().getUndertowHttpBinding().toHttpResponse(httpExchange, camelExchange.getOut());
@@ -126,4 +128,7 @@ public class HttpCamelHandler implements HttpHandler {
return result;
}
+ public void connectConsumer(UndertowConsumer consumer) {
+ consumers.put(consumer.getEndpoint().getEndpointUri(), consumer);
+ }
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHeaderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHeaderTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHeaderTest.java
index 3485da0..937aeea 100644
--- a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHeaderTest.java
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/UndertowHeaderTest.java
@@ -30,7 +30,7 @@ public class UndertowHeaderTest extends BaseUndertowTest {
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URL, "http://localhost:" + getPort() + "/headers");
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URI, "/headers");
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_QUERY, "param=true");
- getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, "/headers");
+ getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, "");
String out = template.requestBody("http://localhost:" + getPort() + "/headers?param=true", null, String.class);
assertEquals("Bye World", out);
@@ -45,7 +45,7 @@ public class UndertowHeaderTest extends BaseUndertowTest {
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URL, "http://localhost:" + getPort() + "/headers");
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_URI, "/headers");
getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_QUERY, "");
- getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, "/headers");
+ getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, "");
String out = template.requestBody("http://localhost:" + getPort() + "/headers", "Hello World", String.class);
assertEquals("Bye World", out);
@@ -53,6 +53,17 @@ public class UndertowHeaderTest extends BaseUndertowTest {
assertMockEndpointsSatisfied();
}
+ @Test
+ public void testHttpPathHeader() throws Exception {
+ getMockEndpoint("mock:input").expectedMessageCount(1);
+ getMockEndpoint("mock:input").expectedHeaderReceived(Exchange.HTTP_PATH, "/headers");
+
+ String out = template.requestBody("http://localhost:" + getPort() + "/hello/headers", null, String.class);
+ assertEquals("Hello World", out);
+
+ assertMockEndpointsSatisfied();
+ }
+
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@@ -61,6 +72,10 @@ public class UndertowHeaderTest extends BaseUndertowTest {
from("undertow:http://localhost:{{port}}/headers")
.to("mock:input")
.transform().constant("Bye World");
+
+ from("undertow:http://localhost:{{port}}/hello?matchOnUriPrefix=true")
+ .to("mock:input")
+ .transform().constant("Hello World");
}
};
}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/CountryPojo.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/CountryPojo.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/CountryPojo.java
new file mode 100644
index 0000000..60de8f0
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/CountryPojo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.component.undertow.rest;
+
+public class CountryPojo {
+
+ private String iso;
+ private String country;
+
+ public String getIso() {
+ return iso;
+ }
+
+ public void setIso(String iso) {
+ this.iso = iso;
+ }
+
+ public String getCountry() {
+ return country;
+ }
+
+ public void setCountry(String country) {
+ this.country = country;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestApiUndertowTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestApiUndertowTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestApiUndertowTest.java
new file mode 100644
index 0000000..946c0b5
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestApiUndertowTest.java
@@ -0,0 +1,67 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestParamType;
+import org.junit.Test;
+
+public class RestApiUndertowTest extends BaseUndertowTest {
+
+ @Override
+ protected boolean useJmx() {
+ return true;
+ }
+
+ @Test
+ public void testApi() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/api-doc", null, String.class);
+ assertNotNull(out);
+ log.info(out);
+
+ assertTrue(out.contains("\"version\" : \"1.2.3\""));
+ assertTrue(out.contains("\"title\" : \"The hello rest thing\""));
+ assertTrue(out.contains("\"/hello/bye/{name}\""));
+ assertTrue(out.contains("\"/hello/hi/{name}\""));
+ assertTrue(out.contains("\"summary\" : \"To update the greeting message\""));
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("undertow").host("localhost").port(getPort()).apiContextPath("/api-doc")
+ .apiProperty("cors", "true").apiProperty("api.title", "The hello rest thing").apiProperty("api.version", "1.2.3");
+
+ rest("/hello").consumes("application/json").produces("application/json")
+ .get("/hi/{name}").description("Saying hi")
+ .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
+ .to("log:hi")
+ .get("/bye/{name}").description("Saying bye")
+ .param().name("name").type(RestParamType.path).dataType("string").description("Who is it").endParam()
+ .responseMessage().code(200).message("A reply message").endResponseMessage()
+ .to("log:bye")
+ .post("/bye").description("To update the greeting message").consumes("application/xml").produces("application/xml")
+ .param().name("greeting").type(RestParamType.body).dataType("string").description("Message to use as greeting").endParam()
+ .to("log:bye");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestGetTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestGetTest.java
new file mode 100644
index 0000000..5474278
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestGetTest.java
@@ -0,0 +1,51 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.junit.Test;
+
+public class RestGetTest extends BaseUndertowTest {
+
+ @Test
+ public void testUndertowProducerGet() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/users/123/basic", null, String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ public void configure() {
+ restConfiguration().component("undertow").host("localhost").port(getPort());
+ rest("/users/")
+ .get("{id}/basic")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithJsonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithJsonTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithJsonTest.java
new file mode 100644
index 0000000..dd03f09
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithJsonTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpBindingModeAutoWithJsonTest extends BaseUndertowTest {
+
+ @Test
+ public void testBindingMode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserPojo.class);
+
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").consumes("application/json").type(UserPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithXmlTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithXmlTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithXmlTest.java
new file mode 100644
index 0000000..528ca4b
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeAutoWithXmlTest.java
@@ -0,0 +1,59 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpBindingModeAutoWithXmlTest extends BaseUndertowTest {
+
+ @Test
+ public void testBindingMode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").consumes("application/xml").type(UserJaxbPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeJsonTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeJsonTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeJsonTest.java
new file mode 100644
index 0000000..d28b45e
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeJsonTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.CamelExecutionException;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpBindingModeJsonTest extends BaseUndertowTest {
+
+ @Test
+ public void testBindingMode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Test
+ public void testBindingModeWrong() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(0);
+
+ // we bind to json, but send in xml, which is not possible
+ String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+ try {
+ template.sendBody("http://localhost:" + getPort() + "/users/new", body);
+ fail("Should have thrown exception");
+ } catch (CamelExecutionException e) {
+ // expected
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.json);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").type(UserJaxbPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeXmlTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeXmlTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeXmlTest.java
new file mode 100644
index 0000000..33cb016
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpBindingModeXmlTest.java
@@ -0,0 +1,77 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpBindingModeXmlTest extends BaseUndertowTest {
+
+ @Test
+ public void testBindingMode() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Test
+ public void testBindingModeWrong() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(0);
+
+ // we bind to xml, but send in json, which is not possible
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ try {
+ template.sendBody("http://localhost:" + getPort() + "/users/new", body);
+ fail("Should have thrown exception");
+ } catch (Exception e) {
+ // expected
+ }
+
+ assertMockEndpointsSatisfied();
+ }
+
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.xml);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").type(UserJaxbPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathConfigurationTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathConfigurationTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathConfigurationTest.java
new file mode 100644
index 0000000..8a61abd
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathConfigurationTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.junit.Test;
+
+public class RestUndertowHttpContextPathConfigurationTest extends BaseUndertowTest {
+
+ @Test
+ public void testProducerGet() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/rest/users/123", null, String.class);
+ assertEquals("123;Donald Duck", out);
+
+ out = template.requestBody("undertow:http://localhost:{{port}}/rest/users/list", null, String.class);
+ assertEquals("123;Donald Duck\n456;John Doe", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ restConfiguration().component("undertow").contextPath("/rest").host("localhost").port(getPort());
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ })
+ .endRest()
+ .get("list")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getOut().setBody("123;Donald Duck\n456;John Doe");
+ }
+ });
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathMatchGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathMatchGetTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathMatchGetTest.java
new file mode 100644
index 0000000..e2b9e2c
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpContextPathMatchGetTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.junit.Test;
+
+public class RestUndertowHttpContextPathMatchGetTest extends BaseUndertowTest {
+
+ @Test
+ public void testProducerGet() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/users/123", null, String.class);
+ assertEquals("123;Donald Duck", out);
+
+ out = template.requestBody("undertow:http://localhost:{{port}}/users/list", null, String.class);
+ assertEquals("123;Donald Duck\n456;John Doe", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ restConfiguration().component("undertow").host("localhost").port(getPort());
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ })
+ .endRest()
+ .get("list")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ exchange.getOut().setBody("123;Donald Duck\n456;John Doe");
+ }
+ });
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetTest.java
new file mode 100644
index 0000000..4b1a256
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetTest.java
@@ -0,0 +1,66 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.component.undertow.DefaultUndertowHttpBinding;
+import org.apache.camel.component.undertow.UndertowHttpBinding;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class RestUndertowHttpGetTest extends BaseUndertowTest {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ UndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+ jndi.bind("mybinding", binding);
+ return jndi;
+ }
+ @Test
+ public void testProducerGet() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/users/123/basic", null, String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ restConfiguration().component("undertow").host("localhost").port(getPort()).endpointProperty("undertowHttpBinding", "#mybinding");
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/basic")
+ .route()
+ .to("mock:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ });
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetWildcardsTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetWildcardsTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetWildcardsTest.java
new file mode 100644
index 0000000..fb2a266
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpGetWildcardsTest.java
@@ -0,0 +1,82 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.Processor;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.component.undertow.DefaultUndertowHttpBinding;
+import org.apache.camel.component.undertow.UndertowHttpBinding;
+import org.apache.camel.impl.JndiRegistry;
+import org.junit.Test;
+
+public class RestUndertowHttpGetWildcardsTest extends BaseUndertowTest {
+
+ @Override
+ protected JndiRegistry createRegistry() throws Exception {
+ JndiRegistry jndi = super.createRegistry();
+ UndertowHttpBinding binding = new DefaultUndertowHttpBinding();
+ jndi.bind("mybinding", binding);
+ return jndi;
+ }
+
+ @Test
+ public void testProducerGet() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/users/123/basic", null, String.class);
+ assertEquals("123;Donald Duck", out);
+ }
+
+ @Test
+ public void testServletProducerGetWildcards() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:{{port}}/users/456/name=g*", null, String.class);
+ assertEquals("456;Goofy", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ restConfiguration().component("undertow").host("localhost").port(getPort()).endpointProperty("undertowHttpBinding", "#mybinding");
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .get("{id}/{query}")
+ .route()
+ .to("log:query")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Goofy");
+ }
+ }).endRest()
+ .get("{id}/basic")
+ .route()
+ .to("log:input")
+ .process(new Processor() {
+ public void process(Exchange exchange) throws Exception {
+ String id = exchange.getIn().getHeader("id", String.class);
+ exchange.getOut().setBody(id + ";Donald Duck");
+ }
+ }).endRest();
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPojoInOutTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPojoInOutTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPojoInOutTest.java
new file mode 100644
index 0000000..efc9a34
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPojoInOutTest.java
@@ -0,0 +1,70 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpPojoInOutTest extends BaseUndertowTest {
+
+ @Test
+ public void testUndertowPojoInOut() throws Exception {
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ String out = template.requestBody("undertow:http://localhost:" + getPort() + "/users/lives", body, String.class);
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
+
+ @Test
+ public void testUndertowGetRequest() throws Exception {
+ String out = template.requestBody("undertow:http://localhost:" + getPort() + "/users/lives", null, String.class);
+
+ assertNotNull(out);
+ assertEquals("{\"iso\":\"EN\",\"country\":\"England\"}", out);
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ // and enable auto binding mode
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ // just return the default country here
+ .get("lives").to("direct:start")
+ .post("lives").type(UserPojo.class).outType(CountryPojo.class)
+ .route()
+ .bean(new UserService(), "livesWhere");
+
+ CountryPojo country = new CountryPojo();
+ country.setIso("EN");
+ country.setCountry("England");
+
+ from("direct:start").transform().constant(country);
+
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonJaxbPojoTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonJaxbPojoTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonJaxbPojoTest.java
new file mode 100644
index 0000000..0d7d2ab
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonJaxbPojoTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpPostJsonJaxbPojoTest extends BaseUndertowTest {
+
+ @Test
+ public void testPostJaxbPojo() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ // and enable auto binding mode
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").type(UserJaxbPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoListTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoListTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoListTest.java
new file mode 100644
index 0000000..8a42dd1
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoListTest.java
@@ -0,0 +1,68 @@
+/**
+ * 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.component.undertow.rest;
+
+import java.util.List;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpPostJsonPojoListTest extends BaseUndertowTest {
+
+ @Test
+ public void testPostPojoList() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+
+ String body = "[ {\"id\": 123, \"name\": \"Donald Duck\"}, {\"id\": 456, \"name\": \"John Doe\"} ]";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ List list = mock.getReceivedExchanges().get(0).getIn().getBody(List.class);
+ assertNotNull(list);
+ assertEquals(2, list.size());
+
+ UserPojo user = (UserPojo) list.get(0);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ user = (UserPojo) list.get(1);
+ assertEquals(456, user.getId());
+ assertEquals("John Doe", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ // and enable auto binding mode
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").typeList(UserPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoTest.java
new file mode 100644
index 0000000..10b7b43
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostJsonPojoTest.java
@@ -0,0 +1,61 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpPostJsonPojoTest extends BaseUndertowTest {
+
+ @Test
+ public void testPostPojo() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserPojo.class);
+
+ String body = "{\"id\": 123, \"name\": \"Donald Duck\"}";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ // and enable auto binding mode
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").type(UserPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostXmlJaxbPojoTest.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostXmlJaxbPojoTest.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostXmlJaxbPojoTest.java
new file mode 100644
index 0000000..1b15bf0
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/RestUndertowHttpPostXmlJaxbPojoTest.java
@@ -0,0 +1,79 @@
+/**
+ * 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.component.undertow.rest;
+
+import org.apache.camel.Exchange;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.component.undertow.BaseUndertowTest;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.junit.Test;
+
+public class RestUndertowHttpPostXmlJaxbPojoTest extends BaseUndertowTest {
+
+ @Test
+ public void testPostJaxbPojo() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "<user name=\"Donald Duck\" id=\"123\"></user>";
+ template.sendBodyAndHeader("undertow:http://localhost:" + getPort() + "/users/new", body, Exchange.CONTENT_TYPE, "text/xml");
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(123, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Test
+ public void testPostJaxbPojoNoContentType() throws Exception {
+ MockEndpoint mock = getMockEndpoint("mock:input");
+ mock.expectedMessageCount(1);
+ mock.message(0).body().isInstanceOf(UserJaxbPojo.class);
+
+ String body = "<user name=\"Donald Duck\" id=\"456\"></user>";
+ template.sendBody("undertow:http://localhost:" + getPort() + "/users/new", body);
+
+ assertMockEndpointsSatisfied();
+
+ UserJaxbPojo user = mock.getReceivedExchanges().get(0).getIn().getBody(UserJaxbPojo.class);
+ assertNotNull(user);
+ assertEquals(456, user.getId());
+ assertEquals("Donald Duck", user.getName());
+ }
+
+ @Override
+ protected RouteBuilder createRouteBuilder() throws Exception {
+ return new RouteBuilder() {
+ @Override
+ public void configure() throws Exception {
+ // configure to use undertow on localhost with the given port
+ // and enable auto binding mode
+ restConfiguration().component("undertow").host("localhost").port(getPort()).bindingMode(RestBindingMode.auto);
+
+ // use the rest DSL to define the rest services
+ rest("/users/")
+ .post("new").type(UserJaxbPojo.class)
+ .to("mock:input");
+ }
+ };
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserJaxbPojo.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserJaxbPojo.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserJaxbPojo.java
new file mode 100644
index 0000000..15b5d7a
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserJaxbPojo.java
@@ -0,0 +1,48 @@
+/**
+ * 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.component.undertow.rest;
+
+import javax.xml.bind.annotation.XmlAccessType;
+import javax.xml.bind.annotation.XmlAccessorType;
+import javax.xml.bind.annotation.XmlAttribute;
+import javax.xml.bind.annotation.XmlRootElement;
+
+@XmlRootElement(name = "user")
+@XmlAccessorType(XmlAccessType.FIELD)
+public class UserJaxbPojo {
+
+ @XmlAttribute
+ private int id;
+ @XmlAttribute
+ private String name;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/2d0c1428/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserPojo.java
----------------------------------------------------------------------
diff --git a/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserPojo.java b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserPojo.java
new file mode 100644
index 0000000..affe0cf
--- /dev/null
+++ b/components/camel-undertow/src/test/java/org/apache/camel/component/undertow/rest/UserPojo.java
@@ -0,0 +1,40 @@
+/**
+ * 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.component.undertow.rest;
+
+public class UserPojo {
+
+ private int id;
+ private String name;
+
+ public int getId() {
+ return id;
+ }
+
+ public void setId(int id) {
+ this.id = id;
+ }
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+}