• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Newbie : Obtain the name of a server in Java
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Newbie : Obtain the name of a server in Java


  • Subject: Re: Newbie : Obtain the name of a server in Java
  • From: Lachlan Deck <email@hidden>
  • Date: Sat, 9 Sep 2006 11:04:08 +1000

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


  • Follow-Ups:
    • Re: Newbie : Obtain the name of a server in Java
      • From: Gilles MATHURIN <email@hidden>
References: 
 >Newbie : Obtain the name of a server in Java (From: Gilles MATHURIN <email@hidden>)

  • Prev by Date: Re: Flattened relationship and iterator oddness
  • Next by Date: Re: Newbie : Obtain the name of a server in Java
  • Previous by thread: Re: Newbie : Obtain the name of a server in Java
  • Next by thread: Re: Newbie : Obtain the name of a server in Java
  • Index(es):
    • Date
    • Thread