Search in sources :

Example 61 with Parser

use of org.eclipse.jetty.http2.parser.Parser in project syncope by apache.

the class AbstractJPAJSONAnyDAO method findByDerAttrValue.

@SuppressWarnings("unchecked")
@Transactional(readOnly = true)
@Override
public <A extends Any<?>> List<A> findByDerAttrValue(final String table, final AnyUtils anyUtils, final DerSchema derSchema, final String value, final boolean ignoreCaseMatch) {
    if (derSchema == null) {
        LOG.error("No DerSchema");
        return List.of();
    }
    Parser parser = new Parser(derSchema.getExpression());
    // Schema keys
    List<String> identifiers = new ArrayList<>();
    // Literals
    List<String> literals = new ArrayList<>();
    // Get schema keys and literals
    for (Token token = parser.getNextToken(); token != null && StringUtils.isNotBlank(token.toString()); token = parser.getNextToken()) {
        if (token.kind == ParserConstants.STRING_LITERAL) {
            literals.add(token.toString().substring(1, token.toString().length() - 1));
        }
        if (token.kind == ParserConstants.IDENTIFIER) {
            identifiers.add(token.toString());
        }
    }
    // Sort literals in order to process later literals included into others
    literals.sort((l1, l2) -> {
        if (l1 == null && l2 == null) {
            return 0;
        } else if (l1 != null && l2 == null) {
            return -1;
        } else if (l1 == null) {
            return 1;
        } else if (l1.length() == l2.length()) {
            return 0;
        } else if (l1.length() > l2.length()) {
            return -1;
        } else {
            return 1;
        }
    });
    // Split value on provided literals
    List<String> attrValues = split(value, literals);
    if (attrValues.size() != identifiers.size()) {
        LOG.error("Ambiguous JEXL expression resolution: literals and values have different size");
        return List.of();
    }
    Map<String, List<Object>> clauses = new LinkedHashMap<>();
    // builder to build the clauses
    StringBuilder bld = new StringBuilder();
    // Contains used identifiers in order to avoid replications
    Set<String> used = new HashSet<>();
    // Create several clauses: one for eanch identifiers
    for (int i = 0; i < identifiers.size(); i++) {
        if (!used.contains(identifiers.get(i))) {
            // verify schema existence and get schema type
            PlainSchema schema = plainSchemaDAO.find(identifiers.get(i));
            if (schema == null) {
                LOG.error("Invalid schema '{}', ignoring", identifiers.get(i));
            } else {
                // clear builder
                bld.delete(0, bld.length());
                PlainAttrValue attrValue;
                if (schema.isUniqueConstraint()) {
                    attrValue = anyUtils.newPlainAttrUniqueValue();
                } else {
                    attrValue = anyUtils.newPlainAttrValue();
                }
                attrValue.setStringValue(attrValues.get(i));
                bld.append('(').append(queryBegin(table)).append("WHERE ").append(attrValueMatch(anyUtils, schema, attrValue, ignoreCaseMatch)).append(')');
                used.add(identifiers.get(i));
                List<Object> queryParams = new ArrayList<>();
                queryParams.add(schema.getKey());
                queryParams.add(attrValues.get(i));
                clauses.put(bld.toString(), queryParams);
            }
        }
    }
    LOG.debug("Generated where clauses {}", clauses);
    return buildResult(anyUtils, findByDerAttrValue(table, clauses));
}
Also used : ArrayList(java.util.ArrayList) Token(org.apache.commons.jexl3.parser.Token) Parser(org.apache.commons.jexl3.parser.Parser) LinkedHashMap(java.util.LinkedHashMap) PlainAttrValue(org.apache.syncope.core.persistence.api.entity.PlainAttrValue) ArrayList(java.util.ArrayList) List(java.util.List) PlainSchema(org.apache.syncope.core.persistence.api.entity.PlainSchema) HashSet(java.util.HashSet) Transactional(org.springframework.transaction.annotation.Transactional)

Example 62 with Parser

use of org.eclipse.jetty.http2.parser.Parser in project sonar-iac by SonarSource.

the class CloudformationParser method parse.

@Override
public FileTree parse(String source, @Nullable InputFileContext inputFileContext) {
    LoadSettings settings = LoadSettings.builder().setParseComments(shouldParseComments(inputFileContext)).build();
    StreamReader reader = new StreamReader(settings, source);
    ScannerImpl scanner = new ScannerImpl(settings, reader);
    Parser parser = new ParserImpl(settings, scanner);
    Composer composer = new Composer(settings, parser);
    List<Node> nodes = composerNodes(composer);
    return CloudformationConverter.convertFile(nodes);
}
Also used : Composer(org.snakeyaml.engine.v2.composer.Composer) StreamReader(org.snakeyaml.engine.v2.scanner.StreamReader) ScannerImpl(org.snakeyaml.engine.v2.scanner.ScannerImpl) Node(org.snakeyaml.engine.v2.nodes.Node) ParserImpl(org.snakeyaml.engine.v2.parser.ParserImpl) LoadSettings(org.snakeyaml.engine.v2.api.LoadSettings) TreeParser(org.sonar.iac.common.extension.TreeParser) Parser(org.snakeyaml.engine.v2.parser.Parser)

Example 63 with Parser

use of org.eclipse.jetty.http2.parser.Parser in project carbon-mediation by wso2.

the class HL7MessageBuilder method serializeHL7toXML.

private String serializeHL7toXML(Message message) throws AxisFault {
    Parser xmlParser = new DefaultXMLParser();
    xmlParser.setValidationContext(new NoValidation());
    try {
        return xmlParser.encode(message);
    } catch (HL7Exception e) {
        throw new AxisFault("Error on converting to HL7 XML: " + e.getMessage(), e);
    }
}
Also used : AxisFault(org.apache.axis2.AxisFault) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser) HL7Exception(ca.uhn.hl7v2.HL7Exception) NoValidation(ca.uhn.hl7v2.validation.impl.NoValidation) Parser(ca.uhn.hl7v2.parser.Parser) DefaultXMLParser(ca.uhn.hl7v2.parser.DefaultXMLParser)

Example 64 with Parser

use of org.eclipse.jetty.http2.parser.Parser in project carbon-mediation by wso2.

the class HL7EndpointManager method validateParameters.

private void validateParameters(InboundProcessorParams params, Map<String, Object> parameters) {
    if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_AUTO_ACK).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_AUTO_ACK).equalsIgnoreCase("false")) {
        log.warn("Parameter inbound.hl7.AutoAck in HL7 inbound " + params.getName() + " is not valid. Default " + "value of true will be used.");
        params.getProperties().setProperty(MLLPConstants.PARAM_HL7_AUTO_ACK, "true");
    }
    try {
        Integer.valueOf(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_TIMEOUT));
    } catch (NumberFormatException e) {
        log.warn("Parameter inbound.hl7.TimeOut in HL7 inbound " + params.getName() + " is not valid. Default timeout " + "of " + MLLPConstants.DEFAULT_HL7_TIMEOUT + " milliseconds will be used.");
        params.getProperties().setProperty(MLLPConstants.PARAM_HL7_TIMEOUT, String.valueOf(MLLPConstants.DEFAULT_HL7_TIMEOUT));
    }
    try {
        if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PRE_PROC) != null) {
            final HL7MessagePreprocessor preProcessor = (HL7MessagePreprocessor) Class.forName(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PRE_PROC)).newInstance();
            Parser preProcParser = new PipeParser() {

                public Message parse(String message) throws HL7Exception {
                    message = preProcessor.process(message, Axis2HL7Constants.MessageType.V2X, Axis2HL7Constants.MessageEncoding.ER7);
                    return super.parse(message);
                }
            };
            parameters.put(MLLPConstants.HL7_PRE_PROC_PARSER_CLASS, preProcParser);
        }
    } catch (Exception e) {
        log.error("Error creating message preprocessor for HL7 inbound " + params.getName() + ": ", e);
    }
    try {
        if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET) == null) {
            params.getProperties().setProperty(MLLPConstants.PARAM_HL7_CHARSET, MLLPConstants.UTF8_CHARSET.displayName());
            parameters.put(MLLPConstants.HL7_CHARSET_DECODER, MLLPConstants.UTF8_CHARSET.newDecoder());
        } else {
            parameters.put(MLLPConstants.HL7_CHARSET_DECODER, Charset.forName(params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET)).newDecoder());
        }
    } catch (UnsupportedCharsetException e) {
        parameters.put(MLLPConstants.HL7_CHARSET_DECODER, MLLPConstants.UTF8_CHARSET.newDecoder());
        log.error("Unsupported charset '" + params.getProperties().getProperty(MLLPConstants.PARAM_HL7_CHARSET) + "' specified in HL7 inbound " + params.getName() + ". Default UTF-8 will be used instead.");
    }
    if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_VALIDATE) == null) {
        params.getProperties().setProperty(MLLPConstants.PARAM_HL7_VALIDATE, "true");
    }
    if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE) == null) {
        params.getProperties().setProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE, "false");
    } else {
        if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE).equalsIgnoreCase("false")) {
            params.getProperties().setProperty(MLLPConstants.PARAM_HL7_BUILD_RAW_MESSAGE, "false");
        }
    }
    if (params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES) == null) {
        params.getProperties().setProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES, "false");
    } else {
        if (!params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES).equalsIgnoreCase("true") && !params.getProperties().getProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES).equalsIgnoreCase("false")) {
            params.getProperties().setProperty(MLLPConstants.PARAM_HL7_PASS_THROUGH_INVALID_MESSAGES, "false");
        }
    }
}
Also used : PipeParser(ca.uhn.hl7v2.parser.PipeParser) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) SynapseException(org.apache.synapse.SynapseException) UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) HL7Exception(ca.uhn.hl7v2.HL7Exception) Parser(ca.uhn.hl7v2.parser.Parser) PipeParser(ca.uhn.hl7v2.parser.PipeParser)

Example 65 with Parser

use of org.eclipse.jetty.http2.parser.Parser in project commons-jexl by apache.

the class Engine method parse.

/**
 * Parses an expression.
 *
 * @param info      information structure
 * @param parsingf  the set of parsing features
 * @param src      the expression to parse
 * @param scope     the script frame
 * @return the parsed tree
 * @throws JexlException if any error occurred during parsing
 */
protected ASTJexlScript parse(final JexlInfo info, final JexlFeatures parsingf, final String src, final Scope scope) {
    final boolean cached = src.length() < cacheThreshold && cache != null;
    JexlFeatures features = parsingf != null ? parsingf : DEFAULT_FEATURES;
    // if (features.getNameSpaces().isEmpty() && !functions.isEmpty()) {
    // features = new JexlFeatures(features).nameSpaces(functions.keySet());
    // }
    final Source source = cached ? new Source(features, src) : null;
    ASTJexlScript script;
    if (source != null) {
        script = cache.get(source);
        if (script != null) {
            final Scope f = script.getScope();
            if ((f == null && scope == null) || (f != null && f.equals(scope))) {
                return script;
            }
        }
    }
    final JexlInfo ninfo = info == null && debug ? createInfo() : info;
    // if parser not in use...
    if (parsing.compareAndSet(false, true)) {
        try {
            // lets parse
            script = parser.parse(ninfo, features, src, scope);
        } finally {
            // no longer in use
            parsing.set(false);
        }
    } else {
        // ...otherwise parser was in use, create a new temporary one
        final Parser lparser = new Parser(new StringProvider(";"));
        script = lparser.parse(ninfo, features, src, scope);
    }
    if (source != null) {
        cache.put(source, script);
    }
    return script;
}
Also used : ASTJexlScript(org.apache.commons.jexl3.parser.ASTJexlScript) StringProvider(org.apache.commons.jexl3.parser.StringProvider) JexlFeatures(org.apache.commons.jexl3.JexlFeatures) JexlInfo(org.apache.commons.jexl3.JexlInfo) Parser(org.apache.commons.jexl3.parser.Parser)

Aggregations

ByteBuffer (java.nio.ByteBuffer)38 ByteBufferPool (org.eclipse.jetty.io.ByteBufferPool)38 Parser (org.eclipse.jetty.http2.parser.Parser)37 Test (org.junit.Test)37 ArrayList (java.util.ArrayList)27 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)26 HeaderGenerator (org.eclipse.jetty.http2.generator.HeaderGenerator)21 HttpFields (org.eclipse.jetty.http.HttpFields)18 MetaData (org.eclipse.jetty.http.MetaData)18 HashMap (java.util.HashMap)16 ServerSessionListener (org.eclipse.jetty.http2.api.server.ServerSessionListener)15 SettingsFrame (org.eclipse.jetty.http2.frames.SettingsFrame)15 OutputStream (java.io.OutputStream)14 Socket (java.net.Socket)14 CountDownLatch (java.util.concurrent.CountDownLatch)13 HeadersFrame (org.eclipse.jetty.http2.frames.HeadersFrame)13 PrefaceFrame (org.eclipse.jetty.http2.frames.PrefaceFrame)13 Parser (ca.uhn.hl7v2.parser.Parser)11 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Generator (org.eclipse.jetty.http2.generator.Generator)8