Skip to content

Commit 5ce2ed2

Browse files
committed
refactor: removes redundant config argument.
1 parent 975fad4 commit 5ce2ed2

File tree

14 files changed

+39
-70
lines changed

14 files changed

+39
-70
lines changed

core/api/src/main/java/io/gatehill/imposter/service/HandlerService.kt

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
*/
4343
package io.gatehill.imposter.service
4444

45-
import io.gatehill.imposter.ImposterConfig
4645
import io.gatehill.imposter.http.HttpExchange
4746
import io.gatehill.imposter.http.HttpExchangeFutureHandler
4847
import io.gatehill.imposter.http.HttpExchangeHandler
@@ -62,21 +61,19 @@ interface HandlerService {
6261
*
6362
* Example:
6463
* ```
65-
* val handler = build(imposterConfig, allPluginConfigs, resourceMatcher) {
64+
* val handler = build(allPluginConfigs, resourceMatcher) {
6665
* // use httpExchange
6766
* }
6867
* router.get("/example").handler(handler)
6968
* ```
7069
*
71-
* @param imposterConfig the Imposter configuration
7270
* @param allPluginConfigs all plugin configurations
7371
* @param resourceMatcher the [ResourceMatcher] to use
74-
* @param httpExchangeHandler the consumer of the [HttpExchange]
7572
* @param handlerType the type of handler to build
73+
* @param httpExchangeHandler the consumer of the [HttpExchange]
7674
* @return the handler
7775
*/
7876
fun build(
79-
imposterConfig: ImposterConfig,
8077
allPluginConfigs: List<PluginConfig>,
8178
resourceMatcher: ResourceMatcher,
8279
handlerType: HandlerType = HandlerType.RESOURCE,
@@ -87,7 +84,6 @@ interface HandlerService {
8784
* Same as [build] but wraps [httpExchangeHandler] in a future.
8885
*/
8986
fun buildAndWrap(
90-
imposterConfig: ImposterConfig,
9187
allPluginConfigs: List<PluginConfig>,
9288
resourceMatcher: ResourceMatcher,
9389
handlerType: HandlerType = HandlerType.RESOURCE,
@@ -99,28 +95,25 @@ interface HandlerService {
9995
*
10096
* Example:
10197
* ```
102-
* val handler = build(imposterConfig, pluginConfig, resourceMatcher) {
98+
* val handler = build(pluginConfig, resourceMatcher) {
10399
* // use httpExchange
104100
* }
105101
* router.get("/example").handler(handler)
106102
* ```
107103
*
108-
* @param imposterConfig the Imposter configuration
109104
* @param pluginConfig the plugin configuration
110105
* @param resourceMatcher the [ResourceMatcher] to use
111106
* @param httpExchangeHandler the consumer of the [HttpExchange]
112107
* @return the handler
113108
*/
114109
fun build(
115-
imposterConfig: ImposterConfig,
116110
pluginConfig: PluginConfig,
117111
resourceMatcher: ResourceMatcher,
118112
handlerType: HandlerType = HandlerType.RESOURCE,
119113
httpExchangeHandler: HttpExchangeFutureHandler,
120114
): HttpExchangeFutureHandler
121115

122116
fun build(
123-
imposterConfig: ImposterConfig,
124117
pluginConfig: PluginConfig,
125118
resourceConfig: BasicResourceConfig,
126119
handlerType: HandlerType = HandlerType.RESOURCE,
@@ -131,7 +124,6 @@ interface HandlerService {
131124
* Same as [build] but wraps [httpExchangeHandler] in a future.
132125
*/
133126
fun buildAndWrap(
134-
imposterConfig: ImposterConfig,
135127
pluginConfig: PluginConfig,
136128
resourceMatcher: ResourceMatcher,
137129
handlerType: HandlerType = HandlerType.RESOURCE,

core/engine/src/main/java/io/gatehill/imposter/Imposter.kt

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,6 @@ class Imposter(
200200
LOGGER.trace("Metrics enabled")
201201
router.route("/system/metrics").handler(
202202
handlerService.build(
203-
imposterConfig,
204203
allConfigs,
205204
resourceMatcher,
206205
httpExchangeHandler = serverFactory.createMetricsHandler()
@@ -210,7 +209,7 @@ class Imposter(
210209

211210
// status check to indicate when server is up
212211
router.get("/system/status").handler(
213-
handlerService.buildAndWrap(imposterConfig, allConfigs, resourceMatcher) { httpExchange ->
212+
handlerService.buildAndWrap(allConfigs, resourceMatcher) { httpExchange ->
214213
httpExchange.response
215214
.putHeader(HttpUtil.CONTENT_TYPE, HttpUtil.CONTENT_TYPE_JSON)
216215
.end(HttpUtil.buildStatusResponse())
@@ -221,7 +220,7 @@ class Imposter(
221220
plugins.filterIsInstance<RoutablePlugin>().forEach { it.configureRoutes(router) }
222221

223222
// configure CORS after all routes have been added
224-
corsService.configure(imposterConfig, allConfigs, router, resourceMatcher)
223+
corsService.configure(allConfigs, router, resourceMatcher)
225224

226225
// fire post route config hooks
227226
engineLifecycle.forEach { listener: EngineLifecycleListener ->

core/engine/src/main/java/io/gatehill/imposter/service/HandlerServiceImpl.kt

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343
package io.gatehill.imposter.service
4444

4545
import com.google.common.collect.Lists
46-
import io.gatehill.imposter.ImposterConfig
4746
import io.gatehill.imposter.config.ResolvedResourceConfig
4847
import io.gatehill.imposter.config.util.EnvVars
4948
import io.gatehill.imposter.http.*
@@ -85,18 +84,16 @@ class HandlerServiceImpl @Inject constructor(
8584
EnvVars.getEnv("IMPOSTER_ADD_ENGINE_RESPONSE_HEADERS")?.toBoolean() != false
8685

8786
override fun build(
88-
imposterConfig: ImposterConfig,
8987
allPluginConfigs: List<PluginConfig>,
9088
resourceMatcher: ResourceMatcher,
9189
handlerType: HandlerType,
9290
httpExchangeHandler: HttpExchangeFutureHandler,
9391
): HttpExchangeFutureHandler {
9492
val selectedConfig = securityService.findConfigPreferringSecurityPolicy(allPluginConfigs)
95-
return build(imposterConfig, selectedConfig, resourceMatcher, handlerType, httpExchangeHandler)
93+
return build(selectedConfig, resourceMatcher, handlerType, httpExchangeHandler)
9694
}
9795

9896
override fun build(
99-
imposterConfig: ImposterConfig,
10097
pluginConfig: PluginConfig,
10198
resourceMatcher: ResourceMatcher,
10299
handlerType: HandlerType,
@@ -118,7 +115,6 @@ class HandlerServiceImpl @Inject constructor(
118115
}
119116

120117
override fun build(
121-
imposterConfig: ImposterConfig,
122118
pluginConfig: PluginConfig,
123119
resourceConfig: BasicResourceConfig,
124120
handlerType: HandlerType,
@@ -140,22 +136,20 @@ class HandlerServiceImpl @Inject constructor(
140136
}
141137

142138
override fun buildAndWrap(
143-
imposterConfig: ImposterConfig,
144139
allPluginConfigs: List<PluginConfig>,
145140
resourceMatcher: ResourceMatcher,
146141
handlerType: HandlerType,
147142
httpExchangeHandler: HttpExchangeHandler,
148143
): HttpExchangeFutureHandler =
149-
build(imposterConfig, allPluginConfigs, resourceMatcher, handlerType, wrapInFuture(httpExchangeHandler))
144+
build(allPluginConfigs, resourceMatcher, handlerType, wrapInFuture(httpExchangeHandler))
150145

151146
override fun buildAndWrap(
152-
imposterConfig: ImposterConfig,
153147
pluginConfig: PluginConfig,
154148
resourceMatcher: ResourceMatcher,
155149
handlerType: HandlerType,
156150
httpExchangeHandler: HttpExchangeHandler,
157151
): HttpExchangeFutureHandler =
158-
build(imposterConfig, pluginConfig, resourceMatcher, handlerType, wrapInFuture(httpExchangeHandler))
152+
build(pluginConfig, resourceMatcher, handlerType, wrapInFuture(httpExchangeHandler))
159153

160154
/**
161155
* Wraps the given [httpExchangeHandler] in a [HttpExchangeFutureHandler] and returns the future.

core/engine/src/main/java/io/gatehill/imposter/service/InterceptorServiceImpl.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
package io.gatehill.imposter.service
4545

46-
import io.gatehill.imposter.ImposterConfig
4746
import io.gatehill.imposter.http.HttpExchange
4847
import io.gatehill.imposter.http.HttpRouter
4948
import io.gatehill.imposter.model.HandlerType
@@ -67,7 +66,6 @@ import javax.inject.Inject
6766
class InterceptorServiceImpl @Inject constructor(
6867
private val handlerService: HandlerService,
6968
private val responseRoutingService: ResponseRoutingService,
70-
private val imposterConfig: ImposterConfig,
7169
) : InterceptorService, CoroutineScope by supervisedDefaultCoroutineScope {
7270

7371
override fun configureInterceptorRoute(
@@ -76,7 +74,6 @@ class InterceptorServiceImpl @Inject constructor(
7674
interceptor: BasicResourceConfig,
7775
) {
7876
val routeHandler = handlerService.build(
79-
imposterConfig,
8077
pluginConfig,
8178
interceptor,
8279
handlerType = HandlerType.INTERCEPTOR

core/engine/src/main/java/io/gatehill/imposter/service/security/CorsService.kt

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,6 @@
4343

4444
package io.gatehill.imposter.service.security
4545

46-
import io.gatehill.imposter.ImposterConfig
4746
import io.gatehill.imposter.http.HttpExchange
4847
import io.gatehill.imposter.http.HttpExchangeFutureHandler
4948
import io.gatehill.imposter.http.HttpMethod
@@ -70,7 +69,6 @@ class CorsService @Inject constructor(
7069
private val logger = LogManager.getLogger(CorsService::class.java)
7170

7271
fun configure(
73-
imposterConfig: ImposterConfig,
7472
allConfigs: List<PluginConfig>,
7573
router: HttpRouter,
7674
resourceMatcher: ResourceMatcher,
@@ -85,7 +83,7 @@ class CorsService @Inject constructor(
8583

8684
// preflight
8785
router.route(HttpMethod.OPTIONS, "/*").handler(
88-
handlePreflight(imposterConfig, selectedConfig, resourceMatcher, cors)
86+
handlePreflight(selectedConfig, resourceMatcher, cors)
8987
)
9088

9189
// request already handled
@@ -97,12 +95,11 @@ class CorsService @Inject constructor(
9795
}
9896

9997
private fun handlePreflight(
100-
imposterConfig: ImposterConfig,
10198
selectedConfig: PluginConfig,
10299
resourceMatcher: ResourceMatcher,
103100
cors: CorsConfig,
104101
): HttpExchangeFutureHandler {
105-
return handlerService.buildAndWrap(imposterConfig, selectedConfig, resourceMatcher) { exchange: HttpExchange ->
102+
return handlerService.buildAndWrap(selectedConfig, resourceMatcher) { exchange: HttpExchange ->
106103
val origin = determineResponseOrigin(cors, exchange.request)
107104
origin?.let {
108105
logger.debug("Serving CORS pre-flight request: ${LogUtil.describeRequest(exchange)}")

mock/hbase/src/main/java/io/gatehill/imposter/plugin/hbase/HBasePluginImpl.kt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@ class HBasePluginImpl @Inject constructor(
133133
*/
134134
private fun addRowRetrievalRoute(pluginConfig: PluginConfig, router: HttpRouter, path: String) {
135135
router.get("$path/{tableName}/{recordId}/").handler(
136-
handlerService.build(imposterConfig, pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
136+
handlerService.build(pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
137137
val request = httpExchange.request
138138
val tableName = request.getPathParam("tableName")!!
139139
val recordId = request.getPathParam("recordId")!!
@@ -191,7 +191,7 @@ class HBasePluginImpl @Inject constructor(
191191
*/
192192
private fun addCreateScannerRoute(pluginConfig: PluginConfig, router: HttpRouter, path: String) {
193193
router.post("$path/{tableName}/scanner").handler(
194-
handlerService.build(imposterConfig, pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
194+
handlerService.build(pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
195195
val tableName = httpExchange.request.getPathParam("tableName")!!
196196

197197
// check that the table is registered
@@ -257,7 +257,7 @@ class HBasePluginImpl @Inject constructor(
257257
*/
258258
private fun addReadScannerResultsRoute(pluginConfig: HBasePluginConfig, router: HttpRouter, path: String) {
259259
router.get("$path/{tableName}/scanner/{scannerId}").handler(
260-
handlerService.build(imposterConfig, pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
260+
handlerService.build(pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
261261
val request = httpExchange.request
262262
val tableName = request.getPathParam("tableName")!!
263263
val scannerId = request.getPathParam("scannerId")!!

mock/openapi/src/main/java/io/gatehill/imposter/plugin/openapi/OpenApiPluginImpl.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -193,12 +193,12 @@ class OpenApiPluginImpl @Inject constructor(
193193
private fun exposeSpec(router: HttpRouter) {
194194
LOGGER.debug("Adding specification UI at: {}{}", imposterConfig.serverUrl, specPathPrefix)
195195
router.get(combinedSpecPath).handler(
196-
handlerService.build(imposterConfig, configs, resourceMatcher) { httpExchange: HttpExchange ->
196+
handlerService.build(configs, resourceMatcher) { httpExchange: HttpExchange ->
197197
handleCombinedSpec(httpExchange)
198198
}
199199
)
200200
router.getWithRegex("$specPathPrefix$").handler(
201-
handlerService.buildAndWrap(imposterConfig, configs, resourceMatcher) { httpExchange: HttpExchange ->
201+
handlerService.buildAndWrap(configs, resourceMatcher) { httpExchange: HttpExchange ->
202202
httpExchange.response
203203
.putHeader("Location", "$specPathPrefix/")
204204
.setStatusCode(HttpUtil.HTTP_MOVED_PERM)
@@ -290,7 +290,7 @@ class OpenApiPluginImpl @Inject constructor(
290290
): HttpExchangeFutureHandler {
291291
// statically calculate as much as possible
292292
val statusCodeFactory = buildStatusCodeCalculator(operation)
293-
return handlerService.build(imposterConfig, pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
293+
return handlerService.build(pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
294294
LOGGER.trace("Operation ${operation.operationId} matched for request: ${describeRequestShort(httpExchange)}")
295295

296296
if (!specificationService.isValidRequest(pluginConfig, httpExchange, allSpecs)) {
@@ -313,7 +313,6 @@ class OpenApiPluginImpl @Inject constructor(
313313
}
314314

315315
exampleService.serveExample(
316-
imposterConfig,
317316
pluginConfig,
318317
httpExchange,
319318
responseBehaviour,

mock/openapi/src/main/java/io/gatehill/imposter/plugin/openapi/service/ExampleService.kt

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
*/
4343
package io.gatehill.imposter.plugin.openapi.service
4444

45-
import io.gatehill.imposter.ImposterConfig
4645
import io.gatehill.imposter.http.HttpExchange
4746
import io.gatehill.imposter.plugin.openapi.config.OpenApiPluginConfig
4847
import io.gatehill.imposter.script.ResponseBehaviour
@@ -56,7 +55,6 @@ interface ExampleService {
5655
/**
5756
* Attempt to respond with an example from the API specification.
5857
*
59-
* @param imposterConfig the Imposter engine configuration
6058
* @param config the plugin configuration
6159
* @param httpExchange the HTTP exchange
6260
* @param responseBehaviour the response behaviour
@@ -65,7 +63,6 @@ interface ExampleService {
6563
* @return `true` if an example was served, otherwise `false`
6664
*/
6765
fun serveExample(
68-
imposterConfig: ImposterConfig,
6966
config: OpenApiPluginConfig,
7067
httpExchange: HttpExchange,
7168
responseBehaviour: ResponseBehaviour,

mock/openapi/src/main/java/io/gatehill/imposter/plugin/openapi/service/ExampleServiceImpl.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,14 +69,14 @@ import javax.inject.Inject
6969
*/
7070
class ExampleServiceImpl @Inject constructor(
7171
private val schemaService: SchemaService,
72-
private val responseTransmissionService: ResponseTransmissionService
72+
private val responseTransmissionService: ResponseTransmissionService,
73+
private val imposterConfig: ImposterConfig,
7374
) : ExampleService {
7475

7576
/**
7677
* {@inheritDoc}
7778
*/
7879
override fun serveExample(
79-
imposterConfig: ImposterConfig,
8080
config: OpenApiPluginConfig,
8181
httpExchange: HttpExchange,
8282
responseBehaviour: ResponseBehaviour,

mock/rest/src/main/java/io/gatehill/imposter/plugin/rest/RestPluginImpl.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ open class RestPluginImpl @Inject constructor(
126126
LOGGER.debug("Adding handler: {} -> {}", method, normalisedPath)
127127

128128
router.route(method, normalisedPath).handler(
129-
handlerService.build(imposterConfig, pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
129+
handlerService.build(pluginConfig, resourceMatcher) { httpExchange: HttpExchange ->
130130
val resourceConfig = httpExchange.get<ContentTypedConfig>(ResourceUtil.RESOURCE_CONFIG_KEY)!!
131131

132132
responseRoutingService.route(pluginConfig, resourceConfig, httpExchange) { responseBehaviour ->

0 commit comments

Comments
 (0)