Skip to content

Commit

Permalink
MOSIP-35176 Added health check (#1577)
Browse files Browse the repository at this point in the history
* MOSIP-35176 Added health check

Signed-off-by: kameshsr <kameshsr1338@gmail.com>

* MOSIP-35176 Added negation

Signed-off-by: kameshsr <kameshsr1338@gmail.com>

---------

Signed-off-by: kameshsr <kameshsr1338@gmail.com>
  • Loading branch information
kameshsr authored Oct 1, 2024
1 parent faee00d commit 6b57f32
Showing 1 changed file with 36 additions and 34 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,46 +51,48 @@ protected void doFilterInternal(HttpServletRequest request, HttpServletResponse
throws ServletException, IOException {
logger.info("inside doFilterInternal");
logger.info("HttpServletRequest request- "+request);
String topic=matchCallbackURL(request.getRequestURI());
if (request.getMethod().equals(HttpMethod.GET.name()) && topic!=null) {
String topicReq = request.getParameter(WebSubClientConstants.HUB_TOPIC);
String modeReq = request.getParameter(WebSubClientConstants.HUB_MODE);
String mode = request.getParameter("intentMode");
if(modeReq.equals("denied")) {
String reason = request.getParameter("hub.reason");
reason = reason.replaceAll("[\n\r\t]", " - ");
LOGGER.error("intent verification failed : {}",reason);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().flush();
response.getWriter().close();
}
if (intentVerifier.isIntentVerified(topic,
mode, topicReq, modeReq)) {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
try {
String challange =request.getParameter(WebSubClientConstants.HUB_CHALLENGE);
String encodedChallange = Encode.forHtml(challange);
response.getWriter().write(encodedChallange);
if(!request.getRequestURI().contains("health")) {
String topic = matchCallbackURL(request.getRequestURI());
if (request.getMethod().equals(HttpMethod.GET.name()) && topic != null) {
String topicReq = request.getParameter(WebSubClientConstants.HUB_TOPIC);
String modeReq = request.getParameter(WebSubClientConstants.HUB_MODE);
String mode = request.getParameter("intentMode");
if (modeReq.equals("denied")) {
String reason = request.getParameter("hub.reason");
reason = reason.replaceAll("[\n\r\t]", " - ");
LOGGER.error("intent verification failed : {}", reason);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().flush();
response.getWriter().close();
}
if (intentVerifier.isIntentVerified(topic,
mode, topicReq, modeReq)) {
response.setStatus(HttpServletResponse.SC_ACCEPTED);
try {
String challange = request.getParameter(WebSubClientConstants.HUB_CHALLENGE);
String encodedChallange = Encode.forHtml(challange);
response.getWriter().write(encodedChallange);
response.getWriter().flush();
response.getWriter().close();
} catch (IOException exception) {
LOGGER.error("error received while writing challange back" + exception.getMessage());
throw new WebSubClientException(WebSubClientErrorCode.IO_ERROR.getErrorCode(),
WebSubClientErrorCode.IO_ERROR.getErrorMessage().concat(exception.getMessage()));
}

} else {
topicReq = topicReq.replaceAll("[\n\r\t]", " - ");
modeReq = modeReq.replaceAll("[\n\r\t]", " - ");
mode = mode.replaceAll("[\n\r\t]", " - ");
LOGGER.error("intent verification failed: {} {} {} {}", topic, mode, topicReq, modeReq);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().flush();
response.getWriter().close();
} catch (IOException exception) {
LOGGER.error("error received while writing challange back"+exception.getMessage());
throw new WebSubClientException(WebSubClientErrorCode.IO_ERROR.getErrorCode(),
WebSubClientErrorCode.IO_ERROR.getErrorMessage().concat(exception.getMessage()));
}

} else {
topicReq = topicReq.replaceAll("[\n\r\t]", " - ");
modeReq = modeReq.replaceAll("[\n\r\t]", " - ");
mode = mode.replaceAll("[\n\r\t]", " - ");
LOGGER.error("intent verification failed: {} {} {} {}",topic,mode,topicReq,modeReq);
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
response.getWriter().flush();
response.getWriter().close();
filterChain.doFilter(request, response);
}

} else {
filterChain.doFilter(request, response);
}
}

Expand Down

0 comments on commit 6b57f32

Please sign in to comment.