This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit d4e208f1d792d9f4d30e28fd4c7fde04875f1a2a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Tue Feb 16 07:25:45 2021 +0100 CAMEL-16215: camel-vertx-http - Optimize isStatusCodeOk --- .../vertx/http/DefaultVertxHttpBinding.java | 6 +++--- .../component/vertx/http/VertxHttpEndpoint.java | 21 +++++++++++++++++++++ 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java index b78354b..8c955b5 100644 --- a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java +++ b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/DefaultVertxHttpBinding.java @@ -138,9 +138,8 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding { if (response.succeeded()) { Message message = exchange.getMessage(); VertxHttpConfiguration configuration = endpoint.getConfiguration(); - boolean statusCodeOk = HttpHelper.isStatusCodeOk(result.statusCode(), configuration.getOkStatusCodeRange()); - - if ((!configuration.isThrowExceptionOnFailure()) || (configuration.isThrowExceptionOnFailure() && statusCodeOk)) { + boolean ok = endpoint.isStatusCodeOk(result.statusCode()); + if ((!configuration.isThrowExceptionOnFailure()) || (configuration.isThrowExceptionOnFailure() && ok)) { populateResponseHeaders(exchange, result, configuration.getHeaderFilterStrategy()); message.setBody(processResponseBody(endpoint, exchange, result)); } else { @@ -239,4 +238,5 @@ public class DefaultVertxHttpBinding implements VertxHttpBinding { } return exception; } + } diff --git a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpEndpoint.java b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpEndpoint.java index a2e27ff..5c49105 100644 --- a/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpEndpoint.java +++ b/components/camel-vertx-http/src/main/java/org/apache/camel/component/vertx/http/VertxHttpEndpoint.java @@ -26,11 +26,13 @@ import org.apache.camel.Category; import org.apache.camel.Consumer; import org.apache.camel.Processor; import org.apache.camel.Producer; +import org.apache.camel.http.base.HttpHelper; import org.apache.camel.spi.UriEndpoint; import org.apache.camel.spi.UriParam; import org.apache.camel.support.DefaultEndpoint; import org.apache.camel.support.jsse.SSLContextParameters; import org.apache.camel.util.ObjectHelper; +import org.apache.camel.util.StringHelper; @UriEndpoint(firstVersion = "3.5.0", scheme = "vertx-http", title = "Vert.x HTTP Client", syntax = "vertx-http:httpUri", category = { Category.HTTP }, producerOnly = true, lenientProperties = true) @@ -40,6 +42,8 @@ public class VertxHttpEndpoint extends DefaultEndpoint { private VertxHttpConfiguration configuration; private WebClient webClient; + private int minOkRange; + private int maxOkRange; public VertxHttpEndpoint(String uri, VertxHttpComponent component, VertxHttpConfiguration configuration) { super(uri, component); @@ -52,6 +56,15 @@ public class VertxHttpEndpoint extends DefaultEndpoint { } @Override + protected void doInit() throws Exception { + if (!configuration.getOkStatusCodeRange().contains(",")) { + // default is 200-299 so lets optimize for this + minOkRange = Integer.parseInt(StringHelper.before(configuration.getOkStatusCodeRange(), "-")); + maxOkRange = Integer.parseInt(StringHelper.after(configuration.getOkStatusCodeRange(), "-")); + } + } + + @Override public Producer createProducer() throws Exception { return new VertxHttpProducer(this); } @@ -113,6 +126,14 @@ public class VertxHttpEndpoint extends DefaultEndpoint { return this.webClient; } + protected boolean isStatusCodeOk(int responseCode) { + if (minOkRange > 0) { + return responseCode >= minOkRange && responseCode <= maxOkRange; + } else { + return HttpHelper.isStatusCodeOk(responseCode, configuration.getOkStatusCodeRange()); + } + } + private void configureProxyOptionsIfRequired(WebClientOptions options) { if (isProxyConfigurationPresent()) { ProxyOptions proxyOptions = new ProxyOptions();