public class JSONHandler extends Object implements HTTPSourceHandler
1. headers - the key for this key-value pair is "headers". The value for this key is another map, which represent the event headers. These headers are inserted into the Flume event as is.
2. body - The body is a string which represents the body of the event. The key for this key-value pair is "body". All key-value pairs are considered to be headers. An example:
[{"headers" : {"a":"b", "c":"d"},"body": "random_body"}, {"headers" : {"e": "f"},"body": "random_body2"}]
would be interpreted as the following two flume events:
* Event with body: "random_body" (in UTF-8/UTF-16/UTF-32 encoded bytes) and headers : (a:b, c:d)
* Event with body: "random_body2" (in UTF-8/UTF-16/UTF-32 encoded bytes) and headers : (e:f)
The charset of the body is read from the request and used. If no charset is set in the request, then the charset is assumed to be JSON's default - UTF-8. The JSON handler supports UTF-8, UTF-16 and UTF-32. To set the charset, the request must have content type specified as "application/json; charset=UTF-8" (replace UTF-8 with UTF-16 or UTF-32 as required). One way to create an event in the format expected by this handler, is to use JSONEvent and use Gson to create the JSON string using the Gson.toJson(java.lang.Object, java.lang.reflect.Type) method. The type token to pass as the 2nd argument of this method for list of events can be created by:
Type type = new TypeToken<List<JSONEvent>>() {}.getType();
Constructor and Description |
---|
JSONHandler() |
Modifier and Type | Method and Description |
---|---|
void |
configure(Context context)
Request the implementing class to (re)configure itself.
|
List<Event> |
getEvents(javax.servlet.http.HttpServletRequest request)
Takes an HttpServletRequest and returns a list of Flume
Events.
|
public List<Event> getEvents(javax.servlet.http.HttpServletRequest request) throws Exception
getEvents
in interface HTTPSourceHandler
request
- The request to be parsed into Flume events.HTTPBadRequestException
- If the was not parsed correctly into an
event because the request was not in the expected format.Exception
- If there was an unexpected error.public void configure(Context context)
Configurable
Request the implementing class to (re)configure itself.
When configuration parameters are changed, they must be reflected by the component asap.
There are no thread safety guarantees on when configure might be called.
configure
in interface Configurable
Copyright © 2009–2019 Apache Software Foundation. All rights reserved.