CAMEL-9945 Upgrade to jetty 9.3 Java compiler uses the actual return type of the method in the compiled class and as the signature of `org.eclipse.jetty.client.HttpClient::getProtocolHandlers` method changed between Jetty 9.2 and 9.3 in return type it could be compiled and run against both versions, but it could not be compiled with one version and run against another.
This commit uses reflection when calling `getProtocolHandlers` method to maintain compatibility with 9.2 and 9.3 versions of Jetty regardless of compile time vs runtime version. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8392379c Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8392379c Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8392379c Branch: refs/heads/master Commit: 8392379c320aa6de48acf0a07105c70148487ff8 Parents: ca624ee Author: Zoran Regvart <[email protected]> Authored: Wed Jan 18 14:54:00 2017 +0100 Committer: Andrea Cosentino <[email protected]> Committed: Thu Jan 19 10:19:53 2017 +0100 ---------------------------------------------------------------------- .../camel/component/salesforce/SalesforceHttpClient.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/8392379c/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java ---------------------------------------------------------------------- diff --git a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java index 95095aa..68187c3 100644 --- a/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java +++ b/components/camel-salesforce/camel-salesforce-component/src/main/java/org/apache/camel/component/salesforce/SalesforceHttpClient.java @@ -52,6 +52,8 @@ public class SalesforceHttpClient extends HttpClient { private final Method addSecuirtyHandlerMethod; + private final Method getProtocolHandlersMethod; + public SalesforceHttpClient() { this(null); } @@ -75,6 +77,8 @@ public class SalesforceHttpClient extends HttpClient { } else { addSecuirtyHandlerMethod = getProtocolHandlersType.getMethod("put", ProtocolHandler.class); } + + getProtocolHandlersMethod = HttpClient.class.getMethod("getProtocolHandlers"); } catch (NoSuchMethodException e) { throw new IllegalStateException("Found no method of adding SalesforceSecurityHandler as ProtocolHandler to Jetty HttpClient. You need Jetty 9.2 or newer on the classpath."); } @@ -99,7 +103,7 @@ public class SalesforceHttpClient extends HttpClient { } // compensate for Jetty 9.2 vs 9.3 API change - final Object protocolHandlers = getProtocolHandlers(); + final Object protocolHandlers = getProtocolHandlersMethod.invoke(this); addSecuirtyHandlerMethod.invoke(protocolHandlers, new SalesforceSecurityHandler(this)); super.doStart();
