Tomcat 和 JMeter 生成 HTTP 404 错误

发布于 2024-08-05 19:01:36 字数 1156 浏览 11 评论 0原文

我对 JMeter 完全是新手。我正在尝试使用 JMeter 连接到 Tomcat 中部署的 Web 应用程序,以模拟少量用户登录并浏览页面。

当我运行测试计划时,JMeter 日志显示一系列 HTTP 404 消息,表明某处存在通信问题。

以下链接显示了测试计划的 HTTP 默认值:

alt text http:// /www.dcs.bbk.ac.uk/~martin/uploads/HTTP_Defaults.PNG

接下来有两个简单的 HTTP 请求。

第一个请求应使用户能够登录:

alt text http: //www.dcs.bbk.ac.uk/~martin/uploads/Login.PNG

第二个请求应允许新登录的用户浏览页面:

替代文本 http://www.dcs.bbk.ac.uk/~martin/uploads/Browse.PNG< /a>

但是,正如我所说,我在 JMeter 日志中收到的只是 HTTP 404 消息:

2009/09/23 15:10:43 INFO  - jmeter.protocol.http.sampler.HTTPSampler: Error Response Code: 404 

Tomcat 在测试期间正在运行,并且在测试计划中,我还将 HTTP Cookie 管理器设置为“默认”。

当我的应用程序在 Tomcat 下测试时运行时,其 URL 为 http://localhost:8080/myDataSharer,我试图让 JMeter 反映这一点。

任何帮助都会受到欢迎,因为我不明白为什么 JMeter 和 Tomcat 不互相交谈。

谢谢马丁

I'm a complete novice with JMeter. I'm trying to use JMeter to connect to a web application deployed in Tomcat to simulate a small number of users logging in and browsing a page.

When I ran the test plan, JMeter log showed a series of HTTP 404 messages indicating that there was a communications problem somewhere.

The following link shows the test plan's HTTP defaults:

alt text http://www.dcs.bbk.ac.uk/~martin/uploads/HTTP_Defaults.PNG

With two simple HTTP requests to follow.

The first request should enable the users to log in:

alt text http://www.dcs.bbk.ac.uk/~martin/uploads/Login.PNG

And the second request should allow the newly logged in users to browse a page:

alt text http://www.dcs.bbk.ac.uk/~martin/uploads/Browse.PNG

But, as I said, all I received in the JMeter logs were HTTP 404 messages:

2009/09/23 15:10:43 INFO  - jmeter.protocol.http.sampler.HTTPSampler: Error Response Code: 404 

Tomcat is running during the test and in the test plan, I also have a HTTP Cookie Manager set to 'default'.

When my application runs under Tomcat in test, its URL is http://localhost:8080/myDataSharer and I'm trying to have JMeter reflect this.

Any help would be welcome as I can't work out why JMeter and Tomcat aren't talking to each other.

Thanks

Martin

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

谢绝鈎搭 2024-08-12 19:01:36

HTTP 请求默认值 中的路径 未添加到HTTP 请求路径 的开头。将上下文根 myDataSharer 添加到 HTTP 请求 中的路径。
如果您不想到处重复,可以使用一个配置元素,您可以在其中定义属性,然后像这样 ${my.propertie} 一样引用它。
另外,您应该添加一个显示请求和响应数据的元素,我认为它称为结果树或类似的东西。

编辑 1: 另一件看起来很奇怪的事情是登录请求的路径。该网址正确吗?不应该是j_acegi_security_check吗?这是出现在登录表单操作中的 url 吗?

编辑2:在Tomcat中有一个用于测试安全性的示例应用程序:
http://example.com:8080/examples/jsp/security/ protected/login.jsp

用户位于 conf/tomcat-users.xml 中。添加一个角色:role1,如下所示:

<role rolename="role1"/>
<user username="test" password="test" roles="role1"/>

启动服务器,您应该能够登录。然后尝试这个JMeter测试计划

<jmeterTestPlan version="1.2" properties="1.8">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Plan de Pruebas" enabled="true">
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <stringProp name="TestPlan.comments"></stringProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Grupo de Hilos" enabled="true">
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <longProp name="ThreadGroup.start_time">1157555458000</longProp>
        <stringProp name="ThreadGroup.on_sample_error">stoptest</stringProp>
        <stringProp name="ThreadGroup.ramp_time">0</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <stringProp name="LoopController.loops">1</stringProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
        </elementProp>
        <longProp name="ThreadGroup.end_time">1157555458000</longProp>
      </ThreadGroup>
      <hashTree>
        <CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="Gestor de Cookies HTTP" enabled="true">
          <boolProp name="CookieManager.clearEachIteration">false</boolProp>
          <collectionProp name="CookieManager.cookies"/>
        </CookieManager>
        <hashTree/>
        <HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="Petición HTTP" enabled="true">
          <stringProp name="HTTPSampler.domain">localhost</stringProp>
          <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
          <stringProp name="HTTPSampler.path">/examples/jsp/security/protected/login.jsp</stringProp>
          <stringProp name="HTTPSampler.method">GET</stringProp>
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
          <stringProp name="HTTPSampler.mimetype"></stringProp>
          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <stringProp name="HTTPSampler.port">8080</stringProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <stringProp name="HTTPSampler.monitor">false</stringProp>
          <stringProp name="HTTPSampler.protocol"></stringProp>
        </HTTPSampler>
        <hashTree/>
        <HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="Petición HTTP" enabled="true">
          <stringProp name="HTTPSampler.domain">localhost</stringProp>
          <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
          <stringProp name="HTTPSampler.path">/examples/jsp/security/protected/j_security_check</stringProp>
          <stringProp name="HTTPSampler.method">POST</stringProp>
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.name">j_username</stringProp>
                <stringProp name="Argument.value">test</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.name">j_password</stringProp>
                <stringProp name="Argument.value">test</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
          <stringProp name="HTTPSampler.mimetype"></stringProp>
          <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <stringProp name="HTTPSampler.port">8080</stringProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <stringProp name="HTTPSampler.monitor">false</stringProp>
          <stringProp name="HTTPSampler.protocol">http</stringProp>
        </HTTPSampler>
        <hashTree/>
        <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="Ver Árbol de Resultados" enabled="true">
          <objProp>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
            </value>
            <name>saveConfig</name>
          </objProp>
          <stringProp name="filename"></stringProp>
          <boolProp name="ResultCollector.error_logging">false</boolProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

看看我在登录获取cookie之前添加了一个额外的请求。如果不这样做,登录将失败并显示 408 代码。

如果您让它正常工作,那么您的应用程序就可以以相同的方式进行测试。

The path in HTTP Request Defaults is not added at the beginning of the path in HTTP Request. Add the context root myDataSharer to the path in HTTP Request.
If you don't want to repeat it everywere, there is a Configuration Element where you can define proeprties and later reference it like this ${my.propertie}.
Also you should add an element that shows request and response data, I think it's called Result Tree or something like that.

Edit 1: Another thing that looks extrange is the path of the Login request. Is that URL correct? Shouldn't it be j_acegi_security_check? Is that the url that appears in the action of the login form?

Edit 2: In Tomcat there is an example application used to test security:
http://example.com:8080/examples/jsp/security/protected/login.jsp

The users are in conf/tomcat-users.xml. Add one with the role: role1 like this:

<role rolename="role1"/>
<user username="test" password="test" roles="role1"/>

Start the server and you should be able to login. Then try this JMeter test plan:

<jmeterTestPlan version="1.2" properties="1.8">
  <hashTree>
    <TestPlan guiclass="TestPlanGui" testclass="TestPlan" testname="Plan de Pruebas" enabled="true">
      <boolProp name="TestPlan.functional_mode">false</boolProp>
      <stringProp name="TestPlan.comments"></stringProp>
      <stringProp name="TestPlan.user_define_classpath"></stringProp>
      <boolProp name="TestPlan.serialize_threadgroups">false</boolProp>
      <elementProp name="TestPlan.user_defined_variables" elementType="Arguments" guiclass="ArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
        <collectionProp name="Arguments.arguments"/>
      </elementProp>
    </TestPlan>
    <hashTree>
      <ThreadGroup guiclass="ThreadGroupGui" testclass="ThreadGroup" testname="Grupo de Hilos" enabled="true">
        <boolProp name="ThreadGroup.scheduler">false</boolProp>
        <stringProp name="ThreadGroup.num_threads">1</stringProp>
        <stringProp name="ThreadGroup.duration"></stringProp>
        <stringProp name="ThreadGroup.delay"></stringProp>
        <longProp name="ThreadGroup.start_time">1157555458000</longProp>
        <stringProp name="ThreadGroup.on_sample_error">stoptest</stringProp>
        <stringProp name="ThreadGroup.ramp_time">0</stringProp>
        <elementProp name="ThreadGroup.main_controller" elementType="LoopController" guiclass="LoopControlPanel" testclass="LoopController" testname="Loop Controller" enabled="true">
          <stringProp name="LoopController.loops">1</stringProp>
          <boolProp name="LoopController.continue_forever">false</boolProp>
        </elementProp>
        <longProp name="ThreadGroup.end_time">1157555458000</longProp>
      </ThreadGroup>
      <hashTree>
        <CookieManager guiclass="CookiePanel" testclass="CookieManager" testname="Gestor de Cookies HTTP" enabled="true">
          <boolProp name="CookieManager.clearEachIteration">false</boolProp>
          <collectionProp name="CookieManager.cookies"/>
        </CookieManager>
        <hashTree/>
        <HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="Petición HTTP" enabled="true">
          <stringProp name="HTTPSampler.domain">localhost</stringProp>
          <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
          <stringProp name="HTTPSampler.path">/examples/jsp/security/protected/login.jsp</stringProp>
          <stringProp name="HTTPSampler.method">GET</stringProp>
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments"/>
          </elementProp>
          <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
          <stringProp name="HTTPSampler.mimetype"></stringProp>
          <boolProp name="HTTPSampler.auto_redirects">false</boolProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <stringProp name="HTTPSampler.port">8080</stringProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <stringProp name="HTTPSampler.monitor">false</stringProp>
          <stringProp name="HTTPSampler.protocol"></stringProp>
        </HTTPSampler>
        <hashTree/>
        <HTTPSampler guiclass="HttpTestSampleGui" testclass="HTTPSampler" testname="Petición HTTP" enabled="true">
          <stringProp name="HTTPSampler.domain">localhost</stringProp>
          <stringProp name="HTTPSampler.FILE_NAME"></stringProp>
          <stringProp name="HTTPSampler.path">/examples/jsp/security/protected/j_security_check</stringProp>
          <stringProp name="HTTPSampler.method">POST</stringProp>
          <elementProp name="HTTPsampler.Arguments" elementType="Arguments" guiclass="HTTPArgumentsPanel" testclass="Arguments" testname="User Defined Variables" enabled="true">
            <collectionProp name="Arguments.arguments">
              <elementProp name="" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.name">j_username</stringProp>
                <stringProp name="Argument.value">test</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
              <elementProp name="" elementType="HTTPArgument">
                <boolProp name="HTTPArgument.use_equals">true</boolProp>
                <boolProp name="HTTPArgument.always_encode">false</boolProp>
                <stringProp name="Argument.name">j_password</stringProp>
                <stringProp name="Argument.value">test</stringProp>
                <stringProp name="Argument.metadata">=</stringProp>
              </elementProp>
            </collectionProp>
          </elementProp>
          <stringProp name="HTTPSampler.FILE_FIELD"></stringProp>
          <stringProp name="HTTPSampler.mimetype"></stringProp>
          <boolProp name="HTTPSampler.auto_redirects">true</boolProp>
          <boolProp name="HTTPSampler.follow_redirects">true</boolProp>
          <stringProp name="HTTPSampler.port">8080</stringProp>
          <boolProp name="HTTPSampler.use_keepalive">true</boolProp>
          <stringProp name="HTTPSampler.monitor">false</stringProp>
          <stringProp name="HTTPSampler.protocol">http</stringProp>
        </HTTPSampler>
        <hashTree/>
        <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="Ver Árbol de Resultados" enabled="true">
          <objProp>
            <value class="SampleSaveConfiguration">
              <time>true</time>
              <latency>true</latency>
              <timestamp>true</timestamp>
              <success>true</success>
              <label>true</label>
              <code>true</code>
              <message>true</message>
              <threadName>true</threadName>
              <dataType>true</dataType>
              <encoding>false</encoding>
              <assertions>true</assertions>
              <subresults>true</subresults>
              <responseData>false</responseData>
              <samplerData>false</samplerData>
              <xml>false</xml>
              <fieldNames>false</fieldNames>
              <responseHeaders>false</responseHeaders>
              <requestHeaders>false</requestHeaders>
              <responseDataOnError>false</responseDataOnError>
              <saveAssertionResultsFailureMessage>false</saveAssertionResultsFailureMessage>
              <assertionsResultsToSave>0</assertionsResultsToSave>
            </value>
            <name>saveConfig</name>
          </objProp>
          <stringProp name="filename"></stringProp>
          <boolProp name="ResultCollector.error_logging">false</boolProp>
        </ResultCollector>
        <hashTree/>
      </hashTree>
    </hashTree>
  </hashTree>
</jmeterTestPlan>

Look that I added an extra request before loging in to get the cookie. If you don't do that login will fail with a 408 code.

If you get this to work then your application can be tested in the same way.

荒人说梦 2024-08-12 19:01:36

最后,我让这个东西工作了 - 这是一个将自动重定向更改为遵循请求中的重定向的情况。感谢罗德里戈普的帮助

Finally, I have this thing working - it was a case of changing Redirect Automatically to Follow Redirects in the requests. Thanks to Rodrigoap for his assistance

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文