- Valid payload should be printed in the console from the method.
- Return corresponding http response code including vehicle id(something like UUID.randomUUID() would be enough) to the client as a part of location header
Path: /vehicle-api/v1/vehicles/vehicle
Content-Type: application/json
Request body:
{
"vin": "1A4AABBC5KD501999",
"year": 2019,
"make": "FCA",
"model": "RAM"
"transmissionType": "MANUAL",
}
- Implement validation for "transmissionType" from the task 2 "Create Vehicle" , MUST accept only "MANUAL" or "AUTO" in the request body.
- Invalid payload use case:
- Invalid payload MUST be thrown with a corresponding error code and error message in the response body
- Any other error MUST throw 500 "Internal Server Error" http response code with some info message in the response body
Logging Cross-cutting concern
We want to keep logging before and after method, however we don't want to put log statement in every method. As a example below are given two classes "DBServiceA" and "HttpServiceB" and the corresponding methods getData(int id) and sendMessage(String message)
Implement Java logging - cross-cutting concern solution for those two classes. Feel free to use any framework and libraries (however Spring preferably). You can create/modify existing
Please explain briefly what are the pros and cons for your solution?
public class DBServiceA {
public String getData(int id) {
log.debug(id);
/*
assume that some data has been retrieved from DB by id
*/
String resultData = "resultData";
log.debug(resultData);
return resultData;
}
}
public class HttpServiceB {
public String sendMessage(String message) {
log.debug(message);
/*
assume that some message sends via rest client and gets "httpResponse"
*/
String httpResponse = "httpResponse";
log.debug(httpResponse);
return httpResponse;
}
}
- Lombok is used as an annotation-processor to avoid boiler plate codes.
- Asynchronous REST API is implemented through
@EnableAsync
annotation-based configuration in java classDemoApplication
along withVehicleService
as a dummy service. - Valid payload is printed in the console using logger.
- Corresponding response code along with random UUID is returned as a part of location header. (UUID is included in location header, not in response body)
- Transmission type accepts only
MANUAL
orAUTO
. It is implemented throughjavax
constraint validator. Custom annotation@TransmissionType
is used for validatingtransmissionType
inVehicle
payload. - Invalid payload is validated as per
javax
validation and corresponding error code and message is thrown in response body. - Any other error is throw with error code
500
through controller.
slf4j
is used for logging.- With reference to the problem statement, logging is implemented in both
Controller
andService
layers. DBServiceA
is referenced asVehicleService
whereasHttpServiceB
is referenced asVehicleController
with logging kept before and after method.