2012-09-18 5 views
3

그라인더는 jython을 기본 스크립트 언어로 사용합니다.The Grinder에서 SOAP 요청을 제출하는 방법

비누 인터페이스 만있는 일부 웹 서비스를 테스트해야합니다.

이 기능을 작동시키는 방법을 찾을 수 없었습니다. The Grinder를 처음 사용하고 XmlRpcClient를 사용하는 샘플 스크립트가 있지만 "가져 오기 오류 : 모듈 이름이 apache가 아닙니다"라는 오류 메시지가 있습니다.

+0

classpath 또는 pythonpath와 같은 소리가 올바르게 설정되지 않았습니다. 아마도 자이 썬 코드와 오류 메시지가 포함 된 로그 출력을 포함시킬 수 있을까? –

답변

2

여기 웹 서비스의 샘플 코드는

입니다.
# 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 = '' 

.

+1

@ user912563 어떤 문제가 발생 했습니까? 나는 비누 반응의 몸을 얻는 나의 버전을 목적에두고있다. 내 솔루션은 2 바이트 인코딩 된 UTF-8 문자를 사용할 때 작동합니다. 예를 들어 šđčćž. 해당 문자가 포함 된 soapResponse에 대해서만 getText()를 사용하면 작동하지 않습니다. –