本文整理匯總了Java中org.apache.flume.Event.getHeaders方法的典型用法代碼示例。如果您正苦於以下問題:Java Event.getHeaders方法的具體用法?Java Event.getHeaders怎麽用?Java Event.getHeaders使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.apache.flume.Event
的用法示例。
在下文中一共展示了Event.getHeaders方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: testExtractBadEvent1
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Test bad event format 1: Priority is not numeric
*/
@Test
public void testExtractBadEvent1() {
String badData1 = "<10F> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
示例2: testExtractBadEvent3
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Test bad event format 3: Empty priority - <>
*/
@Test
public void testExtractBadEvent3() {
String badData1 = "<> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
示例3: testExtractGoodEvent
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Good event
*/
@Test
public void testExtractGoodEvent() {
String priority = "<10>";
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes((priority + goodData1).getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null, headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
new String(e.getBody()).trim());
}
示例4: testLayout
import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testLayout() throws IOException {
configureSource();
props.put("log4j.appender.out2.layout", "org.apache.log4j.PatternLayout");
props.put("log4j.appender.out2.layout.ConversionPattern",
"%-5p [%t]: %m%n");
PropertyConfigurator.configure(props);
Logger logger = LogManager.getLogger(TestLog4jAppender.class);
Thread.currentThread().setName("Log4jAppenderTest");
for (int count = 0; count <= 100; count++) {
/*
* Log4j internally defines levels as multiples of 10000. So if we
* create levels directly using count, the level will be set as the
* default.
*/
int level = ((count % 5) + 1) * 10000;
String msg = "This is log message number" + String.valueOf(count);
logger.log(Level.toLevel(level), msg);
Transaction transaction = ch.getTransaction();
transaction.begin();
Event event = ch.take();
Assert.assertNotNull(event);
StringBuilder builder = new StringBuilder();
builder.append("[").append("Log4jAppenderTest").append("]: ")
.append(msg);
//INFO seems to insert an extra space, so lets split the string.
String eventBody = new String(event.getBody(), "UTF-8");
String eventLevel = eventBody.split("\\s+")[0];
Assert.assertEquals(Level.toLevel(level).toString(), eventLevel);
Assert.assertEquals(
new String(event.getBody(), "UTF8").trim()
.substring(eventLevel.length()).trim(), builder.toString());
Map<String, String> hdrs = event.getHeaders();
Assert.assertNotNull(hdrs.get(Log4jAvroHeaders.TIMESTAMP.toString()));
Assert.assertEquals(Level.toLevel(level),
Level.toLevel(Integer.parseInt(hdrs.get(Log4jAvroHeaders.LOG_LEVEL
.toString()))));
Assert.assertEquals(logger.getName(),
hdrs.get(Log4jAvroHeaders.LOGGER_NAME.toString()));
Assert.assertEquals("UTF8",
hdrs.get(Log4jAvroHeaders.MESSAGE_ENCODING.toString()));
transaction.commit();
transaction.close();
}
}
示例5: intercept
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Modifies events in-place.
*/
@Override
public Event intercept(Event event) {
Map<String, String> headers = event.getHeaders();
if (preserveExisting && headers.containsKey(header)) {
return event;
}
if (host != null) {
headers.put(header, host);
}
return event;
}
示例6: getType
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Returns the index type from the headers
*/
@Override
public String getType(Event event) {
Map<String, String> headers = event.getHeaders();
String type;
if (headers.get(TYPE) != null) {
type = headers.get(TYPE);
} else {
type = super.getType(event);
}
return type;
}
示例7: binding
import org.apache.flume.Event; //導入方法依賴的package包/類
public Object binding(final Event event) {
if (header == null) {
final byte body[] = event.getBody();
return dataType.convert(new String(body, Charsets.UTF_8));
} else {
final Map<String, String> headers = event.getHeaders();
for (final Map.Entry<String, String> entry : headers.entrySet()) {
if (entry.getKey().equals(header)) {
return dataType.convert(entry.getValue());
}
}
}
log.trace("No bindable field found for {}", this);
return null;
}
示例8: dumpEvent
import org.apache.flume.Event; //導入方法依賴的package包/類
public static String dumpEvent(Event event, int maxBytes) {
StringBuilder buffer = new StringBuilder();
if (event == null || event.getBody() == null) {
buffer.append("null");
} else if (event.getBody().length == 0) {
// do nothing... in this case, HexDump.dump() will throw an exception
} else {
byte[] body = event.getBody();
byte[] data = Arrays.copyOf(body, Math.min(body.length, maxBytes));
ByteArrayOutputStream out = new ByteArrayOutputStream();
try {
HexDump.dump(data, 0, out, 0);
String hexDump = new String(out.toByteArray());
// remove offset since it's not relevant for such a small dataset
if (hexDump.startsWith(HEXDUMP_OFFSET)) {
hexDump = hexDump.substring(HEXDUMP_OFFSET.length());
}
buffer.append(hexDump);
} catch (Exception e) {
if (LOGGER.isInfoEnabled()) {
LOGGER.info("Exception while dumping event", e);
}
buffer.append("...Exception while dumping: ").append(e.getMessage());
}
String result = buffer.toString();
if (result.endsWith(EOL) && buffer.length() > EOL.length()) {
buffer.delete(buffer.length() - EOL.length(), buffer.length()).toString();
}
}
return "{ headers:" + event.getHeaders() + " body:" + buffer + " }";
}
示例9: intercept
import org.apache.flume.Event; //導入方法依賴的package包/類
@Override
public Event intercept(Event event) {
Map<String, String> headers = event.getHeaders();
if (headers.containsKey("Bad-Words")) {
headers.remove("Bad-Words");
}
return event;
}
示例10: checkHeader
import org.apache.flume.Event; //導入方法依賴的package包/類
public static void checkHeader(String keepFields, String msg1, String stamp1, String format1,
String host1, String data1) throws ParseException {
SyslogUtils util;
if (keepFields == null || keepFields.isEmpty()) {
util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE, new HashSet<String>(), false);
} else {
util = new SyslogUtils(SyslogUtils.DEFAULT_SIZE,
SyslogUtils.chooseFieldsToKeep(keepFields),
false);
}
ChannelBuffer buff = ChannelBuffers.buffer(200);
buff.writeBytes(msg1.getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e.getHeaders();
if (stamp1 == null) {
Assert.assertFalse(headers2.containsKey("timestamp"));
} else {
SimpleDateFormat formater = new SimpleDateFormat(format1, Locale.ENGLISH);
Assert.assertEquals(String.valueOf(formater.parse(stamp1).getTime()),
headers2.get("timestamp"));
}
if (host1 == null) {
Assert.assertFalse(headers2.containsKey("host"));
} else {
String host2 = headers2.get("host");
Assert.assertEquals(host2, host1);
}
Assert.assertEquals(data1, new String(e.getBody()));
}
示例11: getIndex
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Returns the index name from the headers
*/
@Override
public String getIndex(Event event) {
Map<String, String> headers = event.getHeaders();
String index;
if (headers.get(INDEX) != null) {
index = headers.get(INDEX);
} else {
index = super.getIndex(event);
}
return index;
}
示例12: testBadEventGoodEvent
import org.apache.flume.Event; //導入方法依賴的package包/類
/**
* Bad event immediately followed by a good event
*/
@Test
public void testBadEventGoodEvent() {
String badData1 = "hi guys! <10F> bad bad data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
String priority = "<10>";
String goodData1 = "Good good good data\n";
buff.writeBytes((priority + goodData1).getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("1", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null, headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(), new String(e2.getBody()).trim());
}
示例13: testGoodEventBadEvent
import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testGoodEventBadEvent() {
String badData1 = "hi guys! <10F> bad bad data\n";
String priority = "<10>";
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes((priority + goodData1).getBytes());
buff.writeBytes(badData1.getBytes());
Event e2 = util.extractEvent(buff);
if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("1", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
new String(e2.getBody()).trim());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(badData1.trim(), new String(e.getBody()).trim());
}
示例14: testGoodEventGoodEvent
import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testGoodEventGoodEvent() {
String priority = "<10>";
String goodData1 = "Good good good data\n";
SyslogUtils util = new SyslogUtils(false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes((priority + goodData1).getBytes());
String priority2 = "<20>";
String goodData2 = "Good really good data\n";
buff.writeBytes((priority2 + goodData2).getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority + goodData1.trim(),
new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("2", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("4", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(null,
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals(priority2 + goodData2.trim(),
new String(e2.getBody()).trim());
}
示例15: testExtractBadEventLarge
import org.apache.flume.Event; //導入方法依賴的package包/類
@Test
public void testExtractBadEventLarge() {
String badData1 = "<10> bad bad data bad bad\n";
// The minimum size (which is 10) overrides the 5 specified here.
SyslogUtils util = new SyslogUtils(5, null, false);
ChannelBuffer buff = ChannelBuffers.buffer(100);
buff.writeBytes(badData1.getBytes());
Event e = util.extractEvent(buff);
if (e == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers = e.getHeaders();
Assert.assertEquals("1", headers.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("2", headers.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INCOMPLETE.getSyslogStatus(),
headers.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals("<10> bad b".trim(), new String(e.getBody()).trim());
Event e2 = util.extractEvent(buff);
if (e2 == null) {
throw new NullPointerException("Event is null");
}
Map<String, String> headers2 = e2.getHeaders();
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_FACILITY));
Assert.assertEquals("0", headers2.get(SyslogUtils.SYSLOG_SEVERITY));
Assert.assertEquals(SyslogUtils.SyslogStatus.INVALID.getSyslogStatus(),
headers2.get(SyslogUtils.EVENT_STATUS));
Assert.assertEquals("ad data ba".trim(), new String(e2.getBody()).trim());
}