Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7440599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T10:52:37+00:00 2026-05-29T10:52:37+00:00

I know this question has been asked quite a few times, however, I have

  • 0

I know this question has been asked quite a few times, however, I have a different approach of what I want to achieve.

Since Play 1.1, you’re able to match hosts. This is very useful, however, it means that for every controller, I will need to pass through the subdomain route param. This is quite a burden and repeatful if I have hundreds of controllers which use the subdomain param.

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?

For example (brainstorming), a filter would do the following:

    // 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));
    }

And in the models I’d do something like System.getProperty("host");

I know this isn’t how it should be done, but I’m just brainstorming.

At least with this way:

  1. I don’t have to pass the subdomain param through to every
    controller.
  2. I don’t have to pass the subdomain param through to any models
    either
  3. Models have direct access to the subdomain value so I can filter out objects that belong to the client

Also, I’m aware that System.setProperty() 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?

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.

  • 1 1 Answer
  • 2 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-29T10:52:37+00:00Added an answer on May 29, 2026 at 10:52 am

    I think you are close. If I had to do this, I would write a controller annotated with @Before and have that method extract the hostname from the request headers and put it in renderArgs.

    Something like this (I haven’t tested it):

    public class HostExtractor extends Controller {
    
        @Before
        public static void extractHost() {
           // Code to read from request headers and extract whatever you need here.
           String host = 'Your Code Here'
           renderArgs.put("hostname", host);
        }
    }
    

    Then, in your other controllers, you tell it you want to use that controller above as a filter.

    @With(HostExtractor.class)
    public class MyController extends Controller {
    
        public static void homepage() {
            String hostname = renderArgs.get("host", String.class);
            // Do whatever logic you need to render the page here.
        }
    }
    

    Again, I haven’t tested this, but I’m doing something similar to cache objects in memcache. I hope that helps!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I know this question has been asked several times, but I can't quite seem
I know this question has been asked few times over SO but none of
I know this question has been asked multiple number of times and i have
I know this question has been asked a few times and in a few
I know this question has been asked a couple of times. However, I can't
I know this question has been asked several times, however, after digging through question
I know this question has been asked multiple times (however, I could still not
I know this question has been asked a couple of times before. I m
I know this question has been asked before however the answers I found where
I know this question has been asked a zillion times, but I still feel

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.