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 "Austin, Carl" <Ca...@baesystemsdetica.com> on 2012/08/16 10:40:50 UTC

Inherit cookies from applet session

Hi,

 

I am replacing some code in an applet, where HttpURLConnection was used,
with HttpClient (Version 4.2.1). All has gone well so far, however
unlike HttpURLConnection it seems that HttpClient doesn't inherit the
cookies from the session of the applet and as such the HttpClient
connection gets back a login page as I have the URL secured. I already
have an authenticated session as I authenticated to access the applet in
the first place. Is there a way to inherit this with HttpClient or do I
either need to re-authenticate or need to get the jsessionid (plus any
other cookies that may exist) from the applet's session and recreate
these cookies for the HttpClient request by hand? Ideally I would like
it to perform as URLConnection, and feel that perhaps I am missing
something. 

 

Many Thanks

 

Carl

 


Please consider the environment before printing this email.
 
This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
 
Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. 
 
The contents of this email may relate to dealings with other companies under the control of BAE Systems plc details of which can be found at http://www.baesystems.com/Businesses/index.htm.
 
Detica Limited is a BAE Systems company trading as BAE Systems Detica.
Detica Limited is registered in England and Wales under No: 1337451.
Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.


Re: Inherit cookies from applet session

Posted by Sam Crawford <sa...@gmail.com>.
I've dabbled in this previously. If I understand it correctly, you use
case is that you want to inherit cookies from the *browser* session
and make them available to HttpClient inside the applet. As you say,
HttpUrlConnection handles this transparently, whilst HttpClient does
not, and I think you'll really struggle to get this going. We ended up
using HttpUrlConnection for this part of the code, as it was only very
simple.

My understanding is that HttpUrlConnection uses lots of proprietary
Sun APIs and platform-specific code to achieve this and other things
(such as transparent NTLM / Kerberos auth).

Sorry I couldn't help more,

Sam


On 16 August 2012 17:00, William Speirs <ws...@apache.org> wrote:
> No, it shouldn't be too hard. I haven't done this (and don't have a
> ton of time to play around with it right now... sorry). Hopefully
> someone else on the mailing list will chime in.
>
> Sorry...
>
> Bill-
>
> On Thu, Aug 16, 2012 at 9:30 AM, Austin, Carl
> <Ca...@baesystemsdetica.com> wrote:
>> Thanks, I have seen the tutorial, and this does explain in detail
>> setting cookies. However my applet makes all http calls in background
>> threads so I have to work in an environment with many overlapping
>> threads each of which could return a different jsessionid cookie. This
>> is because the app server can change the session, JBOSS and WebLogic
>> both change the jsessionid during normal access in some circumstances.
>> If all of the threads are overlapping, how do I know which session id
>> cookie to use for following requests if they all return in an
>> unspecified order with more than 1 session id between them?
>>
>> Issues like this, and the seeming complexity of their solutions are
>> leading me back to using HttpURLConnection as this is all managed so
>> simply for me. I just have to sacrifice the extra levels of
>> configuration that HttpClient would give me.
>>
>> Am I over complicating this or is it really this complicated to manage
>> the session within such an applet with HttpClient?
>>
>> -----Original Message-----
>> From: William Speirs [mailto:wspeirs@apache.org]
>> Sent: 16 August 2012 14:20
>> To: HttpClient User Discussion
>> Subject: Re: Inherit cookies from applet session
>>
>> I've never setup the client to deal with cookies, but there is
>> information in the state management section:
>> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.ht
>> ml
>>
>> Bill-
>>
>> On Thu, Aug 16, 2012 at 4:40 AM, Austin, Carl
>> <Ca...@baesystemsdetica.com> wrote:
>>> Hi,
>>>
>>>
>>>
>>> I am replacing some code in an applet, where HttpURLConnection was
>> used,
>>> with HttpClient (Version 4.2.1). All has gone well so far, however
>>> unlike HttpURLConnection it seems that HttpClient doesn't inherit the
>>> cookies from the session of the applet and as such the HttpClient
>>> connection gets back a login page as I have the URL secured. I already
>>> have an authenticated session as I authenticated to access the applet
>> in
>>> the first place. Is there a way to inherit this with HttpClient or do
>> I
>>> either need to re-authenticate or need to get the jsessionid (plus any
>>> other cookies that may exist) from the applet's session and recreate
>>> these cookies for the HttpClient request by hand? Ideally I would like
>>> it to perform as URLConnection, and feel that perhaps I am missing
>>> something.
>>>
>>>
>>>
>>> Many Thanks
>>>
>>>
>>>
>>> Carl
>>>
>>>
>>>
>>>
>>> Please consider the environment before printing this email.
>>>
>>> This message should be regarded as confidential. If you have received
>> this email in error please notify the sender and destroy it immediately.
>>>
>>> Statements of intent shall only become binding when confirmed in hard
>> copy by an authorised signatory.
>>>
>>> The contents of this email may relate to dealings with other companies
>> under the control of BAE Systems plc details of which can be found at
>> http://www.baesystems.com/Businesses/index.htm.
>>>
>>> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
>>> Detica Limited is registered in England and Wales under No: 1337451.
>>> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP,
>> England.
>>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
>> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>>
>> Please consider the environment before printing this email.
>>
>> This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
>>
>> Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory.
>>
>> The contents of this email may relate to dealings with other companies under the control of BAE Systems plc details of which can be found at http://www.baesystems.com/Businesses/index.htm.
>>
>> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
>> Detica Limited is registered in England and Wales under No: 1337451.
>> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.
>>
>>
>>
>> ---------------------------------------------------------------------
>> 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
>

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


Re: Inherit cookies from applet session

Posted by William Speirs <ws...@apache.org>.
No, it shouldn't be too hard. I haven't done this (and don't have a
ton of time to play around with it right now... sorry). Hopefully
someone else on the mailing list will chime in.

Sorry...

Bill-

On Thu, Aug 16, 2012 at 9:30 AM, Austin, Carl
<Ca...@baesystemsdetica.com> wrote:
> Thanks, I have seen the tutorial, and this does explain in detail
> setting cookies. However my applet makes all http calls in background
> threads so I have to work in an environment with many overlapping
> threads each of which could return a different jsessionid cookie. This
> is because the app server can change the session, JBOSS and WebLogic
> both change the jsessionid during normal access in some circumstances.
> If all of the threads are overlapping, how do I know which session id
> cookie to use for following requests if they all return in an
> unspecified order with more than 1 session id between them?
>
> Issues like this, and the seeming complexity of their solutions are
> leading me back to using HttpURLConnection as this is all managed so
> simply for me. I just have to sacrifice the extra levels of
> configuration that HttpClient would give me.
>
> Am I over complicating this or is it really this complicated to manage
> the session within such an applet with HttpClient?
>
> -----Original Message-----
> From: William Speirs [mailto:wspeirs@apache.org]
> Sent: 16 August 2012 14:20
> To: HttpClient User Discussion
> Subject: Re: Inherit cookies from applet session
>
> I've never setup the client to deal with cookies, but there is
> information in the state management section:
> http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.ht
> ml
>
> Bill-
>
> On Thu, Aug 16, 2012 at 4:40 AM, Austin, Carl
> <Ca...@baesystemsdetica.com> wrote:
>> Hi,
>>
>>
>>
>> I am replacing some code in an applet, where HttpURLConnection was
> used,
>> with HttpClient (Version 4.2.1). All has gone well so far, however
>> unlike HttpURLConnection it seems that HttpClient doesn't inherit the
>> cookies from the session of the applet and as such the HttpClient
>> connection gets back a login page as I have the URL secured. I already
>> have an authenticated session as I authenticated to access the applet
> in
>> the first place. Is there a way to inherit this with HttpClient or do
> I
>> either need to re-authenticate or need to get the jsessionid (plus any
>> other cookies that may exist) from the applet's session and recreate
>> these cookies for the HttpClient request by hand? Ideally I would like
>> it to perform as URLConnection, and feel that perhaps I am missing
>> something.
>>
>>
>>
>> Many Thanks
>>
>>
>>
>> Carl
>>
>>
>>
>>
>> Please consider the environment before printing this email.
>>
>> This message should be regarded as confidential. If you have received
> this email in error please notify the sender and destroy it immediately.
>>
>> Statements of intent shall only become binding when confirmed in hard
> copy by an authorised signatory.
>>
>> The contents of this email may relate to dealings with other companies
> under the control of BAE Systems plc details of which can be found at
> http://www.baesystems.com/Businesses/index.htm.
>>
>> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
>> Detica Limited is registered in England and Wales under No: 1337451.
>> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP,
> England.
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
> For additional commands, e-mail: httpclient-users-help@hc.apache.org
>
> Please consider the environment before printing this email.
>
> This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
>
> Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory.
>
> The contents of this email may relate to dealings with other companies under the control of BAE Systems plc details of which can be found at http://www.baesystems.com/Businesses/index.htm.
>
> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
> Detica Limited is registered in England and Wales under No: 1337451.
> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.
>
>
>
> ---------------------------------------------------------------------
> 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: Inherit cookies from applet session

Posted by "Austin, Carl" <Ca...@baesystemsdetica.com>.
Thanks, I have seen the tutorial, and this does explain in detail
setting cookies. However my applet makes all http calls in background
threads so I have to work in an environment with many overlapping
threads each of which could return a different jsessionid cookie. This
is because the app server can change the session, JBOSS and WebLogic
both change the jsessionid during normal access in some circumstances.
If all of the threads are overlapping, how do I know which session id
cookie to use for following requests if they all return in an
unspecified order with more than 1 session id between them?

Issues like this, and the seeming complexity of their solutions are
leading me back to using HttpURLConnection as this is all managed so
simply for me. I just have to sacrifice the extra levels of
configuration that HttpClient would give me.

Am I over complicating this or is it really this complicated to manage
the session within such an applet with HttpClient?

-----Original Message-----
From: William Speirs [mailto:wspeirs@apache.org] 
Sent: 16 August 2012 14:20
To: HttpClient User Discussion
Subject: Re: Inherit cookies from applet session

I've never setup the client to deal with cookies, but there is
information in the state management section:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.ht
ml

Bill-

On Thu, Aug 16, 2012 at 4:40 AM, Austin, Carl
<Ca...@baesystemsdetica.com> wrote:
> Hi,
>
>
>
> I am replacing some code in an applet, where HttpURLConnection was
used,
> with HttpClient (Version 4.2.1). All has gone well so far, however
> unlike HttpURLConnection it seems that HttpClient doesn't inherit the
> cookies from the session of the applet and as such the HttpClient
> connection gets back a login page as I have the URL secured. I already
> have an authenticated session as I authenticated to access the applet
in
> the first place. Is there a way to inherit this with HttpClient or do
I
> either need to re-authenticate or need to get the jsessionid (plus any
> other cookies that may exist) from the applet's session and recreate
> these cookies for the HttpClient request by hand? Ideally I would like
> it to perform as URLConnection, and feel that perhaps I am missing
> something.
>
>
>
> Many Thanks
>
>
>
> Carl
>
>
>
>
> Please consider the environment before printing this email.
>
> This message should be regarded as confidential. If you have received
this email in error please notify the sender and destroy it immediately.
>
> Statements of intent shall only become binding when confirmed in hard
copy by an authorised signatory.
>
> The contents of this email may relate to dealings with other companies
under the control of BAE Systems plc details of which can be found at
http://www.baesystems.com/Businesses/index.htm.
>
> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
> Detica Limited is registered in England and Wales under No: 1337451.
> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP,
England.
>

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

Please consider the environment before printing this email.
 
This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
 
Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory. 
 
The contents of this email may relate to dealings with other companies under the control of BAE Systems plc details of which can be found at http://www.baesystems.com/Businesses/index.htm.
 
Detica Limited is a BAE Systems company trading as BAE Systems Detica.
Detica Limited is registered in England and Wales under No: 1337451.
Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.


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


Re: Inherit cookies from applet session

Posted by William Speirs <ws...@apache.org>.
I've never setup the client to deal with cookies, but there is
information in the state management section:
http://hc.apache.org/httpcomponents-client-ga/tutorial/html/statemgmt.html

Bill-

On Thu, Aug 16, 2012 at 4:40 AM, Austin, Carl
<Ca...@baesystemsdetica.com> wrote:
> Hi,
>
>
>
> I am replacing some code in an applet, where HttpURLConnection was used,
> with HttpClient (Version 4.2.1). All has gone well so far, however
> unlike HttpURLConnection it seems that HttpClient doesn't inherit the
> cookies from the session of the applet and as such the HttpClient
> connection gets back a login page as I have the URL secured. I already
> have an authenticated session as I authenticated to access the applet in
> the first place. Is there a way to inherit this with HttpClient or do I
> either need to re-authenticate or need to get the jsessionid (plus any
> other cookies that may exist) from the applet's session and recreate
> these cookies for the HttpClient request by hand? Ideally I would like
> it to perform as URLConnection, and feel that perhaps I am missing
> something.
>
>
>
> Many Thanks
>
>
>
> Carl
>
>
>
>
> Please consider the environment before printing this email.
>
> This message should be regarded as confidential. If you have received this email in error please notify the sender and destroy it immediately.
>
> Statements of intent shall only become binding when confirmed in hard copy by an authorised signatory.
>
> The contents of this email may relate to dealings with other companies under the control of BAE Systems plc details of which can be found at http://www.baesystems.com/Businesses/index.htm.
>
> Detica Limited is a BAE Systems company trading as BAE Systems Detica.
> Detica Limited is registered in England and Wales under No: 1337451.
> Registered office: Surrey Research Park, Guildford, Surrey, GU2 7YP, England.
>

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