users@jax-ws.java.net

Re: FW: Getting Server Port in a jax-ws web service ?

From: Glenn <gpet44_at_excite.com>
Date: Wed, 14 Feb 2007 18:38:19 -0500 (EST)

 

Jitu,Thanks it worked perfectly.Glenn --- On Wed 02/14, Jitendra Kotamraju &lt; Jitendra.Kotamraju_at_Sun.COM &gt; wrote:From: Jitendra Kotamraju [mailto: Jitendra.Kotamraju_at_Sun.COM]To: users_at_jax-ws.dev.java.netDate: Wed, 14 Feb 2007 13:11:48 -0800Subject: Re: FW: Getting Server Port in a jax-ws web service ?Glenn wrote:&gt; I'm trying to retrieve the server address (host &amp; port), and possibly &gt; the relative path (relative to server root) from within a jax-ws web &gt; service.&gt;&gt; I have a web service, which includes several images for retrieval &gt; based on metadata provided by the caller, below is a very simplified &gt; version of the code. I know I can use InetAddress to get the host &gt; name, but is there a way to retrieve the port number of the server &gt; that the web service is running in ?&gt;&gt; I'd prefer getting the information at run-time rather than playing &gt; with properties or application config files, that would have to be &gt; modified each time
the war file is deployed.&gt;&gt; Any suggestions would be greatly appreciated.&gt;&gt; @WebService()&gt; public class ImageRetriever {_at_ResourceWebServiceContext wsCtxt;&gt; @WebMethodpublic URL[] getImagery(@WebParam(name=&quot;metadata&quot;) &gt; Metadata metadata) {&gt; URL[] urls = new URL[1];&gt; String host = null;&gt; int port = 80;&gt;&gt; // TO-DO set host address to web server host&gt; // TO-DO set port to webserver port&gt;&gt; url[0] = new URL(&quot;http&quot;, host, port, &quot;Imagery/image1.png&quot;);MessageCtxt msgCtxt = wsCtxt.getMessageContext();HttpServletRequest req = (HttpServletRequest)msgCtxt.get(MessageContext.SERVLET_REQUEST)// using req you can get all the information req.getScheme(), req.getServerName(), req.getServerPort() etcJitu&gt; return urls;&gt; }&gt; }&gt;&gt; Thanks,&gt; Glenn

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!