如何使用 Gatling 2.2.0 调用 SOAP Web 服务
How to invoke a SOAP Web service using Gatling 2.2.0
我是 Gatling 和 Scala 的新手。如何使用 Gatling 2.2.0 调用/测试 java SOAP Web 服务?我搜索了 google 和 gatling 文档,但找不到任何 link
代码:
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/MyService")
val headers_0 = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "",
"Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
)
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\">
<greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse>
</soapenv:Body></soapenv:Envelope>\"\r\n")
.headers(headers_0))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
不确定是否有可用的录音机。但是,您可以对脚本进行如下更改:
class testSOAP extends Simulation {
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/")
val header = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "", "Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36")
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("MyService")
.headers(header)
.body(StringBody("""<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\"><greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse></soapenv:Body></soapenv:Envelope>\"\r\n""")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
我认为 SAOP 代码必须在文件中,并且基础 url 不包含 url 上下文。它只是基础 url (localhost:7001)。将 url 上下文放入 post 函数中。
这是代码:
package my.package
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class MyClass extends Simulation {
val httpProtocol = http
.baseURL("http://127.0.0.1:7001")
.inferHtmlResources()
.acceptEncodingHeader("gzip,deflate")
.contentTypeHeader("text/xml;charset=UTF-8")
.userAgentHeader("Apache-HttpClient/4.1.1 (java 1.5)")
val headers_0 = Map("SOAPAction" -> """""""")
val uri1 = "http://127.0.0.1:7001/my-project/my-service"
val scn = scenario("ScenarioName")
.exec(http("request_0")
.post("/my-project/my-service")
.headers(headers_0)
.body(RawFileBody("MyService_0000_request.txt")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
"MyService_0000_request.txt" 是 bodies 文件夹中的一个文件,包含 soap 请求正文。
我是 Gatling 和 Scala 的新手。如何使用 Gatling 2.2.0 调用/测试 java SOAP Web 服务?我搜索了 google 和 gatling 文档,但找不到任何 link
代码:
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/MyService")
val headers_0 = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "",
"Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36"
)
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">
<soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\">
<greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse>
</soapenv:Body></soapenv:Envelope>\"\r\n")
.headers(headers_0))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
不确定是否有可用的录音机。但是,您可以对脚本进行如下更改:
class testSOAP extends Simulation {
val httpProtocol = http
.baseURL("http://PUNITP83267L:8081/WebServiceProject/services/")
val header = Map(
"accept-encoding" -> "gzip, deflate",
"Content-Type" -> "text/xml;charset=UTF-8",
"SOAPAction" -> "", "Content-Length" -> "275",
"Host" -> "PUNITP83267L:8081",
"Connection" -> "alive",
"accept-language" -> "en-US,en;q=0.8",
"user-agent" -> "Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/49.0.2623.112 Safari/537.36")
val scn = scenario("SOAPRecordedSimulation")
.exec(http("simple Soap Request")
.post("MyService")
.headers(header)
.body(StringBody("""<?xml version=\"1.0\" encoding=\"UTF-8\"?><soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"><soapenv:Body><greetMeResponse xmlns=\"http://ws.star.fs.infosys.com\"><greetMeReturn>Hello uMESH</greetMeReturn></greetMeResponse></soapenv:Body></soapenv:Envelope>\"\r\n""")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
我认为 SAOP 代码必须在文件中,并且基础 url 不包含 url 上下文。它只是基础 url (localhost:7001)。将 url 上下文放入 post 函数中。
这是代码:
package my.package
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class MyClass extends Simulation {
val httpProtocol = http
.baseURL("http://127.0.0.1:7001")
.inferHtmlResources()
.acceptEncodingHeader("gzip,deflate")
.contentTypeHeader("text/xml;charset=UTF-8")
.userAgentHeader("Apache-HttpClient/4.1.1 (java 1.5)")
val headers_0 = Map("SOAPAction" -> """""""")
val uri1 = "http://127.0.0.1:7001/my-project/my-service"
val scn = scenario("ScenarioName")
.exec(http("request_0")
.post("/my-project/my-service")
.headers(headers_0)
.body(RawFileBody("MyService_0000_request.txt")))
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
"MyService_0000_request.txt" 是 bodies 文件夹中的一个文件,包含 soap 请求正文。