Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  package com.github.kristofa.test.http.file;
  
  import java.io.File;
  
  
com.github.kristofa.test.http.HttpRequestResponseLogger that logs requests/responses to file. For each request/response that is logged it will generate following files:
  • <fileName>_request_0000x.txt : Contains http method, headers, path and query parameters. Is readable (text file), UTF-8 encoded. 0000x = sequence number that increments with each request.
  • <fileName>_request_entity_0000x.txt : Contains request entity if entity is available. If no entity is specified file is not written. This is a binary file.
  • <fileName>_response_0000x.txt : Contains http code and Content Type. Is readable (text file), UTF-8 encoded. 0000x = sequence number that increments with each request.
  • <fileName>_response_entity_0000x.txt : Contains response entity if entity is available. If no entity is specified file is not written. This is a binary file.
It use FileNameBuilder to build these file names.

Author(s):
kristof
See also:
FileNameBuilder
 
 
     private final String directory;
     private final String fileName;
     private final int seqNr;
     private final HttpRequestFileWriter requestWriter;
     private final HttpResponseFileWriter responseWriter;

    
Creates a new instance.

Parameters:
directory Target directory in which to store request/responses. Directory should already exist.
fileName Base file name. Should not contain extension. Will be suffixed with sequence number and .txt extension.
seqNr Sequence number for request / response.
requestWriter Responsible for writing http request to disk.
responseWriter Responsible for writing http response to disk.
 
     public HttpRequestResponseFileLogger(final String directoryfinal String fileNamefinal int seqNr,
         final HttpRequestFileWriter requestWriterfinal HttpResponseFileWriter responseWriter) {
         Validate.notNull(directory);
         Validate.notBlank(fileName);
         Validate.notNull(requestWriter);
         Validate.notNull(responseWriter);
 
         this. = directory;
         this. = fileName;
         this. = seqNr;
         this. = requestWriter;
         this. = responseWriter;
     }

    
Gets the target directory in which to store request/responses.

Returns:
the target directory in which to store request/responses.
 
     public String getDirectory() {
         return ;
     }

    
Gets the base file name.

Returns:
Base file name.
 
     public String getFileName() {
         return ;
     }

    
Gets the seqnr for request/response.

Returns:
Seqnr for request/response.
 
     public int getSeqNr() {
         return ;
     }

    
Gets the HttpRequestFileWriter instance.

Returns:
the HttpRequestFileWriter instance.
 
         return ;
     }

    
Gets the HttpResponseFileWriter instance.

Returns:
the HttpResponseFileWriter instance.
        return ;
    }

    
    @Override
    public void log(final HttpRequest request) {
        final String requestFileName = ..getFileName();
        final String requestEntityFileName = ..getFileName();
        .write(requestnew File(requestFileName), new File(requestEntityFileName));
    }

    
    @Override
    public void log(final HttpResponse response) {
        final String responseFileName = ..getFileName();
        final String responseEntityFileName = ..getFileName();
        .write(responsenew File(responseFileName), new File(responseEntityFileName));
    }
New to GrepCode? Check out our FAQ X