【问题标题】:How to submit SOAP request in The Grinder如何在 The Grinder 中提交 SOAP 请求
【发布时间】:2012-09-18 23:13:26
【问题描述】:

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

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

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

【问题讨论】:

  • 听起来您的类路径或 pythonpath 设置不正确。也许您可以包含您的 jython 代码和包含错误消息的日志输出?

标签: soap jython grinder


【解决方案1】:

这是我的网络服务的示例代码:

# 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 方法中更改以下内容:

your_url_for_web_service = ''
your_soap_message_body = ''

为您的网络服务提供适当的值。

【讨论】:

  • @user912563 你遇到了什么问题?我故意使用我的版本来获得肥皂反应的主体。当您使用两个字节编码的 utf-8 字符时,我的解决方案有效。例如šđčćž。仅使用 getText() 不适用于包含这些字符的 soapResponse。
猜你喜欢
  • 1970-01-01
  • 2018-06-18
  • 1970-01-01
  • 1970-01-01
  • 2021-05-11
  • 2014-07-04
  • 2013-07-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多