.getResponseMediaType(params, requestMediaType, acceptMediaType);
final HttpRequestAttributes httpAttributes = HttpRequestHelper.getHttpRequestAttributes(httpRequest,
requestBody, requestMediaType, responseMediaType);
// Create logger
final RequestLogger requestLogger = Factory.getRequestLogger();
requestLogger.setHttpRequestAttributes(httpAttributes);
// Authorize
if (!SecurityFactory.getAuthorizer().isAuthorized(new SecurityContextAdapter(securityContext),
requestType, resName)) {
Status status = Status.FORBIDDEN;
requestLogger.log(status.getStatusCode());
return Response.status(status).build();
}
try {
String responseBody = null;
if (sqlResource == null) {
sqlResource = Factory.getSqlResource(resName);
}
// Execute request
if (requestType.equals(Request.Type.SELECT)) {
final Request request = Factory.getRequest(httpAttributes, requestType, resName, resIds,
params, null, requestLogger);
responseBody = sqlResource.read(request, responseMediaType);
} else { // INSERT, UPDATE or DELETE
final WriteResponse writeResponse;
if (requestMediaType != null
&& !requestMediaType.equals(MediaType.APPLICATION_FORM_URLENCODED)
&& requestBody != null && requestBody.length() > 0) {
// requestBody is not null, use request processor
writeResponse = Factory.getRequestDeserializer(requestMediaType).execWrite(httpAttributes,
requestType, resIds, sqlResource, requestBody, requestLogger);
} else {
final Request request = Factory.getRequest(httpAttributes, requestType, resName, resIds,
params, null, requestLogger);
writeResponse = sqlResource.write(request);
}
responseBody = Factory.getResponseSerializer(responseMediaType).serializeWrite(sqlResource, writeResponse);
}
// Log response and send it
requestLogger.log(responseBody);
// Get cache control
String cacheControl = Config.properties.getProperty(Config.KEY_HTTP_CACHE_CONTROL,
Config.DEFAULT_HTTP_CACHE_CONTROL);