Create subdomains programmatically with JBOSS and java

I am currently developing an application on JBOSS 7.1 using JSF, SEAM and Primefaces. The application provides user registration. I need when a user registers an account for an alias like "andrew" his profile will be publicly available as

How can I implement this programmatically.

Thanks in advance,

Ilya Sidorovich


source to share

1 answer

It's just a process of mapping your subdomain to a URL that the application server can access and use something like REST to map the URL to request parameters.

In your example, you will probably need a web server like the Apache web server to handle incoming requests, which might do some kind of URL rewriting. Something like that -->


In Apache, this can be achieved by creating a virtual host and using RewriteCond and RewriteRule. Here's an example

RewriteCond %{HTTP_HOST} ^([^.]+)\.mysite\.com$
RewriteRule ^/(.*)$ $1 [L,R]


Then you can redirect your requests from the web server to the application server. If you are using Apache, this can be done using mod_jk , mod_proxy, or mod_cluster .

After that, you can create a RESTFul service (jboss supports REST ) that can map the url of your application code. Here's an example


public class UserService {

    public Response printMessage(@PathParam("param") String user) {

        String result = "User : " + user;
        return Response.status(200).entity(result).build();






All Articles