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 andrew.mysite.com.

How can I implement this programmatically.

Thanks in advance,

Ilya Sidorovich

+3


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

user.mysite.com --> www.mysite.com/user

      

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 ^/(.*)$           http://www.mysite.com/%1/$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

import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.core.Response;

@Path("/")
public class UserService {

    @GET
    @Path("/{param}")
    public Response printMessage(@PathParam("param") String user) {

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

    }

}

      

+4


source







All Articles