Websocket (pws://)

A-Stack supports pws protocol Handler, that can be used for websocket connections

PWS Protocol Handler Flow:

PWS Protocol Parameters:

The table below lists all the parameters of pws protocol handler and their description

Parameter Name

Parameter Description

URL


The http/https URL of websocket server.

Payload

The Payload of the Post Invoke.


Usage of PWS protocol handler:

  • PWS Get:  the facet given below in for A-Stack Version 1.0.5 or greater.

    PWS GET Facet
    <ThingFacet Name="PWSConnectionFacet">
        <String Format="$ObjectFormat(xml)" KnownBy="PWSConnectionAction" Name="ReceivedData" update="auto"/>
        <String Name="URL"/>
        <Action Name="PWSConnectionAction">
            <Workflow Limit="1" Live="1" Timeout="-1">
                <Task name="Main" while="true">
                    <Event as="ActionArgument" name="Argument"/>
                    <Invoke get="pws://?URL=[%:Event.Argument.URL.Value:%]&amp;" name="InvokePwsSubscription" scope="process" waitFor="Argument">
                        <Headers/>
                        <Cookie/>
                    </Invoke>
                    <Output As="ActionResult" Name="Result">
                        <Value>
                            <ReceivedData>
                                <Include>
    								Invoke.InvokePwsSubscription.Message.Value
                                </Include>
                            </ReceivedData>
                        </Value>
                    </Output>
                </Task>
            </Workflow>
        </Action>
    </ThingFacet>   
    PWS GET Query
    <Query>
        <DeleteAll>
            <PwsGetModel>
                <pwsID ne=""/>
            </PwsGetModel>
        </DeleteAll>
        <Create>
            <PwsGetModel>
                <ReceivedData>$Null()</ReceivedData>
                <URL>ws://localhost:8080/fid-loggerfacet</URL>
            </PwsGetModel>
        </Create>
    </Query>
    PWS POST Facet
    <ThingFacet Name="PwsPostConnectionFacet">
        <String Format="$ObjectFormat(xml)" KnownBy="PwsPostConnectionAction" Name="ReceivedData" update="auto"/>
        <String Name="URL"/>
    	<String Name="Payload"/>
        <Action Name="PwsPostConnectionAction">
            <Workflow Limit="1" Live="1" Timeout="-1">
                <Task name="Main" while="true">
                    <Event as="ActionArgument" name="Argument"/>
                    <Invoke name="InvokePwsSubscription" post="pws://?URL=[%:Event.Argument.URL.Value:%]&amp;" scope="process" waitFor="Argument">
                        <Headers/>
                        <Cookie/>
                        <Message>
                            <Value>[%:Event.Argument.Payload.Value:%]</Value>
                        </Message>
                    </Invoke>
                    <Output As="ActionResult" Name="Result">
                        <Value>
                            <ReceivedData>
                                <Include>
    								Invoke.InvokePwsSubscription.Message.Value
                                </Include>
                            </ReceivedData>
                        </Value>
                    </Output>
                </Task>
            </Workflow>
        </Action>
    </ThingFacet>   
    PWS POST Query
    <Query>
        <DeleteAll>
            <PwsPostModel>
                <pwsID ne=""/>
            </PwsPostModel>
        </DeleteAll>
        <Create>
            <PwsPostModel>
                <ReceivedData>$Null()</ReceivedData>
    			<Payload>Hello World</Payload>
                <URL>ws://localhost:9090</URL>
            </PwsPostModel>
        </Create>
    </Query>


PWS Invoke Output Format: The output message of pws Invoke is an xml structure as shown below


PWS Invoke Output Format
<ReceivedData Value="" Version="1">
	<Known>
		<Data>
			<Log>
				<Level>WARN</Level>
				<Source>SffTcpClient</Source>
				<Timestamp>1481614580958</Timestamp>
				<Message>IO error in SffTqlPolicyFacet:TQL-97069142663125278:http&gt;NioClientSocketChannel[id: 0xc0a611b0]; Caused by: java.net.ConnectException: Connection refused: localhost/127.0.0.1:1212</Message>
			</Log>
		</Data>
	</Known>
</ReceivedData>