Exemplo n.º 1
0
  public WebApplicationException createRESTException(
      int responseCode, String logMessage, boolean logError) {
    Response errorResponse = Response.status(responseCode).build();

    WebApplicationException restException = new WebApplicationException(errorResponse);
    restException.fillInStackTrace();
    UserSessionBase userSession = ContextUtil.getCurrentUserSession();
    Long sessionId = null;
    String loginId = null;
    if (userSession != null) {
      loginId = userSession.getLoginId();
      sessionId = userSession.getSessionId();
    }

    if (logError) {
      logger.info(
          "Request failed. SessionId="
              + sessionId
              + ", loginId="
              + loginId
              + ", logMessage="
              + logMessage,
          restException);
    }

    return restException;
  }
Exemplo n.º 2
0
  public WebApplicationException createRESTException(VXResponse gjResponse) {
    Response errorResponse =
        Response.status(javax.servlet.http.HttpServletResponse.SC_BAD_REQUEST)
            .entity(gjResponse)
            .build();

    WebApplicationException restException = new WebApplicationException(errorResponse);
    restException.fillInStackTrace();
    UserSessionBase userSession = ContextUtil.getCurrentUserSession();
    Long sessionId = null;
    String loginId = null;
    if (userSession != null) {
      loginId = userSession.getLoginId();
      sessionId = userSession.getSessionId();
    }

    logger.info(
        "Request failed. SessionId="
            + sessionId
            + ", loginId="
            + loginId
            + ", logMessage="
            + gjResponse.getMsgDesc(),
        restException);

    return restException;
  }
Exemplo n.º 3
0
  /**
   * @param logMessage This is optional
   * @return
   */
  public WebApplicationException create403RESTException(String logMessage) {
    Response errorResponse =
        Response.status(javax.servlet.http.HttpServletResponse.SC_FORBIDDEN).build();

    WebApplicationException restException = new WebApplicationException(errorResponse);
    restException.fillInStackTrace();
    // TODO:Future:Open: Need to log all these and add user to
    // block list if this is deliberate
    // Get user information
    UserSessionBase userSession = ContextUtil.getCurrentUserSession();
    Long sessionId = null;
    String loginId = null;
    String sessionInfo = "";
    if (userSession != null) {
      loginId = userSession.getLoginId();
      sessionInfo = userSession.toString();
      sessionId = userSession.getSessionId();
    }

    String requestInfo = "";
    try {
      RequestContext reqContext = ContextUtil.getCurrentRequestContext();
      if (reqContext != null) {
        requestInfo = reqContext.toString();
        requestInfo += ", timeTaken=" + (System.currentTimeMillis() - reqContext.getStartTime());
      }
    } catch (Throwable contextEx) {
      logger.error("Error getting request info", contextEx);
    }

    logger.error(
        "Access restricted. SessionId="
            + sessionId
            + ", loginId="
            + loginId
            + ", logMessage="
            + logMessage
            + ", requestInfo="
            + requestInfo
            + ", sessionInfo="
            + sessionInfo,
        restException);

    return restException;
  }