use of org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest in project carbon-identity-framework by wso2.
the class LongWaitStatusServlet method doPost.
@Override
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
if (FrameworkUtils.getMaxInactiveInterval() == 0) {
FrameworkUtils.setMaxInactiveInterval(request.getSession().getMaxInactiveInterval());
}
String id = request.getParameter(PROP_WAITING_ID);
if (id == null) {
if (request.getContentType() != null && request.getContentType().startsWith(FrameworkConstants.ContentTypes.TYPE_APPLICATION_JSON)) {
Gson gson = new Gson();
LongWaitStatusRequest longWaitStatusRequest = gson.fromJson(request.getReader(), LongWaitStatusRequest.class);
id = longWaitStatusRequest.getWaitId();
}
}
LongWaitStatusResponse longWaitResponse = new LongWaitStatusResponse();
longWaitResponse.setWaitId(id);
if (id == null) {
longWaitResponse.setStatus(LongWaitStatus.Status.UNKNOWN.name());
response.setStatus(HttpServletResponse.SC_NOT_FOUND);
} else {
LongWaitStatusStoreService longWaitStatusStoreService = FrameworkServiceDataHolder.getInstance().getLongWaitStatusStoreService();
if (longWaitStatusStoreService == null) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
} else {
LongWaitStatus longWaitStatus = null;
try {
longWaitStatus = longWaitStatusStoreService.getWait(id);
} catch (FrameworkException e) {
response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
}
if (longWaitStatus == null) {
longWaitResponse.setStatus(LongWaitStatus.Status.COMPLETED.name());
} else {
if (longWaitStatus.getStatus() != null) {
if (longWaitStatus.getStatus() == LongWaitStatus.Status.UNKNOWN) {
longWaitResponse.setStatus(LongWaitStatus.Status.COMPLETED.name());
} else {
longWaitResponse.setStatus(longWaitStatus.getStatus().name());
}
} else {
longWaitResponse.setStatus(LongWaitStatus.Status.COMPLETED.name());
}
}
}
}
response.setContentType(FrameworkConstants.ContentTypes.TYPE_APPLICATION_JSON);
String json = new Gson().toJson(longWaitResponse);
try (PrintWriter out = response.getWriter()) {
out.print(json);
out.flush();
}
}
Aggregations