Back to Contents


The HTTP Service Request class

Summary:

See also: The Genero Web Services COM Extension Library


Syntax

The HTTP Service Request class provides an interface to process incoming XML and TEXT requests over HTTP on the server side, with an access to the HTTP layer and additional XML streaming possibilities.

Note that status is set to zero after a successful method call.

Syntax

com.HTTPServiceRequest

Methods


Reading request from client

Object Methods
Name Description
getURL()
   RETURNING
STRING
Returns the entire URL request containing the host, port, document and query string.
getMethod()
   RETURNING
STRING
Returns the HTTP method of the request (GET,POST,PUT,HEAD,DELETE)
getRequestVersion()
   RETURNING
STRING
Returns the HTTP version of the request (1.0 or 1.1).
hasRequestKeepConnection()
   RETURNING
INTEGER
Returns whether the request expect the connection to stay open after the sending of the response.
getRequestHeader(
  name
STRING )
   RETURNING
STRING
Returns the value of the request header name, or NULL.
Throws an exception in case of errors, and updates status with an error code.
getRequestHeaderCount()
   RETURNING
INTEGER
Returns the number of request headers.
getRequestHeaderName(
  index
INTEGER )
 
 RETURNING STRING
Returns the name of the request header at given position (index is starting at 1).
Throws an exception in case of errors, and updates status with an error code.
getRequestHeaderValue(
  index
INTEGER )
  
RETURNING STRING
Returns the value of the request header at given position (index is starting at 1).
Throws an exception in case of errors, and updates status with an error code.
readFormEncodedRequest(
  utf8
INTEGER )
   RETURNING
STRING
Returns the query of a POST application/x-www-form-urlencoded request or the query string of a GET request, decoded according to HTML4 or XFORM if utf8 is TRUE.
Note: If utf8 is TRUE, the decoded query string is translated from utf-8 to the locale charset that might lead to a conversion error.
Throws an exception in case of errors, and updates status with an error code.
readTextRequest()
   RETURNING
STRING
Returns the body of the request as a string. Supported methods are PUT and POST.
Note: The request Content-Type header must be of the form text/* as for instance text/richtext.
Throws an exception in case of errors, and updates status with an error code.
readXmlRequest()
   RETURNING
xml.DomDocument
Returns the body of the request as an entire XML document. Supported methods are PUT and POST.
Note: The request Content-Type header must be of the form */xml or */*+xml as for instance application/xhtml+xml.
Throws an exception in case of errors, and updates status with an error code.
beginXmlRequest()
   RETURNING
xml.StaxReader
Begins the streaming HTTP request and returns a xml.StaxReader object ready to read the XML from the client. Supported methods are PUT and POST.
Note: The request Content-Type header must be of the form */xml or */*+xml as for instance application/xhtml+xml.
Throws an exception in case of errors, and updates status with an error code.
endXmlRequest(
  stax xml.StaxReader )
Ends the streaming HTTP request by closing the StaxReader.
Throws an exception in case of errors, and updates status with an error code.

Back to the top


Responding to the client

Object Methods
Name Description
setResponseVersion(
  version
STRING )
Sets the HTTP response version (1.0 or 1.1).
Notes:
  • If no set, the same version as the request is used.
  • The method must be called before sending the response with sendResponse, sendTextResponse, sendXmlResponse or beginXmlResponse and endXmlResponse

Throws an exception in case of errors, and updates status with an error code.
 

setResponseCharset(
  charset
STRING )
Sets the charset to be used when sending XML or Text.
Notes:
  • If not set, the same charset as the request is used, or the implicit ISO-8859-1 when responding TEXT.
  • The method must be called before sending the response with one of sendResponse, sendTextResponse, sendXmlResponse or beginXmlResponse and endXmlResponse

Throws an exception in case of errors, and updates status with an error code.
 

setResponseHeader(
  name
STRING,
  value
STRING )
Sets or replaces a header name and value to be sent in the response.
Notes:
  • The Content-Length header cannot be set, because it is computed internally according to the body size.
  • The method must be called before sending the response with one of sendResponse, sendTextResponse, sendXmlResponse or beginXmlResponse and endXmlResponse

Throws an exception in case of errors, and updates status with an error code.
 

beginXmlResponse(
  code
INTEGER,
  description
STRING )
  RETURNING
xml.StaxWriter
Begins the HTTP streaming response by sending the given status code and description, followed by the headers previously set, and returns a staxWriter ready to send XML as the HTTP body.
Notes:
  • The default Content-Type header is text/xml, but it can be changed if of the form */xml or */*+xml, for instance application/xhtml+xml.
  • In HTTP 1.1, if the body size is greater than 32k, the response will be sent in several chunks of the same size.
  • If description is NULL, a default description according to the status code is sent.

Throws an exception in case of errors, and updates status with an error code.
 

endXmlResponse(
  stax xml.StaxWriter )
Ends the HTTP streaming response by closing the staxWriter.
Notes:

Throws an exception in case of errors, and updates status with an error code.
 

sendXmlResponse(
  code
INTEGER,
  description
STRING,
  doc
xml.DomDocument )
Performs the HTTP response by sending the given status code and description, followed by the headers previously set, and an entire XML document as body.
Notes:
  • The default Content-Type header is text/xml, but it can be changed if of the form */xml or */*+xml, for instance application/xhtml+xml.
  • In HTTP 1.1, if the body size is greater than 32k, the response will be sent in several chunks of the same size.
  • If description is NULL, a default description according to the status code is sent.
  • The body of the request is discarded.
  • New incoming requests can be retrieved again with com.WebServiceEngine.getHTTPServiceRequest().

Throws an exception in case of errors, and updates status with an error code.
 

sendTextResponse(
  code
INTEGER,
  description
STRING,
  txt
STRING )
Performs the HTTP response by sending the given status code and description, followed by the headers previously set, and an entire string as body.
Notes:
  • The default Content-Type header is text/plain, but it can be changed if of the form text/*, for instance text/richtext.
  • Automatic conversion from locale to user-defined charset is performed when possible, otherwise throws an exception.
  • In HTTP 1.1, if the body size is greater than 32k, the response will be sent in several chunks of the same size.
  • If description is NULL, a default description according to the status code is sent.
  • The body of the request is discarded.
  • New incoming requests can be retrieved again with com.WebServiceEngine.getHTTPServiceRequest().

Throws an exception in case of errors, and updates status with an error code.
 

sendResponse(
  code
INTEGER,
  description
STRING )
Performs the HTTP response by sending the given status code and description, followed by the headers previously set, and without any body.
Notes:
  • If description is NULL, a default description according to the status code is sent.
  • The body of the request is discarded.
  • New incoming requests can be retrieved again with  com.WebServiceEngine.getHTTPServiceRequest().

Throws an exception in case of errors, and updates status with an error code.

Back to the top