Skip to content

Commit

Permalink
TRUNK-6198 Add a REST endpoint to check status of the platform
Browse files Browse the repository at this point in the history
  • Loading branch information
dkayiwa committed Oct 10, 2023
1 parent 298022c commit 37ffbe0
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 9 additions & 0 deletions web/src/main/java/org/openmrs/web/Listener.java
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,15 @@ public static boolean isSetupNeeded() {
return setupNeeded;
}

/**
* Boolean flag that tells if OpenMRS is started and ready to handle requests via REST.
*
* @return true if started, else false.
*/
public static boolean isOpenmrsStarted() {
return openmrsStarted;
}

/**
* Get the error thrown at startup
*
Expand Down
6 changes: 5 additions & 1 deletion web/src/main/java/org/openmrs/web/filter/StartupFilter.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@
import org.openmrs.logging.OpenmrsLoggingUtil;
import org.openmrs.util.LocaleUtility;
import org.openmrs.util.OpenmrsUtil;
import org.openmrs.web.Listener;
import org.openmrs.web.WebConstants;
import org.openmrs.web.filter.initialization.InitializationFilter;
import org.openmrs.web.filter.update.UpdateFilter;
Expand Down Expand Up @@ -107,7 +108,10 @@ public abstract class StartupFilter implements Filter {
@Override
public final void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
if (skipFilter((HttpServletRequest) request)) {
if (((HttpServletRequest)request).getServletPath().equals("/health/started")) {
((HttpServletResponse) response).setStatus(Listener.isOpenmrsStarted() ? HttpServletResponse.SC_OK : HttpServletResponse.SC_SERVICE_UNAVAILABLE);
}
else if (skipFilter((HttpServletRequest) request)) {
chain.doFilter(request, response);
} else {

Expand Down

0 comments on commit 37ffbe0

Please sign in to comment.