com.github.kristofa.test.http
Class LoggingHttpProxy

java.lang.Object
  extended by com.github.kristofa.test.http.LoggingHttpProxy
Direct Known Subclasses:
PassthroughLoggingHttpProxy

public class LoggingHttpProxy
extends Object

Http proxy that supports logging requests/reponses. Its purpose is to be a 'man in the middle' which can be used to capture request/responses that can be mocked later on for testing purposes. It forwards requests it gets to another service and returns the result of that service unmodified to the requester. While doing that it also allows logging request/response pairs.

Those persisted request/response pairs can be mocked by MockHttpServer.

Using the LoggingHttpProxy to persist request/responses and using them with the MockHttpServer is especially useful for complex responses that are not that easy to mock by hand. It allows building a hermetic server.

The LoggingHttpProxy will return following HTTP return codes when things go wrong:

The body of the response will contain the error message.

Author:
kristof

Constructor Summary
LoggingHttpProxy(int port, Collection<ForwardHttpRequestBuilder> requestBuilders, HttpRequestResponseLoggerFactory loggerFactory)
          Create a new instance.
 
Method Summary
 void start()
          Starts proxy.
 void stop()
          Stops proxy.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LoggingHttpProxy

public LoggingHttpProxy(int port,
                        Collection<ForwardHttpRequestBuilder> requestBuilders,
                        HttpRequestResponseLoggerFactory loggerFactory)
Create a new instance.

Parameters:
port - Port at which proxy will be running.
requestBuilders - Forward request builders. Should not be null and at least 1 should be specified.
loggerFactory - Request/Response logger factory.. Should not be null.
Method Detail

start

public void start()
           throws IOException
Starts proxy.

Throws:
Exception - In case starting fails.
IOException

stop

public void stop()
          throws IOException
Stops proxy.

Throws:
IOException - In case closing connection fails.


Copyright © 2014. All Rights Reserved.