5 Replies Latest reply on Mar 8, 2010 7:21 PM by cbensemann

    resolving server contextPath

    cbensemann

      I have JBPM emails configured to use seam mail. I also have in my components.xml defined a couple of factories for the context path the application is deployed under and the base path url of the server.


      <factory name="contextPath" scope="APPLICATION" value="#{facesContext.externalContext.request.contextPath}" auto-create="true"/>
           
      <factory name="basePath" scope="APPLICATION"
           value="#{facesContext.externalContext.request.scheme}://#{facesContext.externalContext.request.serverName}:#{facesContext.externalContext.request.serverPort}#{contextPath}/" auto-create="true"/>



      I would like them to be application scope so that they are not always calculated and so that I can then use the values in seam mail.


      This works fine if after server startup these variables are initialised by someone browsing to a page and any subsequent email sent by jbpm (such as reminder emails) work fine. However if the first thing to request these variables is a scheduelled job to send out reminder emails (jbpm seems to do this on startup if there are outstanding tasks) then the basePath is resolved to ://:0/project. This is due to the Renderer used for sending emails initialising MockHttpServletRequest.


      So hopefullly you have followed all of that. My questions are:


      1. Is it possible to have these factories initialised on startup to their correct values so that if they are called by jbpm prior to the user browsing to a page the values are still correct.


      2. Is there a better way to work out the server url / context path than using the facesContext



      thanks

        • 1. Re: resolving server contextPath
          cbensemann

          Anyone have any ideas for this? I really dont want to have to hard code this path and dont think I should have to

          • 2. Re: resolving server contextPath
            elfuhrer

            Hi Craig,
            What you can do is create a component that is initialized at startup where the values you required are initialized at startup and then added to the application or session scope, wherever you seem fit according to your needs.


            I hope this helps.


            Cheers,
            Fady

            • 3. Re: resolving server contextPath
              cbensemann

              Hi Fady,


              Thanks for your reply. After thinking about your reply I might be better able to clarify my request. The problem is that on startup there is no FacesContext present as that is per request. The question is probably more a general jsf/web application question than as seam one. I need a way to work out where I am (server url and context path) without sending a request. Either the Factories listed in my first post or a component that is initialized at startup suffer from the same problem.


              If seam mail happens to be the first thing that calls the factory method a FacesContext is created with a MockHttpServletRequest which is where the contextPath /project comes from.


              So is there a way to get the full url (for example: http://mydomain.com/pathToApp) from within the application without needing an active request at the time or hard coding the url and path as a property?



              Thanks, Craig

              • 4. Re: resolving server contextPath
                elfuhrer

                This data is available from the ServletContext which is available whenever the application is deployed. I'll run a few tests and get back to you with the results.


                Cheers,


                Fady

                • 5. Re: resolving server contextPath
                  cbensemann

                  Thanks. I new I must be missing something simple :)