Search in sources :

Example 31 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class TokenProcessor method resetToken.

/**
     * Reset the saved transaction token in the user's session.  This
     * indicates that transactional token checking will not be needed on the
     * next request that is submitted.
     *
     * @param request The servlet request we are processing
     */
public synchronized void resetToken(HttpServletRequest request) {
    HttpSession session = request.getSession(false);
    if (session == null) {
        return;
    }
    session.removeAttribute(Globals.TRANSACTION_TOKEN_KEY);
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 32 with HttpSession

use of javax.servlet.http.HttpSession in project sonarqube by SonarSource.

the class TokenProcessor method isTokenValid.

/**
     * Return <code>true</code> if there is a transaction token stored in the
     * user's current session, and the value submitted as a request parameter
     * with this action matches it.  Returns <code>false</code>
     *
     * <ul>
     *
     * <li>No session associated with this request</li> <li>No transaction
     * token saved in the session</li>
     *
     * <li>No transaction token included as a request parameter</li>
     *
     * <li>The included transaction token value does not match the transaction
     * token in the user's session</li>
     *
     * </ul>
     *
     * @param request The servlet request we are processing
     * @param reset   Should we reset the token after checking it?
     */
public synchronized boolean isTokenValid(HttpServletRequest request, boolean reset) {
    // Retrieve the current session for this request
    HttpSession session = request.getSession(false);
    if (session == null) {
        return false;
    }
    // Retrieve the transaction token from this session, and
    // reset it if requested
    String saved = (String) session.getAttribute(Globals.TRANSACTION_TOKEN_KEY);
    if (saved == null) {
        return false;
    }
    if (reset) {
        this.resetToken(request);
    }
    // Retrieve the transaction token included in this request
    String token = request.getParameter(Globals.TOKEN_KEY);
    if (token == null) {
        return false;
    }
    return saved.equals(token);
}
Also used : HttpSession(javax.servlet.http.HttpSession)

Example 33 with HttpSession

use of javax.servlet.http.HttpSession in project MSEC by Tencent.

the class DownloadDevGO method doStep2.

private JsonRPCResponseBase doStep2(DevPackage request) {
    JsonRPCResponseBase response = new JsonRPCResponseBase();
    Logger logger = Logger.getLogger(DownloadDevGO.class);
    HttpSession session = getHttpRequest().getSession();
    DevPackage plan = (DevPackage) session.getAttribute("DevPackage");
    if (plan == null) {
        plan = new DevPackage();
        session.setAttribute("DevPackage", plan);
    }
    //制作tar包,这里还是同步的在当前线程完成,必要的话可以用另外一个
    //线程异步的完成。
    logger.info("begin making dev package...");
    PackDevFile packDevFile = new PackDevFile(plan, getServlet().getServletContext());
    packDevFile.run();
    if (!packDevFile.getResultString().equals("success")) {
        response.setMessage(packDevFile.getResultString());
        response.setStatus(100);
        return response;
    }
    String fileName = packDevFile.getOutputFileName();
    logger.info("dev package path:" + fileName);
    File f = new File(fileName);
    String length = String.format("%d", f.length());
    //将文件内容直接返回,注意MIME 类型,且exec函数应该返回null
    getHttpResponse().setHeader("Content-disposition", "attachment;filename=" + new File(fileName).getName());
    // set the MIME type.
    getHttpResponse().setContentType("application/x-gzip-compressed");
    getHttpResponse().setHeader("Content_Length", length);
    try {
        ServletOutputStream out = getHttpResponse().getOutputStream();
        FileInputStream fileInputStream = new FileInputStream(f);
        byte[] buf = new byte[10240];
        while (true) {
            int len = fileInputStream.read(buf);
            if (len <= 0) {
                break;
            }
            out.write(buf, 0, len);
        }
        out.flush();
        out.close();
        fileInputStream.close();
        f.delete();
        return null;
    } catch (Exception e) {
        e.printStackTrace();
        return null;
    }
}
Also used : JsonRPCResponseBase(ngse.org.JsonRPCResponseBase) ServletOutputStream(javax.servlet.ServletOutputStream) HttpSession(javax.servlet.http.HttpSession) DevPackage(beans.request.DevPackage) Logger(org.apache.log4j.Logger) File(java.io.File) FileInputStream(java.io.FileInputStream) IOException(java.io.IOException)

Example 34 with HttpSession

use of javax.servlet.http.HttpSession in project MSEC by Tencent.

the class DownloadDevGO method doStep1.

private JsonRPCResponseBase doStep1(DevPackage request) {
    JsonRPCResponseBase response = new JsonRPCResponseBase();
    //把计划保存到session里
    HttpSession session = getHttpRequest().getSession();
    DBUtil util = new DBUtil();
    try {
        util.getConnection();
        String sql = "select dev_lang from t_second_level_service where first_level_service_name=? and second_level_service_name=?";
        ArrayList<Object> params = new ArrayList<Object>();
        params.add(request.getFirst_level_service_name());
        params.add(request.getSecond_level_service_name());
        Map<String, Object> map = util.findSimpleResult(sql, params);
        request.setDev_lang((String) map.get("dev_lang"));
    } catch (Exception e) {
        request.setDev_lang("c++");
    } finally {
        util.releaseConn();
    }
    session.setAttribute("DevPackage", request);
    response.setMessage("success");
    response.setStatus(0);
    return response;
}
Also used : DBUtil(ngse.org.DBUtil) JsonRPCResponseBase(ngse.org.JsonRPCResponseBase) HttpSession(javax.servlet.http.HttpSession) ArrayList(java.util.ArrayList) IOException(java.io.IOException)

Example 35 with HttpSession

use of javax.servlet.http.HttpSession in project MSEC by Tencent.

the class ReleaseOnlySharedobject method doRelease.

private ReleaseStepsGOResponse doRelease(ReleasePlan request) {
    ReleaseStepsGOResponse response = new ReleaseStepsGOResponse();
    //把计划保存到session里
    HttpSession session = getHttpRequest().getSession();
    ReleasePlan plan = (ReleasePlan) session.getAttribute("plan");
    if (plan == null) {
        response.setMessage("can NOT find the session, it maybe timeout.");
        response.setStatus(100);
        return response;
    }
    //System.out.println("plan id in session:"+plan.getPlan_id());
    if (request.getSharedobject_tag() == null || request.getSharedobject_tag().length() < 1) {
        response.setMessage("idl tag is empty!");
        response.setStatus(100);
        return response;
    }
    plan.setSharedobject_tag(request.getSharedobject_tag());
    plan.setMemo(request.getMemo());
    //check if saved
    ReleasePlan plan2 = (ReleasePlan) session.getAttribute("plan");
    //System.out.println("so tag:"+plan2.getSharedobject_tag());
    // Commit Plan
    String commitResult = CommitPlan(plan2);
    if (commitResult == null || !commitResult.equals("success")) {
        response.setMessage("commit failed:" + (commitResult == null ? "" : commitResult));
        response.setStatus(100);
        return response;
    }
    response.setPlanDetail(plan2);
    response.setMessage("success");
    response.setStatus(0);
    return response;
}
Also used : HttpSession(javax.servlet.http.HttpSession) ReleaseStepsGOResponse(beans.response.ReleaseStepsGOResponse) ReleasePlan(beans.request.ReleasePlan)

Aggregations

HttpSession (javax.servlet.http.HttpSession)730 HttpServletRequest (javax.servlet.http.HttpServletRequest)151 Test (org.junit.Test)110 IOException (java.io.IOException)80 HttpServletResponse (javax.servlet.http.HttpServletResponse)80 ServletException (javax.servlet.ServletException)75 ArrayList (java.util.ArrayList)65 RequestDispatcher (javax.servlet.RequestDispatcher)59 HashMap (java.util.HashMap)48 Map (java.util.Map)44 Locale (java.util.Locale)39 Properties (java.util.Properties)39 PrintWriter (java.io.PrintWriter)38 Cookie (javax.servlet.http.Cookie)27 List (java.util.List)24 SQLException (java.sql.SQLException)23 WebUser (org.compiere.util.WebUser)23 FlakyTest (org.apache.geode.test.junit.categories.FlakyTest)20 IntegrationTest (org.apache.geode.test.junit.categories.IntegrationTest)20 ModelAndView (org.springframework.web.servlet.ModelAndView)20