// ************************************************************************
// STEP #4) Get the Response (static,dynamic, or proxy).
// ************************************************************************
service.setHttpMethod(originalHttpReqFromClient.getMethod());
ResponseFromService response = service.execute(request, serviceUrl);
// ************************************************************************
// STEP #5) If twisting was enabled, let's be sure to set the original URL
// ************************************************************************
if (!originalHttpReqURI.equalsIgnoreCase(targetHttpReqURI)) {
response.setOriginalRequestUrlBeforeTwisting(new Url(originalHttpReqURI));
}
logRequestAsFulfilled(service, request, response, originalHttpReqFromClient.getRemoteAddr(), inspectionMessage);
try {
// Wait for a X hang time seconds.
logger.debug("Waiting..." + service.getHangTime() + " miliseconds ");
Thread.currentThread().sleep(service.getHangTime());
logger.debug("Done Waiting");
} catch (Exception e) {
// Catch interrupt exception.
// Or not.
}
if (!(service.getServiceResponseType() == Service.SERVICE_RESPONSE_TYPE_PROXY)) {
if (response.getHeaders() != null) {
for (Header h : response.getHeaders()) {
resp.setHeader(h.getName(), h.getValue());
}
}
try {
resp.setStatus(response.getHttpResponseStatusCode());
} catch (java.lang.IllegalArgumentException iae) {
logger.debug("Unable to set the response status to '" + response.getHttpResponseStatusCode() + "'", iae);
}
byte[] myCharSetBytes = response.getBody().getBytes();
new PrintStream(resp.getOutputStream()).write(myCharSetBytes);
resp.getOutputStream().flush();
} else {
// RULE_FOR_HEADERS
try {
resp.setStatus(response.getHttpResponseStatusCode());
} catch (java.lang.IllegalArgumentException iae) {
logger.debug("Unable to set the response status to '" + response.getHttpResponseStatusCode() + "'", iae);
}
response.writeToOutput(resp);
}
}