Search in sources :

Example 6 with DissectionFailure

use of nl.basjes.parse.core.exceptions.DissectionFailure in project logparser by nielsbasjes.

the class QueryStringFieldDissector method dissect.

// --------------------------------------------
@Override
public void dissect(final Parsable<?> parsable, final String inputname) throws DissectionFailure {
    final ParsedField field = parsable.getParsableField(INPUT_TYPE, inputname);
    String fieldValue = field.getValue().getString();
    if (fieldValue == null || fieldValue.isEmpty()) {
        // Nothing to do here
        return;
    }
    String[] allValues = fieldValue.split("&");
    for (String value : allValues) {
        int equalPos = value.indexOf('=');
        if (equalPos == -1) {
            if (!"".equals(value)) {
                String name = value.toLowerCase();
                if (wantAllFields || requestedParameters.contains(name)) {
                    parsable.addDissection(inputname, "STRING", name, "");
                }
            }
        } else {
            String name = value.substring(0, equalPos).toLowerCase();
            if (wantAllFields || requestedParameters.contains(name)) {
                try {
                    parsable.addDissection(inputname, "STRING", name, resilientUrlDecode(value.substring(equalPos + 1, value.length())));
                } catch (IllegalArgumentException e) {
                    // This usually means that there was invalid encoding in the line
                    throw new DissectionFailure(e.getMessage());
                }
            }
        }
    }
}
Also used : ParsedField(nl.basjes.parse.core.ParsedField) DissectionFailure(nl.basjes.parse.core.exceptions.DissectionFailure)

Aggregations

DissectionFailure (nl.basjes.parse.core.exceptions.DissectionFailure)6 ParsedField (nl.basjes.parse.core.ParsedField)4 Matcher (java.util.regex.Matcher)2 URI (java.net.URI)1 LocalDateTime (java.time.LocalDateTime)1 ZonedDateTime (java.time.ZonedDateTime)1 DateTimeParseException (java.time.format.DateTimeParseException)1 InvalidDissectorException (nl.basjes.parse.core.exceptions.InvalidDissectorException)1 MissingDissectorsException (nl.basjes.parse.core.exceptions.MissingDissectorsException)1 SerDeException (org.apache.hadoop.hive.serde2.SerDeException)1 Text (org.apache.hadoop.io.Text)1