You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Jeremy Cowgar <jc...@cowgar.com> on 2004/06/16 16:10:46 UTC

Respond Differently based upon host name

Greetings.

I run lifewithchrist.org, a blogging system. I writing version 2.0 and 
doing so in struts (1.0 is PHP). I am not certian of one thing. 
Currently (and it must remain this way), I have DNS setup to a wildcard, 
and it ships it all to the same webserver (apache). The webserver then 
directs (through mod_rewrite) to /index.php ... this then looks at the 
host name and determines which weblog is being accessed, then uses 
certian settings for that weblog and also the user supplied template.

How would I go about making this decision with a struts based 
application? I can handle the server setup about directing all host 
names to a certian server, but I'm talking about Java code. The user 
supplied templates will be velocity templates so I am assuming it will 
have something to do with inheriting from the VelocityViewServlet.

Any input would be appriciated.

Jeremy


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: Respond Differently based upon host name

Posted by Joe Germuska <Jo...@Germuska.com>.
At 10:10 AM -0400 6/16/04, Jeremy Cowgar wrote:
>Greetings.
>
>I run lifewithchrist.org, a blogging system. I writing version 2.0 
>and doing so in struts (1.0 is PHP). I am not certian of one thing. 
>Currently (and it must remain this way), I have DNS setup to a 
>wildcard, and it ships it all to the same webserver (apache). The 
>webserver then directs (through mod_rewrite) to /index.php ... this 
>then looks at the host name and determines which weblog is being 
>accessed, then uses certian settings for that weblog and also the 
>user supplied template.
>
>How would I go about making this decision with a struts based 
>application? I can handle the server setup about directing all host 
>names to a certian server, but I'm talking about Java code. The user 
>supplied templates will be velocity templates so I am assuming it 
>will have something to do with inheriting from the 
>VelocityViewServlet.

Supporting this would involve more than just changing the view, no? 
Wouldn't the host name control things like the data to use and such?

My first thought would be to modify the RequestProcessor to make the 
determination of the "host context" at the earliest possible point, 
setting data into the request scope based on that so that all later 
processes could count on it being there.

Personally, I'd use a Struts 1.2.x nightly build and the struts-chain 
contrib package, because it puts you in a position to make a lot more 
small changes to the request processing chain as you go -- but if you 
prefer released software, you could certainly extend RequestProcessor 
or TilesRequestProcessor and override processPreprocess.  Of course, 
in that method you only have the request and the response, so if you 
wanted to actually get at some application-scoped resource to lookup 
a "host name blog context" and put that information into the request, 
it might be tricky.  This is another reason why struts-chain is nice 
-- you can arrange to have a "richer context" available for the 
command to do work than may be provided by the more binding API of 
the original RequestProcessor class.

Then, of course, if you want to add in a chain command that does view 
preprocessing, you can insert one somewhere between the ExecuteAction 
command and the PerformForward command.

Bleeding edge stuff here, but since we're hoping to steer Struts to 
use the chained request processor as its default request processor, 
it would be good to see Struts users jumping in and helping to chart 
the territory.

Joe

-- 
Joe Germuska            
Joe@Germuska.com  
http://blog.germuska.com    
"In fact, when I die, if I don't hear 'A Love Supreme,' I'll turn 
back; I'll know I'm in the wrong place."
    - Carlos Santana

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org