You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by or...@apache.org on 2023/11/29 10:20:45 UTC
(camel) branch main updated (83aac223453 -> fa15bc9bfb8)
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a change to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
from 83aac223453 CAMEL-20159 - Camel-AWS-Config: Add Test-infra module (#12250)
new 66945c13aa2 CAMEL-20163: consolidate duplicated logging code
new 7ce96fd05f0 CAMEL-20163: consolidate channel handler code
new 4cbe31c0d81 CAMEL-20163: consolidate recreate URL code
new d45210afb84 CAMEL-20163: consolidate rest check code
new 8fc78a973c1 CAMEL-20163: consolidate adding in/out HTTP filters
new fa15bc9bfb8 CAMEL-20163: consolidate HTTP status range check
The 6 revisions listed above as "new" are entirely new to this
repository and will be described in separate emails. The revisions
listed as "add" were already present in the repository and have only
been added to this reference.
Summary of changes:
.../org/apache/camel/http/base/HttpHelper.java | 18 +-----
.../http/common/HttpHeaderFilterStrategy.java | 20 ++-----
.../common/HttpProtocolHeaderFilterStrategy.java | 16 +-----
.../apache/camel/component/http/HttpComponent.java | 7 +--
.../http/HttpComponentVerifierExtension.java | 12 ++--
.../http/KnativeHttpHeaderFilterStrategy.java | 16 +-----
.../netty/http/HttpClientInitializerFactory.java | 41 +++++---------
.../netty/http/HttpServerInitializerFactory.java | 12 +---
.../component/netty/http/InitializerHelper.java} | 27 +++++----
.../netty/http/NettyHttpHeaderFilterStrategy.java | 16 +-----
.../component/netty/http/NettyHttpHelper.java | 28 +---------
.../component/netty/http/NettyHttpProducer.java | 4 +-
.../http/PlatformHttpHeaderFilterStrategy.java | 16 +-----
.../component/undertow/UndertowComponent.java | 8 +--
.../undertow/UndertowHeaderFilterStrategy.java | 16 +-----
.../vertx/http/VertxHttpHeaderFilterStrategy.java | 19 ++-----
.../org/apache/camel/support/http/HttpUtil.java | 65 ++++++++++++++++++++++
17 files changed, 137 insertions(+), 204 deletions(-)
copy components/{camel-xmpp/src/main/java/org/apache/camel/component/xmpp/XmppLogger.java => camel-netty-http/src/main/java/org/apache/camel/component/netty/http/InitializerHelper.java} (53%)
(camel) 03/06: CAMEL-20163: consolidate recreate URL code
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 4cbe31c0d813631fb92902152aac17d51e90609d
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 05:58:43 2023 +0100
CAMEL-20163: consolidate recreate URL code
---
.../org/apache/camel/component/http/HttpComponent.java | 7 ++-----
.../camel/component/undertow/UndertowComponent.java | 8 +++-----
.../java/org/apache/camel/support/http/HttpUtil.java | 17 +++++++++++++++++
3 files changed, 22 insertions(+), 10 deletions(-)
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
index 9c49a4de718..779dfdf2cbb 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponent.java
@@ -46,6 +46,7 @@ import org.apache.camel.support.CamelContextHelper;
import org.apache.camel.support.PluginHelper;
import org.apache.camel.support.PropertyBindingSupport;
import org.apache.camel.support.RestProducerFactoryHelper;
+import org.apache.camel.support.http.HttpUtil;
import org.apache.camel.support.jsse.SSLContextParameters;
import org.apache.camel.support.service.ServiceHelper;
import org.apache.camel.util.FileUtil;
@@ -623,11 +624,7 @@ public class HttpComponent extends HttpCommonComponent implements RestProducerFa
}
}
- // get the endpoint
- String query = URISupport.createQueryString(map);
- if (!query.isEmpty()) {
- url = url + "?" + query;
- }
+ url = HttpUtil.recreateUrl(map, url);
parameters = parameters != null ? new HashMap<>(parameters) : new HashMap<>();
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 9ae60b8ae7f..e809dd90d65 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
@@ -59,6 +59,8 @@ import org.apache.camel.util.UnsafeUriCharactersEncoder;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.camel.support.http.HttpUtil.recreateUrl;
+
/**
* Represents the component that manages {@link UndertowEndpoint}.
*/
@@ -317,11 +319,7 @@ public class UndertowComponent extends DefaultComponent
}
}
- // get the endpoint
- String query = URISupport.createQueryString(map);
- if (!query.isEmpty()) {
- url = url + "?" + query;
- }
+ url = recreateUrl(map, url);
parameters = parameters != null ? new HashMap<>(parameters) : new HashMap<>();
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
index 6ba015fe164..e65edf7ef4d 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
@@ -17,11 +17,14 @@
package org.apache.camel.support.http;
+import java.util.Map;
+
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
import org.apache.camel.Message;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.StringHelper;
+import org.apache.camel.util.URISupport;
public final class HttpUtil {
private static final int INTERNAL_SERVER_ERROR = 500;
@@ -93,4 +96,18 @@ public final class HttpUtil {
}
}
+ /**
+ * Recreates the URL from a map of options
+ * @param map the map of options
+ * @param url the base URL
+ * @return the recreated URL
+ */
+ public static String recreateUrl(Map<String, Object> map, String url) {
+ // get the endpoint
+ String query = URISupport.createQueryString(map);
+ if (!query.isEmpty()) {
+ url = url + "?" + query;
+ }
+ return url;
+ }
}
(camel) 05/06: CAMEL-20163: consolidate adding in/out HTTP filters
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 8fc78a973c176d1873714c77816e5e56252787e5
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 06:20:36 2023 +0100
CAMEL-20163: consolidate adding in/out HTTP filters
---
.../http/common/HttpHeaderFilterStrategy.java | 20 ++++++--------------
.../common/HttpProtocolHeaderFilterStrategy.java | 16 ++--------------
.../http/KnativeHttpHeaderFilterStrategy.java | 16 ++--------------
.../netty/http/NettyHttpHeaderFilterStrategy.java | 16 ++--------------
.../http/PlatformHttpHeaderFilterStrategy.java | 16 ++--------------
.../undertow/UndertowHeaderFilterStrategy.java | 16 ++--------------
.../vertx/http/VertxHttpHeaderFilterStrategy.java | 19 +++++--------------
.../org/apache/camel/support/http/HttpUtil.java | 22 ++++++++++++++++++++++
8 files changed, 43 insertions(+), 98 deletions(-)
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
index 367630b3b12..bc7ca239979 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpHeaderFilterStrategy.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.http.common;
+import java.util.Set;
+
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -25,20 +28,8 @@ public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
}
protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ final Set<String> outFilter = getOutFilter();
+ HttpUtil.addCommonFilters(outFilter);
setLowerCase(true);
@@ -47,4 +38,5 @@ public class HttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
setOutFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
setInFilterStartsWith(CAMEL_FILTER_STARTS_WITH);
}
+
}
diff --git a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpProtocolHeaderFilterStrategy.java b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpProtocolHeaderFilterStrategy.java
index 59103f36c8d..dad15351231 100644
--- a/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpProtocolHeaderFilterStrategy.java
+++ b/components/camel-http-common/src/main/java/org/apache/camel/http/common/HttpProtocolHeaderFilterStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.http.common;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -26,14 +27,11 @@ public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrateg
// Just add the http headers here
protected void initialize() {
- getInFilter().add("host");
getInFilter().add("content-encoding");
getInFilter().add("content-language");
getInFilter().add("content-location");
getInFilter().add("content-md5");
- getInFilter().add("content-length");
- getInFilter().add("content-type");
getInFilter().add("content-range");
getInFilter().add("dav");
@@ -54,7 +52,6 @@ public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrateg
getInFilter().add("lock-token");
getInFilter().add("max-forwards");
getInFilter().add("overwrite");
- getInFilter().add("pragma");
getInFilter().add("proxy-authenticate");
getInFilter().add("proxy-authorization");
getInFilter().add("range");
@@ -70,16 +67,7 @@ public class HttpProtocolHeaderFilterStrategy extends DefaultHeaderFilterStrateg
getInFilter().add("www-authenticate");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getInFilter().add("cache-control");
- getInFilter().add("connection");
- getInFilter().add("date");
- getInFilter().add("trailer");
- getInFilter().add("transfer-encoding");
- getInFilter().add("upgrade");
- getInFilter().add("via");
- getInFilter().add("warning");
+ HttpUtil.addCommonFilters(getInFilter());
setLowerCase(true);
}
diff --git a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpHeaderFilterStrategy.java b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpHeaderFilterStrategy.java
index db3d165074e..342c371741f 100644
--- a/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpHeaderFilterStrategy.java
+++ b/components/camel-knative/camel-knative-http/src/main/java/org/apache/camel/component/knative/http/KnativeHttpHeaderFilterStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.knative.http;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
public class KnativeHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
public KnativeHttpHeaderFilterStrategy() {
@@ -24,20 +25,7 @@ public class KnativeHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy
}
protected final void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ HttpUtil.addCommonFilters(getOutFilter());
setLowerCase(true);
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
index 264dfa9f1a1..cb9bfb334b0 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHeaderFilterStrategy.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.netty.http;
import org.apache.camel.spi.HeaderFilterStrategy;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
/**
* Default Netty {@link HeaderFilterStrategy} used when binding with {@link NettyHttpBinding}.
@@ -29,20 +30,7 @@ public class NettyHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
}
protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ HttpUtil.addCommonFilters(getOutFilter());
setLowerCase(true);
diff --git a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
index 1e1780148a4..b3981e45f3e 100644
--- a/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
+++ b/components/camel-platform-http/src/main/java/org/apache/camel/component/platform/http/PlatformHttpHeaderFilterStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.platform.http;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
/**
* A copy of {@code org.apache.camel.http.common.HttpHeaderFilterStrategy}. Keep in sync or refactor
@@ -30,20 +31,7 @@ public class PlatformHttpHeaderFilterStrategy extends DefaultHeaderFilterStrateg
}
protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ HttpUtil.addCommonFilters(getOutFilter());
setLowerCase(true);
diff --git a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
index 7847a3df470..5805cb626b3 100644
--- a/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
+++ b/components/camel-undertow/src/main/java/org/apache/camel/component/undertow/UndertowHeaderFilterStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.component.undertow;
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
public class UndertowHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -25,20 +26,7 @@ public class UndertowHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
}
protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ HttpUtil.addCommonFilters(getOutFilter());
setLowerCase(true);
diff --git a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpHeaderFilterStrategy.java b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpHeaderFilterStrategy.java
index 6e36030d7fd..734eeea1ff0 100644
--- a/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpHeaderFilterStrategy.java
+++ b/components/camel-vertx/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpHeaderFilterStrategy.java
@@ -16,7 +16,10 @@
*/
package org.apache.camel.component.vertx.http;
+import java.util.Set;
+
import org.apache.camel.support.DefaultHeaderFilterStrategy;
+import org.apache.camel.support.http.HttpUtil;
public class VertxHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
@@ -25,20 +28,8 @@ public class VertxHttpHeaderFilterStrategy extends DefaultHeaderFilterStrategy {
}
protected void initialize() {
- getOutFilter().add("content-length");
- getOutFilter().add("content-type");
- getOutFilter().add("host");
- // Add the filter for the Generic Message header
- // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
- getOutFilter().add("cache-control");
- getOutFilter().add("connection");
- getOutFilter().add("date");
- getOutFilter().add("pragma");
- getOutFilter().add("trailer");
- getOutFilter().add("transfer-encoding");
- getOutFilter().add("upgrade");
- getOutFilter().add("via");
- getOutFilter().add("warning");
+ final Set<String> outFilter = getOutFilter();
+ HttpUtil.addCommonFilters(outFilter);
setLowerCase(true);
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
index e65edf7ef4d..7d2d028bf7b 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
@@ -18,6 +18,7 @@
package org.apache.camel.support.http;
import java.util.Map;
+import java.util.Set;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
@@ -110,4 +111,25 @@ public final class HttpUtil {
}
return url;
}
+
+ /**
+ * Add common in/out filters used in HTTP components
+ * @param filterSet The set instance containing the out filters
+ */
+ public static void addCommonFilters(Set<String> filterSet) {
+ filterSet.add("content-length");
+ filterSet.add("content-type");
+ filterSet.add("host");
+ // Add the filter for the Generic Message header
+ // http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html#sec4.5
+ filterSet.add("cache-control");
+ filterSet.add("connection");
+ filterSet.add("date");
+ filterSet.add("pragma");
+ filterSet.add("trailer");
+ filterSet.add("transfer-encoding");
+ filterSet.add("upgrade");
+ filterSet.add("via");
+ filterSet.add("warning");
+ }
}
(camel) 01/06: CAMEL-20163: consolidate duplicated logging code
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 66945c13aa25765ba8502328afbb306a616cc5ea
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 05:39:56 2023 +0100
CAMEL-20163: consolidate duplicated logging code
---
.../netty/http/HttpClientInitializerFactory.java | 10 +-----
.../netty/http/HttpServerInitializerFactory.java | 12 ++-----
.../component/netty/http/InitializerHelper.java | 42 ++++++++++++++++++++++
3 files changed, 46 insertions(+), 18 deletions(-)
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
index 2a0bc816f49..1e022ae112d 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
@@ -150,15 +150,7 @@ public class HttpClientInitializerFactory extends ClientInitializerFactory {
sniServerNames = answer.getSupportedSSLParameters().getServerNames();
}
} else {
- if (configuration.getKeyStoreFile() == null && configuration.getKeyStoreResource() == null) {
- LOG.debug("keystorefile is null");
- }
- if (configuration.getTrustStoreFile() == null && configuration.getTrustStoreResource() == null) {
- LOG.debug("truststorefile is null");
- }
- if (configuration.getPassphrase() == null) {
- LOG.debug("passphrase is null");
- }
+ InitializerHelper.logConfiguration(configuration);
char[] pw = configuration.getPassphrase() != null ? configuration.getPassphrase().toCharArray() : null;
SSLEngineFactory sslEngineFactory;
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
index 3badc6b9246..4d5a33ddbd3 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpServerInitializerFactory.java
@@ -42,6 +42,8 @@ import org.apache.camel.component.netty.ssl.SSLEngineFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.camel.component.netty.http.InitializerHelper.logConfiguration;
+
/**
* {@link ServerInitializerFactory} for the Netty HTTP server.
*/
@@ -147,15 +149,7 @@ public class HttpServerInitializerFactory extends ServerInitializerFactory {
if (configuration.getSslContextParameters() != null) {
answer = configuration.getSslContextParameters().createSSLContext(camelContext);
} else {
- if (configuration.getKeyStoreFile() == null && configuration.getKeyStoreResource() == null) {
- LOG.debug("keystorefile is null");
- }
- if (configuration.getTrustStoreFile() == null && configuration.getTrustStoreResource() == null) {
- LOG.debug("truststorefile is null");
- }
- if (configuration.getPassphrase() == null) {
- LOG.debug("passphrase is null");
- }
+ logConfiguration(configuration);
char[] pw = configuration.getPassphrase() != null ? configuration.getPassphrase().toCharArray() : null;
SSLEngineFactory sslEngineFactory;
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/InitializerHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/InitializerHelper.java
new file mode 100644
index 00000000000..b59e230bd3f
--- /dev/null
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/InitializerHelper.java
@@ -0,0 +1,42 @@
+/*
+ * 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.netty.http;
+
+import org.apache.camel.component.netty.NettyServerBootstrapConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public final class InitializerHelper {
+ private static final Logger LOG = LoggerFactory.getLogger(InitializerHelper.class);
+
+ private InitializerHelper() {
+
+ }
+
+ static void logConfiguration(NettyServerBootstrapConfiguration configuration) {
+ if (configuration.getKeyStoreFile() == null && configuration.getKeyStoreResource() == null) {
+ LOG.debug("keystorefile is null");
+ }
+ if (configuration.getTrustStoreFile() == null && configuration.getTrustStoreResource() == null) {
+ LOG.debug("truststorefile is null");
+ }
+ if (configuration.getPassphrase() == null) {
+ LOG.debug("passphrase is null");
+ }
+ }
+}
(camel) 02/06: CAMEL-20163: consolidate channel handler code
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit 7ce96fd05f082e12267e112d0a4851039b008422
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 05:48:55 2023 +0100
CAMEL-20163: consolidate channel handler code
---
.../netty/http/HttpClientInitializerFactory.java | 31 +++++++++-------------
1 file changed, 13 insertions(+), 18 deletions(-)
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
index 1e022ae112d..f8a549f4d78 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/HttpClientInitializerFactory.java
@@ -95,25 +95,9 @@ public class HttpClientInitializerFactory extends ClientInitializerFactory {
pipeline.addLast("http", new HttpClientCodec());
- List<ChannelHandler> encoders = producer.getConfiguration().getEncodersAsList();
- for (int x = 0; x < encoders.size(); x++) {
- ChannelHandler encoder = encoders.get(x);
- if (encoder instanceof ChannelHandlerFactory) {
- // use the factory to create a new instance of the channel as it may not be shareable
- encoder = ((ChannelHandlerFactory) encoder).newChannelHandler();
- }
- pipeline.addLast("encoder-" + x, encoder);
- }
+ addToPipeline(producer.getConfiguration().getEncodersAsList(), pipeline, "encoder-");
- List<ChannelHandler> decoders = producer.getConfiguration().getDecodersAsList();
- for (int x = 0; x < decoders.size(); x++) {
- ChannelHandler decoder = decoders.get(x);
- if (decoder instanceof ChannelHandlerFactory) {
- // use the factory to create a new instance of the channel as it may not be shareable
- decoder = ((ChannelHandlerFactory) decoder).newChannelHandler();
- }
- pipeline.addLast("decoder-" + x, decoder);
- }
+ addToPipeline(producer.getConfiguration().getDecodersAsList(), pipeline, "decoder-");
if (configuration.isDisableStreamCache()) {
pipeline.addLast("inbound-streamer", new HttpInboundStreamHandler());
}
@@ -133,6 +117,17 @@ public class HttpClientInitializerFactory extends ClientInitializerFactory {
pipeline.addLast("handler", new HttpClientChannelHandler(producer));
}
+ private void addToPipeline(List<ChannelHandler> handlers, ChannelPipeline pipeline, String prefix) {
+ for (int x = 0; x < handlers.size(); x++) {
+ ChannelHandler handler = handlers.get(x);
+ if (handler instanceof ChannelHandlerFactory) {
+ // use the factory to create a new instance of the channel as it may not be shareable
+ handler = ((ChannelHandlerFactory) handler).newChannelHandler();
+ }
+ pipeline.addLast(prefix + x, handler);
+ }
+ }
+
private SSLContext createSSLContext(NettyProducer producer) throws Exception {
NettyConfiguration configuration = producer.getConfiguration();
(camel) 06/06: CAMEL-20163: consolidate HTTP status range check
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit fa15bc9bfb82b656adb91ea76f60b0ea6ac24396
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 06:25:28 2023 +0100
CAMEL-20163: consolidate HTTP status range check
---
.../org/apache/camel/http/base/HttpHelper.java | 18 ++------------
.../component/netty/http/NettyHttpHelper.java | 28 +---------------------
.../component/netty/http/NettyHttpProducer.java | 4 +++-
.../org/apache/camel/support/http/HttpUtil.java | 26 ++++++++++++++++++++
4 files changed, 32 insertions(+), 44 deletions(-)
diff --git a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
index e13b4059774..fceec1ad010 100644
--- a/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
+++ b/components/camel-http-base/src/main/java/org/apache/camel/http/base/HttpHelper.java
@@ -24,6 +24,7 @@ import java.util.function.BiConsumer;
import org.apache.camel.Exchange;
import org.apache.camel.ExchangePropertyKey;
+import org.apache.camel.support.http.HttpUtil;
import org.apache.camel.util.CollectionHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -133,22 +134,7 @@ public final class HttpHelper {
* @return <tt>true</tt> if ok, <tt>false</tt> otherwise
*/
public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange) {
- String[] ranges = okStatusCodeRange.split(",");
- for (String range : ranges) {
- boolean ok;
- if (range.contains("-")) {
- int from = Integer.parseInt(StringHelper.before(range, "-"));
- int to = Integer.parseInt(StringHelper.after(range, "-"));
- ok = statusCode >= from && statusCode <= to;
- } else {
- int exact = Integer.parseInt(range);
- ok = exact == statusCode;
- }
- if (ok) {
- return true;
- }
- }
- return false;
+ return HttpUtil.isStatusCodeOk(statusCode, okStatusCodeRange);
}
/**
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
index 2ce85dd4a23..bae93d831e1 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpHelper.java
@@ -28,6 +28,7 @@ import io.netty.handler.codec.http.HttpMethod;
import org.apache.camel.Exchange;
import org.apache.camel.Message;
import org.apache.camel.RuntimeExchangeException;
+import org.apache.camel.support.http.HttpUtil;
import org.apache.camel.util.CollectionHelper;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -228,31 +229,4 @@ public final class NettyHttpHelper {
}
return uri;
}
-
- /**
- * Checks whether the given http status code is within the ok range
- *
- * @param statusCode the status code
- * @param okStatusCodeRange the ok range (inclusive)
- * @return <tt>true</tt> if ok, <tt>false</tt> otherwise
- */
- public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange) {
- String[] ranges = okStatusCodeRange.split(",");
- for (String range : ranges) {
- boolean ok;
- if (range.contains("-")) {
- int from = Integer.parseInt(StringHelper.before(range, "-"));
- int to = Integer.parseInt(StringHelper.after(range, "-"));
- ok = statusCode >= from && statusCode <= to;
- } else {
- int exact = Integer.parseInt(range);
- ok = exact == statusCode;
- }
- if (ok) {
- return true;
- }
- }
- return false;
- }
-
}
diff --git a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
index b86108e65b6..2c93e3ea2e0 100644
--- a/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
+++ b/components/camel-netty-http/src/main/java/org/apache/camel/component/netty/http/NettyHttpProducer.java
@@ -35,6 +35,8 @@ import org.apache.camel.util.StringHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import static org.apache.camel.support.http.HttpUtil.isStatusCodeOk;
+
/**
* HTTP based {@link NettyProducer}.
*/
@@ -167,7 +169,7 @@ public class NettyHttpProducer extends NettyProducer {
if (minOkRange > 0) {
ok = code >= minOkRange && code <= maxOkRange;
} else {
- ok = NettyHttpHelper.isStatusCodeOk(code, configuration.getOkStatusCodeRange());
+ ok = isStatusCodeOk(code, configuration.getOkStatusCodeRange());
}
if (ok) {
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
index 7d2d028bf7b..ef18289ca7f 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/http/HttpUtil.java
@@ -132,4 +132,30 @@ public final class HttpUtil {
filterSet.add("via");
filterSet.add("warning");
}
+
+ /**
+ * Checks whether the given http status code is within the ok range
+ *
+ * @param statusCode the status code
+ * @param okStatusCodeRange the ok range (inclusive)
+ * @return <tt>true</tt> if ok, <tt>false</tt> otherwise
+ */
+ public static boolean isStatusCodeOk(int statusCode, String okStatusCodeRange) {
+ String[] ranges = okStatusCodeRange.split(",");
+ for (String range : ranges) {
+ boolean ok;
+ if (range.contains("-")) {
+ int from = Integer.parseInt(StringHelper.before(range, "-"));
+ int to = Integer.parseInt(StringHelper.after(range, "-"));
+ ok = statusCode >= from && statusCode <= to;
+ } else {
+ int exact = Integer.parseInt(range);
+ ok = exact == statusCode;
+ }
+ if (ok) {
+ return true;
+ }
+ }
+ return false;
+ }
}
(camel) 04/06: CAMEL-20163: consolidate rest check code
Posted by or...@apache.org.
This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
commit d45210afb847bf0b9931feaf9e9bd61dbfbd26f6
Author: Otavio Rodolfo Piske <an...@gmail.com>
AuthorDate: Wed Nov 29 06:03:55 2023 +0100
CAMEL-20163: consolidate rest check code
---
.../camel/component/http/HttpComponentVerifierExtension.java | 12 ++++++++----
1 file changed, 8 insertions(+), 4 deletions(-)
diff --git a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
index b9d2d30210a..b600df01316 100644
--- a/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
+++ b/components/camel-http/src/main/java/org/apache/camel/component/http/HttpComponentVerifierExtension.java
@@ -51,14 +51,14 @@ final class HttpComponentVerifierExtension extends DefaultComponentVerifierExten
// Make a copy to avoid clashing with parent validation
final HashMap<String, Object> verifyParams = new HashMap<>(parameters);
// Check if validation is rest-related
- final boolean isRest = verifyParams.entrySet().stream().anyMatch(e -> e.getKey().startsWith("rest."));
+ final boolean isRest = verifyParams.entrySet().stream().anyMatch(HttpComponentVerifierExtension::isRest);
if (isRest) {
// Build the httpUri from rest configuration
verifyParams.put("httpUri", buildHttpUriFromRestParameters(parameters));
// Cleanup parameters map from rest related stuffs
- verifyParams.entrySet().removeIf(e -> e.getKey().startsWith("rest."));
+ verifyParams.entrySet().removeIf(HttpComponentVerifierExtension::isRest);
}
// Validate using the catalog
@@ -79,14 +79,14 @@ final class HttpComponentVerifierExtension extends DefaultComponentVerifierExten
// Make a copy to avoid clashing with parent validation
final HashMap<String, Object> verifyParams = new HashMap<>(parameters);
// Check if validation is rest-related
- final boolean isRest = verifyParams.entrySet().stream().anyMatch(e -> e.getKey().startsWith("rest."));
+ final boolean isRest = verifyParams.entrySet().stream().anyMatch(HttpComponentVerifierExtension::isRest);
if (isRest) {
// Build the httpUri from rest configuration
verifyParams.put("httpUri", buildHttpUriFromRestParameters(parameters));
// Cleanup parameters from rest related stuffs
- verifyParams.entrySet().removeIf(e -> e.getKey().startsWith("rest."));
+ verifyParams.entrySet().removeIf(HttpComponentVerifierExtension::isRest);
}
String httpUri = getOption(verifyParams, "httpUri", String.class).orElse(null);
@@ -146,6 +146,10 @@ final class HttpComponentVerifierExtension extends DefaultComponentVerifierExten
return builder.build();
}
+ private static boolean isRest(Map.Entry<String, Object> e) {
+ return e.getKey().startsWith("rest.");
+ }
+
// *********************************
// Helpers
// *********************************