Hi Chatree, Perhaps if you could explain the purpose of the initialPath and a use case for it then I might be able to offer some suggestions but without that I don't really understand the problem you are trying to solve.
How are you handling this problem for webapps that aren't mounted at root? Thanks Scott HotWax Media http://www.hotwaxmedia.com On 10/11/2010, at 5:35 PM, Chatree Srichart wrote: > Hi Scott Gray, > > I found this solution: > > Index: framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java > =================================================================== > --- framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java > (revision 1033345) > +++ framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java > (working copy) > @@ -196,6 +196,8 @@ > } > > // test to see if we have come through the control servlet already, > if not do the processing > + String requestPath = null; > + String contextUri = null; > if (request.getAttribute(ContextFilter.FORWARDED_FROM_SERVLET) == > null) { > // Debug.logInfo("In ContextFilter.doFilter, > FORWARDED_FROM_SERVLET is NOT set", module); > String allowedPath = config.getInitParameter("allowedPaths"); > @@ -208,7 +210,7 @@ > > if (debug) Debug.log("[Request]: " + > httpRequest.getRequestURI(), module); > > - String requestPath = httpRequest.getServletPath(); > + requestPath = httpRequest.getServletPath(); > if (requestPath == null) requestPath = ""; > if (requestPath.lastIndexOf("/") > 0) { > if (requestPath.indexOf("/") == 0) { > @@ -234,7 +236,7 @@ > if (httpRequest.getPathInfo() != null) { > contextUriBuffer.append(httpRequest.getPathInfo()); > } > - String contextUri = contextUriBuffer.toString(); > + contextUri = contextUriBuffer.toString(); > > // Verbose Debugging > if (Debug.verboseOn()) { > @@ -288,10 +290,11 @@ > GenericValue tenant = EntityUtil.getFirst(tenants); > String tenantId = tenant.getString("tenantId"); > > - // if the request URI is "/control/main" then redirect > to the initial path > - if > (httpRequest.getRequestURI().startsWith("/control/main")) { > + // if the request path is a root mount then redirect to > the initial path > + if (UtilValidate.isNotEmpty(requestPath) && > requestPath.equals(contextUri)) { > String initialPath = > tenant.getString("initialPath"); > > ((HttpServletResponse)response).sendRedirect(initialPath); > + return; > } > > // make that tenant active, setup a new delegator and a > new dispatcher > > Could you approve this solution, please? > > Regards, > Chatree Srichart > > On Wed, Nov 10, 2010 at 10:17 AM, Chatree Srichart < > chatree.srich...@gmail.com> wrote: > >> Hi Scott Gray, >> May I ask you some suggestion? Is there anyway to handle the root mount >> point when an user enter only domain name in a web browser. The purpose of >> this code is I need to handle the first URI after an user enter only domain >> name on a web browser and redirect to the initial path that be specified in >> the Tenant entity. >> >> Regards, >> Chatree Srichart >> >> >> On Wed, Nov 10, 2010 at 3:00 AM, Scott Gray >> <scott.g...@hotwaxmedia.com>wrote: >> >>> On 9/11/2010, at 10:14 PM, hans...@apache.org wrote: >>> >>>> Author: hansbak >>>> Date: Tue Nov 9 09:14:33 2010 >>>> New Revision: 1032896 >>>> >>>> URL: http://svn.apache.org/viewvc?rev=1032896&view=rev >>>> Log: >>>> removing the tenant servlet because that gave a problem with the root >>> mountpoint defined twice in systems which already use the root mount point >>>> >>>> Removed: >>>> >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/TenantServlet.java >>>> Modified: >>>> >>> ofbiz/trunk/framework/catalina/src/org/ofbiz/catalina/container/CatalinaContainer.java >>>> >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java >>>> >>>> >>>> Modified: >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java >>>> URL: >>> http://svn.apache.org/viewvc/ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java?rev=1032896&r1=1032895&r2=1032896&view=diff >>>> >>> ============================================================================== >>>> --- >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java >>> (original) >>>> +++ >>> ofbiz/trunk/framework/webapp/src/org/ofbiz/webapp/control/ContextFilter.java >>> Tue Nov 9 09:14:33 2010 >>>> @@ -288,6 +288,12 @@ public class ContextFilter implements Fi >>>> GenericValue tenant = EntityUtil.getFirst(tenants); >>>> String tenantId = tenant.getString("tenantId"); >>>> >>>> + // if the request URI is "/control/main" then >>> redirect to the initial path >>>> + if >>> (httpRequest.getRequestURI().startsWith("/control/main")) { >>>> + String initialPath = >>> tenant.getString("initialPath"); >>>> + >>> ((HttpServletResponse)response).sendRedirect(initialPath); >>>> + } >>>> + >>>> // make that tenant active, setup a new delegator >>> and a new dispatcher >>>> String tenantDelegatorName = >>> delegator.getDelegatorBaseName() + "#" + tenantId; >>>> >>> httpRequest.getSession().setAttribute("delegatorName", tenantDelegatorName); >>> >>> Hi Hans, >>> >>> You should always return after sending a redirect or otherwise the request >>> continues to be processed. >>> >>> Also, I'm not sure what the /control/main redirect is for but keep in mind >>> that the framework shouldn't really know anything about URIs like that and >>> depending on them decreases flexibility. "control" is just a url pattern >>> defined in each webapp's web.xml and can be changed to anything and there is >>> no requirement for each application to have a "main" request. The only >>> reason "main" is the default page is because each webapp's index.jsp >>> redirects to it. >>> >>> Regards >>> Scott >>> >>> >>
smime.p7s
Description: S/MIME cryptographic signature