2016-04-14 76 views
1

我是Gatling和Scala的新手。如何使用Gatling 2.2.0调用/测试Java SOAP Web服务?我已经搜索谷歌和加特林的文件,但找不到任何链接对于如何使用Gatling调用SOAP Web服务2.2.0

代码 VAL httpProtocol = HTTP .baseURL( “http://PUNITP83267L:8081/WebServiceProject/services/MyService”) VAL headers_0 =地图( “接受编码” - >“压缩,“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,li柯壁虎)的Chrome/Safari浏览器49.0.2623.112/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) 
} 
+0

是否有任何SOAP服务调用记录器?使用SOAP UI? – UmeshPathak

回答

1

我不知道是否有记录可用。但是,你可以更改您的脚本如下:

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) 
} 
+0

非常感谢黄金。文档中提到了哪些地方?由于这是Java Web服务,因此我们在post中添加了MyService,并且URL被更改(从baseURL中删除了MyService)。如果它是一个.NET Web服务呢?或者服务URL以?WSDL – UmeshPathak

+0

结尾我已经将MyService从基本URL中分离出来,就像编码标准一样。它与java或.NET无关。你也可以说'.post(“http:// PUNITP83267L:8081/WebServiceProject/services/MyService”)'并且去掉httpProtocol。 –

0

我认为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”是机构文件夹一个文件,包含SOAP请求主体。