Configuring for Response (Outbound or Fault) Flow
You can configure outbound messages sent from a service by configuring the following:
- Supported Type: Basic, Bag
- Supported Header Source: HTTP_HEADERS
- Direction: Outbound / Fault
Add the following code.
To set a 'Basic' context parameter:
//Create a Mutable callbackContext (Response flow) from the original RequestContext MutableCallbackContext originalCallbackContext = (MutableCallbackContext) originalRequestContext.createCallbackContext(); originalCallbackContext.setParameter("bookCategoryCP", String.class, "Classic");
The value
Classic
is set for the HTTP Header
bookCategory
(corresponding to the context parameter
bookCategoryCP
) in the outgoing REST Response.
To set a context parameter 'Bag':
//Create a Mutable callbackContext (Response flow) from the original RequestContext MutableCallbackContext originalCallbackContext = (MutableCallbackContext) originalRequestContext.createCallbackContext(); HashMap<String, String> responseHeadersAllCP_service_map = new HashMap<String, String>(); responseHeadersAllCP_service_map.put("bookAuthor", "Harper Lee"); responseHeadersAllCP_service_map.put("bookPublishYear", "1960"); originalCallbackContext.setParameter("responseHeadersAllCP", Map.class, responseHeadersAllCP_service_map);
The contents of the HashMap
responseHeadersAllCP_service_map
is set as HTTP Headers (user-defined, corresponding to context parameter
responseHeadersAllCP
) in the outgoing REST response. Setting native HTTP Headers is not permitted.