I've got a web service 'TestService' which calls a stored procedure 'TestProcedure'. I'd like to include some error handling (e.g. the web service is called with the wrong parameters).
But when I use the HTTP___RESPONSE_HEADER function to retrieve the HTTP status code, the result is empty. Am I missing something?
The client who sends the request receives the HTTP status code correctly, is just not possible to retrieve the value in the stored procedure.
CREATE SERVICE "TestService" TYPE 'RAW' AUTHORIZATION OFF USER "dba" METHODS 'GET' AS call TestProcedure();
CREATE PROCEDURE "dba"."TestProcedure"() result (TestProcedureResult xml) begin declare sReponse xml; /* Set 'Bad Request' status */ call sa_set_http_header('@HttpStatus','400'); /* Set Content-Type to XML */ call sa_set_http_header('Content-Type','application/xml'); /* Write messages to console */ message 'Status code: '||http_response_header('@HttpStatus') to console; message 'Content-Type: '||http_response_header('Content-Type') to console; set sReponse = xmlelement(name "Error",'This is not a valid request'); select sReponse; end;
In the console the following lines are displayed:
asked 31 Jan '14, 07:50
For those not familiar with this feature, the http_response_header() builtin function is used to query the outgoing header that will be sent in the response to the web service call.
However, I just checked the code and despite what the documentation says the http_response_header does not currently recognize the special @HttpStatus 'header' name ... so I'm not sure how it ever got into the documentation. Since I can see that this would be a useful feature, I'll see about getting this fixed in a future SP (aka EBF).
answered 31 Jan '14, 09:23