Java Code Examples for nl.basjes.parse.core.Parser#getPossiblePaths()

The following examples show how to use nl.basjes.parse.core.Parser#getPossiblePaths() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Main.java    From logparser with Apache License 2.0 6 votes vote down vote up
private void printAllPossibles(String logformat) throws NoSuchMethodException, MissingDissectorsException, InvalidDissectorException {
    // To figure out what values we CAN get from this line we instantiate the parser with a dummy class
    // that does not have ANY @Field annotations.
    Parser<Object> dummyParser= new HttpdLoglineParser<>(Object.class, logformat);

    List<String> possiblePaths;
    possiblePaths = dummyParser.getPossiblePaths();

    // If you want to call 'getCasts' then the actual parser needs to be constructed.
    // Simply calling getPossiblePaths does not build the actual parser.
    // Because we want this for all possibilities yet we are never actually going to use this instance of the parser
    // We simply give it a random method with the right signature and tell it we want all possible paths
    dummyParser.addParseTarget(String.class.getMethod("indexOf", String.class), possiblePaths);

    LOG.info("==================================");
    LOG.info("Possible output:");
    for (String path : possiblePaths) {
        LOG.info("{}     {}", path, dummyParser.getCasts(path));
    }
    LOG.info("==================================");
}
 
Example 2
Source File: ApacheHttpdLogParserTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPossiblePaths() {
    Parser<TestRecord> parser = new HttpdLoglineParser<>(TestRecord.class, LOG_FORMAT);

    List<String> paths = parser.getPossiblePaths(5);
    assertEquals(true, paths.contains("TIME.SECOND:request.receive.time.second"));
    assertEquals(true, paths.contains("STRING:request.firstline.uri.query.*"));
    assertEquals(true, paths.contains("STRING:response.cookies.*.expires"));
    assertEquals(true, paths.contains("HTTP.HEADER:response.header.etag"));

    assertEquals(false, paths.contains("FIXED_STRING:fixed_string"));
}
 
Example 3
Source File: ApacheHttpdLogParserTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testGetPossiblePathsWithUnusableLogFormat() {
    Parser<TestRecord> parser = new HttpdLoglineParser<>(TestRecord.class, "Empty");

    List<String> paths = parser.getPossiblePaths(5);
    assertTrue("The output should be empty!", paths == null || paths.isEmpty());
}
 
Example 4
Source File: CookiesTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testEmptyRecordPossibles() {
    Parser<EmptyTestRecord> parser = new HttpdLoglineParser<>(EmptyTestRecord.class, LOG_FORMAT);

    List<String> possibles = parser.getPossiblePaths();
    for (String possible : possibles) {
        System.out.println(possible);
    }
}
 
Example 5
Source File: CookiesTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testRecordPossibles() {
    Parser<TestRecord> parser = new HttpdLoglineParser<>(TestRecord.class, LOG_FORMAT);

    List<String> possibles = parser.getPossiblePaths();
    for (String possible : possibles) {
        System.out.println(possible);
    }
}
 
Example 6
Source File: JsonLogFormatTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicParsing() {
    Parser<TestRecord> parser = new HttpdLoglineParser<>(TestRecord.class, LOGFORMAT);

    DissectorTester tester = DissectorTester.create()
        .withParser(parser)
        .verbose();

    for (String logline: LOGLINES){
        tester.withInput(logline);
    }

    tester.expectValuePresent("TIME.LOCALIZEDSTRING:request.receive.time")
          .expectValuePresent("STRING:connection.server.name")
          .expectValuePresent("NUMBER:connection.client.logname")
          .expectValuePresent("STRING:connection.client.user")
          .expectValuePresent("HTTP.HEADER:request.header.x-forwarded-for")
          .expectValuePresent("HTTP.URI:request.referer")
          .expectValuePresent("HTTP.USERAGENT:request.user-agent")
          .expectValuePresent("HTTP.HEADER:request.header.host")
          .expectValuePresent("HTTP.FIRSTLINE:request.firstline")
          .expectValuePresent("HTTP.METHOD:request.firstline.method")
          .expectValuePresent("HTTP.URI:request.firstline.uri")
          .expectValuePresent("HTTP.PROTOCOL:request.firstline.protocol")
          .expectValuePresent("HTTP.PROTOCOL.VERSION:request.firstline.protocol.version")
          .expectValuePresent("STRING:request.status.last")
          .expectValuePresent("BYTES:response.body.bytes")
          .expectValuePresent("MICROSECONDS:response.server.processing.time")
          .expectValuePresent("HTTP.QUERYSTRING:request.firstline.uri.query")
          .expectValuePresent("HTTP.PATH:request.firstline.uri.path")
          .expectValuePresent("HTTP.REF:request.firstline.uri.ref");

    for (String path: parser.getPossiblePaths()){
        tester.expectPossible(path);
    }

    tester.checkExpectations();
}
 
Example 7
Source File: BasicOverallTest.java    From logparser with Apache License 2.0 5 votes vote down vote up
@Test
public void testBasicParsing() throws Exception {
    Parser<MyRecord> parser = new HttpdLoglineParser<>(MyRecord.class, LOG_FORMAT);
    MyRecord         record = new MyRecord();

    List<String> paths = parser.getPossiblePaths();

    parser.addParseTarget(record.getClass().getMethod("setValue", String.class, String.class), paths);

    for (String logline : LOG_LINES) {
        record.clear();
        parser.parse(record, logline);
        System.out.println(record.toString());
    }
}