use of com.clicklogs.model.ClickLogResponse in project aws-ingesting-click-logs-using-terraform by aws-samples.
the class ClickLoggerHandler method handleRequest.
@Override
public ClickLogResponse handleRequest(final ClickLogRequest clickLogRequest, final Context context) {
final LambdaLogger logger = context.getLogger();
final String success_response = new String("200 OK");
final String fail_response = new String("200 OK");
ResponseBuilder responseBuilder = new ResponseBuilder();
ClickLogResponse response = responseBuilder.badRequest(fail_response).build();
String req = clickLogRequest.getRequestid() + " - " + clickLogRequest.getCallerid() + " - " + clickLogRequest.getComponent() + " - " + clickLogRequest.getType() + " - " + clickLogRequest.getAction() + " - " + clickLogRequest.getUser() + " - " + clickLogRequest.getClientip() + " - " + clickLogRequest.getCreatedtime();
logger.log("Incoming request variables - " + req);
String env_stream_name = System.getenv("STREAM_NAME");
if (!StringUtils.isBlank(env_stream_name)) {
stream_name = env_stream_name;
}
// System.getenv("REGION");
String env_region = System.getenv("AWS_REGION");
logger.log("Environment region name - " + env_region);
if (!StringUtils.isBlank(env_region)) {
region = env_region;
}
if (clickLogRequest != null) {
logger.log("Validating inputs");
if (StringUtils.isBlank(clickLogRequest.getRequestid())) {
logger.log("error occurred - requestid missing");
return response;
}
if (StringUtils.isBlank(clickLogRequest.getContextid())) {
logger.log("error occurred - contextid missing");
return response;
}
if (StringUtils.isBlank(clickLogRequest.getCallerid())) {
logger.log("error occurred - caller missing");
return response;
}
if (StringUtils.isBlank(clickLogRequest.getType())) {
logger.log("error occurred - type missing");
return response;
}
if (StringUtils.isBlank(clickLogRequest.getAction())) {
logger.log("error occurred - action missing");
return response;
}
if (StringUtils.isBlank(clickLogRequest.getComponent())) {
logger.log("error occurred - component missing");
return response;
}
String user = "GUEST";
if (StringUtils.isBlank(clickLogRequest.getUser())) {
logger.log("setting default user");
clickLogRequest.setUser(user);
}
String clientip = "APIGWY";
if (StringUtils.isBlank(clickLogRequest.getClientip())) {
logger.log("setting default clientip");
clickLogRequest.setClientip(clientip);
}
String datetime = "";
if (StringUtils.isBlank(clickLogRequest.getCreatedtime())) {
logger.log("setting default createdtime");
Format f = new SimpleDateFormat("MM-dd-yyyy hh:mm:ss");
datetime = f.format(new Date());
clickLogRequest.setCreatedtime(datetime);
}
logger.log("Validated inputs");
}
System.out.println("Calling updateclicklogs method for the received clicklogrequest");
updateClickLogRequestToStream(clickLogRequest);
logger.log(success_response);
responseBuilder = new ResponseBuilder();
responseBuilder.ok();
response = responseBuilder.originHeader("*").build();
return response;
}
Aggregations