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:org.magnum.mobilecloud.video.VideoController.java

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/likedby", method = RequestMethod.GET)
public @ResponseBody Collection<String> getUsersWhoLikedVideo(@PathVariable long id,
        HttpServletResponse response) {
    Video v = _videoRepository.findOne(id);
    if (v == null) {
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        return new ArrayList<String>();
    }//w ww .  ja  v a  2s.c om
    return v.getUsersWhoLiked();
}

From source file:com.jamespot.glifpix.wrappers.SampleHtmlTestService.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    response.setContentType("text/html;charset=UTF-8");
    response.setStatus(HttpServletResponse.SC_OK);
    PrintWriter out = response.getWriter();

    SampleTagsServiceHandler tsh = new SampleTagsServiceHandler();

    out.println("<h1>HtmlTestService</h1>");
    out.println("<table>");
    String[] tags = tsh.getTags(request.getParameter("text"), request.getParameter("lng"),
            Integer.parseInt(request.getParameter("nbTags")));

    if (tags != null && tags.length > 0) {
        for (int i = 0; i < tags.length; i++) {
            out.println("<tr><td>" + tags[i] + "</td></tr>");
        }/*w  ww  .j a  v a 2s. c om*/

    }
    out.println("</table>");

    out.println("<p><a href='/html/form'>Back</a></p>");
}

From source file:com.tc.admin.UpdateCheckRequestTest.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    response.setContentType("text/html");
    response.setStatus(HttpServletResponse.SC_OK);

    String[] expectedParams = { "kitID", "pageID", "id", "os-name", "jvm-name", "jvm-version", "platform",
            "tc-version", "tc-product", "source" };
    Map paramMap = request.getParameterMap();
    for (String expectedParam : expectedParams) {
        if (paramMap.get(expectedParam) == null) {
            response.getWriter().println("Missing parameter '" + expectedParam + "'");
            return;
        }//from  w  w w.j  a va  2  s.co  m
    }
    if (paramMap.size() != expectedParams.length) {
        response.getWriter()
                .println("Parameter count doesn't match expected count='" + expectedParams.length + "'");
        return;
    }
    response.getWriter().println("OK");
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/unlike", method = RequestMethod.POST)
public void unlikeVideo(@PathVariable long id, Principal principal, HttpServletResponse response) {
    Video v = _videoRepository.findOne(id);
    if (v == null) {
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        return;// w ww .  j a  v  a  2 s  .c  om
    }
    String username = principal.getName();
    v.unlike(username);
    _videoRepository.save(v);
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/like", method = RequestMethod.POST)
public void likeVideo(@PathVariable long id, Principal principal, HttpServletResponse response) {
    Video v = _videoRepository.findOne(id);
    if (v == null) {
        response.setStatus(HttpStatus.SC_NOT_FOUND);
        return;//  w  w w. j a v  a2s.  c  om
    }
    String username = principal.getName();
    if (!v.like(username))
        response.setStatus(HttpStatus.SC_BAD_REQUEST);
    _videoRepository.save(v);
}

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

@RequestMapping(value = "/metrics/threaddump", method = RequestMethod.GET)
protected void doGet(HttpServletResponse resp) throws ServletException, IOException {
    resp.setContentType("text/plain");
    resp.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
    resp.setStatus(HttpServletResponse.SC_OK);
    OutputStream output = resp.getOutputStream();
    try {// w w  w.  j a  va 2 s.co  m
        threadDump.dump(output);
    } finally {
        output.close();
    }
}

From source file:com.pearson.developer.xapi.proxy.AuthFilter.java

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws java.io.IOException, ServletException {

    HttpServletRequest req = (HttpServletRequest) request;

    // AJAX will preflight xAPI request with OPTIONS request without Authorization header
    if ("OPTIONS".equals(req.getMethod())) {
        chain.doFilter(request, response);
        return;//from   w ww.  j av  a  2s  . c  o m
    }

    boolean authorized = false;
    try { // decode and verify the basic auth credentials
        String authHeader = req.getHeader("Authorization");
        authHeader = authHeader.substring("Basic ".length());
        String decodedAuthHeader = new String(Base64.decodeBase64(authHeader), "UTF-8");
        String[] credentials = decodedAuthHeader.split(":");
        if (credentials.length == 2) {
            String username = credentials[0];
            String password = credentials[1];
            authorized = SessionDatabase.verify(username, password);
        }
    } catch (Exception e) {
        // do nothing
    }

    // proceed to xAPI if session was authorized
    if (authorized) {
        final String targetBasicAuth = config.getInitParameter("targetBasicAuth");

        // need to give the LRS it's expected Authorization value
        HttpServletRequestWrapper requestWrapper = new HttpServletRequestWrapper(req) {
            @Override
            public String getHeader(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    return targetBasicAuth;
                }
                return super.getHeader(name);
            }

            @Override
            public Enumeration<String> getHeaders(String name) {
                if ("Authorization".equalsIgnoreCase(name)) {
                    List<String> values = new ArrayList<String>();
                    values.add(targetBasicAuth);
                    return Collections.enumeration(values);
                }
                return super.getHeaders(name);
            }
        };
        chain.doFilter(requestWrapper, response);
        return;
    }

    // respond with a 401 if missing auth
    HttpServletResponse resp = (HttpServletResponse) response;
    resp.reset();
    resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    resp.getWriter().println("401 - Unauthorized");
}

From source file:org.smigo.species.vernacular.VernacularController.java

@PreAuthorize("isAuthenticated()")
@RequestMapping(value = "/rest/vernacular", method = RequestMethod.POST)
@ResponseBody/*  w  w w  .  j av  a2 s. co m*/
public Object addVernacular(@Valid @RequestBody Vernacular vernacular, BindingResult result,
        @AuthenticationPrincipal AuthenticatedUser user, Locale locale, HttpServletResponse response) {
    log.info("Adding vernacular:" + vernacular);
    if (result.hasErrors()) {
        response.setStatus(HttpStatus.UNPROCESSABLE_ENTITY.value());
        return result.getAllErrors();
    }
    CrudResult review = vernacularHandler.addVernacular(vernacular, user, locale);
    if (review.getReview() == Review.MODERATOR) {
        response.setStatus(HttpStatus.ACCEPTED.value());
    }
    return review.getId();
}

From source file:ro.allevo.fintpws.security.CustomAccessDeniedHandler.java

@Produces(MediaType.APPLICATION_JSON)
@Override//from  w  w w  .j  a  v  a 2  s .c o m
public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException exception)
        throws IOException, ServletException {

    response.setContentType("application/json");
    response.setStatus(403);
    try {
        JSONObject obj = JsonResponseWrapper.getEntity(Status.FORBIDDEN.getStatusCode(), ERROR_FORBIDDEN, null,
                null);
        PrintWriter out = response.getWriter();
        out.print(obj);
    } catch (JSONException e) {
        e.printStackTrace();
    }
}

From source file:com.ebay.pulsar.analytics.security.spring.PlainTextBasicAuthenticationEntryPoint.java

@Override
public void commence(HttpServletRequest request, HttpServletResponse response,
        AuthenticationException authException) throws IOException, ServletException {
    response.addHeader("WWW-Authenticate", "Basic realm=\"" + getRealmName() + "\"");
    response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    PrintWriter writer = response.getWriter();
    writer.println("HTTP Status " + HttpServletResponse.SC_UNAUTHORIZED + " - " + authException.getMessage());

}