@Test public void illegal_activation_context_leads_to_http_404() throws Exception { ComponentClassResolver resolver = mockComponentClassResolver(); Request request = mockRequest(); Response response = mockResponse(); LocalizationSetter ls = mockLocalizationSetter(); MetaDataLocator metaDataLocator = neverWhitelistProtected(); train_getPath(request, "/foo/pageid=123"); train_setLocaleFromLocaleName(ls, "foo", false); train_isPageName(resolver, "foo/pageid=123", false); train_isPageName(resolver, "foo", false); train_isPageName(resolver, "", true); train_canonicalizePageName(resolver, "", "Index"); replay(); ComponentEventLinkEncoderImpl linkEncoder = new ComponentEventLinkEncoderImpl(resolver, contextPathEncoder, ls, response, null, null, null, true, null, "", metaDataLocator, null); PageRenderRequestParameters parameters = linkEncoder.decodePageRenderRequest(request); assertNull(parameters); verify(); }
public PageRenderRequestParameters decodePageRenderRequest(Request request) { boolean explicitLocale = false; String path = request.getPath(); if (applicationFolderPrefix != null) { path = removeApplicationPrefix(path); } String extendedName = path.length() == 0 ? path : path.substring(1); while (extendedName.endsWith("/")) { extendedName = extendedName.substring(0, extendedName.length() - 1); } int slashx = extendedName.indexOf('/'); String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName; if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) { extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : ""; explicitLocale = true; } slashx = extendedName.length(); boolean atEnd = true; while (slashx > 0) { String pageName = extendedName.substring(0, slashx); String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1); PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext); if (parameters != null) { return parameters; } slashx = extendedName.lastIndexOf('/', slashx - 1); atEnd = false; } PageRenderRequestParameters result = checkIfPage(request, "", extendedName); if (result != null && !explicitLocale) { setLocaleFromRequest(request); } return result; }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public PageRenderRequestParameters decodePageRenderRequest(Request request) { boolean explicitLocale = false; String path = request.getPath(); if (applicationFolderPrefix != null) { path = removeApplicationPrefix(path); } String extendedName = path.length() == 0 ? path : path.substring(1); while (extendedName.endsWith("/")) { extendedName = extendedName.substring(0, extendedName.length() - 1); } int slashx = extendedName.indexOf('/'); String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName; if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) { extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : ""; explicitLocale = true; } slashx = extendedName.length(); boolean atEnd = true; while (slashx > 0) { String pageName = extendedName.substring(0, slashx); String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1); PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext); if (parameters != null) { return parameters; } slashx = extendedName.lastIndexOf('/', slashx - 1); atEnd = false; } PageRenderRequestParameters result = checkIfPage(request, "", extendedName); if (result != null && !explicitLocale) { setLocaleFromRequest(request); } return result; } }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public PageRenderRequestParameters decodePageRenderRequest(Request request) { boolean explicitLocale = false; String path = request.getPath(); if (applicationFolderPrefix != null) { path = removeApplicationPrefix(path); } String extendedName = path.length() == 0 ? path : path.substring(1); while (extendedName.endsWith("/")) { extendedName = extendedName.substring(0, extendedName.length() - 1); } int slashx = extendedName.indexOf('/'); String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName; if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) { extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : ""; explicitLocale = true; } slashx = extendedName.length(); boolean atEnd = true; while (slashx > 0) { String pageName = extendedName.substring(0, slashx); String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1); PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext); if (parameters != null) { return parameters; } slashx = extendedName.lastIndexOf('/', slashx - 1); atEnd = false; } PageRenderRequestParameters result = checkIfPage(request, "", extendedName); if (result != null && !explicitLocale) { setLocaleFromRequest(request); } return result; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public PageRenderRequestParameters decodePageRenderRequest(Request request) { boolean explicitLocale = false; String path = request.getPath(); if (applicationFolderPrefix != null) { path = removeApplicationPrefix(path); } String extendedName = path.length() == 0 ? path : path.substring(1); while (extendedName.endsWith("/")) { extendedName = extendedName.substring(0, extendedName.length() - 1); } int slashx = extendedName.indexOf('/'); String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName; if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) { extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : ""; explicitLocale = true; } slashx = extendedName.length(); boolean atEnd = true; while (slashx > 0) { String pageName = extendedName.substring(0, slashx); String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1); PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext); if (parameters != null) { return parameters; } slashx = extendedName.lastIndexOf('/', slashx - 1); atEnd = false; } PageRenderRequestParameters result = checkIfPage(request, "", extendedName); if (result != null && !explicitLocale) { setLocaleFromRequest(request); } return result; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); Link createPageRenderLink(PageRenderRequestParameters parameters); Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm); ComponentEventRequestParameters decodeComponentEventRequest(Request request); PageRenderRequestParameters decodePageRenderRequest(Request request); void appendContext(boolean seperatorRequired, EventContext context, StringBuilder builder); }
ComponentEventLinkEncoderImpl implements ComponentEventLinkEncoder { public PageRenderRequestParameters decodePageRenderRequest(Request request) { boolean explicitLocale = false; String path = request.getPath(); if (applicationFolderPrefix != null) { path = removeApplicationPrefix(path); } String extendedName = path.length() == 0 ? path : path.substring(1); while (extendedName.endsWith("/")) { extendedName = extendedName.substring(0, extendedName.length() - 1); } int slashx = extendedName.indexOf('/'); String possibleLocaleName = slashx > 0 ? extendedName.substring(0, slashx) : extendedName; if (localizationSetter.setLocaleFromLocaleName(possibleLocaleName)) { extendedName = slashx > 0 ? extendedName.substring(slashx + 1) : ""; explicitLocale = true; } slashx = extendedName.length(); boolean atEnd = true; while (slashx > 0) { String pageName = extendedName.substring(0, slashx); String pageActivationContext = atEnd ? "" : extendedName.substring(slashx + 1); PageRenderRequestParameters parameters = checkIfPage(request, pageName, pageActivationContext); if (parameters != null) { return parameters; } slashx = extendedName.lastIndexOf('/', slashx - 1); atEnd = false; } PageRenderRequestParameters result = checkIfPage(request, "", extendedName); if (result != null && !explicitLocale) { setLocaleFromRequest(request); } return result; } ComponentEventLinkEncoderImpl(ComponentClassResolver componentClassResolver,
                                         ContextPathEncoder contextPathEncoder, LocalizationSetter localizationSetter,
                                         Response response, RequestSecurityManager requestSecurityManager, BaseURLSource baseURLSource,
                                         PersistentLocale persistentLocale,
                                         @Symbol(SymbolConstants.ENCODE_LOCALE_INTO_PATH)
                                         boolean encodeLocaleIntoPath,
                                         @Symbol(SymbolConstants.CONTEXT_PATH)
                                         String contextPath,
                                         @Symbol(SymbolConstants.APPLICATION_FOLDER) String applicationFolder,
                                         MetaDataLocator metaDataLocator,
                                         ClientWhitelist clientWhitelist); Link createPageRenderLink(PageRenderRequestParameters parameters); Link createComponentEventLink(ComponentEventRequestParameters parameters, boolean forForm); ComponentEventRequestParameters decodeComponentEventRequest(Request request); PageRenderRequestParameters decodePageRenderRequest(Request request); void appendContext(boolean seperatorRequired, EventContext context, StringBuilder builder);  }