Config - Canned Responses
Canned Responses are response definitions that can be reused across multiple locations - this is especially useful if you have many locations that need to emit the same responses, e.g. if authorization or authentication fails - by using Canned Responses you can refer to a response definition and reuse it instead of repeating the same response multiple times.
Example JSON:
"cannedresponses" is a JSON Array of JSON Objects - each object contains the definition of a single response.
"cannedresponses": [ { "response.name": "plain ok", "response.headers": [{ "name": "Server", "value": "hidden" }], "response.reason": "OK", "response.status": 200 }, { "response.contenttype": "%{script:if (state.httpExchange.getRequestHeaders().getFirst('Content-Type') == 'application/json') 'application/json'; else 'text/html';}", "response.name": "Access Denied", "response.reason": "Invalid or missing credentials", "response.status": 403, "response.content": "%{script:if (state.httpExchange.getRequestHeaders().getFirst('Content-Type') == 'application/json') '{\"error\":\"access.denied\"\\}'; else '<html><head><title>No access<\/title><body><h1>Invalid credentials<\/h1><\/body><\/html>';}" } ]
Configuration Using Ceptor Console
If you press Add, you get to fill in the details for this response like this:
Once added you can edit the values.
Canned Response Name
Specify the name of a "canned" response here.
Default: none
JSON key: response.name
HTTP Response code
HTTP Response code to send back to client. Must be specified.
JSON key: response.status
HTTP Response reason
HTTP response reason text
Default: No additional information
JSON key: response.reason
Redirect Location
Response Redirect Location URL - if set, a redirect will be sent instead of a normal response, the Location header in the response will be set to this value.
Default: none
JSON key: response.redirect
Content-Type
HTTP Response content-type
Default: none
JSON key: response.contenttype
Response Body
Response body contents
By using macros such as the ones below, you can add information about the failure to the response:
<html><body>Authentication failed<p/>
Details:</br>
<pre>
%{htmlencode:EXCEPTION_LOG}
</pre>
</body></html>
Default: none
JSON key: response.body
Response Headers
Response headers can also be added to the response, if any are specified, they are in an JSON array called response.headers within the response JSON object.
You can add headers by clicking "Add", then you get a popup where you can set the name and value of the header.
Once created, they are added to the JSON Array response.headers within the JSON object, as a new object with the attributes name and value set to the entered name and value.
© Ceptor ApS. All Rights Reserved.