[scaldi-play 0.5.8] HttpRequestHandler

108 views
Skip to first unread message

Santiago Gutierrez

unread,
Aug 20, 2015, 9:56:15 AM8/20/15
to scaldi
Hello guys;

I face a issue while trying to override onRouteRequest, the problem is that sometimes it does inject the extended class but other when I re compile not.

Can you help me?


Versions:
Play 2.4.1
Scaldi 0.5.8

Config:
play.modules.enabled += configurations.settings.SettingsModule
GlobalSettings.onRouteRequest = configurations.settings.VRouteHandler
play.application.loader = configurations.ExtendedScaldiApplicationLoader

class SettingsModule extends Module {
   bind[HttpRequestHandler] toNonLazy new VRouteHandler
}

My Class: 
class VRouteHandler(errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: HttpFilters, routes: Router)
  extends DefaultHttpRequestHandler( routes, errorHandler, configuration, filters) {

  override def routeRequest(request: RequestHeader) = {
        super.routeRequest(request.copy(path = request.path.replace("context1","context2")))
  }
}

class ExtendedScaldiApplicationLoader extends ScaldiApplicationLoader {
  override def load(context: Context): Application =
    super.load(context.copy(
      initialConfiguration = context.initialConfiguration.getString("environment", Some(Set("rc", "prod"))).flatMap(env => context.initialConfiguration.getConfig(env).map(_ ++ context.initialConfiguration)).getOrElse(context.initialConfiguration)
    ))
}

Ty!


Alexandre Bedrytski

unread,
Aug 23, 2015, 12:52:08 PM8/23/15
to scaldi
In case you didn't find a solution yet: could you, please, provide us with some vanilla play project with those modifications so that we could reproduce the problem in our own environment?

Oleg Ilyenko

unread,
Aug 24, 2015, 6:34:23 PM8/24/15
to scaldi
Hi guys,

Sorry for the late reply. Maybe you can try this one, it should work for your example:

class SettingsModule extends Module {
  bind [HttpRequestHandler] toNonLazy injected [VRouteHandler] ('routes -> injectProvider[Router])
}

class VRouteHandler(errorHandler: HttpErrorHandler, configuration: HttpConfiguration, filters: HttpFilters, routes: () => Router) extends HttpRequestHandler {
  lazy val Handler = new DefaultHttpRequestHandler(routes(), errorHandler, configuration, filters) {
    override def routeRequest(request: RequestHeader) =
      super.routeRequest(request.copy(path = request.path.replace("context1", "context2")))
  }

  override def handlerForRequest(request: RequestHeader) = Handler.handlerForRequest(request)
}

`lazy val Handler` is unfortunately necessary, because of the `routes`, which is circular dependency. I find the fact that it's circular dependency a bit strange, so will investigate this and hopefully come up with proper solution. With this setup you don't need `GlobalSettings.onRouteRequest` config property - `VRouteHandler` will be discovered and used automatically.

hope this helps.

Cheers,
Oleg
Reply all
Reply to author
Forward
0 new messages