The business handler is the last handler in the request/response chain after all the middleware handlers. There are two types of middleware handlers: Technical and Business.
The Light-Platform is dedicated to providing all the technical middleware handlers to address technical cross-cutting concerns so that users can focus on their business logic to increase productivity and maintainability.
Big organizations will leverage the plugin architecture of the light platform to add another layer of business middleware handlers after the technical middleware handlers in the request/response chain. These handlers are industry-specific, and they usually call them together as their API platform. For example, one of the banking customers built their platform on top of light-4j to address Auditing, Fine-Grained Authorization, Result Filtering and Compliance to share these across all the APIs and applications.
Most developers who are working on the light-platform are building the final business handlers. Their job is to get the HTTP query parameters, path parameters and request body in the generated request handlers and create the corresponding response based on the input above. When users choose different HTTP frameworks, they need to know how to get the details from the request and then send the response. This document will be focusing on the request details.
To read the header, you can use the following method.
The Headers class defines a lot of HttpString objects for standard headers. If you cannot find yours, you can create a constant to define yours. It is faster than creating HttpString every time it is used.
public static final HttpString BASIC = new HttpString("Basic");
List<Map<String, Object>> body = (List)exchange.getAttachment(BodyHandler.REQUEST_BODY);
This is the normal web form submission, and the result will be converted to a map or list if the body handler is configured in the chain just like the JSON above.
In case you don’t have BodyHandler in the chain for the endpoint, you can use the following code to parse the form data manually.
// get the form from the exchange
final FormData data = exchange.getAttachment(FormDataParser.FORM_DATA);
final FormData.FormValue jClientId = data.getFirst("client_id");
final FormData.FormValue jRedirectUri = data.getFirst("redirect_uri");
final FormData.FormValue jState = data.getFirst("state");
final FormData.FormValue jRemember = data.getFirst("remember");
final String clientId = jClientId.getValue();
final String remember = jRemember == null ? null : jRemember.getValue(); // should be 'Y' or 'N' if not null.
String redirectUri = jRedirectUri == null ? null : jRedirectUri.getValue();
final String state = jState == null ? null : jState.getValue();
logger.debug("client_id = " + clientId + " state = " + state + " redirectUri = " + redirectUri + " remember = " + remember);
For most users, we recommend to add the BodyHandler to the endpoint in the handler.yml and get the map from the exchange attachment.
For users who want to send binary data from a client to a server, you can use this media type. The BodyHander will convert this to a stream and put it into the exchange as an attachment. Here is the code in the BodyHandler.