project BLF > class BXmlDaemonQueue > method ApiSubmitXML

Description

submit an XML document to the XML daemon


Parameters


icFileNameinputcharacterfile name
ivBXmlDaemonQueueinputdatasetXml document
oiReturnStatusoutputintegerReturn status of the method.


Internal usage


unused


program code (program3/bxmldaemonqueue.p)

if icFileName = ""
or icFileName = ?
then assign icFileName = "Input":U + string (random(1,9999),"9999":U).

if index (icFileName,chr(47)) > 0 /*slash*/
or index (icFileName,chr(92)) > 0 /*backslash*/
then do:
    <M-1 run SetMessage
          (input  'Invalid file name.':U (icMessage), 
           input  '' (icArguments), 
           input  '' (icFieldName), 
           input  '' (icFieldValue), 
           input  'S':U (icType), 
           input  3 (iiSeverity), 
           input  '' (icRowid), 
           input  'BLF-293':U (icFcMsgNumber), 
           input  '' (icFcExplanation), 
           input  '' (icFcIdentification), 
           input  '' (icFcContext), 
           output viFcReturnSuper (oiReturnStatus)) in BXmlDaemonQueue>
    assign oiReturnStatus = -3.
    return.
end.

/* lookup daemon input directory */
<Q-2 run XmlDaemonInfo (all) (Read) (NoCache)
          (input 0, (DaemonId)
           output dataset tqXmlDaemonInfo) in BXmlDaemon >
find first tqXmlDaemonInfo no-error.
if not available tqXmlDaemonInfo
then return.

if can-find (first t_sXmlDaemonQueueSegment)
then do:
    output to value (tqXmlDaemonInfo.tcXmlDaemonDirectory + "/":U + icFileName).
    for each t_sXmlDaemonQueueSegment
          by t_sXmlDaemonQueueSegment.XmlDaemonQueueSegmentSeq:
        put unformatted t_sXmlDaemonQueueSegment.XmlDaemonQueueSegmentText.
    end.
    output close.
end.
else for each t_sXmlDaemonQueue on error undo, throw:
    copy-lob from t_sXmlDaemonQueue.XmlDaemonQueueLOB to file (tqXmlDaemonInfo.tcXmlDaemonDirectory + "/":U + icFileName).
    leave.
end.


Sample code: how to call this method through RPCRequestService (QXtend Inbound)

define temp-table ttContext no-undo
    field propertyQualifier as character
    field propertyName as character
    field propertyValue as character
    index entityContext is primary unique
        propertyQualifier
        propertyName
    index propertyQualifier
        propertyQualifier.

define dataset dsContext for ttContext.

define variable vhContextDS as handle no-undo.
define variable vhExceptionDS as handle no-undo.
define variable vhServer as handle no-undo.
define variable vhInputDS as handle no-undo.
define variable vhInputOutputDS as handle no-undo.
define variable vhOutputDS as handle no-undo.
define variable vhParameter as handle no-undo.

/* Create context */
create ttContext.
assign ttContext.propertyName = "programName"
       ttContext.propertyValue = "BXmlDaemonQueue".
create ttContext.
assign ttContext.propertyName = "methodName"
       ttContext.propertyValue = "ApiSubmitXML".
create ttContext.
assign ttContext.propertyName = "applicationId"
       ttContext.propertyValue = "fin".
create ttContext.
assign ttContext.propertyName = "entity"
       ttContext.propertyValue = "1000".
create ttContext.
assign ttContext.propertyName = "userName"
       ttContext.propertyValue = "mfg".
create ttContext.
assign ttContext.propertyName = "password"
       ttContext.propertyValue = "".

/* Create input dataset */
create dataset vhInputDS.
vhInputDS:read-xmlschema("file", "xml/bxmldaemonqueue.apisubmitxml.i.xsd", ?).
vhParameter = vhInputDS:get-buffer-handle("tParameterI").
vhParameter:buffer-create().
assign vhParameter::icFileName = <parameter value>.

vhParameter = vhInputDS:get-buffer-handle("tfcDaemonQueue").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tfcDaemonQueueLog").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tCustomTable0").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tCustomTable1").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tCustomTable2").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tXmlDaemonQueue").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tXmlDaemonQueueObject").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

vhParameter = vhInputDS:get-buffer-handle("tXmlDaemonQueueSegment").
vhParameter:buffer-create().
assign vhParameter::<field-name-1> = <field-value-1>
       vhParameter::<field-name-2> = <field-value-2>
       ...

/* Connect the AppServer */
create server vhServer.
vhServer:connect("-URL <appserver-url>").

if not vhServer:connected()
then do:
    message "Could not connect AppServer" view-as alert-box error title "Error".
    return.
end.

/* Run */
assign vhContextDS = dataset dsContext:handle.

run program/rpcrequestservice.p on vhServer
    (input-output dataset-handle vhContextDS by-reference,
           output dataset-handle vhExceptionDS,
     input        dataset-handle vhInputDS by-reference,
     input-output dataset-handle vhInputOutputDS by-reference,
           output dataset-handle vhOutputDS).

/* Handle output however you want, in this example, we dump it to xml */
if valid-handle(vhExceptionDS)
then vhExceptionDS:write-xml("file", "Exceptions.xml", true).

if valid-handle(vhOutputDS)
then vhOutputDS:write-xml("file", "Output.xml", true).

/* Cleanup */
vhServer:disconnect().
assign vhServer = ?.

if valid-handle(vhInputDS)
then delete object vhInputDS.

if valid-handle(vhOutputDS)
then delete object vhOutputDS.

if valid-handle(vhExceptionDS)
then delete object vhExceptionDS.