3 Replies Latest reply on Aug 3, 2005 12:01 PM by starksm64

    HOW-TO obtain URL for Web Application

      I frequently load URL based resources and I can get the URL using request attributes to generate a URL like this: https://acme:8443/portal

      The code is dirt simple:

      getURL( HTTPServletRequest r)
      {
       return r.getScheme() + "://" + r.getServerName() + ":" +
       r.getServerPort() + r.getContextPath();
      }
      


      The problem is I need that URL before a request is made and I do not want to hard-wire that. The ServletContext passed to Servlet.init() does not get me that information so I cannot use a load-on-start servlet, either.

      How can I get the scheme, host and port at startup? The context path is not an issue since obviously there can be several of those and I can hard wire that one.

        • 1. Re: HOW-TO obtain URL for Web Application

          The scheme is also dynamic (ftp, https, http, file...) so obviously I will have to assume that also. That leaves the host and port number. Is there a runtime config setting for those I can get at somewhere?



          • 2. Re: HOW-TO obtain URL for Web Application

            OK, there's jboss.bind.address so that will take care of the host name. That leaves the port number. That reduces my question to the following:

            I How can I programatically retrieve the port number the web container is listening on before my first request comes in.

            • 3. Re: HOW-TO obtain URL for Web Application
              starksm64

               

              MBeanServer = ...;
              ObjectName query = new ObjectName("jboss.web:type=Connector,*");
              Set matches = server.queryNames(query, null);
              ObjectName connector = findMatchingConnector(matches);
              Integer port = (Integer) server.getAttribute(connector, "port");