Search in sources :

Example 56 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 57 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 58 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 59 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)

Example 60 with Parser

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

the class JexlTest method testAssignment.

/**
 * Test assignment.
 * @throws Exception
 */
@Test
public void testAssignment() throws Exception {
    final JexlContext jc = new MapContext();
    jc.set("aString", "Hello");
    final Foo foo = new Foo();
    jc.set("foo", foo);
    final Parser parser = new Parser(";");
    parser.parse(null, new JexlFeatures().register(false), "aString = 'World';", null);
    assertExpression(jc, "hello = 'world'", "world");
    Assert.assertEquals("hello variable not changed", "world", jc.get("hello"));
    assertExpression(jc, "result = 1 + 1", new Integer(2));
    Assert.assertEquals("result variable not changed", new Integer(2), jc.get("result"));
// todo: make sure properties can be assigned to, fall back to flat var if no property
// assertExpression(jc, "foo.property1 = '99'", "99");
// Assert.assertEquals("property not set", "99", foo.getProperty1());
}
Also used : BigInteger(java.math.BigInteger) Parser(org.apache.commons.jexl3.parser.Parser) Test(org.junit.Test)

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 MappedByteBufferPool (org.eclipse.jetty.io.MappedByteBufferPool)26 ArrayList (java.util.ArrayList)25 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)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)9 Generator (org.eclipse.jetty.http2.generator.Generator)8