Search in sources :

Example 31 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class TestRequestUtils method testSelectApplication1b.

// Map to the second module -- direct
public void testSelectApplication1b() {
    String[] prefixes = { "/1", "/2" };
    context.setAttribute(Globals.MODULE_PREFIXES_KEY, prefixes);
    request.setPathElements("/myapp", "/2/noform.do", null, null);
    ModuleUtils.getInstance().selectModule(request, context);
    ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    assertNotNull("Selected a module", moduleConfig);
    assertEquals("Selected correct module", "/2", moduleConfig.getPrefix());
// FIXME - check module resources?
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 32 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class TestRequestUtils method testSelectApplication2a.

// Map to the default module -- include
public void testSelectApplication2a() {
    request.setPathElements("/myapp", "/2/noform.do", null, null);
    request.setAttribute(RequestProcessor.INCLUDE_SERVLET_PATH, "/noform.do");
    ModuleUtils.getInstance().selectModule(request, context);
    ModuleConfig moduleConfig = (ModuleConfig) request.getAttribute(Globals.MODULE_KEY);
    assertNotNull("Selected an application", moduleConfig);
    assertEquals("Selected correct application", "", moduleConfig.getPrefix());
// FIXME - check application resources?
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Example 33 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class TestTagUtils method testModuleConfig_getModuleConfig_PageContext.

// ----public ModuleConfig getModuleConfig(PageContext pageContext)
public void testModuleConfig_getModuleConfig_PageContext() {
    MockServletConfig mockServletConfig = new MockServletConfig();
    ModuleConfig moduleConfig = new ModuleConfigImpl("");
    MockServletContext mockServletContext = new MockServletContext();
    MockHttpServletRequest mockHttpServletRequest = new MockHttpServletRequest();
    MockHttpServletResponse mockHttpServletResponse = new MockHttpServletResponse();
    mockServletConfig.setServletContext(mockServletContext);
    MockPageContext mockPageContext = new MockPageContext(mockServletConfig, mockHttpServletRequest, mockHttpServletResponse);
    ModuleConfig foundModuleConfig = null;
    try {
        foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
        fail("Expected ModuleConfig to not be found");
    } catch (NullPointerException ignore) {
    // expected result
    }
    mockHttpServletRequest.setAttribute(Globals.MODULE_KEY, moduleConfig);
    mockPageContext.getServletContext().setAttribute(Globals.MODULE_KEY, mockPageContext);
    foundModuleConfig = tagutils.getModuleConfig(mockPageContext);
    assertNotNull(foundModuleConfig);
}
Also used : MockHttpServletRequest(org.apache.struts.mock.MockHttpServletRequest) MockServletConfig(org.apache.struts.mock.MockServletConfig) ModuleConfig(org.apache.struts.config.ModuleConfig) MockPageContext(org.apache.struts.mock.MockPageContext) ModuleConfigImpl(org.apache.struts.config.impl.ModuleConfigImpl) MockServletContext(org.apache.struts.mock.MockServletContext) MockHttpServletResponse(org.apache.struts.mock.MockHttpServletResponse)

Example 34 with ModuleConfig

use of org.apache.struts.config.ModuleConfig in project sonarqube by SonarSource.

the class RequestUtils method actionIdURL.

/**
     * <p>Returns the true path of the destination action if the specified forward
     * is an action-aliased URL. This method version forms the URL based on
     * the current request; selecting the current module if the forward does not
     * explicitly contain a module path.</p>
     *
     * @param forward the forward config
     * @param request the current request
     * @param servlet the servlet handling the current request
     * @return the context-relative URL of the action if the forward has an action identifier; otherwise <code>null</code>.
     * @since Struts 1.3.6
     */
public static String actionIdURL(ForwardConfig forward, HttpServletRequest request, ActionServlet servlet) {
    ModuleConfig moduleConfig = null;
    if (forward.getModule() != null) {
        String prefix = forward.getModule();
        moduleConfig = ModuleUtils.getInstance().getModuleConfig(prefix, servlet.getServletContext());
    } else {
        moduleConfig = ModuleUtils.getInstance().getModuleConfig(request);
    }
    return actionIdURL(forward.getPath(), moduleConfig, servlet);
}
Also used : ModuleConfig(org.apache.struts.config.ModuleConfig)

Aggregations

ModuleConfig (org.apache.struts.config.ModuleConfig)34 HttpServletRequest (javax.servlet.http.HttpServletRequest)5 JspException (javax.servlet.jsp.JspException)5 Iterator (java.util.Iterator)4 ActionConfig (org.apache.struts.config.ActionConfig)4 ForwardConfig (org.apache.struts.config.ForwardConfig)4 MessageResources (org.apache.struts.util.MessageResources)4 ArrayList (java.util.ArrayList)3 Enumeration (java.util.Enumeration)2 List (java.util.List)2 Locale (java.util.Locale)2 ServletException (javax.servlet.ServletException)2 ActionServlet (org.apache.struts.action.ActionServlet)2 ServletActionContext (org.apache.struts.chain.contexts.ServletActionContext)2 MalformedURLException (java.net.MalformedURLException)1 URL (java.net.URL)1 HashMap (java.util.HashMap)1 Hashtable (java.util.Hashtable)1 Map (java.util.Map)1 ServletContext (javax.servlet.ServletContext)1