newbie error

125 views
Skip to first unread message

Hari Prabu

unread,
Jan 28, 2015, 7:15:58 AM1/28/15
to gat...@googlegroups.com
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"

Hari Prabu

unread,
Jan 28, 2015, 8:51:02 AM1/28/15
to gat...@googlegroups.com
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. 

Stéphane LANDELLE

unread,
Jan 28, 2015, 8:53:16 AM1/28/15
to gat...@googlegroups.com
Using BodyPart is for multipart.
You seem to only want a simple Body, not a BodyPart.

Stéphane Landelle
Lead developer


--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Hari Prabu

unread,
Jan 28, 2015, 9:33:49 AM1/28/15
to gat...@googlegroups.com

that worked thanks

Hari Prabu

unread,
Jan 28, 2015, 10:17:27 AM1/28/15
to gat...@googlegroups.com
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 = """
 <TestData xmlns="http://someurl/">
  <Header>
    <SourceMessageID>2014-10-25-2114-5033446-443045380</SourceMessageID> 
    <SourceVersion>1</SourceVersion> 
    <Sender>TEST</Sender> 
    <Receiver>TEST1</Receiver> 
    <CreationTimestamp>2015-01-09T10:14:39.265Z</CreationTimestamp> 
  </Header>
  <Test>
    <TestID>${testID}</testID> 
    <CreationTimestamp>2014-01-09T11:20:49.266Z</CreationTimestamp> 
    <Name>${name}</Name> 
    <Bust>false</Bust> 
    <Quantity>${quantity}</Quantity> 
    <Price>${price}</Price> 
  </Test>
</TestData>
"""
  
  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
a:78)

Stéphane LANDELLE

unread,
Jan 28, 2015, 10:48:16 AM1/28/15
to gat...@googlegroups.com
The file editor you used for editing your file uses an encoding different from the one configured in gatling.conf (default is UTF-8).

Stéphane Landelle
Lead developer


--
Reply all
Reply to author
Forward
0 new messages