You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@tomcat.apache.org by Dave Breeze <da...@gmail.com> on 2023/01/20 09:53:31 UTC

Setting java.protocol.handler.pkgs for Tomcat

Tomcat 9.0.71

I need to use a custom protocol handler. I set JAVA_OPTS to:

 -Djava.protocol.handler.pkgs=com.ibm.crypto.provider

My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
containing

JAVA_OPTS="$JAVA_OPTS
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources"

The result of catalina.sh is that the jvm has
2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
then org.apache.catalina.webresources. The net result being that Tomcat is
started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.


   1. What is the best way of setting java.protocol.handler.pkgs other than
   modifying catalina.sh
   2. do i need to set java.protocol.handler.pkgs to just my custom handler
   or should it be set to a concatenation of
   custom + org.apache.catalina.webresources
   3. if a concatenation of handlers is required what is the syntax

thank you


Dave Breeze
Linkedin:https://uk.linkedin.com/in/dabreeze

Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Dave Breeze <da...@gmail.com>.
thanks
i have just done a quick and dirty test - I found a tomcat launcher code I
did as an exercise - quickly modified it to set the handler to a
concatenation. Tomcat launches correctly and uses the ibm safkeyring

thanks again
Dave Breeze
Linkedin:https://uk.linkedin.com/in/dabreeze


On Fri, 20 Jan 2023 at 15:55, Thomas Meyer <th...@m3y3r.de> wrote:

> The reason was class loader issues
>
> Am 20. Januar 2023 13:37:11 MEZ schrieb Mark Thomas <ma...@apache.org>:
> >From memory, there is a reason the Tomcat handler has to be first. I
> forget exactly why that is. I'd need to dig into this some more (and I have
> my hands full working on the RFC 9128 implementation at the moment).
> >
> >In your case, it looks like a custom LifecycleListener would work. In
> terms of changes to Tomcat, I'd lean more towards a Tomcat specific system
> property you could use instead of java.protocol.handler.pkgs
> >for Tomcat 8.5.x - 10.1x with the whole lot being replaced by a
> ServiceLoader in 11.0.x
> >
> >Mark
> >
> >
> >On 20/01/2023 12:28, Dave Breeze wrote:
> >> Thanks again Mark
> >> I have no access to the source for the webapp.
> >> what I was think was that if in catalina.sh the line:
> >>
> >> JAVA_OPTS="$JAVA_OPTS
> >> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> >>
> >> was simply re-ordered to
> >>
> >> JAVA_OPTS="-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
> >> $JAVA_OPTS "
> >>
> >> then users could use JAVA_OPTS to set the value.
> >>
> >> thanks
> >>
> >> Dave Breeze
> >> Linkedin:https://uk.linkedin.com/in/dabreeze
> >>
> >> On Fri, 20 Jan 2023 at 12:17, Mark Thomas <ma...@apache.org> wrote:
> >>>
> >>> On 20/01/2023 11:18, Dave Breeze wrote:
> >>>> Many thanks Mark for the answers - appreciated.
> >>>>
> >>>> Just to be clear I am running 9.0.71 simply by invoking startup.sh
> >>>> (currently testing). I am not running embedded. I am not too sure
> >>>> therefore about the "Call
> >>>>
> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
> >>>> Could you please explain further
> >>>
> >>> You'd need to call it from your application code (probably a
> >>> ServletContextListener).
> >>>
> >>> Alternatively, you could write a Tomcat level LifecycleListener to add
> >>> it if the JAR with the handler is in $CATALINA_BASE/lib
> >>>
> >>> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the
> >>> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and
> >>> remove it in Tomcat 11).
> >>>
> >>> Mark
> >>>
> >>>
> >>>>
> >>>> thanks again
> >>>> Dave Breeze
> >>>> Linkedin:https://uk.linkedin.com/in/dabreeze
> >>>>
> >>>> Dave Breeze
> >>>> Linkedin:https://uk.linkedin.com/in/dabreeze
> >>>>
> >>>>
> >>>> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
> >>>>>
> >>>>> On 20/01/2023 09:53, Dave Breeze wrote:
> >>>>>> Tomcat 9.0.71
> >>>>>>
> >>>>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
> >>>>>>
> >>>>>>     -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
> >>>>>>
> >>>>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
> >>>>>> containing
> >>>>>>
> >>>>>> JAVA_OPTS="$JAVA_OPTS
> >>>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> >>>>>>
> >>>>>> The result of catalina.sh is that the jvm has
> >>>>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom
> protocol
> >>>>>> then org.apache.catalina.webresources. The net result being that
> Tomcat is
> >>>>>> started with
> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
> >>>>>>
> >>>>>>
> >>>>>>       1. What is the best way of setting java.protocol.handler.pkgs
> other than
> >>>>>>       modifying catalina.sh
> >>>>>
> >>>>> Call
> >>>>>
> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
> >>>>>
> >>>>> to add your custom handler.
> >>>>>
> >>>>>>       2. do i need to set java.protocol.handler.pkgs to just my
> custom handler
> >>>>>>       or should it be set to a concatenation of
> >>>>>>       custom + org.apache.catalina.webresources
> >>>>>
> >>>>> If you do it that way, it needs to be both.
> >>>>>
> >>>>>>       3. if a concatenation of handlers is required what is the
> syntax
> >>>>>
> >>>>> | delimited
> >>>>>
> >>>>> Mark
> >>>>>
> >>>>> ---------------------------------------------------------------------
> >>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>>> For additional commands, e-mail: users-help@tomcat.apache.org
> >>>>>
> >>>>
> >>>> ---------------------------------------------------------------------
> >>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>>> For additional commands, e-mail: users-help@tomcat.apache.org
> >>>>
> >>>
> >>> ---------------------------------------------------------------------
> >>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >>> For additional commands, e-mail: users-help@tomcat.apache.org
> >>>
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >
> >---------------------------------------------------------------------
> >To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> --
> Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Thomas Meyer <th...@m3y3r.de>.
The reason was class loader issues

Am 20. Januar 2023 13:37:11 MEZ schrieb Mark Thomas <ma...@apache.org>:
>From memory, there is a reason the Tomcat handler has to be first. I forget exactly why that is. I'd need to dig into this some more (and I have my hands full working on the RFC 9128 implementation at the moment).
>
>In your case, it looks like a custom LifecycleListener would work. In terms of changes to Tomcat, I'd lean more towards a Tomcat specific system property you could use instead of java.protocol.handler.pkgs
>for Tomcat 8.5.x - 10.1x with the whole lot being replaced by a ServiceLoader in 11.0.x
>
>Mark
>
>
>On 20/01/2023 12:28, Dave Breeze wrote:
>> Thanks again Mark
>> I have no access to the source for the webapp.
>> what I was think was that if in catalina.sh the line:
>> 
>> JAVA_OPTS="$JAVA_OPTS
>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>> 
>> was simply re-ordered to
>> 
>> JAVA_OPTS="-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
>> $JAVA_OPTS "
>> 
>> then users could use JAVA_OPTS to set the value.
>> 
>> thanks
>> 
>> Dave Breeze
>> Linkedin:https://uk.linkedin.com/in/dabreeze
>> 
>> On Fri, 20 Jan 2023 at 12:17, Mark Thomas <ma...@apache.org> wrote:
>>> 
>>> On 20/01/2023 11:18, Dave Breeze wrote:
>>>> Many thanks Mark for the answers - appreciated.
>>>> 
>>>> Just to be clear I am running 9.0.71 simply by invoking startup.sh
>>>> (currently testing). I am not running embedded. I am not too sure
>>>> therefore about the "Call
>>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
>>>> Could you please explain further
>>> 
>>> You'd need to call it from your application code (probably a
>>> ServletContextListener).
>>> 
>>> Alternatively, you could write a Tomcat level LifecycleListener to add
>>> it if the JAR with the handler is in $CATALINA_BASE/lib
>>> 
>>> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the
>>> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and
>>> remove it in Tomcat 11).
>>> 
>>> Mark
>>> 
>>> 
>>>> 
>>>> thanks again
>>>> Dave Breeze
>>>> Linkedin:https://uk.linkedin.com/in/dabreeze
>>>> 
>>>> Dave Breeze
>>>> Linkedin:https://uk.linkedin.com/in/dabreeze
>>>> 
>>>> 
>>>> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>>>>> 
>>>>> On 20/01/2023 09:53, Dave Breeze wrote:
>>>>>> Tomcat 9.0.71
>>>>>> 
>>>>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
>>>>>> 
>>>>>>     -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
>>>>>> 
>>>>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
>>>>>> containing
>>>>>> 
>>>>>> JAVA_OPTS="$JAVA_OPTS
>>>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>>>>>> 
>>>>>> The result of catalina.sh is that the jvm has
>>>>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
>>>>>> then org.apache.catalina.webresources. The net result being that Tomcat is
>>>>>> started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
>>>>>> 
>>>>>> 
>>>>>>       1. What is the best way of setting java.protocol.handler.pkgs other than
>>>>>>       modifying catalina.sh
>>>>> 
>>>>> Call
>>>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>>>>> 
>>>>> to add your custom handler.
>>>>> 
>>>>>>       2. do i need to set java.protocol.handler.pkgs to just my custom handler
>>>>>>       or should it be set to a concatenation of
>>>>>>       custom + org.apache.catalina.webresources
>>>>> 
>>>>> If you do it that way, it needs to be both.
>>>>> 
>>>>>>       3. if a concatenation of handlers is required what is the syntax
>>>>> 
>>>>> | delimited
>>>>> 
>>>>> Mark
>>>>> 
>>>>> ---------------------------------------------------------------------
>>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>> 
>>>> 
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>> 
>>> 
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>> 
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>> 
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>For additional commands, e-mail: users-help@tomcat.apache.org
>

-- 
Diese Nachricht wurde von meinem Android-Gerät mit K-9 Mail gesendet.

Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Mark Thomas <ma...@apache.org>.
 From memory, there is a reason the Tomcat handler has to be first. I 
forget exactly why that is. I'd need to dig into this some more (and I 
have my hands full working on the RFC 9128 implementation at the moment).

In your case, it looks like a custom LifecycleListener would work. In 
terms of changes to Tomcat, I'd lean more towards a Tomcat specific 
system property you could use instead of java.protocol.handler.pkgs
for Tomcat 8.5.x - 10.1x with the whole lot being replaced by a 
ServiceLoader in 11.0.x

Mark


On 20/01/2023 12:28, Dave Breeze wrote:
> Thanks again Mark
> I have no access to the source for the webapp.
> what I was think was that if in catalina.sh the line:
> 
> JAVA_OPTS="$JAVA_OPTS
> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> 
> was simply re-ordered to
> 
> JAVA_OPTS="-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
> $JAVA_OPTS "
> 
> then users could use JAVA_OPTS to set the value.
> 
> thanks
> 
> Dave Breeze
> Linkedin:https://uk.linkedin.com/in/dabreeze
> 
> On Fri, 20 Jan 2023 at 12:17, Mark Thomas <ma...@apache.org> wrote:
>>
>> On 20/01/2023 11:18, Dave Breeze wrote:
>>> Many thanks Mark for the answers - appreciated.
>>>
>>> Just to be clear I am running 9.0.71 simply by invoking startup.sh
>>> (currently testing). I am not running embedded. I am not too sure
>>> therefore about the "Call
>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
>>> Could you please explain further
>>
>> You'd need to call it from your application code (probably a
>> ServletContextListener).
>>
>> Alternatively, you could write a Tomcat level LifecycleListener to add
>> it if the JAR with the handler is in $CATALINA_BASE/lib
>>
>> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the
>> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and
>> remove it in Tomcat 11).
>>
>> Mark
>>
>>
>>>
>>> thanks again
>>> Dave Breeze
>>> Linkedin:https://uk.linkedin.com/in/dabreeze
>>>
>>> Dave Breeze
>>> Linkedin:https://uk.linkedin.com/in/dabreeze
>>>
>>>
>>> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>>>>
>>>> On 20/01/2023 09:53, Dave Breeze wrote:
>>>>> Tomcat 9.0.71
>>>>>
>>>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
>>>>>
>>>>>     -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
>>>>>
>>>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
>>>>> containing
>>>>>
>>>>> JAVA_OPTS="$JAVA_OPTS
>>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>>>>>
>>>>> The result of catalina.sh is that the jvm has
>>>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
>>>>> then org.apache.catalina.webresources. The net result being that Tomcat is
>>>>> started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
>>>>>
>>>>>
>>>>>       1. What is the best way of setting java.protocol.handler.pkgs other than
>>>>>       modifying catalina.sh
>>>>
>>>> Call
>>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>>>>
>>>> to add your custom handler.
>>>>
>>>>>       2. do i need to set java.protocol.handler.pkgs to just my custom handler
>>>>>       or should it be set to a concatenation of
>>>>>       custom + org.apache.catalina.webresources
>>>>
>>>> If you do it that way, it needs to be both.
>>>>
>>>>>       3. if a concatenation of handlers is required what is the syntax
>>>>
>>>> | delimited
>>>>
>>>> Mark
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Dave Breeze <da...@gmail.com>.
Thanks again Mark
I have no access to the source for the webapp.
what I was think was that if in catalina.sh the line:

JAVA_OPTS="$JAVA_OPTS
-Djava.protocol.handler.pkgs=org.apache.catalina.webresources"

was simply re-ordered to

JAVA_OPTS="-Djava.protocol.handler.pkgs=org.apache.catalina.webresources
$JAVA_OPTS "

then users could use JAVA_OPTS to set the value.

thanks

Dave Breeze
Linkedin:https://uk.linkedin.com/in/dabreeze

On Fri, 20 Jan 2023 at 12:17, Mark Thomas <ma...@apache.org> wrote:
>
> On 20/01/2023 11:18, Dave Breeze wrote:
> > Many thanks Mark for the answers - appreciated.
> >
> > Just to be clear I am running 9.0.71 simply by invoking startup.sh
> > (currently testing). I am not running embedded. I am not too sure
> > therefore about the "Call
> > org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
> > Could you please explain further
>
> You'd need to call it from your application code (probably a
> ServletContextListener).
>
> Alternatively, you could write a Tomcat level LifecycleListener to add
> it if the JAR with the handler is in $CATALINA_BASE/lib
>
> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the
> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and
> remove it in Tomcat 11).
>
> Mark
>
>
> >
> > thanks again
> > Dave Breeze
> > Linkedin:https://uk.linkedin.com/in/dabreeze
> >
> > Dave Breeze
> > Linkedin:https://uk.linkedin.com/in/dabreeze
> >
> >
> > On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
> >>
> >> On 20/01/2023 09:53, Dave Breeze wrote:
> >>> Tomcat 9.0.71
> >>>
> >>> I need to use a custom protocol handler. I set JAVA_OPTS to:
> >>>
> >>>    -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
> >>>
> >>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
> >>> containing
> >>>
> >>> JAVA_OPTS="$JAVA_OPTS
> >>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> >>>
> >>> The result of catalina.sh is that the jvm has
> >>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
> >>> then org.apache.catalina.webresources. The net result being that Tomcat is
> >>> started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
> >>>
> >>>
> >>>      1. What is the best way of setting java.protocol.handler.pkgs other than
> >>>      modifying catalina.sh
> >>
> >> Call
> >> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
> >>
> >> to add your custom handler.
> >>
> >>>      2. do i need to set java.protocol.handler.pkgs to just my custom handler
> >>>      or should it be set to a concatenation of
> >>>      custom + org.apache.catalina.webresources
> >>
> >> If you do it that way, it needs to be both.
> >>
> >>>      3. if a concatenation of handlers is required what is the syntax
> >>
> >> | delimited
> >>
> >> Mark
> >>
> >> ---------------------------------------------------------------------
> >> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> >> For additional commands, e-mail: users-help@tomcat.apache.org
> >>
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> > For additional commands, e-mail: users-help@tomcat.apache.org
> >
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 21/01/2023 15:07, Christopher Schultz wrote:
> Mark,
> 
> On 1/20/23 07:17, Mark Thomas wrote:
>> On 20/01/2023 11:18, Dave Breeze wrote:
>>> Many thanks Mark for the answers - appreciated.
>>>
>>> Just to be clear I am running 9.0.71 simply by invoking startup.sh
>>> (currently testing). I am not running embedded. I am not too sure
>>> therefore about the "Call
>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
>>> Could you please explain further
>>
>> You'd need to call it from your application code (probably a 
>> ServletContextListener).
>>
>> Alternatively, you could write a Tomcat level LifecycleListener to add 
>> it if the JAR with the handler is in $CATALINA_BASE/lib
>>
>> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the 
>> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and 
>> remove it in Tomcat 11).
> 
> Would it make sense to have Tomcat's webresources loader consult a new, 
> similar system property such as 
> -Dtomcat.protocol.handler.pkgs=custom1|custom2|... or 
> -Dtomcat.protocol.handler.factories=FactoryClass1|FactoryClass2|... or 
> similar ?
> 
> That way, users would only have to change the name of the system 
> property they would usually have used, and no additional user code needs 
> to be written.

+1. I had the same idea for Tomcat 9 and earlier further on in the thread.

Mark

> 
> -chris
> 
>>> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>>>>
>>>> On 20/01/2023 09:53, Dave Breeze wrote:
>>>>> Tomcat 9.0.71
>>>>>
>>>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
>>>>>
>>>>>    -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
>>>>>
>>>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
>>>>> containing
>>>>>
>>>>> JAVA_OPTS="$JAVA_OPTS
>>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>>>>>
>>>>> The result of catalina.sh is that the jvm has
>>>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
>>>>> then org.apache.catalina.webresources. The net result being that 
>>>>> Tomcat is
>>>>> started with 
>>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
>>>>>
>>>>>
>>>>>      1. What is the best way of setting java.protocol.handler.pkgs 
>>>>> other than
>>>>>      modifying catalina.sh
>>>>
>>>> Call
>>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>>>>
>>>> to add your custom handler.
>>>>
>>>>>      2. do i need to set java.protocol.handler.pkgs to just my 
>>>>> custom handler
>>>>>      or should it be set to a concatenation of
>>>>>      custom + org.apache.catalina.webresources
>>>>
>>>> If you do it that way, it needs to be both.
>>>>
>>>>>      3. if a concatenation of handlers is required what is the syntax
>>>>
>>>> | delimited
>>>>
>>>> Mark
>>>>
>>>> ---------------------------------------------------------------------
>>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Christopher Schultz <ch...@christopherschultz.net>.
Mark,

On 1/20/23 07:17, Mark Thomas wrote:
> On 20/01/2023 11:18, Dave Breeze wrote:
>> Many thanks Mark for the answers - appreciated.
>>
>> Just to be clear I am running 9.0.71 simply by invoking startup.sh
>> (currently testing). I am not running embedded. I am not too sure
>> therefore about the "Call
>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
>> Could you please explain further
> 
> You'd need to call it from your application code (probably a 
> ServletContextListener).
> 
> Alternatively, you could write a Tomcat level LifecycleListener to add 
> it if the JAR with the handler is in $CATALINA_BASE/lib
> 
> Hmm. It looks like we can remove this in Tomcat 10 onwards and use the 
> ServiceLoader mechanism. (OK, may need to deprecate this in 10 and 
> remove it in Tomcat 11).

Would it make sense to have Tomcat's webresources loader consult a new, 
similar system property such as 
-Dtomcat.protocol.handler.pkgs=custom1|custom2|... or 
-Dtomcat.protocol.handler.factories=FactoryClass1|FactoryClass2|... or 
similar ?

That way, users would only have to change the name of the system 
property they would usually have used, and no additional user code needs 
to be written.

-chris

>> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>>>
>>> On 20/01/2023 09:53, Dave Breeze wrote:
>>>> Tomcat 9.0.71
>>>>
>>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
>>>>
>>>>    -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
>>>>
>>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
>>>> containing
>>>>
>>>> JAVA_OPTS="$JAVA_OPTS
>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>>>>
>>>> The result of catalina.sh is that the jvm has
>>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
>>>> then org.apache.catalina.webresources. The net result being that 
>>>> Tomcat is
>>>> started with 
>>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
>>>>
>>>>
>>>>      1. What is the best way of setting java.protocol.handler.pkgs 
>>>> other than
>>>>      modifying catalina.sh
>>>
>>> Call
>>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>>>
>>> to add your custom handler.
>>>
>>>>      2. do i need to set java.protocol.handler.pkgs to just my 
>>>> custom handler
>>>>      or should it be set to a concatenation of
>>>>      custom + org.apache.catalina.webresources
>>>
>>> If you do it that way, it needs to be both.
>>>
>>>>      3. if a concatenation of handlers is required what is the syntax
>>>
>>> | delimited
>>>
>>> Mark
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>>> For additional commands, e-mail: users-help@tomcat.apache.org
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 20/01/2023 11:18, Dave Breeze wrote:
> Many thanks Mark for the answers - appreciated.
> 
> Just to be clear I am running 9.0.71 simply by invoking startup.sh
> (currently testing). I am not running embedded. I am not too sure
> therefore about the "Call
> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
> Could you please explain further

You'd need to call it from your application code (probably a 
ServletContextListener).

Alternatively, you could write a Tomcat level LifecycleListener to add 
it if the JAR with the handler is in $CATALINA_BASE/lib

Hmm. It looks like we can remove this in Tomcat 10 onwards and use the 
ServiceLoader mechanism. (OK, may need to deprecate this in 10 and 
remove it in Tomcat 11).

Mark


> 
> thanks again
> Dave Breeze
> Linkedin:https://uk.linkedin.com/in/dabreeze
> 
> Dave Breeze
> Linkedin:https://uk.linkedin.com/in/dabreeze
> 
> 
> On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>>
>> On 20/01/2023 09:53, Dave Breeze wrote:
>>> Tomcat 9.0.71
>>>
>>> I need to use a custom protocol handler. I set JAVA_OPTS to:
>>>
>>>    -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
>>>
>>> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
>>> containing
>>>
>>> JAVA_OPTS="$JAVA_OPTS
>>> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
>>>
>>> The result of catalina.sh is that the jvm has
>>> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
>>> then org.apache.catalina.webresources. The net result being that Tomcat is
>>> started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
>>>
>>>
>>>      1. What is the best way of setting java.protocol.handler.pkgs other than
>>>      modifying catalina.sh
>>
>> Call
>> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>>
>> to add your custom handler.
>>
>>>      2. do i need to set java.protocol.handler.pkgs to just my custom handler
>>>      or should it be set to a concatenation of
>>>      custom + org.apache.catalina.webresources
>>
>> If you do it that way, it needs to be both.
>>
>>>      3. if a concatenation of handlers is required what is the syntax
>>
>> | delimited
>>
>> Mark
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
>> For additional commands, e-mail: users-help@tomcat.apache.org
>>
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
> 

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Dave Breeze <da...@gmail.com>.
Many thanks Mark for the answers - appreciated.

Just to be clear I am running 9.0.71 simply by invoking startup.sh
(currently testing). I am not running embedded. I am not too sure
therefore about the "Call
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)"
Could you please explain further

thanks again
Dave Breeze
Linkedin:https://uk.linkedin.com/in/dabreeze

Dave Breeze
Linkedin:https://uk.linkedin.com/in/dabreeze


On Fri, 20 Jan 2023 at 11:01, Mark Thomas <ma...@apache.org> wrote:
>
> On 20/01/2023 09:53, Dave Breeze wrote:
> > Tomcat 9.0.71
> >
> > I need to use a custom protocol handler. I set JAVA_OPTS to:
> >
> >   -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
> >
> > My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
> > containing
> >
> > JAVA_OPTS="$JAVA_OPTS
> > -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> >
> > The result of catalina.sh is that the jvm has
> > 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
> > then org.apache.catalina.webresources. The net result being that Tomcat is
> > started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
> >
> >
> >     1. What is the best way of setting java.protocol.handler.pkgs other than
> >     modifying catalina.sh
>
> Call
> org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)
>
> to add your custom handler.
>
> >     2. do i need to set java.protocol.handler.pkgs to just my custom handler
> >     or should it be set to a concatenation of
> >     custom + org.apache.catalina.webresources
>
> If you do it that way, it needs to be both.
>
> >     3. if a concatenation of handlers is required what is the syntax
>
> | delimited
>
> Mark
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
> For additional commands, e-mail: users-help@tomcat.apache.org
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Re: Setting java.protocol.handler.pkgs for Tomcat

Posted by Mark Thomas <ma...@apache.org>.
On 20/01/2023 09:53, Dave Breeze wrote:
> Tomcat 9.0.71
> 
> I need to use a custom protocol handler. I set JAVA_OPTS to:
> 
>   -Djava.protocol.handler.pkgs=com.ibm.crypto.provider
> 
> My JAVA_OPTS setting,however, is ignored. This is due to catalina.sh
> containing
> 
> JAVA_OPTS="$JAVA_OPTS
> -Djava.protocol.handler.pkgs=org.apache.catalina.webresources"
> 
> The result of catalina.sh is that the jvm has
> 2  -Djava.protocol.handler.pkgs settings - first  the custom protocol
> then org.apache.catalina.webresources. The net result being that Tomcat is
> started with -Djava.protocol.handler.pkgs=org.apache.catalina.webresources.
> 
> 
>     1. What is the best way of setting java.protocol.handler.pkgs other than
>     modifying catalina.sh

Call 
org.apache.catalina.webresources.TomcatURLStreamHandlerFactory#addUserFactory(URLStreamHandlerFactory)

to add your custom handler.

>     2. do i need to set java.protocol.handler.pkgs to just my custom handler
>     or should it be set to a concatenation of
>     custom + org.apache.catalina.webresources

If you do it that way, it needs to be both.

>     3. if a concatenation of handlers is required what is the syntax

| delimited

Mark

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org