users@glassfish.java.net

Re: How to get endpoint URL from ServletContext

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 11 Mar 2010 17:51:39 -0500

Dear GF colleagues,

Please let me know if m question is not clear. I would be very grateful
for some help on what seems to be a simple question worthy of an FAQ
entry. Thanks.

On 03/11/2010 10:31 AM, Farrukh Najmi wrote:
>
> Hi Guys,
>
> I am using spring-ws in Glassfish V3 container and need to get
> endpoint URL from ServletContext for my endpoint bean.
>
> So I used the following code:
>
> javax.servlet.ServletContext sc = ...
> URL baseURL = sc.getResource("/");
> The only problem is that above returns a URL like:
>
> jndi:/server/myserver/
> Where as I was expecting to get a URL like:
>
> http://localhost:8080/myserver/
> So it looks like I have to do a JNDI lookup. So I tried the following:
>
> if (baseURL.getProtocol().equals("jndi")) {
> //Resolve via JNDI lookup
> Context jndiContext = new InitialContext();
> String s = baseURL.toString();
> Object o = jndiContext.lookup(s);
> }
>
> But above code does not work and gives the following exception:
>
> javax.naming.NamingException: Lookup failed for 'server/myserver/' in
> SerialContext [Root exception is javax.naming.NameNotFoundException:
> server]
>
> Looking at the server using the admin console I see no JNDI entries
> under Resources / JNDI.
>
> Can someone tell me what I need to do to get my servlet endpoint url
> from the ServletContext in Glassfish V3? Thanks very much.
>
> --
> Regards,
> Farrukh
>
> Web:http://www.wellfleetsoftware.com
>
>


-- 
Regards,
Farrukh
Web: http://www.wellfleetsoftware.com