Class MockService

java.lang.Object
com.yahoo.jdisc.AbstractResource
com.yahoo.jdisc.handler.AbstractRequestHandler
All Implemented Interfaces:
HttpRequestHandler, com.yahoo.jdisc.handler.RequestHandler, com.yahoo.jdisc.SharedResource

public class MockService extends ThreadedHttpRequestHandler
This is a generic http handler that can be used to mock a service when testing your application on jDISC. Configuration and necessary files are given to the handle in its configuration. Example config:
 <handler id="MockService">
     <config name="container.handler.test.mockservice">
         <file>myresponses.txt</file>
     </config>
     <binding>http://*\/my/service/path1/*</binding>
 </handler>
 
The file formats supported out of the box is text, see MockService.TextFileHandler. for descriptions of the format.
Author:
Ulf Lilleengen
  • Constructor Details

    • MockService

      public MockService(Executor executor, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, MockserviceConfig config, com.yahoo.jdisc.Metric metric) throws InterruptedException, IOException
      Create a mock service that mocks an external service using data provided via file distribution. A custom handler can be created by subclassing and overriding the createHandler method.
      Parameters:
      executor - used to create threads
      fileAcquirer - used to fetch file from config
      config - the mock config for this service
      Throws:
      InterruptedException - if unable to get data file within timeout
      IOException - if unable to create handler due to some IO errors
  • Method Details

    • createHandler

      protected MockServiceHandler createHandler(File dataFile) throws IOException
      Create a handler for a file. Override this method to handle a custom file syntax of your own.
      Parameters:
      dataFile - the file to read
      Returns:
      the handler used to handle requests
      Throws:
      IOException - if errors occurred when loading the file
    • handle

      public final HttpResponse handle(HttpRequest request)
      Description copied from class: ThreadedHttpRequestHandler
      Override this to implement a synchronous style handler.
      Specified by:
      handle in class ThreadedHttpRequestHandler
      Parameters:
      request - incoming HTTP request
      Returns:
      a valid HTTP response for presentation to the user