Search in sources :

Example 1 with LongWaitStatusRequest

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();
    }
}
Also used : LongWaitStatusResponse(org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusResponse) LongWaitStatusRequest(org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest) FrameworkException(org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException) LongWaitStatus(org.wso2.carbon.identity.application.authentication.framework.model.LongWaitStatus) LongWaitStatusStoreService(org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService) Gson(com.google.gson.Gson) PrintWriter(java.io.PrintWriter)

Aggregations

Gson (com.google.gson.Gson)1 PrintWriter (java.io.PrintWriter)1 FrameworkException (org.wso2.carbon.identity.application.authentication.framework.exception.FrameworkException)1 LongWaitStatusRequest (org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusRequest)1 LongWaitStatusResponse (org.wso2.carbon.identity.application.authentication.framework.javascript.flow.LongWaitStatusResponse)1 LongWaitStatus (org.wso2.carbon.identity.application.authentication.framework.model.LongWaitStatus)1 LongWaitStatusStoreService (org.wso2.carbon.identity.application.authentication.framework.store.LongWaitStatusStoreService)1