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

Filters not working #66

Closed
jkischkel opened this Issue Oct 28, 2013 · 1 comment

Comments

2 participants
@jkischkel

jkischkel commented Oct 28, 2013

Hey, I'm using the latest version of finatra, but it seem that filters are not working as described here:

http://finatra.info/docs/index.html#filters

I built a single file example with a filter that throws an exception to isolate the problem:

package com.fintest

import com.twitter.finatra._
import com.twitter.finagle._
import com.twitter.app.App
import com.twitter.finagle.http.{Request => FinagleRequest}
import com.twitter.finagle.http.{Response => FinagleResponse}

class Example extends Controller {
  get("/") { request =>
     render.plain("hi").toFuture
  }
}

class MyServer extends FinatraServer {
    val controller = new Example()
    addFilter(new TestFilter)
    register(controller)
}

class TestFilter extends SimpleFilter[FinagleRequest, FinagleResponse] with App {

  def apply(
    request: FinagleRequest,
    service: Service[FinagleRequest, FinagleResponse]) = {
    service(request) map { response =>
        throw new Exception("!") // this is never executed
        response
    }
  }
}

object Runner {
    def main(args: Array[String]): Unit = {
        val server = new MyServer()
        server.start()
    }  
}

The exception is never thrown. Any idea why this is the case?

@salomvary

This comment has been minimized.

salomvary commented Oct 28, 2013

Ugly workaround:

class MyServer extends FinatraServer {
    val controller = new Example()
    register(controller)

    override def allFilters(baseService: Service[FinagleRequest, FinagleResponse]):
        Service[FinagleRequest, FinagleResponse] = {
      filters = filters ++ Seq(new TestFilter)
      super.allFilters(baseService)
    }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment