mock-server / mockserver

MockServer enables easy mocking of any system you integrate with via HTTP or HTTPS with clients written in Java, JavaScript and Ruby. MockServer also includes a proxy that introspects all proxied traffic including encrypted SSL traffic and supports Port Forwarding, Web Proxying (i.e. HTTP proxy), HTTPS Tunneling Proxying (using HTTP CONNECT) and SOCKS Proxying (i.e. dynamic port forwarding).
http://mock-server.com
Apache License 2.0
4.57k stars 1.07k forks source link

Transferring values from the request to the response issue#158 #160

Closed fatihtekin closed 9 years ago

fatihtekin commented 9 years ago

Regarding https://github.com/jamesdbloom/mockserver/issues/158 can you provide java script code for callback

jamesdbloom commented 9 years ago

It is not possible to do this with Javascript without first writing a Java class.

However if you have already written a Java class and you have added this class to the classpath of the JVM running the Mock Server then you can submit an expectation in JavaScript as follows:

mockServerClient("localhost", 1080).mockAnyResponse(
    {
        'httpRequest': {
            'method': 'POST',
            'path': '/somePath'
        },
        'httpCallback': {
            'callbackClass' : 'com.some.package.MyCallbackAction'
        },
        'times': {
            'remainingTimes': 1,
            'unlimited': false
        }
    }
);
jamesdbloom commented 9 years ago

Given the solution for #120 will use WebSockets it should be possible to support function based callbacks for JavaScript. I'll add a comment to that ticket so that it included. This would dramatically improve the JavaScript experience for callback logic. This however is not likely to be completed for roughly 4-6 weeks.