0
votes

I am developing a service that is called on one path with different query parameters. I have bind a Route to Http:

val route: Route = {
    get {
        pathPrefix("myRoute"){
            parameterMap{ params =>
                complete(
                   MyHandler.genExternResponse(params)
                )
            }
        }
    }

val bindingFuture = Http().bindAndHandleAsync(Route.asyncHandler(new myEndpoint().route), "localhost", 8081)

Since i have no influence on what parameters are used, i can't eliminate the calls that contain not-encoded special chars like German umlauts or trademark signs. for example

www.myhost.com/myRoute?param1=asd&param2=adäöü

I know that those URLs are not valid But one of the requirements is that even requests with those chars are accepted und that i handle them with URL encoding. The problem is that when i call the service like above, akka-http rejects the request with the Response-status 400 without even handing it to my code. Is there a way that i can catch those request and handle them by myself or let akka-http URL-encode the special chars for me.

edit: will not solve

1
could you post a stacktrace?Stefano Bonetti
don't know how since there is no error in code that prints a stacktrace and akka-http is just responding with 400.tjarko großmann
Could it be MyHandler.genExternResponse which is throwing an exception? Exceptions thrown here will convert to a 400. If you change your code to a complete ("ok") you don't get the error, so it's unlikely to be Akka's faultStefano Bonetti
no the problem is, that the request never even reaches my endpoint. even if i use the most basic examples from the akka-http dokumentation it wont except uri parameters with umlautstjarko großmann
uhmm weird it did work fine when I tried with complete("ok")Stefano Bonetti

1 Answers

1
votes

Try This

 val route: Route = {
  get {
    pathPrefix("myRoute"){
        parameters('params)
           { params =>
            complete(
               MyHandler.genExternResponse(params)
            )
        }
    }
}

val bindingFuture = Http().bindAndHandleAsync(Route.asyncHandler(new myEndpoint().route), "localhost", 8081)