How to call WebSockets directly via Java?
Copy link to clipboard
Copied
In order to enable WebSockets, the following example is given:
application.cfc
this.name = "WebSocketDemo"; this.wschannels = [{name="stocks"},{name="chat"}];
When application variables are dumped, this.name looks like it gets translated into application.applicationname. However, wschannels is nowhere to be found. How would one be able to enable websockets via a call in application.cfm or any cfm page?
I tried this but neither worked:
<cfset application.wschannels = [{name="stocks"},{name="chat"}]>
<cfset application.this.wschannels = [{name="stocks"},{name="chat"}]>
Copy link to clipboard
Copied
// The application name (this setting is not for the websocket)..
this.name = "WebSocketDemo";
// You must include the listener (CFC) of a websocket.
this.wschannels = [{name="stocks",cfclistener="stockListener"},{name="chat",cfclistener="chatListener"}];
Example: ChatListener.cfc
component extends="CFIDE.websocket.ChannelListener"
{
public boolean function allowSubscribe(Struct subscriberInfo)
{
if(structKeyExists(subscriberInfo,"utype"))
{
//Validating if a user has publish right & adding a new key to ConnectionInfo
if(subscriberInfo.utype eq "Moderator" or subscriberInfo.utype eq "Member" ){
subscriberInfo.connectioninfo.havepublishright=true;
return true;
} else {
subscriberInfo.connectioninfo.havepublishright=false;
return false;
}
}
}
public boolean function allowPublish(Struct publisherInfo)
{
if(structKeyExists(publisherInfo.connectioninfo,"havepublishright")){
if(publisherInfo.connectioninfo.havepublishright){
return true;
} else {
return false;
}
}
}
}
Copy link to clipboard
Copied
Thanks -- but I don't see how this would work in, say, an application.cfm file. "this.wschannel" seems to only exist inside application.cfc -- or am I mistaken?
Copy link to clipboard
Copied
I would advise you to use Application.cfc. Application.cfm is outdated.
But, to answer your question, Application.cfm may use something like
<cfapplication name="WebSocketDemo"
wschannels=[{name="stocks",cfclistener="stockListener"},{name="chat",cfclistener="chatListener"}]
clientmanagement="No"
sessionmanagement="Yes"
sessionTimeout=createTimespan(0,0,30,0)>
Copy link to clipboard
Copied
No go...
Attribute validation error for tag CFAPPLICATION.
It does not allow the attribute(s) WSCHANNELS. The valid attribute(s) are APPLICATIONTIMEOUT,AUTHCOOKIE,CLIENTMANAGEMENT,CLIENTSTORAGE,COMPILEEXTFORINCLUDE,DATASOURCE,ENABLENULLSUPPORT,EXCHANGESERVERVERSION,LOGINSTORAGE,NAME,PASSARRAYBYREFERENCE,SAMEFORMFIELDSASARRAY,SCRIPTPROTECT,SEARCHIMPLICITSCOPES,SECUREJSON,SECUREJSONPREFIX,SERVERSIDEFORMVALIDATION,SESSIONCOOKIE,SESSIONMANAGEMENT,SESSIONTIMEOUT,SETCLIENTCOOKIES,SETDOMAINCOOKIES,STRICTNUMBERVALIDATION,WSVERSION.
WSCHANNEL doesn't work, either...
Copy link to clipboard
Copied
That can only mean that the ColdFusion team didn't consider it worthwhile to include the attribute wschannel to the cfapplication tag. They generally do their best to ensure that new additions to Application.cfc are backward-compatible with Application.cfm. Hence my assumption. But, unfortunately, not in this case.
As I said earlier, Application.cfm is outdated. You should continue with your original idea to use Application.cfc.
In any case, I have answered your original question. The Application.cfm issue arises from a new question. If you feel strongly about the absence of the wschannel attribute in <cfapplication>, report a bug. You might just get the ColdFusion team to include it.
Copy link to clipboard
Copied
Please mark the correct answer. That will help someone else in future.

