[ https://issues.apache.org/jira/browse/CAMEL-20763?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]
Claus Ibsen updated CAMEL-20763: -------------------------------- Fix Version/s: 4.7.0 > Rest template with underscore fails after Camel 4.2.0 > ----------------------------------------------------- > > Key: CAMEL-20763 > URL: https://issues.apache.org/jira/browse/CAMEL-20763 > Project: Camel > Issue Type: Bug > Components: camel-core > Affects Versions: 4.2.0 > Environment: Camel 4.2.0 or later > Reporter: Dave Riseley > Priority: Minor > Fix For: 4.7.0 > > > We have a camel route, which in it's simplified form looks like this: > {code:java} > @Component > public class CamelRouteBuilder extends RouteBuilder{ > @Override > public void configure() throws Exception { > restConfiguration().component("servlet"); > rest("/hello") > .get("/{first_name}") > .to("direct:helloworld"); > from("direct:helloworld") > .transform() > .simple("Hi ${header.first_name}"); > } > } > {code} > This works fine on Spring Boot 3.1.11 / Camel 4.0.5 . When we upgrade to > Camel 4.2.0 or later, it fails on startup with the following exception: > > {code:java} > Caused by: java.util.regex.PatternSyntaxException: named capturing group is > missing trailing '>' near index 17 > \/hello\/(?<first_name>[^\/]+) > ^ > at java.base/java.util.regex.Pattern.error(Pattern.java:2028) ~[na:na] > at java.base/java.util.regex.Pattern.groupname(Pattern.java:2945) > ~[na:na] > at java.base/java.util.regex.Pattern.group0(Pattern.java:2990) > ~[na:na] > at java.base/java.util.regex.Pattern.sequence(Pattern.java:2124) > ~[na:na] > at java.base/java.util.regex.Pattern.expr(Pattern.java:2069) ~[na:na] > at java.base/java.util.regex.Pattern.compile(Pattern.java:1783) > ~[na:na] > at java.base/java.util.regex.Pattern.<init>(Pattern.java:1430) > ~[na:na] > at java.base/java.util.regex.Pattern.compile(Pattern.java:1069) > ~[na:na] > at > org.apache.camel.support.RestConsumerContextPathMatcher.register(RestConsumerContextPathMatcher.java:255) > ~[camel-support-4.2.0.jar:4.2.0] > at > org.apache.camel.http.common.CamelServlet.connect(CamelServlet.java:424) > ~[camel-http-common-4.2.0.jar:4.2.0] > at > org.apache.camel.component.servlet.CamelHttpTransportServlet.connect(CamelHttpTransportServlet.java:100) > ~[camel-servlet-4.2.0.jar:4.2.0] > .... > {code} > I believe this is due to a change introduced by > https://issues.apache.org/jira/browse/CAMEL-8306 in which the following > method: > {code:java} > /** > * Pre-compiled consumer path for wildcard match > * > * @param consumerPath a consumer path > */ > public static void register(String consumerPath) { > // Convert URI template to a regex pattern > String regex = consumerPath > .replace("/", "\\/") > .replace("{", "(?<") > .replace("}", ">[^\\/]+)"); > // Add support for wildcard * as path suffix > regex = regex.replace("*", ".*"); > // Match the provided path against the regex pattern > Pattern pattern = Pattern.compile(regex); > PATH_PATTERN.put(consumerPath, pattern); > } > {code} > > does not allow for underscore (and other regex special characters) in the > parameter name. I could not find any documentation that describes limits on > the characters that can be used in rest templates. > Our production code has many, many rest routes with many parameters with > underscores in them. > I will prepare a PR with a proposed fix -- This message was sent by Atlassian Jira (v8.20.10#820010)