Close http exchange at the end of http handler
This commit is contained in:
parent
ab2b3f9481
commit
5a3af95f0b
2 changed files with 48 additions and 18 deletions
|
@ -1114,4 +1114,23 @@ class MockServerIntegrationTest extends Specification {
|
||||||
remoteMockServer.removeMock('testRest')?.size() == 0
|
remoteMockServer.removeMock('testRest')?.size() == 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def "should handle empty post"() {
|
||||||
|
expect:
|
||||||
|
remoteMockServer.addMock(new AddMock(
|
||||||
|
name: 'testRest',
|
||||||
|
path: 'testEndpoint',
|
||||||
|
port: 9999,
|
||||||
|
statusCode: 201,
|
||||||
|
soap: false
|
||||||
|
))
|
||||||
|
when:
|
||||||
|
HttpPost restPost = new HttpPost('http://localhost:9999/testEndpoint')
|
||||||
|
CloseableHttpResponse response = client.execute(restPost)
|
||||||
|
then:
|
||||||
|
response.statusLine.statusCode == 201
|
||||||
|
Util.consumeResponse(response)
|
||||||
|
expect:
|
||||||
|
remoteMockServer.removeMock('testRest')?.size() == 1
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -20,6 +20,18 @@ class ContextExecutor {
|
||||||
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
this.mocks = new CopyOnWriteArrayList<>([initialMock])
|
||||||
httpServerWraper.createContext(path) {
|
httpServerWraper.createContext(path) {
|
||||||
HttpExchange ex ->
|
HttpExchange ex ->
|
||||||
|
try {
|
||||||
|
applyMocks(ex)
|
||||||
|
} catch (Exception e) {
|
||||||
|
log.error("Exceptiony occured handling request", e)
|
||||||
|
throw e
|
||||||
|
} finally {
|
||||||
|
ex.close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void applyMocks(HttpExchange ex) {
|
||||||
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI)
|
MockRequest request = new MockRequest(ex.requestBody.text, ex.requestHeaders, ex.requestURI)
|
||||||
log.info('Mock received input')
|
log.info('Mock received input')
|
||||||
log.debug("Request: ${request.text}")
|
log.debug("Request: ${request.text}")
|
||||||
|
@ -40,7 +52,6 @@ class ContextExecutor {
|
||||||
log.warn("Any mock does not match request ${request.text}")
|
log.warn("Any mock does not match request ${request.text}")
|
||||||
Util.createResponse(ex, request.text, 404)
|
Util.createResponse(ex, request.text, 404)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
String getPath() {
|
String getPath() {
|
||||||
return path.substring(1)
|
return path.substring(1)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue