You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Raman Gupta <ro...@fastmail.fm> on 2008/04/30 15:55:02 UTC

Static Protocol Registry visibility problems

I'm having problems related to HttpClient using a static protocol
registry.

I have an application that needs to talk SSL to various systems.
However, each SSL connection needs to use its own SSLContext
(different key and trust configurations).

Normally, this would be accomplished in HttpClient 3.x by doing:

Protocol.registerProtocol("https1", new Protocol(...));
Protocol.registerProtocol("https2", new Protocol(...));
etc.

Unfortunately, for these SSL connections, I am using HttpClient
indirectly via another library (Spring-WS) that chokes on URLs that
don't start with https or http.

I figured no problem, I would simply use a different HttpClient
instance for each unique SSL socket factory, and register the relevant
protocol as "https" for each. Unfortunately, it seems that all
HttpClient instances share a single static Protocol registry. Ouch.

To add insult to injury, if I pass in a Protocol instance via the
executeMethod HostConfiguration parameter, HttpClient says "oops,
sorry, you're using an absolute URI so I'm going to ignore the
HostConfiguration you just passed me, and go build a new
HostConfiguration based on the protocol registry".

Is there any way around this, other than the solution I am immediately
considering, which is patching the HttpClient codebase to change the
global static protocol registry to be per-HttpClient?

Cheers,
Raman Gupta

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


Re: Static Protocol Registry visibility problems

Posted by Raman Gupta <ro...@fastmail.fm>.
Sam Berlin wrote:
> On Wed, Apr 30, 2008 at 9:55 AM, rocketraman@fastmail.fm wrote:
>> I'm having problems related to HttpClient using a static protocol
>> registry.
>
> HttpClient 4.0 is redesigned such that there is no longer a global 
> static Protocol registry (among many other nice redesigns). If 
> possible, I suggest migrating to 4.0.

Good, I'm looking forward to that. Unfortunately, for now, I'm stuck
with 3.x unless 4.0 is binary compatible.

> Alternately, if you must stick with 3.0, you can try to manually 
> modify the calls to executeMethod so that the URIs have the
> protocol hacked out, ie changing myprotocol://host.com to host.com,
> and passing a custom protocol.

I'll look into doing that.

Cheers,
Raman Gupta

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


Re: Static Protocol Registry visibility problems

Posted by Sam Berlin <sb...@gmail.com>.
HttpClient 4.0 is redesigned such that there is no longer a global
static Protocol registry (among many other nice redesigns).  If
possible, I suggest migrating to 4.0.

Alternately, if you must stick with 3.0, you can try to manually
modify the calls to executeMethod so that the URIs have the protocol
hacked out, ie changing myprotocol://host.com to host.com, and passing
a custom protocol.

Sam

On Wed, Apr 30, 2008 at 9:55 AM, Raman Gupta <ro...@fastmail.fm> wrote:
> I'm having problems related to HttpClient using a static protocol
> registry.
>
> I have an application that needs to talk SSL to various systems.
> However, each SSL connection needs to use its own SSLContext
> (different key and trust configurations).
>
> Normally, this would be accomplished in HttpClient 3.x by doing:
>
> Protocol.registerProtocol("https1", new Protocol(...));
> Protocol.registerProtocol("https2", new Protocol(...));
> etc.
>
> Unfortunately, for these SSL connections, I am using HttpClient
> indirectly via another library (Spring-WS) that chokes on URLs that
> don't start with https or http.
>
> I figured no problem, I would simply use a different HttpClient
> instance for each unique SSL socket factory, and register the relevant
> protocol as "https" for each. Unfortunately, it seems that all
> HttpClient instances share a single static Protocol registry. Ouch.
>
> To add insult to injury, if I pass in a Protocol instance via the
> executeMethod HostConfiguration parameter, HttpClient says "oops,
> sorry, you're using an absolute URI so I'm going to ignore the
> HostConfiguration you just passed me, and go build a new
> HostConfiguration based on the protocol registry".
>
> Is there any way around this, other than the solution I am immediately
> considering, which is patching the HttpClient codebase to change the
> global static protocol registry to be per-HttpClient?
>
> Cheers,
> Raman Gupta
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
>

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


Re: Static Protocol Registry visibility problems

Posted by Raman Gupta <ro...@fastmail.fm>.
Oleg Kalnichevski wrote:
> On Wed, 2008-04-30 at 09:55 -0400, Raman Gupta wrote:
>> I'm having problems related to HttpClient using a static protocol
>> registry.
>> [...snip...]
> 
> Use HostConfigurationWithStickyProtocol from the contrib package to
> work the problem around.

Thanks for the pointer! I had already tried something very similar but
it wasn't working for me. I was using version 3.0 which does not allow
for overriding HostConfiguration, since it does the following in
executeMethod:

hostconfig = new HostConfiguration(hostconfig);

With your pointer, I saw thatHostConfigurationWithStickyProtocol was
introduced in 3.1, so I checked the executeMethod method in 3.1, and
saw that it has been changed to:

hostconfig = (HostConfiguration) hostconfig.clone();

Problem solved until 4.0, when this hack won't be needed! Thank you Oleg.

Cheers,
Raman Gupta

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


Re: Static Protocol Registry visibility problems

Posted by Oleg Kalnichevski <ol...@apache.org>.
On Wed, 2008-04-30 at 09:55 -0400, Raman Gupta wrote:
> I'm having problems related to HttpClient using a static protocol
> registry.
> 
> I have an application that needs to talk SSL to various systems.
> However, each SSL connection needs to use its own SSLContext
> (different key and trust configurations).
> 
> Normally, this would be accomplished in HttpClient 3.x by doing:
> 
> Protocol.registerProtocol("https1", new Protocol(...));
> Protocol.registerProtocol("https2", new Protocol(...));
> etc.
> 
> Unfortunately, for these SSL connections, I am using HttpClient
> indirectly via another library (Spring-WS) that chokes on URLs that
> don't start with https or http.
> 
> I figured no problem, I would simply use a different HttpClient
> instance for each unique SSL socket factory, and register the relevant
> protocol as "https" for each. Unfortunately, it seems that all
> HttpClient instances share a single static Protocol registry. Ouch.
> 
> To add insult to injury, if I pass in a Protocol instance via the
> executeMethod HostConfiguration parameter, HttpClient says "oops,
> sorry, you're using an absolute URI so I'm going to ignore the
> HostConfiguration you just passed me, and go build a new
> HostConfiguration based on the protocol registry".
> 

Hi Raman,

Use HostConfigurationWithStickyProtocol from the contrib package to
work the problem around.

Hope this helps

Oleg



> Is there any way around this, other than the solution I am immediately
> considering, which is patching the HttpClient codebase to change the
> global static protocol registry to be per-HttpClient?
> 
> Cheers,
> Raman Gupta
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
> 


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