You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by Claus Ibsen <cl...@gmail.com> on 2013/09/25 15:14:04 UTC

Re: git commit: CAMEL-6584: Fixed the compile-time dependency to the class 'sun.net.www.protocol.https.Handler'.

Hi

Great spotted Babak about the sun dependency.

Just a note that on camelContext you can/should use getInjector to
create a new instance of a class.
This supports using dependency injection that eg spring / blueprint
would do etc. But of course in this use-case
there is no such need and using object helper is fine. Just that if
you need to use that in the future the injector is the better choice.

On Wed, Sep 25, 2013 at 9:34 AM,  <bv...@apache.org> wrote:
> Updated Branches:
>   refs/heads/master bf7a5bc35 -> 0035248cc
>
>
> CAMEL-6584: Fixed the compile-time dependency to the class 'sun.net.www.protocol.https.Handler'.
>
> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0035248c
> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0035248c
> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0035248c
>
> Branch: refs/heads/master
> Commit: 0035248cc777a44f5e2b6a54bd49cda736553bf6
> Parents: bf7a5bc
> Author: Babak Vahdat <bv...@apache.org>
> Authored: Wed Sep 25 10:34:06 2013 +0200
> Committer: Babak Vahdat <bv...@apache.org>
> Committed: Wed Sep 25 10:34:06 2013 +0200
>
> ----------------------------------------------------------------------
>  .../component/splunk/SplunkConnectionFactory.java     | 14 ++++++++++++--
>  1 file changed, 12 insertions(+), 2 deletions(-)
> ----------------------------------------------------------------------
>
>
> http://git-wip-us.apache.org/repos/asf/camel/blob/0035248c/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
> ----------------------------------------------------------------------
> diff --git a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
> index e23a9b3..b64102f 100644
> --- a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
> +++ b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectionFactory.java
> @@ -16,6 +16,7 @@
>   */
>  package org.apache.camel.component.splunk;
>
> +import java.net.URLStreamHandler;
>  import java.util.concurrent.Callable;
>  import java.util.concurrent.ExecutorService;
>  import java.util.concurrent.Future;
> @@ -25,6 +26,7 @@ import com.splunk.Service;
>  import com.splunk.ServiceArgs;
>
>  import org.apache.camel.CamelContext;
> +import org.apache.camel.util.ObjectHelper;
>  import org.slf4j.Logger;
>  import org.slf4j.LoggerFactory;
>
> @@ -84,7 +86,6 @@ public class SplunkConnectionFactory {
>          this.useSunHttpsHandler = useSunHttpsHandler;
>      }
>
> -    @SuppressWarnings("restriction")
>      public Service createService(CamelContext camelContext) {
>          final ServiceArgs args = new ServiceArgs();
>          if (host != null) {
> @@ -108,8 +109,17 @@ public class SplunkConnectionFactory {
>          // useful in cases where you want to bypass app. servers https handling
>          // (wls i'm looking at you)
>          if (isUseSunHttpsHandler()) {
> -            args.setHTTPSHandler(new sun.net.www.protocol.https.Handler());
> +            String sunHandlerClassName = "sun.net.www.protocol.https.Handler";
> +            Class<URLStreamHandler> clazz = camelContext.getClassResolver().resolveClass(sunHandlerClassName, URLStreamHandler.class);
> +            if (clazz != null) {
> +                URLStreamHandler handler = ObjectHelper.newInstance(clazz);
> +                args.setHTTPSHandler(handler);
> +                LOG.debug("using the URLStreamHandler {} for {}", handler, args);
> +            } else {
> +                LOG.warn("could not resolve and use the URLStreamHandler class '{}'", sunHandlerClassName);
> +            }
>          }
> +
>          ExecutorService executor = camelContext.getExecutorServiceManager().newSingleThreadExecutor(this, "DefaultSplunkConnectionFactory");
>
>          Future<Service> future = executor.submit(new Callable<Service>() {
>



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen

Re: git commit: CAMEL-6584: Fixed the compile-time dependency to the class 'sun.net.www.protocol.https.Handler'.

Posted by Babak Vahdat <ba...@swissonline.ch>.
Hi Claus

Thanks for the hint.

As you said, although not much difference in this concrete case, but just
for the sake of being aligned with the good coding practice I changed the
code accordingly.

Babak

Am 25.09.13 15:14 schrieb "Claus Ibsen" unter <cl...@gmail.com>:

>Hi
>
>Great spotted Babak about the sun dependency.
>
>Just a note that on camelContext you can/should use getInjector to
>create a new instance of a class.
>This supports using dependency injection that eg spring / blueprint
>would do etc. But of course in this use-case
>there is no such need and using object helper is fine. Just that if
>you need to use that in the future the injector is the better choice.
>
>On Wed, Sep 25, 2013 at 9:34 AM,  <bv...@apache.org> wrote:
>> Updated Branches:
>>   refs/heads/master bf7a5bc35 -> 0035248cc
>>
>>
>> CAMEL-6584: Fixed the compile-time dependency to the class
>>'sun.net.www.protocol.https.Handler'.
>>
>> Project: http://git-wip-us.apache.org/repos/asf/camel/repo
>> Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/0035248c
>> Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/0035248c
>> Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/0035248c
>>
>> Branch: refs/heads/master
>> Commit: 0035248cc777a44f5e2b6a54bd49cda736553bf6
>> Parents: bf7a5bc
>> Author: Babak Vahdat <bv...@apache.org>
>> Authored: Wed Sep 25 10:34:06 2013 +0200
>> Committer: Babak Vahdat <bv...@apache.org>
>> Committed: Wed Sep 25 10:34:06 2013 +0200
>>
>> ----------------------------------------------------------------------
>>  .../component/splunk/SplunkConnectionFactory.java     | 14
>>++++++++++++--
>>  1 file changed, 12 insertions(+), 2 deletions(-)
>> ----------------------------------------------------------------------
>>
>>
>> 
>>http://git-wip-us.apache.org/repos/asf/camel/blob/0035248c/components/cam
>>el-splunk/src/main/java/org/apache/camel/component/splunk/SplunkConnectio
>>nFactory.java
>> ----------------------------------------------------------------------
>> diff --git 
>>a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk
>>/SplunkConnectionFactory.java
>>b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk
>>/SplunkConnectionFactory.java
>> index e23a9b3..b64102f 100644
>> --- 
>>a/components/camel-splunk/src/main/java/org/apache/camel/component/splunk
>>/SplunkConnectionFactory.java
>> +++ 
>>b/components/camel-splunk/src/main/java/org/apache/camel/component/splunk
>>/SplunkConnectionFactory.java
>> @@ -16,6 +16,7 @@
>>   */
>>  package org.apache.camel.component.splunk;
>>
>> +import java.net.URLStreamHandler;
>>  import java.util.concurrent.Callable;
>>  import java.util.concurrent.ExecutorService;
>>  import java.util.concurrent.Future;
>> @@ -25,6 +26,7 @@ import com.splunk.Service;
>>  import com.splunk.ServiceArgs;
>>
>>  import org.apache.camel.CamelContext;
>> +import org.apache.camel.util.ObjectHelper;
>>  import org.slf4j.Logger;
>>  import org.slf4j.LoggerFactory;
>>
>> @@ -84,7 +86,6 @@ public class SplunkConnectionFactory {
>>          this.useSunHttpsHandler = useSunHttpsHandler;
>>      }
>>
>> -    @SuppressWarnings("restriction")
>>      public Service createService(CamelContext camelContext) {
>>          final ServiceArgs args = new ServiceArgs();
>>          if (host != null) {
>> @@ -108,8 +109,17 @@ public class SplunkConnectionFactory {
>>          // useful in cases where you want to bypass app. servers https
>>handling
>>          // (wls i'm looking at you)
>>          if (isUseSunHttpsHandler()) {
>> -            args.setHTTPSHandler(new
>>sun.net.www.protocol.https.Handler());
>> +            String sunHandlerClassName =
>>"sun.net.www.protocol.https.Handler";
>> +            Class<URLStreamHandler> clazz =
>>camelContext.getClassResolver().resolveClass(sunHandlerClassName,
>>URLStreamHandler.class);
>> +            if (clazz != null) {
>> +                URLStreamHandler handler =
>>ObjectHelper.newInstance(clazz);
>> +                args.setHTTPSHandler(handler);
>> +                LOG.debug("using the URLStreamHandler {} for {}",
>>handler, args);
>> +            } else {
>> +                LOG.warn("could not resolve and use the
>>URLStreamHandler class '{}'", sunHandlerClassName);
>> +            }
>>          }
>> +
>>          ExecutorService executor =
>>camelContext.getExecutorServiceManager().newSingleThreadExecutor(this,
>>"DefaultSplunkConnectionFactory");
>>
>>          Future<Service> future = executor.submit(new
>>Callable<Service>() {
>>
>
>
>
>-- 
>Claus Ibsen
>-----------------
>Red Hat, Inc.
>Email: cibsen@redhat.com
>Twitter: davsclaus
>Blog: http://davsclaus.com
>Author of Camel in Action: http://www.manning.com/ibsen