newbie error

I’m a new user to Gatling. I have to load test a HTTP POST request which has XML Data. I’ve the following scala snippet

val headers = Map(“Content-Type” → “”“application/xml”"")
val scn = scenario(“Performance Test”)
.exec(
http(“test”)
.post(“https://myurl/new”)
.headers(headers)
.bodyPart(RawFileBodyPart(“binary”, “C:\tmp\test_file.xml”).contentType(“application/xml”).fileName(“test_file.xml”))
.check(status.is(200))
)

setUp(scn.inject(atOnceUsers(1)))

When i run this. I get a 400 error. Can please some one correct what it wrong with this.

Here is the corresponding cURL code I use which is executed successfully

curl -v -X POST --data-binary @C:\tmp\test_file.xml --insecure -H “Content-Type: application/xml” “https://myurl/new

more information from 400 error

When Gatlin posts this XML to the server, It adds these below 4 lines before the actual xml content

–lBV9T3G0fxXw2tPgwQBDlCAtgnRZYRvq-25LtRP
Content-Disposition: form-data; name=“data”; filename=“test_file.xml”
Content-Type: application/xml
Content-Transfer-Encoding: binary

So the server responds with 400 with below stack

Content is not allowed in prolog.
javax.xml.bind.UnmarshalException

  • with linked exception:
    [org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in prolog.]

When cURL sends the same xml it doesn’t add those information so it works just fine. Can anybody provide me with an insight what i need to change.

Using BodyPart is for multipart.
You seem to only want a simple Body, not a BodyPart.

that worked thanks

New Issue this time around. I’m trying to make my request Dynamic.
I’m feeding a csv and the code is below

val headers = Map(“Content-Type” → “application/xml”)

val deal_info = csv(“test_info.csv”).random

def PostRequest = “”"

2014-10-25-2114-5033446-443045380 1 TEST TEST1 2015-01-09T10:14:39.265Z ${testID} 2014-01-09T11:20:49.266Z ${name} false ${quantity} ${price} """

val scn = scenario(“Performance Test”)
.feed(test_info)
.exec(
http(“Post Test”)
.post(“https://myurl/new”)
.body(RawFileBody(PostRequest)).asXML
// .body(StringBody(PostRequest)).asXML
.headers(headers)
.check(status.is(200))
)

setUp(scn.inject(atOnceUsers(3)))
}

I tried both the RawFileBody and StringBody also tried to make them as xml.

When i run this, I get the below error. Looks like some problem with my body but i can’t figure it out

Exception in thread “main” java.nio.charset.MalformedInputException: Input lengt
h = 1
at java.nio.charset.CoderResult.throwException(Unknown Source)
at sun.nio.cs.StreamDecoder.implRead(Unknown Source)
at sun.nio.cs.StreamDecoder.read(Unknown Source)
at java.io.InputStreamReader.read(Unknown Source)
at java.io.BufferedReader.fill(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at java.io.BufferedReader.readLine(Unknown Source)
at scala.io.BufferedSource$BufferedLineIterator.next(BufferedSource.scal

The file editor you used for editing your file uses an encoding different from the one configured in gatling.conf (default is UTF-8).