Built-in subroutines that generate output to the web service client

The MVS Toolkit provides the ability for subroutines called from the Web Service to access the HTTP header data and generate direct responses to the Web Service client. This feature enables the developer to override default formatting by generating custom XML, JSON, HTML, or other formats.

The following built-in subroutines are provided to facilitate interaction between the user’s subroutine and the Web Service client.

MVSP.GET.HTTP.URI(URI)

Returns the URI of the web service being called.

For example, if the Web Service is invoked with http://www.yourserver.com:8181/orders/inquiry

/orders/inquiry will be returned.

MVSP.GET.HTTP.URI.PARAMETERS(URI.PARAMETERS)

Returns the URI parameters as a dynamic array containing a multi-attribute, multi-valued table of parameters (URL encoded) passed typically in HTTP GET requests.

For example:

http://host:port/ws/wso?ID=1&name=acme&phone=800-555-5555

will result in two attributes, each with three values:

Value Attribute 1 Attribute 2
Value 1 ID 1
Value 2 name acme
Value 3 phone 800-555-5555

MVSP.GET.HTTP.REQUEST.HEADER(REQUEST.HEADER)

Returns a dynamic array containing a multi-attribute, multi-valued table of HTTP request header content.

For example, the following HTTP Request header:

POST /ws/wso HTTP/1.0
Host: www.yourserver.com
Accept: application/json
Content-type: application/  x-www-form-urlencoded
Content-length: 120

will result in two attributes each with four values:

Value Attribute 1 Attribute 2
Value 1 Host www.yourserver.com
Value 2 Accept application/json
Value 3 Content-type application/x-www-form-urlencoded
Value 4 Content-length 120

Accessing the requestor's IP address

The IP Address/port number of the requestor is returned in the request header's dynamic array value. To access this value, call the MVSP.GET.HTTP.REQUEST.HEADER subroutine to get the request header dynamic array and return the Remote-Address value.  For example:

CALL MVSP.GET.HTTP.REQUEST.HEADER(REQUEST.HEADER)
LOCATE('Remote-Address', REQUEST.HEADER, 1; VMC) THEN
REMOTE.ADDRESS = REQUEST.HEADER<2, VMC>
END

MVSP.GET.HTTP.REQUEST(REQUEST)

Returns a dynamic array containing a multi-attribute, multi-valued table of HTTP request content.

For example, the following HTTP Request content:

ID=1&name=acme&phone=800-555-5555

will result in two attributes, each with three values:

Value  Attribute 1 Attribute 2
Value 1 ID 1
Value 2 name acme
Value 3 phone 800-555-5555

MVSP.SET.HTTP.RESPONSE.HEADER(RESPONSE.HEADER)

Sets a dynamic array containing a multi-attribute, multi-valued table of items you want to add to the standard HTTP response or data you want to overwrite in the standard HTTP response.

For example, the following is a standard HTTP Response header:

HTTP/1.1 200 OK
Content-type: application/json; charset=UTF-8
Server: Jetty(6.1.26)

If you are sending an XML response and want to add a Content length and Content type, build a two-attribute, two-valued dynamic array as follows:

Value  Attribute 1 Attribute 2
Value 1 Content-type text/xml; charset=UTF-8
Value 2 Content-length 147

The default status code that is returned upon success is 200. If you want to return a different status code, build a two-attribute dynamic array as follows:

Value Attribute 1 Attribute 2
Value 1 status valid 3-digit status code

In this example, setting the status code to 401 would return the following HTTP Response header:

HTTP/1.1 401 Unauthorized
Content-type: application/json; charset=UTF-8
Server: Jetty(6.1.26)

MVSP.SET.HTTP.RESPONSE(RESPONSE)

Sets the HTTP response content. Whatever you pass in as RESPONSE will be passed back to the Web Service user as HTTP response content without any interference from the MVS Server.

CAUTION:
It is your responsibility to construct well-formed XML, HTML, JSON, etc., and properly match it to the Content-type as specified in the HTTP response header.