Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Java regex pathmatcher missing. #2749

dleacock opened this issue Oct 10, 2019 · 3 comments

Java regex pathmatcher missing. #2749

dleacock opened this issue Oct 10, 2019 · 3 comments


Copy link

@dleacock dleacock commented Oct 10, 2019

Apologies up front if the error is due to myself. I'm unable to find any java side information on this online or on the lightbend forums.

Intent: I wanted to create a route that matches for *.ts (i.e localhost:8080/video/1.ts). I've tried pathSuffix for ".ts" which didn't work so I attempt to use regex.

  1. According to the Basic PathMatchers there should be a PathMatchers.regex in the javadsl. Every other PathMatcher exists in javadsl (slash, end, segment, remaining, etc) but no .regex

  2. I tried to create my own PathMatcher1 based off a regex query and use
    path(PathMatcher1<T> p, java.util.function.Function<T,Route> inner)

I constructed my pathmatcher through:

Pattern regexPattern = Pattern.compile('some regex');
PathMatcher1<String> pathMatcher= PathMatchers.segment(regexPattern);

and my function,

private Function<String, Route> regexFunctionRoute = new Function<String, Route>() {
        public Route apply(String pathString) {
            return path(pathString, () ->
                    get(() -> extractRequest(request -> complete(testHandler.handleTS(request))))

When I try to use path(pathMatcher, regexFunctionRoute) it doesn't recognize pathMatcher as PathMatcher1. Intellij tells me that

Cannot resolve method 'path(akka.http.javadsl.server.PathMatcher1<java.lang.String>, java.util.function.Function<java.lang.String, akka.http.javadsl.server.Route>'.

It recognizes the function as being correct, but not the PathMatcher1. Am I doing something wrong or is there something missing from the javadsl?

Thank you very much

johanandren added a commit to johanandren/akka-http that referenced this issue Oct 17, 2019
Also added a test making sure it is accessible from Java.

This comment has been minimized.

Copy link

@johanandren johanandren commented Oct 17, 2019

The docs mentioning PathMatchers.regexp is an oversight, it should simply be PathMathers.segment(Pattern). Not sure why your code does not compile, in the PR to fix the docs I included a test case that uses a regex from Java that you can compare your code with:


This comment has been minimized.

Copy link

@dleacock dleacock commented Oct 17, 2019

Thank you for your help.

@jrudolph jrudolph added this to the 10.1.11 milestone Oct 21, 2019

This comment has been minimized.

Copy link

@jrudolph jrudolph commented Oct 21, 2019

Docs fixed in #2767.

@jrudolph jrudolph closed this Oct 21, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
None yet
3 participants
You can’t perform that action at this time.