Package com.yahoo.container.handler.test
Class MockService
- java.lang.Object
-
- com.yahoo.jdisc.AbstractResource
-
- com.yahoo.jdisc.handler.AbstractRequestHandler
-
- com.yahoo.container.jdisc.ThreadedRequestHandler
-
- com.yahoo.container.jdisc.ThreadedHttpRequestHandler
-
- com.yahoo.container.jdisc.LoggingRequestHandler
-
- com.yahoo.container.handler.test.MockService
-
- All Implemented Interfaces:
com.yahoo.jdisc.handler.RequestHandler
,com.yahoo.jdisc.SharedResource
@Beta public class MockService extends LoggingRequestHandler
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, seeMockService.TextFileHandler
. for descriptions of the format.- Author:
- Ulf Lilleengen
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.yahoo.container.jdisc.LoggingRequestHandler
LoggingRequestHandler.Context
-
Nested classes/interfaces inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
ThreadedHttpRequestHandler.LazyContentChannel
-
-
Field Summary
-
Fields inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
CONTENT_TYPE, log
-
Fields inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
metric
-
-
Constructor Summary
Constructors Constructor Description MockService(java.util.concurrent.Executor executor, com.yahoo.container.logging.AccessLog accessLog, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, MockserviceConfig config, com.yahoo.jdisc.Metric metric)
Create a mock service that mocks an external service using data provided via file distribution.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected MockServiceHandler
createHandler(java.io.File dataFile)
Create a handler for a file.HttpResponse
handle(HttpRequest request)
Override this to implement a synchronous style handler.-
Methods inherited from class com.yahoo.container.jdisc.LoggingRequestHandler
createLoggingCompletionHandler, testOnlyContext
-
Methods inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
addDateHeader, asHttpRequest, handle, handleRequest
-
Methods inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
getTimeout, handleRequest
-
Methods inherited from class com.yahoo.jdisc.AbstractResource
currentState, destroy, refer, release, retainCount
-
-
-
-
Constructor Detail
-
MockService
public MockService(java.util.concurrent.Executor executor, com.yahoo.container.logging.AccessLog accessLog, com.yahoo.filedistribution.fileacquirer.FileAcquirer fileAcquirer, MockserviceConfig config, com.yahoo.jdisc.Metric metric) throws java.lang.InterruptedException, java.io.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
- AnExecutor
used to create threads.accessLog
- AnAccessLog
where requests will be logged.fileAcquirer
- AFileAcquirer
which is used to fetch file from config.config
- AMockserviceConfig
for this service.- Throws:
java.lang.InterruptedException
- if unable to get data file within timeout.java.io.IOException
- if unable to create handler due to some IO errors.
-
-
Method Detail
-
createHandler
protected MockServiceHandler createHandler(java.io.File dataFile) throws java.io.IOException
Create a handler for a file. Override this method to handle a custom file syntax of your own.- Parameters:
dataFile
- A file to read.- Returns:
- a
MockServiceHandler
used to handle requests. - Throws:
java.io.IOException
- if errors occured 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 classThreadedHttpRequestHandler
- Parameters:
request
- incoming HTTP request- Returns:
- a valid HTTP response for presentation to the user
-
-