Loading...
 

CX_HTTP_RESPONSE

CX_HTTP_RESPONSE

Class hierarchy
Description:

Class to assemble an HTTP response (consisting of status code, header and body) in InstantView code via method calls. At the end of a message that handles an HTTP request, the Web service server expects either a string returned with ReturnStack and implicitly converted into an HTTP response object with status code 200. Alternatively, a CX_HTTP_RESPONSE object can be returned directly with ReturnStack .

When an HTTP request is sent via SendRequest , the server response is placed on the stack as a CX_HTTP_RESPONSE object.

The specification of an HTTP response can be found at http://tools.ietf.org/html/rfc2616#section-6

Code example:

Incoming GET request

GET /call_person?person_name=Schmidt

Implementation of the message (the two macros "GetPersonFromName" and "FormatPersonAsJSON" are assumed to be implemented)

Var(jsonReturnValue, response)

CALL_PERSON_GET: "person_name" Swap Call(GetParameter) GetPersonFromName FormatPersonAsJSON -> jsonReturnValue
                 CreateTransObject(CX_HTTP_RESPONSE) -> response

                 jsonReturnValue response Call(SetBody)
                 "Content-Type" "application/json" response Call(SetHeader)

                 "Server" "ClassiX/4.5.2" response Call(SetHeader)
                 200 response Call(SetStatus) // not actually neccessary, as this is already the default
                 response ReturnStack

This results in the following outgoing HTTP response:

HTTP/1.1 200 OK
Date: Thu, 15 Jul 2004 19:20:21 GMT
Content-length: 42
Content-type: application/json

Connection: close
Server: ClassiX/4.5.2

{ "vorname" : "Hugo", "name" : "Schmidt" }

List of methods (MDI)
Function MA* Parameters Return Brief description
GetBody STRING Returns the Reponse Body
GetBodyAsBase64
222628
STRINGReturns the response body as a base64 encoded string.
GetBodyAsFile
222628
STRING Writes the response body to the specified file.
GetHeader STRING STRING Returns the header of the response object
GetHeaderNames
VECTOR<STRING>
Returns the names of all set headers
GetStatus INTEGER Returns the set HTTP status
GetTime CX_DATETIME Returns the time at which the request has been completely processed
SetBody STRING Defines the body of the response
SetBodyFromBase64
222628
STRING Sets the response body from a Base64-encoded string
SetBodyFromFile
222628
STRING Sets the response body from the content of the transferred file.
SetHeader STRING, STRING Defines the value for a header field
SetStatus INTEGER Defines the status code of the response

* MA = Member Access function,
grey background = inherited function

Data directory (DDI)
Data field Type Reference class I* Brief description
status INTEGER HTTP status of the response

* I = Indexable data field,
grey background = inherited data field

Use in AppsWH
Module Brief description