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.handler.test.MockService
- All Implemented Interfaces:
HttpRequestHandler
,com.yahoo.jdisc.handler.RequestHandler
,com.yahoo.jdisc.SharedResource
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
-
Nested Class Summary
Nested classes/interfaces inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
ThreadedHttpRequestHandler.Context, ThreadedHttpRequestHandler.LazyContentChannel
Nested classes/interfaces inherited from interface com.yahoo.jdisc.SharedResource
com.yahoo.jdisc.SharedResource.Debug
-
Field Summary
Fields inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
CONTENT_TYPE, log
Fields inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
metric
Fields inherited from interface com.yahoo.jdisc.SharedResource
DEBUG, SYSTEM_PROPERTY_NAME_DEBUG
-
Constructor Summary
ConstructorDescriptionMockService
(Executor executor, 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
Modifier and TypeMethodDescriptionprotected MockServiceHandler
createHandler
(File dataFile) Create a handler for a file.final HttpResponse
handle
(HttpRequest request) Override this to implement a synchronous style handler.Methods inherited from class com.yahoo.container.jdisc.ThreadedHttpRequestHandler
addDateHeader, asHttpRequest, createLoggingCompletionHandler, handle, handleRequest, testContext
Methods inherited from class com.yahoo.container.jdisc.ThreadedRequestHandler
executor, getRequestType, getTimeout, handleRequest, writeErrorResponseOnOverload
Methods inherited from class com.yahoo.jdisc.handler.AbstractRequestHandler
handleTimeout
Methods inherited from class com.yahoo.jdisc.AbstractResource
currentState, destroy, refer, refer, release, retainCount
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.yahoo.container.jdisc.HttpRequestHandler
requestHandlerSpec
Methods inherited from interface com.yahoo.jdisc.handler.RequestHandler
handleRequest, handleTimeout
Methods inherited from interface com.yahoo.jdisc.SharedResource
refer, refer, release
-
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 threadsfileAcquirer
- used to fetch file from configconfig
- the mock config for this service- Throws:
InterruptedException
- if unable to get data file within timeoutIOException
- if unable to create handler due to some IO errors
-
-
Method Details
-
createHandler
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
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
-