Generate XML header information in CGI mode

0 Likes

This article explains how to generate XML header information when running in CGI mode.

Problem:

A COBOL program that runs in background mode must write to SYSOUT so that it will be shown in a web browser. The problem however is that the output must be in XML format instead of HTML. The error indicates that the content type needs to be XML. How can this be done this using AcuCOBOL?

This is what has been suggested for php: header ("Content-type:text/xml")

But this is not something that can be done in the XML file itself, but must be set as part of the header. How can this be accomplished with the AcuCOBOL-GT Runtime?

Resolution:

Set this variable in the runtime configuration file or environment:

CGI_CONTENT_TYPE=text/xml.

This will direct the runtime to provide the specified value for the Content-type header that the runtime automatically generates.

The runtime can also be prevented from supplying _any_ HTTP headers automatically. To do this, set:

CGI_AUTO_HEADER=0 (or false, no, off)

This might be useful if some other process is already providing the HTTP headers (PHP, Perl, shell script, etc) and the output from the COBOL program is just being merged into that process's STDOUT stream. If, for some reason HTTP headers need to be explicitly generated from COBOL, use the DISPLAY verb, for instance:

DISPLAY "Content-type: text/xml" UPON SYSOUT (Omit UPON SYSOUT if compiling with -Ca)

The DISPLAY statement above will include a trailing newline character (0x0a). To strictly comply with Internet standards, use the NO ADVANCING clause, then DISPLAY a CR/LF pair explicitly. If it is the end of the HTTP headers, DISPLAY two successive CR/LF pairs:

DISPLAY "Content-type: text/xml" UPON SYSOUT, NO ADVANCING.

DISPLAY x"0D0A" UPON SYSOUT, NO ADVANCING. | single CR/LF

or

DISPLAY x"0D0A0D0A" UPON SYSOUT, NO ADVANCING. | consecutive CR/LF's

Incident Number: 2287482

Old KB# 14596
Comment List
Anonymous
Related Discussions
Recommended