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:hr.diskobolos.controller.MembershipCategoryController.java

/**
 * REST service responsible for deletion of the membership category data
 *
 * @param membershipCategory//from ww  w  .j a v a2  s  .  c  o  m
 * @param request
 * @param response
 * @return
 * @throws JSONException
 */
@RequestMapping(value = "/delete", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String deleteSportData(@RequestBody MembershipCategory membershipCategory, HttpServletRequest request,
        HttpServletResponse response) throws JSONException {
    try {
        membershipCategoryService.delete(membershipCategory);
        response.setStatus(HttpServletResponse.SC_OK);
        return new JSONObject().put("result", 200).toString();
    } catch (Exception e) {
        return ErrorHandlerUtils.handleAjaxError(request, response);
    }
}

From source file:io.lavagna.web.helper.GeneralHandlerExceptionResolver.java

private void handleException(Exception ex, HttpServletResponse response) {
    for (Entry<Class<? extends Throwable>, Integer> entry : statusCodeResolver.entrySet()) {
        if (ex.getClass().equals(entry.getKey())) {
            response.setStatus(entry.getValue());
            LOG.info("Class: {} - Message: {} - Cause: {}", ex.getClass(), ex.getMessage(), ex.getCause());
            LOG.info("Cnt", ex);
            return;
        }//ww w .j av  a  2s  . c  o m
    }
    /**
     * Non managed exceptions flow Set HTTP status 500 and log the exception with a production visible level
     */
    response.setStatus(HttpStatus.INTERNAL_SERVER_ERROR.value());
    LOG.warn(ex.getMessage(), ex);
}

From source file:com.indoqa.httpproxy.HttpClientProxy.java

private void writeResponseStatus(HttpServletResponse response, HttpResponse proxyResponse) {
    response.setStatus(proxyResponse.getStatusLine().getStatusCode());
}

From source file:com.rest4j.impl.ApiResponseImpl.java

@Override
public void outputBody(HttpServletResponse response) throws IOException {
    if (statusMessage == null)
        response.setStatus(status);
    else/*  w ww . j a va2s .  co  m*/
        response.setStatus(status, statusMessage);
    headers.outputHeaders(response);
    if (this.response == null)
        return;
    response.addHeader("Content-type", this.response.getContentType());
    if (addEtag) {
        String etag = this.response.getETag();
        if (etag != null)
            response.addHeader("ETag", etag);
    }

    OutputStream outputStream;
    byte[] resourceBytes = ((JSONResource) this.response).getJSONObject().toString().getBytes();
    int contentLength = resourceBytes.length;
    if (compress) {
        response.addHeader("Content-encoding", "gzip");
        ByteArrayOutputStream outputByteStream = new ByteArrayOutputStream();
        GZIPOutputStream gzipOutputStream = new GZIPOutputStream(outputByteStream);
        gzipOutputStream.write(resourceBytes);
        gzipOutputStream.finish(); //     ??!
        contentLength = outputByteStream.toByteArray().length;
        gzipOutputStream.close();
        outputByteStream.close();

        outputStream = new GZIPOutputStream(response.getOutputStream());
    } else {
        outputStream = response.getOutputStream();
    }
    response.addHeader("Content-Length", String.valueOf(contentLength));

    if (this.response instanceof JSONResource) {
        ((JSONResource) this.response).setPrettify(prettify);
    }
    if (callbackFunctionName == null) {
        this.response.write(outputStream);
    } else {
        this.response.writeJSONP(outputStream, callbackFunctionName);
    }
    outputStream.close();
}

From source file:it.smartcommunitylab.aac.controller.BasicProfileController.java

@ApiOperation(value = "Get basic profile of a current user")
@RequestMapping(method = RequestMethod.GET, value = "/basicprofile/me")
public @ResponseBody BasicProfile findProfile(HttpServletResponse response) throws IOException {
    Long user = userManager.getUserId();
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
    }// w w w .j av a 2 s .co  m
    return profileManager.getBasicProfileById(user.toString());
}

From source file:it.smartcommunitylab.aac.controller.BasicProfileController.java

@ApiOperation(value = "Get account data of a current user")
@RequestMapping(method = RequestMethod.GET, value = "/accountprofile/me")
public @ResponseBody AccountProfile findAccountProfile(HttpServletResponse response) throws IOException {
    Long user = userManager.getUserId();
    if (user == null) {
        response.setStatus(HttpServletResponse.SC_FORBIDDEN);
        return null;
    }/*  w ww .  ja  va  2  s  .  c  o m*/
    return profileManager.getAccountProfileById(user.toString());
}

From source file:com.ebay.pulsar.metric.servlet.MetricRestServlet.java

private void ping(HttpServletRequest request, String pathInfo, HttpServletResponse response) {
    response.setStatus(HttpServletResponse.SC_OK);
}

From source file:hr.diskobolos.controller.MembershipCategoryController.java

/**
 * REST service responsible for editing membership category data
 *
 * @param membershipCategory/*from  w w  w. j a v a2  s .  com*/
 * @param request
 * @param response
 * @return
 * @throws JSONException
 */
@RequestMapping(value = "/edit", method = RequestMethod.POST)
@ResponseBody
@PreAuthorize("hasAnyRole('ROLE_USER','ROLE_ADMIN')")
public String editMembershipCategorysData(@RequestBody MembershipCategory membershipCategory,
        HttpServletRequest request, HttpServletResponse response) throws JSONException {
    try {
        membershipCategoryService.update(membershipCategory);
        response.setStatus(HttpServletResponse.SC_OK);
        return new JSONObject().put("result", 200).toString();
    } catch (Exception e) {
        logger.error("Error during editing membership category data: ", e.getMessage());
        return ErrorHandlerUtils.handleAjaxError(request, response);
    }
}

From source file:ch.algotrader.rest.LookupRestController.java

@ExceptionHandler()
public InternalErrorVO handleLuceneParseException(final HttpServletResponse response, final ParseException ex) {

    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    return new InternalErrorVO(ex.getClass(), ex.getMessage());
}