|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object org.apache.flume.source.http.JSONHandler
public class JSONHandler
JSONHandler for HTTPSource that accepts an array of events. This handler throws exception if the deserialization fails because of bad format or any other reason. Each event must be encoded as a map with two key-value pairs.
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
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 guarrantees on when configure might be called.
>() {}.getType();
Constructor Summary
JSONHandler()
Method Summary
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.
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Constructor Detail
JSONHandler
public JSONHandler()
Method Detail
getEvents
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.
configure
public void configure(Context context)
Configurable
configure
in interface Configurable
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
Copyright © 2009-2012 Apache Software Foundation. All Rights Reserved.