users@glassfish.java.net

How to get endpoint URL from ServletContext

From: Farrukh Najmi <farrukh_at_wellfleetsoftware.com>
Date: Thu, 11 Mar 2010 10:31:42 -0500

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