Programmatically create subdomains with JBOSS and java

喜欢而已 提交于 2019-12-05 20:06:58

This is simply a process of mapping your subdomain to URL's that can be accessed by the appserver and use something like REST to map the URL to request parameters.

In your example, you will probably need a webserver like Apache web server to handle the incoming requests that can do some URL rewriting. Something like this

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

In Apache this can be achieved by creating a virtualhost and using RewriteCond and RewriteRule. Here is an example

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

You can then forward your requests from the webserver to your application server. If using Apache this can be done using mod_jk, mod_proxy or mod_cluster.

Once you have that, you can create a RESTFul service (jboss supports REST) that can map the URL to your application code. Here is 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();

    }

}
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!