How to tell whether Cometd Client is connected to http or https?

22 views
Skip to first unread message

Probie

unread,
May 30, 2012, 11:04:41 PM5/30/12
to cometd-users
Hi,

In my cometd client, I had successfully handshake and connect to
cometd server. Then only in some function I want it to be https
secure. So I had something like this:-

final String url = "https://10.241.15.60/cometdServer/foo/";

Map<String, Object> options = new HashMap<String, Object>();
LongPollingTransport transport = new LongPollingTransport(
options, httpClient) {

@Override
protected void customize(ContentExchange exchange) {
exchange.setURL(url);
super.customize(exchange);
}
};
bayeuxClient = new BayeuxClient("http://10.241.15.60/cometdServer/
foo/", transport);

then I rehandshake the bayeuxClient again so the changes for url in
httpClient take place. But when I want to check whether now my
connection is either http or https, in debug inspect it shows me two
values:-

transportRegistry --> _transports 's HashMap -->
url - http://10.241.15.60/cometdServer/foo/
val$url - https://10.241.15.60/cometdServer/foo/

Is the val$url is the result after changing httpClient in bayeuxClient
to https? Or the url of results still remains as http? I tried to find
on google what is val$url in transportRegistry is but no results. So I
am a bit doubtful whether I did the correct way or wrong. Please help
me? Thank you.



Simone Bordet

unread,
May 31, 2012, 2:47:30 AM5/31/12
to cometd...@googlegroups.com
Hi,
val$url is the way anonymous classes are implemented.
You can only use variables outside anonymous classes if they are
final, and the Java compiler translates them into fields with the
"val$" prefix (just change the variable name and you'll see).

As for using https URL only for some request, I would rather use https
for every request and keep it simpler.

You solution will work only for long-polling and not for websocket,
although in the current way it will convert *every* request to https.

Simon
--
http://cometd.org
http://intalio.com
http://bordet.blogspot.com
----
Finally, no matter how good the architecture and design are,
to deliver bug-free software with optimal performance and reliability,
the implementation technique must be flawless.   Victoria Livschitz

Simone Bordet

unread,
May 31, 2012, 3:56:05 AM5/31/12
to cometd-users
Hi,

On Thu, May 31, 2012 at 9:41 AM, Probie <cheah....@gmail.com> wrote:
> Hi Simon,
>
> is it means that my cometd Client is connecting to https if I code it
> this way? Because of the url and val$url difference I am a bit confuse
> whether I done it the right way or not. And after I changed it to
> https, I had found out that for the rest of the following request
> after this, it remains as https already. Not the behavior of the
> program I wanted as only for certain request only I needed them as
> https, and the rest only normal http. Hope you can enlighten me? Thank
> you.

The code you posted replaces the URL every request with a HTTPS one,
in the customize(...) method.
So yes, all your request, with that code in place, will use HTTPS.
But at this point, avoid overriding customize(...) and just use HTTPS
from the beginning.

If you want only certain requests over HTTPS, inside customize(...)
you have to look at what it is being sent, and decide whether you want
it HTTPS or not.
I don't particularly recommend this approach, however.
Depending on the numbers you have, running on full HTTPS should do the
job just fine and it's way simpler.

Why you want only some request over HTTPS ?
If the answer is "for performance", how many *concurrent* clients do you have ?
Message has been deleted

Probie

unread,
May 31, 2012, 4:50:44 AM5/31/12
to cometd-users
To Simon,

is it means that after changing to HTTPS, it will stays as it for the
following request also? Not a one time changes then revert back to
http, but permanent effect?

Hmm.. you are right, changing once into HTTPS really works, but for
some of it, I still need to retain as HTTP only. No choice.

The client handle all separate function in system, and it will
constantly push updates to them if data is changed. So everything is
going through my part.

On May 31, 3:56 pm, Simone Bordet <sbor...@intalio.com> wrote:
> Hi,
>
> On Thu, May 31, 2012 at 9:41 AM, Probie <cheah.choo...@gmail.com> wrote:
> > Hi Simon,
>
> > is it means that my cometd Client is connecting to https if I code it
> > this way? Because of the url and val$url difference I am a bit confuse
> > whether I done it the right way or not. And after I changed it to
> > https, I had found out that for the rest of the following request
> > after this, it remains as https already. Not the behavior of the
> > program I wanted as only for certain request only I needed them as
> > https, and the rest only normal http. Hope you can enlighten me? Thank
> > you.
>
> The code you posted replaces the URL every request with a HTTPS one,
> in the customize(...) method.
> So yes, all your request, with that code in place, will use HTTPS.
> But at this point, avoid overriding customize(...) and just use HTTPS
> from the beginning.
>
> If you want only certain requests over HTTPS, inside customize(...)
> you have to look at what it is being sent, and decide whether you want
> it HTTPS or not.
> I don't particularly recommend this approach, however.
> Depending on the numbers you have, running on full HTTPS should do the
> job just fine and it's way simpler.
>
> Why you want only some request over HTTPS ?
> If the answer is "for performance", how many *concurrent* clients do you have ?
>
> Simon
> --http://cometd.orghttp://intalio.comhttp://bordet.blogspot.com

Probie

unread,
Jun 1, 2012, 4:53:31 AM6/1/12
to cometd-users
Hi Simon,

Map<String, Object> options = new HashMap<String, Object>();
LongPollingTransport transport = new LongPollingTransport(
options, httpClient) {

@Override
protected void customize(ContentExchange exchange) {
if(isHTTPS){
exchange.setURL(urls);
} else {
exchange.setURL(url);
}
super.customize(exchange);

}
};

I think this might be the best possible way to solved the problem.
Anyway I might be wrong. So if the boolean isHTTPS I set it to true
for certain function I want to use HTTPS, it will override the url in
customize to secure url, otherwise use back url. Problem solved.

Simone Bordet

unread,
Jun 1, 2012, 4:58:10 AM6/1/12
to cometd...@googlegroups.com
Hi,

On Fri, Jun 1, 2012 at 10:53 AM, Probie <cheah....@gmail.com> wrote:
> Hi Simon,
>
>                Map<String, Object> options = new HashMap<String, Object>();
>                LongPollingTransport transport = new LongPollingTransport(
>                          options, httpClient) {
>
>                        @Override
>                        protected void customize(ContentExchange exchange) {
>                                if(isHTTPS){
>                                        exchange.setURL(urls);
>                                } else {
>                                        exchange.setURL(url);
>                                }
>                                super.customize(exchange);
>
>                        }
>                };
>
> I think this might be the best possible way to solved the problem.
> Anyway I might be wrong. So if the boolean isHTTPS I set it to true
> for certain function I want to use HTTPS, it will override the url in
> customize to secure url, otherwise use back url. Problem solved.

Not really.
If "isHTTPS" is a field, then the code above is not thread-safe.

You have to have some kind of logic like the one you wrote above, but
must be thread safe.

Probie

unread,
Jun 1, 2012, 5:03:45 AM6/1/12
to cometd-users
To Simon,

Noted, I will make isHTTPS field to thread-safe and test a few more
rounds to see its results. Thank you Simon. Appreciate.

On Jun 1, 4:58 pm, Simone Bordet <sbor...@intalio.com> wrote:
> Hi,
>
>
>
>
>
>
>
>
>
> On Fri, Jun 1, 2012 at 10:53 AM, Probie <cheah.choo...@gmail.com> wrote:
> > Hi Simon,
>
> >                Map<String, Object> options = new HashMap<String, Object>();
> >                LongPollingTransport transport = new LongPollingTransport(
> >                          options, httpClient) {
>
> >                        @Override
> >                        protected void customize(ContentExchange exchange) {
> >                                if(isHTTPS){
> >                                        exchange.setURL(urls);
> >                                } else {
> >                                        exchange.setURL(url);
> >                                }
> >                                super.customize(exchange);
>
> >                        }
> >                };
>
> > I think this might be the best possible way to solved the problem.
> > Anyway I might be wrong. So if the boolean isHTTPS I set it to true
> > for certain function I want to use HTTPS, it will override the url in
> > customize to secure url, otherwise use back url. Problem solved.
>
> Not really.
> If "isHTTPS" is a field, then the code above is not thread-safe.
>
> You have to have some kind of logic like the one you wrote above, but
> must be thread safe.
>
> Simon
> --http://cometd.orghttp://intalio.comhttp://bordet.blogspot.com
Reply all
Reply to author
Forward
0 new messages