OMX Components

[Previous] [Next]

OmniMark supports the use of files and constant expressions as input directly in the language. OMX components provide input from other sources and supply a variety of external functionality to OmniMark programs. Components are used to attach to external data sources and destinations, to create and manage connections to the source using the appropriate protocols, and to provide an interface to an OmniMark program that is either an OmniMark source or an OmniMark sink. You can then process the source or attach a stream to the sink and make the stream part of the current output scope.

The following two programs create a client-server environment where data is passed back and forth. The first program, server.xom, creates a TCP/IP connection and waits for something to happen on it. The second program, client.xom, creates a TCP/IP connection and attaches a source and a stream to the connection to read and write data to it:

 include "" process ;establish the service local TCPService service initial {TCPServiceOpen at 5436} ;server loop repeat ;receive a connection from a client local TCPConnection connection initial {TCPServiceAcceptConnection service} ;receive the request string and print it out put #error TCPConnectionGetSource connection protocol IOProtocolMultiPacket || "%n" ;send a response set TCPConnectionGetOutput connection protocol IOProtocolMultiPacket to "<foo><bar>text</bar><baz bat='gruznatz'/></foo>" catch #program-error again 

This is the client code:

 include "" include "" global stream server-host initial {"localhost"} global integer server-port initial {5436} declare catch connection-error define switch function TCPconnection-is-working read-only TCPconnection connection as do when TCPConnectionIsInError connection local stream error-report variable TCPConnectionGetStatusReport connection into error-report log-message "TCP connection error:" repeat over error-report log-message error-report again return false else return true done process local TCPConnection connection local stream output-file local stream request ;open connection set connection to TCPConnectionOpen on server-host at server-port throw connection-error unless TCPconnection-is-working connection ;send the request set TCPConnectionGetOutput connection protocol IOProtocolMultiPacket to "<request><typelist/></request>" ;process the response do xml-parse instance scan TCPConnectionGetSource connection protocol IOProtocolMultiPacket put #error "%c" done catch connection-error put #error "Unable to connect%n" element #implied put #error "%n[%q]%c[/%q]" 

Run the server in one Command window, and then run the client in the other to observe the interaction. In these programs, the function TCPConnectionOpen—which you'll find in the omtcp library—creates a connection to a TCP/IP server and returns an OMX variable (connection) of type TCPConnection. This variable is a handle to the actual TCPConnection OMX, which manages the connection.

The function TCPConnectionGetOutput attaches an OmniMark stream (request) to the connection. You can then use this stream to send data to the server. The program generates the appropriate request by scanning the first item on the command line, represented by args[1]. The output generated by the find rules invoked by the submit statement will go straight to the server.

The function TCPConnectionGetSource returns an OmniMark source attached to the TCP/IP connection. This source is named in the scan parameter of do xml-parse, meaning that the data returned from the server is streamed directly into the XML parser.

XML and SOAP Programming for BizTalk Servers
XML and SOAP Programming for BizTalk(TM) Servers (DV-MPS Programming)
ISBN: 0735611262
EAN: 2147483647
Year: 2000
Pages: 150 © 2008-2017.
If you may any questions please contact us: