Example usage for javax.servlet.http HttpServletResponse setStatus

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

Introduction

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

Prototype

public void setStatus(int sc);

Source Link

Document

Sets the status code for this response.

Usage

From source file:net.mindengine.oculus.frontend.view.JsonView.java

@Override
protected void renderMergedOutputModel(Map model, HttpServletRequest request, HttpServletResponse response)
        throws Exception {
    ObjectMapper mapper = new ObjectMapper();
    mapper.writeValue(response.getOutputStream(), model.get("response"));
    response.setStatus(200);
}

From source file:org.smigo.message.MessageController.java

@RequestMapping(value = "/rest/message", produces = "application/json", method = RequestMethod.POST)
@ResponseBody//from  www .ja  v  a 2 s.co m
public int addMessage(@RequestBody MessageAdd message, @AuthenticationPrincipal AuthenticatedUser user,
        HttpServletResponse response, Locale locale) {
    mailHandler.sendAdminNotification("message added to forum", message);
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
        return 0;
    }
    return messageHandler.addMessage(message, user, locale);
}

From source file:com.skcraft.launcher.creator.server.PackagesHandler.java

public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {
    response.setContentType("text/plain; charset=utf-8");
    response.setStatus(HttpServletResponse.SC_OK);

    List<ManifestInfo> packages = Lists.newArrayList();
    PackageList packageList = new PackageList();
    packageList.setPackages(packages);//from  w ww.j a va  2 s.c o  m

    File[] files = baseDir.listFiles(new PackageFileFilter());
    if (files != null) {
        for (File file : files) {
            Manifest manifest = mapper.readValue(file, Manifest.class);
            ManifestInfo info = new ManifestInfo();
            info.setName(manifest.getName());
            info.setTitle(manifest.getTitle());
            info.setVersion(manifest.getVersion());
            info.setLocation(file.getName());
            packages.add(info);
        }
    }

    mapper.writeValue(response.getWriter(), packageList);
    baseRequest.setHandled(true);
}

From source file:alfio.controller.api.admin.UtilsApiController.java

@RequestMapping(value = "/short-name/validate", method = POST)
public boolean validateShortName(@RequestParam("shortName") String shortName, HttpServletResponse response) {
    boolean unique = eventNameManager.isUnique(shortName);
    if (!unique) {
        response.setStatus(HttpServletResponse.SC_CONFLICT);
    }/*from w w  w  .j  a  va2  s .  c o m*/
    return unique;
}

From source file:com.parleys.server.frontend.web.ipad.filters.LoginFilter.java

@Override
public void doFilter(final ServletRequest req, final ServletResponse response, final FilterChain chain)
        throws IOException {
    final HttpServletResponse res = (HttpServletResponse) response;
    final PrintWriter writer = res.getWriter();
    res.setStatus(HttpServletResponse.SC_OK);
    res.setHeader("Cache-Control", "must-revalidate");
    res.setHeader("Expires", "Fri, 30 Oct 1998 14:19:41 GMT");
    try {/*from   w w  w  .  ja v a 2s  . c  o  m*/
        final String username = req.getParameter("username");
        final String password = req.getParameter("password");
        if (StringUtils.isNotBlank(username) && StringUtils.isNotBlank(password)) {
            final ParleysService bean = applicationContext.getBean(ParleysService.class);
            final Long userId = bean.getUserId(username, password);

            final String usernameAndPassword = username + ";" + password;
            final String encrypted = AESEncrypter.INSTANCE.encrypt(usernameAndPassword);
            final Cookie rememberMeCookie = new Cookie(PARLEYS_REMEMBER_ME_IPAD, encrypted);
            rememberMeCookie.setMaxAge(3600 * 24 * 7 * 26); // A half year
            res.addCookie(rememberMeCookie);

            writeUserId(writer, userId);
        } else {
            writeError(writer);
        }
    } catch (Exception e) {
        writeError(writer);
    }
}

From source file:de.micromata.genome.tpsb.httpmockup.internaltest.TestServletOne.java

@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String data = req.getParameter("data");
    if (StringUtils.contains(data, "OK") == true) {
        resp.setStatus(200);
        resp.getWriter().println("Ja, Kammer ist auch OK");
    } else {/* w w  w  .j  a  v a 2s.  c o m*/
        resp.setStatus(500);
        resp.getWriter().println("Ojeoje");
    }
    resp.getWriter().flush();
}

From source file:de.onyxbits.raccoon.net.ResourceHandler.java

@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
        throws IOException, ServletException {

    response.setContentType("application/octet-stream");
    response.setStatus(HttpServletResponse.SC_OK);
    if (target.toLowerCase().endsWith("png")) {
        response.setContentType("image/png");
    }/*w ww  .  j  a v a 2s .co m*/
    if (target.toLowerCase().endsWith("css")) {
        response.setContentType("text/css");
    }

    // Prevent path traversal -> all resources must be in /web, no sub
    // directories.
    String tmp = target.substring(target.lastIndexOf('/'), target.length());

    InputStream in = getClass().getResourceAsStream("/web" + tmp);
    OutputStream out = response.getOutputStream();

    IOUtils.copy(in, out);
    in.close();
    out.flush();
    out.close();

    baseRequest.setHandled(true);
}

From source file:com.sentinel.rest.handlers.AuthFailureHandler.java

@Override
public void onAuthenticationFailure(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException exception) throws IOException, ServletException {
    LOG.trace("Method: onAuthenticationFailure called.");

    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.write(exception.getMessage());
    writer.flush();//  www.  j a  v a 2 s.  co  m
    LOG.trace("Method: onAuthenticationFailure finished.");
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST)
public void likeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse resp) {
    Video v = videos.findOne(id);//www  .  j av  a 2 s  . co m
    if (v == null) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {
        Set<String> likedUsernames = v.getLikedUsernames();
        String username = p.getName();
        if (likedUsernames.contains(username)) {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        } else {
            likedUsernames.add(username);
            v.setLikedUsernames(likedUsernames);
            v.setLikes(likedUsernames.size());
            videos.save(v);
        }
    }
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public void unlikeVideo(@PathVariable("id") long id, Principal p, HttpServletResponse resp) {
    Video v = videos.findOne(id);/*from w w  w.  java 2 s  .com*/
    if (v == null) {
        resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
    } else {
        Set<String> likedUsernames = v.getLikedUsernames();
        String username = p.getName();
        if (!likedUsernames.contains(username)) {
            resp.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        } else {
            likedUsernames.remove(username);
            v.setLikedUsernames(likedUsernames);
            v.setLikes(likedUsernames.size());
            videos.save(v);
        }
    }
}