Seeking Help Urgently (error 411)

Hi All

I wrote a simple testing script on Gatling to test a web API. But an error 411 is on put process. It took me one week on finding a solution to fix this issue. But no topic related to this issue on internet was found. Please help me.

The below is the code

`
import scala.concurrent.duration._

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._

import io.gatling.http.request.builder.AbstractHttpRequestBuilder.toActionBuilder
import com.ning.http.client._
import com.ning.http.client.Realm.AuthScheme
import com.ning.http.client.Response
import com.ning.http.client.Realm

class RecordedSimulation extends Simulation {

val builder = new AsyncHttpClientConfig.Builder();

val realm = new Realm.RealmBuilder().setUsePreemptiveAuth(true)
.setPrincipal(“ouw”)
.setPassword(“Dede0415”)
.setNtlmDomain(“xxxxx.xxxx.xxx.nz”)
.setNtlmHost(“HWL61532D”)
.setScheme(AuthScheme.NTLM)
.build()
builder.setRealm(realm).build();

val httpProtocol = http
.baseURL(“http://whiteboard-test”)
.inferHtmlResources(BlackList("""..js""", “”"..css""", “”"..gif""", “”"..jpeg""", “”"..jpg""", “”"..ico""", “”"..woff""", “”"..(t|o)tf""", “”".*.png"""), WhiteList())
.acceptHeader(""“application/json, text/plain, /”"")
.acceptEncodingHeader(""“gzip, deflate”"")
.acceptLanguageHeader(""“en-US,en;q=0.5"”")
.authRealm(realm)
.connection(""“keep-alive”"")
.userAgentHeader(""“Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0"”")

val uri1 = “”“http://whiteboard-test/api”""

val headers_8 = Map(
“Accept” → “application/json, text/plain, /; q=0.01”,
“Referer” → “http://whiteboard-test/#/dosa/preop”)

val scn = scenario(“RecordedSimulation”)
.exec(http(“request_0”)
.get("/#/dosa/preop"))
.pause(9)

.exec(http(“Update”)
.put(uri1 + “”"/commonapi/putstatus?referenceNo=12798190&statusCode=ARR&stage=1&view=dosapreop""")
// .headers(headers_8)
)

setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
`

When running this script on Gatling an error (status.find.in(200,304,201,202,203,204,205,206,207,208,209), but actually found 411) always raises on “Update” stage. I have no idea where the code is wrong.

Please help me. Thank in Adv!!

Add .disableResponseChunksDiscarding to httpProtocol :

`

val httpProtocol = http
.baseURL("[http://whiteboard-test](http://whiteboard-test)")
.inferHtmlResources(BlackList(""".*\.js""", """.*\.css""", """.*\.gif""", """.*\.jpeg""", """.*\.jpg""", """.*\.ico""", """.*\.woff""", """.*\.(t|o)tf""", """.*\.png"""), WhiteList())
.acceptHeader("""application/json, text/plain, */*""")
.acceptEncodingHeader("""gzip, deflate""")
.acceptLanguageHeader("""en-US,en;q=0.5""")
.authRealm(realm)
.connection("""keep-alive""")
.userAgentHeader("""Mozilla/5.0 (Windows NT 6.1; WOW64; rv:32.0) Gecko/20100101 Firefox/32.0""")
.disableResponseChunksDiscarding

`

Then go to logback.xml and uncomment the following line

`

`

Now you should be able to see the response and be able to debug as to what’s wrong.

My best guess is that in your httpProtocol, you are passing too many parameters. When using NtlmAuthentication, I usually do this

`

val httpProtocol = http
.baseURL("[http://whiteboard-test](http://whiteboard-test)")
````.authRealm(realm)``

``
`

Also, you need to pass the queryParam in your put method. The ‘&’ in /commonapi/putstatus?referenceNo=12798190&statusCode=ARR&stage=1&view=dosapreop is probably breaking things.

The solution is very simple to add a header.

`
val headers_8 = Map(
“Content-Length” → “0”
)

val scn = scenario(“RecordedSimulation”)
.exec(http(“home”)
.get("/#/dosa/preop"))
.pause(9)

.exec(http(“Update”)
.put("""/api/commonapi/putstatus?referenceNo=12798190&statusCode=ARR&stage=1&view=dosapreop""")
.headers(headers_8)
.check(status.is(200))
)
`

Where do the logs end up? Where are they saved? Uncommeting the logback.xml generates logs, but where can U find them?

It looks like a bug in your application to me. It shouldn’t require a 0 Content-Length header when there’s no request body.

Unrelated to this topic.

I didn’t change anything. Only changed header_8 to content-length → 0. the logs information was display on Command Prompt.

I don’t know where the bug is in application. But when I changed content-length to 0. The error 411 was not raised again. Even content-length was changed not equal to 0 the other error such as time out is raised. I use Gatling 2.01.

The response is OK what I expected when content-length is equal to 0.

From http://www.w3.org/Protocols/rfc2616/rfc2616-sec4.html:
“The presence of a message-body in a request is signaled by the inclusion of a Content-Length or Transfer-Encoding header field in the request’s message-headers.”

Some people believe that POST and PUT method should always send one of those headers, and implemented frameworks and servers based on this.
This is completely wrong. For example, NginX exhibited this bug on PUT for quite a long time.

If you set Content-Length to something more that zero, you tell the server to expect a body, but there’s none, hence the timeout.

If setting a Content-Length to 0 works for you, great. But still, that’s a bug in your application, not Gatling. Gatling automatically computes and adds Content-Length header as soon as there’s a request body, which is not the case here.