3

The grinder uses jython as it's primary scripting language.

I need to test some web services that only have soap interfaces.

I have not been able to find a way to get this to work. I'm new to The Grinder, and although they have a sample script showing use of XmlRpcClient, even this example errors out stating "Import Error: No module named apache"

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
alphanumericone
  • 268
  • 3
  • 12
  • Sounds like your classpath or pythonpath is not set up correctly. Perhaps you could include your jython code and the log output containing the error message? – Travis Bear Sep 21 '12 at 00:35

1 Answers1

2

here is sample code for my web service:

# 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')

Be sure to change the following in the call method:

your_url_for_web_service = ''
your_soap_message_body = ''

with appropriate values for your web service.

Matthew Murdoch
  • 30,874
  • 30
  • 96
  • 127
Karlo Smid
  • 525
  • 1
  • 5
  • 13
  • 1
    @user912563 What issues have you encountered? I put on purpose my version of getting the body of soap response. My solution works when you use two byte encoded utf-8 characters. For example šđčćž. Using just getText() does not work for soapResponse that contains those characters. – Karlo Smid Nov 04 '12 at 20:53