[CAMEL-9842] Expose additional endpoint configuration options to UndertowHost handler methods
Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8537bdd9 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8537bdd9 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8537bdd9 Branch: refs/heads/master Commit: 8537bdd99bdfe623083002bf011f9c326451cb55 Parents: 18f3e27 Author: James Netherton <jamesnether...@gmail.com> Authored: Fri Apr 8 16:33:52 2016 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Sat Apr 9 07:43:40 2016 +0200 ---------------------------------------------------------------------- .../undertow/HttpHandlerRegistrationInfo.java | 50 ++++++++++++++++++++ .../component/undertow/UndertowConsumer.java | 29 ++++++++---- .../camel/component/undertow/UndertowHost.java | 10 ++-- 3 files changed, 76 insertions(+), 13 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/8537bdd9/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/HttpHandlerRegistrationInfo.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/HttpHandlerRegistrationInfo.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/HttpHandlerRegistrationInfo.java new file mode 100644 index 0000000..85a1874 --- /dev/null +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/HttpHandlerRegistrationInfo.java @@ -0,0 +1,50 @@ +/** + * 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; + +import java.net.URI; + +public class HttpHandlerRegistrationInfo { + + private Boolean matchOnUriPrefix; + private String methodRestrict; + private URI uri; + + public String getMethodRestrict() { + return methodRestrict; + } + + public void setMethodRestrict(String methodRestrict) { + this.methodRestrict = methodRestrict; + } + + public URI getUri() { + return uri; + } + + public void setUri(URI uri) { + this.uri = uri; + } + + public Boolean isMatchOnUriPrefix() { + return matchOnUriPrefix; + } + + public void setMatchOnUriPrefix(Boolean matchOnUriPrefix) { + this.matchOnUriPrefix = matchOnUriPrefix; + } +} http://git-wip-us.apache.org/repos/asf/camel/blob/8537bdd9/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 f7d9ace..49efe0a 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 @@ -34,6 +34,7 @@ public class UndertowConsumer extends DefaultConsumer { private static final Logger LOG = LoggerFactory.getLogger(UndertowConsumer.class); private UndertowHost undertowHost; + private HttpHandlerRegistrationInfo registrationInfo; public UndertowConsumer(UndertowEndpoint endpoint, Processor processor) { super(endpoint, processor); @@ -61,28 +62,40 @@ public class UndertowConsumer extends DefaultConsumer { LOG.debug("Undertow consumer is starting"); getEndpoint().getComponent().registerConsumer(this); - URI httpUri = getEndpoint().getHttpURI(); UndertowHost host = getUndertowHost(); HttpCamelHandler httpCamelHandler = new HttpCamelHandler(); httpCamelHandler.connectConsumer(this); - host.validateEndpointURI(httpUri); - host.registerHandler(httpUri.getPath(), httpCamelHandler); + HttpHandlerRegistrationInfo registrationInfo = getHttpHandlerRegistrationInfo(); + + host.validateEndpointURI(registrationInfo.getUri()); + host.registerHandler(registrationInfo, httpCamelHandler); } @Override protected void doStop() { LOG.debug("Undertow consumer is stopping"); - URI httpUri = getEndpoint().getHttpURI(); + HttpHandlerRegistrationInfo registrationInfo = getHttpHandlerRegistrationInfo(); UndertowHost host = getUndertowHost(); - - host.unregisterHandler(httpUri.getPath()); + host.unregisterHandler(registrationInfo); getEndpoint().getComponent().unregisterConsumer(this); } + private HttpHandlerRegistrationInfo getHttpHandlerRegistrationInfo() { + if (registrationInfo == null) { + UndertowEndpoint endpoint = getEndpoint(); + + registrationInfo = new HttpHandlerRegistrationInfo(); + registrationInfo.setUri(endpoint.getHttpURI()); + registrationInfo.setMethodRestrict(endpoint.getHttpMethodRestrict()); + registrationInfo.setMatchOnUriPrefix(endpoint.getMatchOnUriPrefix()); + } + return registrationInfo; + } + class DefaultUndertowHost implements UndertowHost { @Override @@ -91,12 +104,12 @@ public class UndertowConsumer extends DefaultConsumer { } @Override - public void registerHandler(String path, HttpHandler handler) { + public void registerHandler(HttpHandlerRegistrationInfo registrationInfo, HttpHandler handler) { getEndpoint().getComponent().startServer(UndertowConsumer.this); } @Override - public void unregisterHandler(String path) { + public void unregisterHandler(HttpHandlerRegistrationInfo registrationInfo) { // do nothing } } http://git-wip-us.apache.org/repos/asf/camel/blob/8537bdd9/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHost.java ---------------------------------------------------------------------- diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHost.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHost.java index bd79986..1609ab6 100644 --- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHost.java +++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHost.java @@ -32,12 +32,12 @@ public interface UndertowHost { void validateEndpointURI(URI httpURI); /** - * Register a handler on the given path + * Register a handler with the given {@link HttpHandlerRegistrationInfo} */ - void registerHandler(String path, HttpHandler handler); + void registerHandler(HttpHandlerRegistrationInfo registrationInfo, HttpHandler handler); /** - * Unregister a handler on the given path + * Unregister a handler with the given {@link HttpHandlerRegistrationInfo} */ - void unregisterHandler(String path); -} \ No newline at end of file + void unregisterHandler(HttpHandlerRegistrationInfo registrationInfo); +}