2016-09-05 41 views
-1

使用Jmeter测试JSF应用程序时出现问题。 我在的JMeter是新手,请按照净我没有
和代码过滤一些后Jmeter + JSF无法通过登录过滤器

@Override 
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, 
     ServletException { 
    try { 

     HttpServletRequest httpRequest = (HttpServletRequest) request; 
     HttpServletResponse httpResponse = (HttpServletResponse) response; 
     HttpSession httpSession = httpRequest.getSession(false); 

     if (!httpRequest.getRequestURI().startsWith(httpRequest.getContextPath() + ResourceHandler.RESOURCE_IDENTIFIER)) { // Skip JSF resources (CSS/JS/Images/etc) 
      httpResponse.setHeader("Cache-Control", "no-cache, no-store, must-revalidate"); // HTTP 1.1. 
      httpResponse.setHeader("Pragma", "no-cache"); // HTTP 1.0. 
      httpResponse.setDateHeader("Expires", 0); // Proxies. 
     } 

     String strRequestURI = httpRequest.getRequestURI(); 
     // httpRequest.getServletPath() 
     // httpRequest.getServerName() 
     if (strRequestURI.indexOf("/public/") >= 0) 
      chain.doFilter(request, response); 
     else if ((strRequestURI.indexOf("/login.xhtml") >= 0) 
       || strRequestURI.contains("javax.faces.resource") 
       || (strRequestURI.indexOf("/admin-access-denied.xhtml") >= 0)) { 
      chain.doFilter(request, response); 
     } else if ((httpSession != null) && (httpSession.getAttribute(SessionBean.SESSION_KEY) != null)) { 
      if (strRequestURI.indexOf("/lazy-load.xhtml") >= 0) { 
       chain.doFilter(request, response); 
      } else { 
       chain.doFilter(request, response); 
      } 
     } else { 
      httpResponse.sendRedirect(httpRequest.getContextPath() + "/login.xhtml"); 
     } 
    } catch (Exception e) { 
     e.printStackTrace(); 
    } 

我这样做,我读了所有的东西:添加Coockie经理,加入正则表达式Extrator,添加参数Http请求,但试验前后,我的反应数据是空白的(仅访问login.xhtml页)

,但反应是空白,只能登录页面显示。

请帮我解决这个问题。 PS:我运行调试模式,并且httpSession.getAttribute(SessionBean.SESSION_KEY)始终为空,它在登录控制器上设置(登录成功时)。

HttpSession session = SessionBean.getSession(); 
      session.setAttribute(SessionBean.SESSION_KEY, sessionData); 

非常感谢,

回答

1
  1. 最有可能你的javax.faces.Viewstate值不propertly相关,你发送${viewstate}而非提取价值,最有可能您Regular Expression某处出现故障

    Regular Expression Extractor

  2. 最好把PostProcessors当作chi具体采样的ldren,否则会被触发每个采样造成执行开销,并在某些情况下JMeter Variables数据丢失

    所以你的测试应该具有以下结构:

    • 懒load.xhtml
      • 摘录视图状态
    • login.xhtml
  3. 您可能需要考虑使用CSS/JQuery ExtractorXPath Extractor而不是正则表达式提取器作为正则表达式易碎,对标记更改敏感,复杂的表达式很难理解和维护。

    实施例的表达式:

    • 的XPath://input[@id='javax.faces.ViewState]/@value
    • CSS: - 表达:input[id=javax.faces.ViewState] - 属性:value