首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在Grinder中提交SOAP请求

如何在Grinder中提交SOAP请求
EN

Stack Overflow用户
提问于 2012-09-19 07:13:26
回答 1查看 1.6K关注 0票数 3

研磨器使用jython作为它的主要脚本语言。

我需要测试一些只有soap接口的web服务。

我还没能找到一种让它工作的方法。我刚接触Grinder,虽然他们有一个示例脚本来说明XmlRpcClient的用法,但即使这个示例错误地指出“导入错误:没有模块名为apache”

EN

回答 1

Stack Overflow用户

发布于 2012-10-02 19:51:27

以下是我的web服务的示例代码:

代码语言:javascript
复制
# coding=utf-8

import traceback
from net.grinder.script.Grinder import grinder
from net.grinder.script import Test
from net.grinder.plugin.http import HTTPPluginControl, HTTPRequest
from HTTPClient import NVPair

connectionDefaults = HTTPPluginControl.getConnectionDefaults()
httpUtilities = HTTPPluginControl.getHTTPUtilities()
connectionDefaults.useContentEncoding = 1
log = grinder.logger.info

class TestRunner:

    def __call__(self):
        your_url_for_web_service = ''
        your_soap_message_body = ''
        soapMessage = """<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>"""+
    your_soap_message_body+"""
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>"""
        self.send_service( your_url_for_web_service, soapMessage )

    def send_service( self, soapMessage ):                
        request = HTTPRequest()
        headers =   (
                    NVPair( "Content-Type", "text/xml; charset=utf-8" ),
                    NVPair( "Content-Length", str( len( soapMessage ) ) ),
                    )
        request.setHeaders(headers)
        httpResponseObject = request.POST( url, soapMessage )
        soapAsString = httpResponseObject.getText()
        log( soapAsString )

def instrumentMethod(test, method_name, c=TestRunner):
  """Instrument a method with the given Test."""
  unadorned = getattr(c, method_name)
  import new
  method = new.instancemethod(test.wrap(unadorned), None, c)
  setattr(c, method_name, method)


# Replace each method with an instrumented version.
instrumentMethod(Test(1, 'soap request showcase example'), 'send_service')

请确保在call方法中更改以下内容:

代码语言:javascript
复制
your_url_for_web_service = ''
your_soap_message_body = ''

为您的web服务设置适当的值。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/12486405

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档