Permalink
Browse files

added a getProxy method to Recorder

  • Loading branch information...
1 parent bd7c43d commit bdf223e4e3e5dbfb991e1dde6019be90c66e9e1a Rob Fletcher committed Oct 12, 2012
View
@@ -186,12 +186,10 @@ _HTTPBuilder_ also includes a [_HttpURLClient_][httpurlclient] class which needs
### WSLite
-The [groovy-wslite][wslite] library is not aware of the default JVM proxy settings so the proxy needs to be explicitly configured.
+The [groovy-wslite][wslite] library is not aware of the default JVM proxy settings so the proxy needs to be explicitly configured with a `java.net.Proxy`. The `Recorder` class provides a convenience method for getting a `Proxy` instance. For example:
def client = new RESTClient(targetUrl)
- def proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress('localhost', recorder.proxyPort))
-
- def response = client.get(path: '/', proxy: proxy)
+ def response = client.get(path: '/', proxy: recorder.proxy)
## HTTPS
@@ -171,6 +171,10 @@ class Recorder implements MethodRule {
}
}
+ Proxy getProxy() {
+ new Proxy(Proxy.Type.HTTP, new InetSocketAddress(InetAddress.localHost.hostAddress, proxyPort))
+ }
+
@Override
Statement apply(Statement statement, FrameworkMethod method, Object target) {
def annotation = method.getAnnotation(Betamax)
@@ -33,10 +33,9 @@ class WsLiteSpec extends Specification {
void 'can record a connection made with WsLite'() {
given: 'a properly configured wslite instance'
def http = new RESTClient(endpoint.url)
- def proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress('localhost', recorder.proxyPort))
when: 'a request is made'
- def response = http.get(path: '/', proxy: proxy)
+ def response = http.get(path: '/', proxy: recorder.proxy)
then: 'the request is intercepted'
response.statusCode == HTTP_OK
@@ -48,10 +47,9 @@ class WsLiteSpec extends Specification {
void 'proxy intercepts HTTPS requests'() {
given: 'a properly configured wslite instance'
def http = new RESTClient(httpsEndpoint.url)
- def proxy = new Proxy(Proxy.Type.HTTP, new InetSocketAddress('localhost', recorder.proxyPort))
when: 'a request is made'
- def response = http.get(path: '/', proxy: proxy)
+ def response = http.get(path: '/', proxy: recorder.proxy)
then: 'the request is intercepted'
response.statusCode == HTTP_OK

0 comments on commit bdf223e

Please sign in to comment.