Author Topic: OCS SCXML Http Request Get Data  (Read 5356 times)

Offline volkandemirpence

  • Newbie
  • *
  • Posts: 3
  • Karma: 0
OCS SCXML Http Request Get Data
« on: December 21, 2015, 09:11:59 AM »
I want to get response data of http request posted page.
I tried a few different things. But i didn't succeed yet. Does anyone have a different idea about this?
Need help.

- With JavaScript XmlHttpRequest. Failed. XmlHttpRequest is a browser object. Couldn't use in SCXML.

- Basichttp: This just send variables to the specified address. Can't get response.

[i]<send type="basichttp" target="http://example.com/cgi-bin/main.py" >
    <param name="variable1" expr="1" />
    <param name="variable2" expr="2" />
</send>[/i]

- Web service call. This theoretical. Trial and error Not working.

[i]    <state id="WebServiceRequest">
    <invoke id="i" type="application/soap+xml" src="http://myserver/MyService.svc?wsdl" />
    <transition event="init.invoke.i">
      <send target="#i" type="application/soap+xml" event="GetData"  >
        <param name="value" expr="5" />
      </send>
    </transition> 
    <transition event="result.invoke.i.GetData">
      <log label="result" expr="_event.data" />
    </transition>
  </state>[/i]

- This sample from Orchestration Server routing project scxml. I simplified this code for OCS SCXML. Didn't work. [i] session.fetch.done[/i] not a true event for OCS transition.

[i]<state id="WebRequest1">
<onentry>
    <log expr="_sessionid + ': Inside WebRequest Block: WebRequest1'" />
<script>
var parameters = new Object();
parameters['Var1'] = DNIS;
parameters['Var2'] = CallID;
var InputParamString = '(' + JSON.stringify(parameters) + ')';
</script>
<session:fetch requestid="App_WebRequest1"
      srcexpr="App_RelativePathURL + 'include/getWebRequestDataWorkflow.aspx'"
      method="'post'" enctype="'application/x-www-form-urlencoded'">
<param name="WebUrl" expr="''http://Myserver/MySite/Default.aspx?function=ScxmlTest''" />
<param name="Protocol" expr="'post'" />
<param name="AuthenAccess" expr="'false'" />
<param name="InputParamString" expr="InputParamString"/>
</session:fetch>
  </onentry>
<transition event="session.fetch.done">
<log expr="'Session FETCH  DONE'" />
<log expr="'Composer Application:' + App_Name + ' Block: WebRequest1'" />
<log expr="'Data Fetched:' + _event.data.content" />
<script>App_WebRequest1 = eval('(' + _event.data.content + ')');</script>
<assign location="webServiceOutput" expr="App_WebRequest1" />
<log expr="'Data Assigned: ' + webServiceOutput.toSource()"/>
<if cond="typeof App_WebRequest1.errorMsg == 'undefined'">
<log expr="'received no error msgs'" />
<raise event="com.genesyslab.composer.sessionfetchdone" />
<else/>
<log expr="'received error msgs: sending error event'" />
<raise event="error.com.genesyslab.composer.servererror">
  <param name="description" expr="App_WebRequest1.errorMsg" />
</raise>
</if>
<log expr="'Session FETCH  DONE'" />
    </transition>
    <transition event="com.genesyslab.composer.sessionfetchdone" target="$$_MY_PREFIX_$$.Exit1" />
</state>[/i]
« Last Edit: December 21, 2015, 09:56:52 AM by volkandemirpence »

Offline abudwill

  • Full Member
  • ***
  • Posts: 157
  • Karma: 4
Re: OCS SCXML Http Request Get Data
« Reply #1 on: December 31, 2015, 06:37:54 PM »
Hello,

I have been down the road of trying to figure out how to "get" data in SCXML/OCS before and came up empty.  The JavaScript engine the SCXML engine implements is SpiderMonkey which does not implement XmlHttpRequest.

My only solution was to place the data I needed inside my calling list.

Within the SCXML you can HTTP POST data back to a system.  See OCS SCXML example sample07.scxml.

Regards,
Andrew


Offline abudwill

  • Full Member
  • ***
  • Posts: 157
  • Karma: 4
Re: OCS SCXML Http Request Get Data
« Reply #2 on: January 01, 2016, 12:36:22 AM »
I have been thinking about this more.

You might also want to look at the OCS pre dial validation feature.

The pre dial validation feature causes OCS to HTTP POST data in JSON format to a URI of your choosing.  OCS then expects a response (also in JSON format).  There are some other things to know as described in documentation (for example the E-Tag in the response to the POST must be the record handle of the record).  Although not documented older versions of OCS will not process responses that are chunked.  I raise this because the response your endpoint provides to OCS has the potential to write data to calling list fields (again described in documentation).  Connection pooling is also supported.

I am not sure what the order of operations is here - for example is pre dial validation executed first, then advanced treatments (scxml)?  If so, you have a fighting shot at being able to utilize pre dial validation to populate a calling list field a retrieval time which can then be referred to inside of your SCXML.

Offline gkhnvrl

  • Newbie
  • *
  • Posts: 12
  • Karma: 0
Re: OCS SCXML Http Request Get Data
« Reply #3 on: January 08, 2016, 08:21:37 AM »
As it is not documented well, we generate steps according to OCS Logs that covers both scxml & predial :

- Retrieved record comes to [b]scxml[/b] session first.
- When [b]<ocs:makecall />[/b] called inside [b]scxml[/b], [b]predial[/b] kicks in.
- If [b]predial[/b] returns 200 OK, [b]OCS[/b] calls the record.
- After call finishes, [b]scxml[/b] kicks in again. According to call result, it jumps related target (apply treatment, etc.)
- ..