java - Add custom fields to CometD subscribe message -


i using cometd java client on android.

compile group: 'org.cometd.java', name: 'cometd-java-client', version: '2.9.1'

i need subscribe channel on cometd server. there problem - server requires custom subscribe message (this expected subscribe message payload server docs):

[     {         "user": "xyz-wquaq3shwho1zcjhaibqyzch2ilmmx1o-ga6nuehtfymhvviv6ow3dvpbyt8zwg10-bd8bd779f107615b1c5a1470706e4050e5389ddc",         "domain": "xyz",         "pid": "ga6nuehtfymhvviv6ow3dvpbyt8zwg10",         "sid": "85f103a2",         "gid": "wquaq3shwho1zcjhaibqyzch2ilmmx1o",         "pageid": "6ea23e",         "entityid": "xyz",         "triggeringgoal": "3e955818355c44e2479b2a26629e69566c8c6376",         "chatsearchpattern": "ua.domain=xyz",         "starttime": 1482931626853,         "metadata": "{}",         "chatmetadata": "{}",         "language": "en",          "id": "3",         "channel": "\/meta\/subscribe",         "subscription": "\/chat\/xyz-wquaq3shwho1zcjhaibqyzch2ilmmx1o-ga6nuehtfymhvviv6ow3dvpbyt8zwg10-bd8bd779f107615b1c5a1470706e4050e5389ddc",         "clientid": "26l1v2ngpdcwdtno1wu30rk92dur4",         "ext": {         }     } ] 

so question how add custom fields subscribe message (user, domain, pid, sid etc)? subscribing channels this:

cometdclient.getchannel("/chat/" + clientid).subscribe(new channellistener("/chat/ messages"), new channellistener("/chat/ progress")); 

but failing expected.

by way using org.eclipse.jetty.client.httpclient httpclient.

first of all, should upgrade cometd 2.9.1 old now, , jdk 7 supported on android.

the design of server requiring fields in /meta/subscribe message wrong. of information static (e.g. user , various "cookies" such pid etc.) , can determined @ time of cometd handshake, there no need send on during subscription.

also, sending during /meta/subscribe message makes subject attacks (an attacker can forge message different user field, example). want read security section of cometd documentation.

furthermore, using channel per user (as appears channel name concatenation of /chat/ , user field) not recommended approach, since create possibly lot of channels, while same functionality can achieved more efficiently single service channel (and user field of messages being sent).

if have add fields /meta/subscribe message, way use custom extension, along these lines:

class subscribeextension extends clientsession.extension.adapter {     @override     public boolean sendmeta(clientsession session, message.mutable message) {         if (channel.meta_subscribe.equals(message.getchannel())) {             string subscription = (string)message.get(message.subscription_field);             if (subscription.startswith("/chat/") {                 // add fields.             }         }         return true;     } } 

finally, if need add fields /meta/subscribe message, want inside ext field, proper namespacing:

{     "id": "3",     "channel": "/meta/subscribe",     "subscription": "/chat/xyz-wquaq3shwho1zcjhaibqyzch2ilmmx1o-ga6nuehtfymhvviv6ow3dvpbyt8zwg10-bd8bd779f107615b1c5a1470706e4050e5389ddc",     "clientid": "26l1v2ngpdcwdtno1wu30rk92dur4",     "ext": {         "com.acme.myapp": {             "time": 1234567890,             "pageid": "6ea23e",             ...         }     } } 

note how fields no pollute message itself, grouped in ext field under namespace com.acme.app represent company , application.


Comments

Popular posts from this blog

python Tkinter Capturing keyboard events save as one single string -

android - InAppBilling registering BroadcastReceiver in AndroidManifest -

javascript - Z-index in d3.js -