Sunday, 15 February 2015

java - Play Framework 2.1: Overriding configuration file programmatically in Global settings -


I am working to develop the multi-tenant Play Framework 2.1 application. I intend to override the On-Rivest method of the GlobalSettings class to load and set a custom configuration based on the request subdomain. The problem is, I do not know how this would be possible in Play 2.x.

When I start the server, I can override system properties on the command line, but how can I do this program in Java code? For each request

code will appear something like this (I think):

  @override public play.mvc.Action onRequest (request request, method actionMethod) {/ / See configuration settings in the cache / if not in the cache: // Load the appropriate configuration file for this subdomain (java.io.), depending on the subdomain // (ie cash.Ast ("subdomain.can")). File) // Set a new configuration from the file for this request // Request a new thread from the cache // // Cash to configure for future use in the configuration. Super.onRequest (request, verb method); }}   

The url is easy to find and to set up the cache, but I can not understand how to set a new configuration program for Play Framework 2.1 and the documentation is a bit light. Things

Any thoughts? Does anyone know a better and more efficient way to do this?

So, in a way intersection, I used multi-tenant using Scala Global Built the basis for the app. Using filters can be a more effective way to implement it, but I think it seems that it is still working. It is not easily implemented in Java.

Rather than using the configuration file, I am using the database. I think it would be more efficient to use a significant value cache, but it works for now.

In Global.scala:

  Object Global Global Advertising Settings {Override def onRouteRequest (Request: RequestHeader): Option [Handler] = {if (request.session.get) ("Site"). IsEmpty) {val id = models.Site.getSiteIDFromURL (request.host) request.session. ("Site" -> ID)} super.onRouteRequest (request)}} And then, of course, you can use a database model to query the site based on the request domain Create and / or Session session set in the request If anyone knows a better way then I would love to hear it.   

No comments:

Post a Comment