Re: extending HTTPRequest

Philip Aston <[email protected]>
Newsgroups gmane.comp.java.grinder.user
Message-ID <[email protected]>
This is a limitation of the Jython instrumentation engine.

There are a couple of workarounds.

1. You could implement MyHTTPRequest in Java.

2. You could avoid selective instrumentation. For example:

    class MyHTTPRequest(HTTPRequest):
        def __init__(self, url):
            HTTPRequest.__init__(self)
            self.url = url

        def processResponse(self, response):
            # ...

    def createRequest(test, url, headers=None):
        """Create an instrumented HTTPRequest."""
        request = MyHTTPRequest(url=url)
        if headers: request.headers=headers
        test.record(request.GET)
        test.record(request.POST)# etc
        return request


    NB, fix to the MyHTTPRequest constructor to set the URL.

HTH,

- Phil


On 17/03/14 17:33, Joan Picanyol i Puig wrote:
> Hi,
>
> I'm trying to modify a test recorded with the TCPProxy & HTTP filter so
> that all HTTP failures fail the tests.
>
> I thought I'd be as easy as extending HTTPRequest to raise an Exception
> and use it in the createRequest() method, but I'm getting a
> net.grinder.script.NonInstrumentableTypeException: The Jython instrumenters do not support selective instrumenters
>
> I've been unable to gather from
> http://grinder.sourceforge.net/g3/instrumentation.html#Selective+instrumentation
> what the correct approach would be. Any ideas?
>
> For the record, I'm modifying the generated script with:
>
> class MyHTTPRequest(HTTPRequest):
>     def __init__(self, url):
>         # super(MyHTTPRequest, self).__init__()
>         HTTPRequest.__init__(self)
>
>     def processResponse(self, response):
>         if response.getStatusCode >= 400:
>             log("KO %(status)s: %(msg)s" %
>                 {"status": response.getStatusCode(), "msg": response.getText()})
>             raise Exception(response.getText())
>
> def createRequest(test, url, headers=None):
>     """Create an instrumented HTTPRequest."""
>     # request = HTTPRequest(url=url)
>     request = MyHTTPRequest(url=url)
>     if headers: request.headers = headers
>     test.record(request, HTTPRequest.getHttpMethodFilter())
>     return request
>
> And this is the exception I'm getting:
>
> net.grinder.script.NonInstrumentableTypeException: The Jython instrumenters do not support selective instrumenters
>         at net.grinder.scriptengine.jython.instrumentation.dcr.AbstractJythonDCRInstrumenter.disallowSelectiveFilter(AbstractJythonDCRInstrumenter.java:183) ~[grinder-core-3.11.jar:na]
>         at net.grinder.scriptengine.jython.instrumentation.dcr.AbstractJythonDCRInstrumenter.instrument(AbstractJythonDCRInstrumenter.java:167) ~[grinder-core-3.11.jar:na]
>         at net.grinder.scriptengine.AbstractDCRInstrumenter.instrument(AbstractDCRInstrumenter.java:93) ~[grinder-core-3.11.jar:na]
>         at net.grinder.scriptengine.CompositeInstrumenter.instrument(CompositeInstrumenter.java:103) ~[grinder-core-3.11.jar:na]
>
> tks

------------------------------------------------------------------------------
Learn Graph Databases - Download FREE O'Reilly Book
"Graph Databases" is the definitive new guide to graph databases and their
applications. Written by three acclaimed leaders in the field,
this first edition is now available. Download your free book today!
http://p.sf.net/sfu/13534_NeoTech

_______________________________________________
grinder-use mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/grinder-use
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.