in wilma-application/modules/wilma-webapp/src/main/java/com/epam/wilma/webapp/config/servlet/service/ServiceServlet.java [57:98]
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
//first identify the requested service
String requestUri = req.getRequestURI();
logger.info("Service call to: {}, method: {}", requestUri, req.getMethod());
int positionOfLeadingText = requestUri.indexOf(LEADING_TEXT);
int requestedServicePosition = positionOfLeadingText + LEADING_TEXT.length();
String requestedService = positionOfLeadingText >= 0 ? requestUri.substring(requestedServicePosition) : "";
//set the default answer
resp.setContentType("application/json");
resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
String response = null;
//call the built-in service, as necessary - later should be part of the registered services !!!
if ("UniqueIdGenerator/uniqueId".equalsIgnoreCase(requestedService) && "get".equalsIgnoreCase(req.getMethod())) {
// get a new unique id
response = getUniqueId();
resp.setStatus(HttpServletResponse.SC_OK);
}
//call further registered services
if (response == null) {
response = serviceMap.callExternalService(req, requestedService, resp);
}
//if we still don't have the response, then either provide the service map, or send back that it is unknown request
if (response == null) {
if (requestedService.length() > 0) {
response = "{ \"unknownServiceCall\": \"" + req.getMethod() + " " + requestedService + "\" }";
} else {
//call the built-in listing service (service-map)
response = serviceMap.getMapAsResponse();
resp.setStatus(HttpServletResponse.SC_OK);
}
}
//write the answer back
PrintWriter out = resp.getWriter();
out.write(response);
out.flush();
out.close();
}