使用JBOSS和Java以编程方式创建子域 [英] Programmatically create subdomains with JBOSS and java

查看:125
本文介绍了使用JBOSS和Java以编程方式创建子域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

现在,我正在使用JSF,SEAM和Primefaces在JBOSS 7.1上开发应用程序.该应用程序正在提供用户注册.我需要的是,当用户注册一个昵称帐户(例如"andrew")时,他的个人资料将作为andrew.mysite.com公开访问.

Right now I am developing an application on JBOSS 7.1 using JSF, SEAM and Primefaces. The application is providing a user registration. What I need is when the user registers an account for the nickname for example "andrew", his profile will be publicly accessed as andrew.mysite.com.

如何以编程方式实现此目标.

How can I implement this programmatically.

预先感谢

Ilya Sidorovich

Ilya Sidorovich

推荐答案

这只是将您的子域映射到应用服务器可以访问的URL的过程,并使用诸如REST之类的方法将URL映射为请求参数.

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.

在您的示例中,您可能需要一个Web服务器(如Apache Web服务器)来处理可以进行一些URL重写的传入请求.像这样

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

在Apache中,这可以通过创建虚拟主机并使用RewriteCond和RewriteRule来实现.这是一个例子

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]

然后,您可以将请求从Web服务器转发到应用程序服务器.如果使用Apache,则可以使用 mod_jk mod_cluster .

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.

有了这些,就可以创建一个RESTFul服务(jboss支持 REST ),该服务可以映射您的应用程序代码的URL.这是一个例子

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();

    }

}

这篇关于使用JBOSS和Java以编程方式创建子域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆