RestDocClientInterceptor implements ClientHttpRequestInterceptor { @Override public ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution) throws IOException { ClientHttpResponse response = new CachedBodyHttpResponse(execution.execute(request, body)); Map<String, Object> configuration; if (request instanceof RestDocConfiguredHttpRequest) { configuration = ((RestDocConfiguredHttpRequest) request).getConfiguration(); configuration.put(RestDocumentationContext.class.getName(), ((RestDocConfiguredHttpRequest) request).getContext()); } else { configuration = new HashMap<>(); } this.documentationGenerator.handle(new CachedBodyHttpRequest(request, body), response, configuration); return response; } RestDocClientInterceptor(RestDocumentationGenerator<CachedBodyHttpRequest, ClientHttpResponse> documentationGenerator); @Override ClientHttpResponse intercept(HttpRequest request, byte[] body, ClientHttpRequestExecution execution); RestDocClientInterceptor snippets(Snippet... snippets); RestDocumentationGenerator<CachedBodyHttpRequest, ClientHttpResponse> getDocumentationGenerator();  }
@Test public void testIntercept() throws Exception { prepareExecution("http: ClientHttpRequestExecution configureExecution = Mockito.mock(ClientHttpRequestExecution.class); when(configureExecution.execute(any(HttpRequest.class), any(byte[].class))).thenAnswer(new Answer<ClientHttpResponse>() { @Override public ClientHttpResponse answer(InvocationOnMock invocation) throws Throwable { interceptor.intercept((HttpRequest) invocation.getArguments()[0], (byte[]) invocation.getArguments()[1], execution); return response; } }); CitrusRestDocsSupport.restDocsConfigurer(restDocumentation).intercept(request, "TestMessage".getBytes(), configureExecution); assertExpectedSnippetFilesExist("default", "http-request.adoc", "http-response.adoc", "curl-request.adoc"); }