com.github.kristofa.test.http.HttpRequestResponseFileLoggerFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mock-http-server Show documentation
Show all versions of mock-http-server Show documentation
Mock and Proxy HTTP Server for testing purposes. Forked from https://github.com/jharlap/mock-http-server
package com.github.kristofa.test.http;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.lang3.Validate;
/**
* Factory that creates {@link HttpRequestResponseFileLogger} instances.
*
* @see HttpRequestResponseFileLogger
* @see LoggingHttpProxy
* @author kristof
*/
public class HttpRequestResponseFileLoggerFactory implements HttpRequestResponseLoggerFactory {
private final AtomicInteger atomicInteger = new AtomicInteger();
private final String directory;
private final String fileName;
private final HttpRequestFileWriter requestWriter;
private final HttpResponseFileWriter responseWriter;
/**
* Creates a new instance.
*
* @param directory Target directory in which to store request/responses. Directory should already exist. Should not be
* null
or blank.
* @param fileName Base file name. Should not contain extension. Will be suffixed with sequence number and .txt
* extension. Should not be null
or blank.
*/
public HttpRequestResponseFileLoggerFactory(final String directory, final String fileName) {
Validate.notBlank(directory);
Validate.notBlank(fileName);
this.directory = directory;
this.fileName = fileName;
requestWriter = new HttpRequestFileWriterImpl();
responseWriter = new HttpResponseFileWriterImpl();
}
/**
* {@inheritDoc}
*/
@Override
public HttpRequestResponseLogger getHttpRequestResponseLogger() {
return new HttpRequestResponseFileLogger(directory, fileName, atomicInteger.incrementAndGet(), requestWriter,
responseWriter);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy