title: Play! Framework - SaaS subdomain name filter
body: <p>I know this question has been asked quite a few times, however, I have a different approach of what I want to achieve.</p>
  
  <p><a href="http://www.playframework.org/documentation/1.1.1/releasenotes-1.1#routeHost" rel="nofollow">Since Play 1.1, you're able to match hosts.</a> This is very useful, however, it means that for every controller, I will need to pass through the <code>subdomain</code> route param. This is quite a burden and repeatful if I have hundreds of controllers which use the <code>subdomain</code> param.</p>
  
  <p>Is there not a way to create a filter which looks at the host name before everything else is executed and then sets an on-the-fly config value for that request?</p>
  
  <p>For example (brainstorming), a filter would do the following:</p>
  
  <pre><code>    // use request host, but hard-coded for now...
      String host = "test.example.com";
      Pattern p = Pattern.compile("^([a-z0-9]+)\\.example\\.com$");
      Matcher m = p.matcher(host);
      if (m.matches()) {
          // OUT: test
          System.out.println(m.group(1));
          System.setProperty("host", m.group(1));
      }
  </code></pre>
  
  <p>And in the models I'd do something like <code>System.getProperty("host");</code></p>
  
  <p>I know this isn't how it should be done, but I'm just brainstorming. </p>
  
  <p>At least with this way:</p>
  
  <ol>
  <li>I don't have to pass the <code>subdomain</code> param through to every
  controller.</li>
  <li>I don't have to pass the <code>subdomain</code> param through to any models
  either</li>
  <li>Models have direct access to the <code>subdomain</code> value so I can filter out objects that belong to the client</li>
  </ol>
  
  <p>Also, I'm aware that <code>System.setProperty()</code> always applies to the entire JVM; which is a problem. I only want this value to be available throughout the duration of the request. What should I use?</p>
  
  <p>Let's analyse. How would you do it?  What would be a good approach? Is this possible with Play?  I'm sure there are quite a few running into this problem. Your input is highly appreciated.</p>