JAX-RS Path with count regular expression - jax-rs

If I use the "{}" to specify the count condition in the regular expression of JAX-RS #Path, eclipse throws as error.
#Path("/apps/{itemId:\\d{10}}")
public Response getItems(...
The #Path annotation value '/apps/{itemId:\d{10}}' is invalid:
missing '{' or '}'.
Is above JAX-RS Path not a valid path ? Is it due to eclipse JAX-RS validator problem ? If I just specify #Path("/apps/{itemId}") there is no error.

You can't use curly brackets inside variable when using regex in Path annotation. Use instead:
#Path("/apps/{itemId: \\d+}")
regex = *( nonbrace / "{" *nonbrace "}" ) ; where nonbrace is any char other than "{" and "}"
Theoretically you can check 10 digits as you want using multiple [0-9]:
#Path("/apps/{itemId: [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]}")

Related

How to escape '(' in Karate feature file

I am trying to do an assertion in my feature file where my expected value is having '('
Is there any escape character to be used in the feature file. I have used '\' as escape character but no luck
Karate feature file statement:
And match response ProcessCustomer/header/status/description == 'Successful(EFT Payment)'
Getting below error:
com.intuit.karate.exception.KarateException: ESB_PaymentCardPayment.feature:20 - syntax error, expected '==' for match
The same statement works if I use 'contains' instead of '=='
You must be missing something, maybe unpack the XML value first into a string and try again. There is no special behavior for strings, try the following two lines and see it work:
* def test = 'Successful(EFT Payment)'
* match test == 'Successful(EFT Payment)'
* def xml = <root>Successful(EFT Payment)</root>
* match xml/root == 'Successful(EFT Payment)'

SPARQL Update: Underscore not allowed in language tag

I am trying to insert data into blazegraph using the 'Update' tab of blazegraph workbench. Below is a sample code snippet:
INSERT DATA
{
ns:MyNode ns:hasValue "MyValue"#en_us
}
I am specifying language tag with # symbol. However, it throws following exception:
org.openrdf.query.MalformedQueryException: Lexical error at line 8,
column 49. Encountered: "u" (117), after : "_"
It seems that it does not allow an underscore as part of language tag. If try just with 'en' it works fine.
Why is that so? Is underscore a special character here? If so, what is the way to escape it?
The syntax for language tags is defined by an RFC, now revised in RFC5646. Registration of language tags is controlled by IANA.
Subtags are separated by "-"; only A-Z,0-9 are legal in subtags.
When adopted for RDF syntaxes (N3, SPARQL, Turtle etc), the grammar pattern adopted was a compromise syntax that weakly matches the RFC. '#' [a-zA-Z]+ ('-' [a-zA-Z0-9]+)* without taking all the details. The subtag separator is "-". "_" is not allowed in a language tag.

XML parsing error for amersand in CDATA section

CDATA section is used to treat character '&' and '<' as normal text string but my XML is failing to parse due to '&' in CDATA section.
It says SAXParser exception with lex code 3 invalid character ' ' found.
Can you please suggest how to correct this?
<![CDATA[xxxxxx > 0]]>
its that using my project CDATA TYPE. I think is useful for you.

Lucene queryparser with "/" in query criteria

When I try to search for something such as "workaround/fix" within Lucene, it throws this error:
org.apache.lucene.queryparser.classic.ParseException: Cannot parse 'workaround/fix': Lexical error at line 1, column 15. Encountered: <EOF> after : "/fix"
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:131)
at pi.lucengine.LucIndex.main(LucIndex.java:112)
Caused by: org.apache.lucene.queryparser.classic.TokenMgrError: Lexical error at line 1, column 15. Encountered: <EOF> after : "/fix"
at org.apache.lucene.queryparser.classic.QueryParserTokenManager.getNextToken(QueryParserTokenManager.java:1133)
at org.apache.lucene.queryparser.classic.QueryParser.jj_scan_token(QueryParser.java:599)
at org.apache.lucene.queryparser.classic.QueryParser.jj_3R_2(QueryParser.java:482)
at org.apache.lucene.queryparser.classic.QueryParser.jj_3_1(QueryParser.java:489)
at org.apache.lucene.queryparser.classic.QueryParser.jj_2_1(QueryParser.java:475)
at org.apache.lucene.queryparser.classic.QueryParser.Clause(QueryParser.java:226)
at org.apache.lucene.queryparser.classic.QueryParser.Query(QueryParser.java:181)
at org.apache.lucene.queryparser.classic.QueryParser.TopLevelQuery(QueryParser.java:170)
at org.apache.lucene.queryparser.classic.QueryParserBase.parse(QueryParserBase.java:121)
This are my lines 111 and 112:
QueryParser parser = new QueryParser(Version.LUCENE_43, field, analyzer);
Query query = parser.parse(newLine);
What do I need to do to allow it to parse the "/"?
The query parser interprets slashes as the beginning/end or a regex query (as of 4.0, see documentation here).
So, to incorporate slashes into the query, you will need to escape them by adding a backslash (\) before them.
You can handle escaping with QueryParser.escape(String).
I encountered a similar problem when using '/' in lucene queries issued from the elastic search kibana dashboard. I was escaping the '/' characters as indicated in the documentation and still not getting any success. I think this is related to the template bug reported here : https://github.com/elastic/kibana/issues/789. Not sure yet, will update when we update the logstash components
I had a case where when using forward slash with wildcard it just wouldn't return any result, even if escaped it:
+(*16/17*)
+(*16\/17*)
The solution was to add double quote:
+("*16/17*")
+("*16\/17*")

How do I exclude characters / symbols using ANTLR grammar?

I'm trying to write a grammar for various time formats (12:30, 0945, 1:30-2:45, ...) using ANTLR. So far it works like a charm as long as I don't type in characters that haven't been defined in the grammar file.
I'm using the following JUnit test for example:
final CharStream stream = new ANTLRStringStream("12:40-1300,15:123-18:59");
final TimeGrammarLexer lexer = new TimeGrammarLexer(stream);
final CommonTokenStream tokenStream = new CommonTokenStream(lexer);
final TimeGrammarParser parser = new TimeGrammarParser(tokenStream);
try {
final timeGrammar_return tree = parser.timeGrammar();
fail();
} catch (final Exception e) {
assertNotNull(e);
}
An Exception gets thrown (as expected) because "15:123" isn't valid.
If I try ("15:23a") though, no exception gets thrown and ANTLR treats it like a valid input.
Now if I define characters in my grammar, ANTLR seems to notice them and I once again get the exception I want:
CHAR: ('a'..'z')|('A'..'Z');
But how do I exclude umlauts, symbols and other stuff a user is able to type in (äöü{%&<>!). So basically I'm looking for some kind of syntax that says: match everything BUT "0..9,:-"
...
So basically I'm looking for some kind of syntax that says: match everything BUT "0..9,:-"
The following rule matches any single character except a digit, ,, : and -:
Foo
: ~('0'..'9' | ',' | ':' | '-')
;
(the ~ negates single characters inside lexer-rules)
But you might want to post your entire grammar: I get the impression there are some other things you're not doing as they should have been done. Your call.
you can define a literal, that matches all the characters, that you do not want. If this literal is not contained in any of your rules, antlr will throw a NonViableException.
For unicode this could look like this:
UTF8 : ('\u0000'..'\u002A' // ! to *
| '\u002E'..'\u002F' // . /
| '\u003B'..'\u00FF' // ; < = > ? # as well as letters brackets and stuff
)
;