Re: Newbie : Obtain the name of a server in Java
Re: Newbie : Obtain the name of a server in Java
- Subject: Re: Newbie : Obtain the name of a server in Java
- From: Gilles MATHURIN <email@hidden>
- Date: Fri, 8 Sep 2006 21:47:21 -0400
Hello all,
Thank you for your support, i learn a lot owe to u .
In my case i did a mistake in explaining my problem. By getting the
server name in a ivar, I meant the "static domain name" not the app
server name. So as Paul Lynch said to me, using the "host()" method
would get me the application server domain name.
As i am reading what you post me, i wonder if it will not end in the
same result : getting or setting the app server domain name.
I'll think about it.
With Regards
GM
Le 8 sept. 06 à 21:04, Lachlan Deck a écrit :
Hi there,
On 07/09/2006, at 9:28 AM, Gilles MATHURIN wrote:
Is there a way to obtain programmaticaly the name of the server in
order to put it in a ivar ?
Example : "http://g-five.local/cgi-bin/Webobjects/WOapp.woa"
i'd like to be able to have the "g-five.local" part in a
programmatic way, in that way my method and component would be
more reusable…
In your Properties file put:
WOHost=my.desired.host
Or in Java monitor:
"-DWOHost=my.desired.host"
String host = Application.application().host();
If the above fails to return the desired result... (and you cannot
necessary trust the host that user requests from) ... you might
also like to set:
WOCGIAdaptorURL=http://my.desire.host/cgi-bin/WebObjects"
And parse it out as follows...
public class Application extends WOApplication {
private static final Pattern DOMAIN_PATTERN;
static {
String outerChars = "[\\w&&[^_]]+"
String middleChars = "[\\w-&&[^_]]*";
String partPtn;
String domainPtn;
partPtn = outerchars + "(?:" + middleChars + outerChars + ")?";
domainPtn = "(" + partPtn + "(?:\\." + partPtn + ")+).*";
DOMAIN_PATTERN = Pattern.compile( domainPtn );
// or simpler but not checking for correctness:
// "https?://([\\.\\w-&&[^_]]+/?.*";
}
<...>
/**
* @return the domain from the cgiAdaptorUrl.
*/
public String domain() {
Matcher m;
String adaptorUrl;
m = DOMAIN_PATTERN.matcher( cgiAdaptorURL() );
if ( m.matches() && m.groupCount() == 1 ) {
return m.group( 1 );
}
throw new RuntimeException( "Cannot obtain adaptor url!" );
}
<...>
}
with regards,
--
Lachlan Deck
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden