Example usage for javax.servlet.http HttpServletResponse SC_OK

List of usage examples for javax.servlet.http HttpServletResponse SC_OK

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_OK.

Prototype

int SC_OK

To view the source code for javax.servlet.http HttpServletResponse SC_OK.

Click Source Link

Document

Status code (200) indicating the request succeeded normally.

Usage

From source file:de.hska.ld.core.config.security.AjaxLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    ////www  . j  a  va  2s. c o  m
    // To delete a cookie, we need to create a cookie that has the same
    // name with the cookie that we want to delete. We also need to set
    // the max age of the cookie to 0 and then add it to the Servlet's
    // response method.
    //
    javax.servlet.http.Cookie cookie = new Cookie("sessionID", "");
    cookie.setPath("/");
    if (!"localhost".equals(env.getProperty("module.core.oidc.server.endpoint.main.domain"))) {
        cookie.setDomain(env.getProperty("module.core.oidc.server.endpoint.main.domain"));
    }
    cookie.setMaxAge(0);
    response.addCookie(cookie);

    // TODO destory session in etherpad

    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:com.cloud.servlet.StaticResourceServlet.java

@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
        throws ServletException, IOException {
    final File requestedFile = getRequestedFile(req);
    if (!requestedFile.exists() || !requestedFile.isFile()) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;//from   w w w . j  av  a2s. co m
    }
    final String etag = getEtag(requestedFile);
    if (etag.equals(req.getHeader("If-None-Match"))) {
        resp.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return;
    }
    // have to send data, either compressed or the original
    final File compressedStatic = getCompressedVersion(requestedFile);
    InputStream fileContent = null;
    try {
        resp.setContentType(getContentType(requestedFile.getName()));
        resp.setHeader("ETag", etag);
        resp.setStatus(HttpServletResponse.SC_OK);
        if (isClientCompressionSupported(req) && compressedStatic.exists()) {
            // gzip compressed
            resp.setHeader("Content-Encoding", "gzip");
            resp.setContentLength((int) compressedStatic.length());
            fileContent = new FileInputStream(compressedStatic);
        } else {
            // uncompressed
            resp.setContentLength((int) requestedFile.length());
            fileContent = new FileInputStream(requestedFile);
        }
        IOUtils.copy(fileContent, resp.getOutputStream());
    } finally {
        IOUtils.closeQuietly(fileContent);
    }
}

From source file:org.magnum.mobilecloud.video.VideoSvcCtrl.java

@PreAuthorize("hasRole(USER)")
@RequestMapping(method = RequestMethod.GET, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}")
public @ResponseBody Video getVideoById(@PathVariable("id") long id, HttpServletResponse response) {
    Video ret = videoRepo.findOne(id);//w ww .  j a v a  2 s.  c  o  m
    if (ret == null)
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    else
        response.setStatus(HttpServletResponse.SC_OK);

    return ret;
}

From source file:com.panet.imeta.www.GetJobStatusServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (!request.getContextPath().equals(CONTEXT_PATH))
        return;/* ww w . jav  a2  s. c om*/

    if (log.isDebug())
        log.logDebug(toString(), Messages.getString("GetJobStatusServlet.Log.JobStatusRequested"));

    String jobName = request.getParameter("name");
    boolean useXML = "Y".equalsIgnoreCase(request.getParameter("xml"));

    response.setStatus(HttpServletResponse.SC_OK);

    if (useXML) {
        response.setContentType("text/xml");
        response.setCharacterEncoding(Const.XML_ENCODING);
    } else {
        response.setContentType("text/html");
    }

    PrintWriter out = response.getWriter();

    Job job = jobMap.getJob(jobName);
    if (job != null) {
        String status = job.getStatus();

        if (useXML) {
            response.setContentType("text/xml");
            response.setCharacterEncoding(Const.XML_ENCODING);
            out.print(XMLHandler.getXMLHeader(Const.XML_ENCODING));

            SlaveServerJobStatus jobStatus = new SlaveServerJobStatus(jobName, status);

            Log4jStringAppender appender = (Log4jStringAppender) jobMap.getAppender(jobName);
            if (appender != null) {
                // The log can be quite large at times, we are going to put a base64 encoding around a compressed stream
                // of bytes to handle this one.

                ByteArrayOutputStream baos = new ByteArrayOutputStream();
                GZIPOutputStream gzos = new GZIPOutputStream(baos);
                gzos.write(appender.getBuffer().toString().getBytes());
                gzos.close();

                String loggingString = new String(Base64.encodeBase64(baos.toByteArray()));
                jobStatus.setLoggingString(loggingString);
            }

            // Also set the result object...
            //
            jobStatus.setResult(job.getResult()); // might be null

            out.println(jobStatus.getXML());
        } else {
            response.setContentType("text/html");

            out.println("<HTML>");
            out.println("<HEAD>");
            out.println("<TITLE>" + Messages.getString("GetJobStatusServlet.KettleJobStatus") + "</TITLE>");
            out.println("<META http-equiv=\"Refresh\" content=\"10;url=/kettle/jobStatus?name="
                    + URLEncoder.encode(jobName, "UTF-8") + "\">");
            out.println("</HEAD>");
            out.println("<BODY>");
            out.println("<H1>" + Messages.getString("GetJobStatusServlet.JobStatus") + "</H1>");

            try {
                out.println("<table border=\"1\">");
                out.print("<tr> <th>" + Messages.getString("GetJobStatusServlet.Jobname") + "</th> <th>"
                        + Messages.getString("TransStatusServlet.TransStatus") + "</th> </tr>");

                out.print("<tr>");
                out.print("<td>" + jobName + "</td>");
                out.print("<td>" + status + "</td>");
                out.print("</tr>");
                out.print("</table>");

                out.print("<p>");

                if (job.isFinished()) {
                    out.print("<a href=\"/kettle/startJob?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">"
                            + Messages.getString("GetJobStatusServlet.StartJob") + "</a>");
                    out.print("<p>");
                } else {
                    out.print("<a href=\"/kettle/stopJob?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">"
                            + Messages.getString("GetJobStatusServlet.StopJob") + "</a>");
                    out.print("<p>");
                }

                out.println("<p>");

                out.print("<a href=\"/kettle/jobStatus/?name=" + URLEncoder.encode(jobName, "UTF-8")
                        + "&xml=y\">" + Messages.getString("TransStatusServlet.ShowAsXml") + "</a><br>");
                out.print("<a href=\"/kettle/status\">"
                        + Messages.getString("TransStatusServlet.BackToStatusPage") + "</a><br>");
                out.print("<p><a href=\"/kettle/jobStatus?name=" + URLEncoder.encode(jobName, "UTF-8") + "\">"
                        + Messages.getString("TransStatusServlet.Refresh") + "</a>");

                // Put the logging below that.
                Log4jStringAppender appender = (Log4jStringAppender) jobMap.getAppender(jobName);
                if (appender != null) {
                    out.println("<p>");
                    /*
                    out.println("<pre>");
                    out.println(appender.getBuffer().toString());
                    out.println("</pre>");
                    */
                    out.println(
                            "<textarea id=\"joblog\" cols=\"120\" rows=\"20\" wrap=\"off\" name=\"Job log\" readonly=\"readonly\">"
                                    + appender.getBuffer().toString() + "</textarea>");

                    out.println("<script type=\"text/javascript\"> ");
                    out.println("  joblog.scrollTop=joblog.scrollHeight; ");
                    out.println("</script> ");
                    out.println("<p>");
                }
            } catch (Exception ex) {
                out.println("<p>");
                out.println("<pre>");
                ex.printStackTrace(out);
                out.println("</pre>");
            }

            out.println("<p>");
            out.println("</BODY>");
            out.println("</HTML>");
        }
    } else {
        if (useXML) {
            out.println(new WebResult(WebResult.STRING_ERROR,
                    Messages.getString("StartJobServlet.Log.SpecifiedJobNotFound", jobName)));
        } else {
            out.println("<H1>Job '" + jobName + "' could not be found.</H1>");
            out.println("<a href=\"/kettle/status\">"
                    + Messages.getString("TransStatusServlet.BackToStatusPage") + "</a><p>");
        }
    }
}

From source file:com.controller.email.GetEmailTagsServlet.java

/**
 * Processes requests for both HTTP <code>GET</code> and <code>POST</code>
 * methods.//  w  w  w.j a v  a  2 s  .  co m
 *
 * @param request servlet request
 * @param response servlet response
 * @throws ServletException if a servlet-specific error occurs
 * @throws IOException if an I/O error occurs
 */
protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    List<Map<String, Object>> tagsFromMandrill = MandrillApiHandler.getTags();
    List<Map<String, Object>> tagsFromMandrillForUser = new ArrayList<>();

    HttpSession session = request.getSession();
    if (session.getAttribute("UID") == null || StringUtils.isEmpty(session.getAttribute("UID").toString())) {
        Map<String, String> responseMap = new HashMap<>();
        responseMap.put("error", "user is not logged in");
        response.getWriter().write(new Gson().toJson(responseMap));
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return;
    }
    int userId = Integer.parseInt(session.getAttribute("UID").toString());
    Set<String> tagsForUser = EmailHistoryDAO.getTagsForUser(userId);
    for (Map<String, Object> mTag : tagsFromMandrill) {
        if (mTag.get("tag") != null) {
            if (tagsForUser.contains(mTag.get("tag").toString())) {
                tagsFromMandrillForUser.add(mTag);
            }
        }
    }
    response.getWriter().write(new Gson().toJson(tagsFromMandrillForUser));

    response.getWriter().flush();
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:org.obm.healthcheck.server.HealthCheckServletNoHandlersTest.java

@Test
public void testRootUrl() throws Exception {
    HttpResponse response = get("/");

    assertThat(response.getStatusLine().getStatusCode()).isEqualTo(HttpServletResponse.SC_OK);
    assertThat(JSON.parse(IO.toString(response.getEntity().getContent()))).isEqualTo(new Object[0]);
}

From source file:org.vbossica.springbox.metrics.MetricsController.java

@RequestMapping(value = "/metrics/metrics", method = RequestMethod.GET)
public void process(
        @RequestParam(value = "pretty", required = false, defaultValue = "true") boolean prettyPrint,
        HttpServletResponse resp) throws IOException {
    resp.setContentType("application/json");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);

    final OutputStream output = resp.getOutputStream();
    try {//from  w ww  .  j av a  2 s . c o  m
        (prettyPrint ? mapper.writerWithDefaultPrettyPrinter() : mapper.writer()).writeValue(output, registry);
    } finally {
        output.close();
    }
}

From source file:gr.cti.android.experimentation.controller.api.AndroidExperimentationWS.java

@ResponseBody
@RequestMapping(value = "/data", method = RequestMethod.POST, produces = "application/json", consumes = "text/plain")
public JSONObject data(@RequestBody String body, final HttpServletResponse response)
        throws JSONException, IOException {

    Result newResult = null;/*  www .ja va 2 s.  co  m*/
    try {
        newResult = extractResultFromBody(body);
    } catch (Exception e) {
        LOGGER.error(e, e);

    }
    if (newResult != null) {
        //store to sql
        try {
            sqlDbService.store(newResult);
        } catch (Exception e) {
            LOGGER.error(e, e);
        }

    }
    response.setStatus(HttpServletResponse.SC_OK);
    final JSONObject responseObject = new JSONObject();
    responseObject.put("status", "Ok");
    responseObject.put("code", 202);
    return responseObject;
}

From source file:com.ar.dev.tierra.api.config.security.CustomLogoutSuccessHandler.java

@Override
public void onLogoutSuccess(HttpServletRequest request, HttpServletResponse response,
        Authentication authentication) throws IOException, ServletException {

    String token = request.getHeader(HEADER_AUTHORIZATION);
    if (token != null && token.startsWith(BEARER_AUTHENTICATION)) {
        OAuth2AccessToken oAuth2AccessToken = tokenStore.readAccessToken(token.split(" ")[1]);
        if (oAuth2AccessToken != null) {
            Calendar cal = Calendar.getInstance();
            Date date = cal.getTime();
            Map<String, Object> map = oAuth2AccessToken.getAdditionalInformation();
            OAuth2Authentication auth = tokenStore.readAuthentication(oAuth2AccessToken);
            User user = (User) auth.getPrincipal();
            Usuarios u = usuariosDAO.findUsuarioByUsername(user.getUsername());
            u.setUltimaConexion(date);//from ww w. j ava2s .c o m
            usuariosDAO.updateUsuario(u);
            tokenStore.removeAccessToken(oAuth2AccessToken);
            response.setStatus(HttpServletResponse.SC_OK);
        } else {
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:otherpackage.MyConfigurerTests.java

@Test
public void customConfiguerPermitAll() throws Exception {
    loadContext(Config.class);

    request.setPathInfo("/public/something");

    springSecurityFilterChain.doFilter(request, response, chain);

    assertThat(response.getStatus()).isEqualTo(HttpServletResponse.SC_OK);
}