Apigee Environment: Cloud
Problem Description:
I was attempting to modify the regular expression on a Condition that was included in the OOTB SOAP pass thru proxy and was unable to use a regular expression that contained a match on the double quote (") character. Whenever I attempted to save the regular expression (which was validated using the Java run time) Apigee would display the following error:
Error in proxy default. Invalid condition: !((request.header.Content-Type ~~ "(text|application)\/(xml|([a-z]*\+xml))(;(\w)*=(\S*))?") or (request.header.Content-Type ~~ "(multipart\/related)[;[ ]*[\w]+=[\S]+]*(;[ ]*type="application\/xop\+xml")[;[ ]*[\w]+=[\S]+]*")) and (request.verb != "GET") in policy Invalid-SOAP. Reason: Unmatched closing ) near index 224
Failing condition:
The condition below caused the failure message shown above in Apigee.
<Condition>!((request.header.Content-Type ~~ "(text|application)\/(xml|([a-z]*\+xml))(;(\w)*=(\S*))?") or (request.header.Content-Type ~~ "(multipart\/related)[;[ ]*[\w]+=[\S]+]*(;[ ]*type="application\/xop\+xml")[;[ ]*[\w]+=[\S]+]*")) and (request.verb != "GET")</Condition>
Working condition:
The condition below worked around the issue and allowed me to successfully save the proxy changes.
<Condition>!((request.header.Content-Type ~~ "(text|application)\/(xml|([a-z]*\+xml))(;(\w)*=(\S*))?") or (request.header.Content-Type ~~ "(multipart\/related)[;[ ]*[\w]+=[\S]+]*(;[ ]*type=(.{1})application\/xop\+xml(.{1}))[;[ ]*[\w]+=[\S]+]*")) and (request.verb != "GET")</Condition>
Is there a way to escape double quote (") characters in regular expressions? I couldn't find the answer looking at the regular expression and/or condition documentation.
Solved! Go to Solution.
Using unicode to specify the rabbit ears works for me. Here's my simple test case.
request.header.Content-Type ~~ "(multipart\/related)(; *type=\u0022application\/xop\+xml\u0022)"
If I pass in
-H 'content-type:multipart/related; type="application/xop+xml"'
...then the condition evaluates to true.
Using unicode to specify the rabbit ears works for me. Here's my simple test case.
request.header.Content-Type ~~ "(multipart\/related)(; *type=\u0022application\/xop\+xml\u0022)"
If I pass in
-H 'content-type:multipart/related; type="application/xop+xml"'
...then the condition evaluates to true.
Thanks! I wasn't able to find the proper escape character to use from the documentation. It would be great if this was added.
I'll ask for that to be added!
@Dino-at-Google, If i want to escape ? in my regex then what should i do? I am using some regex in which i want to use ? as character, how can i do that?
<Condition>(proxy.pathsuffix JavaRegex "(/|\?)([wW][sS][dD][lL])") and (request.verb = "GET")</Condition>
Here,In (/|\?). / condition is working fine but ? condition is working. Can you please asiste here.
did you try the unicode sequence for ?
\u003F
<Condition>(proxy.pathsuffix JavaRegex "(/|\u003F)([wW][sS][dD][lL])") and (request.verb = "GET")</Condition>
Also you didn't ask, but it is possible to use case-insensitive patterns in the regex, so you could avoid [wW][sS][dD][lL] . Do this with the (?i) directive preceding your query.
<Condition>(proxy.pathsuffix ~~ "(?i)(/|\u003F)wsdl$"</Condition>
User | Count |
---|---|
1 | |
1 | |
1 | |
1 | |
1 |