public ClientResponse execute(ClientRequest clientRequest) throws Exception {
final InProcRequest testerRequest = new RestEasyClientInProcRequest(clientRequest);
final InProcResponse testerResponse = routeToTesterApplication(testerRequest.getUri()).getResponses(testerRequest);
BaseClientResponse<?> clientResponse = new BaseClientResponse(new BaseClientResponse.BaseClientResponseStreamFactory() {
InputStream stream;
public InputStream getInputStream() {
if (stream == null) {
stream = new SelfExpandingBufferredInputStream(new ByteArrayInputStream(testerResponse.getContentBytes()));
}
return stream;
}
public void performReleaseConnection() {
try {
stream.close();
} catch (Exception ignored) {
}
}
}, this);
clientResponse.setStatus(testerResponse.getStatus());
clientResponse.setHeaders(extractHeaders(testerResponse));
clientResponse.setProviderFactory(clientRequest.getProviderFactory());
return clientResponse;
}