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:gov.nist.appvet.tool.synchtest.util.ReportUtil.java

/**
 * This method returns report information to the AppVet ToolAdapter as ASCII
 * text and cannot attach a file to the response.
 *///ww  w  . ja v  a2 s .  c o m
public static boolean sendInHttpResponse(HttpServletResponse response, String reportText,
        ToolStatus reportStatus) {
    try {
        response.setStatus(HttpServletResponse.SC_OK); // HTTP 200
        response.setContentType("text/html");
        response.setHeader("apprisk", reportStatus.name());
        PrintWriter out = response.getWriter();
        out.println(reportText);
        out.flush();
        out.close();
        log.info("Returned report");
        return true;
    } catch (IOException e) {
        log.error("Report not sent: " + e.toString());
        return false;
    }
}

From source file:com.wadpam.guja.oauth2.web.Oauth2ClientAuthenticationFilter.java

private static void errorMessage(HttpServletResponse response, int responseCode, String errorMessage) {
    response.setStatus(responseCode);
    try {/*from w ww .j ava  2  s . c  o m*/
        response.getWriter().write(String.format("{\"error\":\"%s\"}", errorMessage));
        response.setContentType(APPLICATION_JSON_WITH_UTF8_CHARSET);
    } catch (IOException e) {
        LOGGER.error("Failed to write json body {}", e);
    }
}

From source file:com.berrysys.ussdgw.HttpUtils.java

/**
 * Queue full logic.//  w  ww.  j  a v a2  s .  c o  m
 *
 * @param resp the resp
 * @throws IOException Signals that an I/O exception has occurred.
 */
private static void queueFullLogic(HttpServletResponse resp) throws IOException {
    // TODO Auto-generated method stub
    String response = "Message Queue full";
    resp.setContentType("text/html");
    resp.setStatus(HttpServletResponse.SC_OK);
    resp.getWriter().println(response);

}

From source file:com.github.rnewson.couchdb.lucene.util.ServletUtils.java

public static void sendJsonError(final HttpServletRequest request, final HttpServletResponse response,
        final int code, final JSONObject error) throws IOException, JSONException {
    setResponseContentTypeAndEncoding(request, response);
    response.setHeader(HttpHeaders.CACHE_CONTROL, "must-revalidate,no-cache,no-store");
    response.setStatus(code);
    error.put("code", code);

    final Writer writer = response.getWriter();
    try {//from   w  w w.  j a  va 2s .  c om
        writer.write(error.toString());
        writer.write("\r\n");
    } finally {
        writer.close();
    }
}

From source file:com.cueup.hegemon.testing.server.HegemonTestServer.java

private static void markHandled(Request baseRequest, HttpServletResponse response, int status,
        String contentType) {//w w  w . ja v  a  2s  . c o  m
    response.setContentType(contentType + ";charset=utf-8");
    response.setStatus(status);
    baseRequest.setHandled(true);
}

From source file:org.ambraproject.wombat.controller.WombatController.java

protected static void forwardAssetResponse(CloseableHttpResponse remoteResponse,
        HttpServletResponse responseToClient, boolean isDownloadRequest) throws IOException {
    if (remoteResponse.getStatusLine().getStatusCode() == org.apache.http.HttpStatus.SC_NOT_MODIFIED) {
        responseToClient.setStatus(org.apache.http.HttpStatus.SC_NOT_MODIFIED);
    } else {/*from w  ww.j  a  va 2 s.  c om*/
        HttpMessageUtil.copyResponseWithHeaders(remoteResponse, responseToClient,
                getAssetResponseHeaderFilter(isDownloadRequest));
    }
}

From source file:com.dosport.system.utils.ServletUtils.java

/**
 * ??If-Modified-Since Header, ?./* w ww .  j av  a 2 s .c o  m*/
 * 
 * , checkIfModifyfalse ,304 not modify status.
 * 
 * @param lastModified
 *            ?.
 */
public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }
    return true;
}

From source file:com.handpay.ibenefit.framework.util.WebUtils.java

public static boolean checkIfModifiedSince(HttpServletRequest request, HttpServletResponse response,
        long lastModified) {
    long ifModifiedSince = request.getDateHeader("If-Modified-Since");
    if ((ifModifiedSince != -1) && (lastModified < ifModifiedSince + 1000)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return false;
    }//from w  ww .j a  va 2s . c  o  m
    return true;
}

From source file:com.eucalyptus.www.X509Download.java

public static void hasError(int statusCode, String message, HttpServletResponse response) {
    try {/*from  w w  w  .  j  a  v  a2 s.c  o  m*/
        response.setStatus(statusCode);
        response.setContentType("text/plain; charset=utf-8");
        response.getWriter().print(getError(message));
        response.getWriter().flush();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:io.mapzone.controller.vm.http.ProvisionErrorResponse.java

public static void send(HttpServletResponse response, int status, String msg) {
    try {//from   www . j a va  2 s.  com
        response.setContentType("text/html");
        OutputStreamWriter out = new OutputStreamWriter(response.getOutputStream(), Charset.forName("UTF-8"));
        out.write("<html>\n");
        out.write("<h1>" + msg + "</h1>\n");
        out.write("</html>");
        out.flush();
        response.setStatus(status);
    } catch (IOException e) {
        log.warn("", e);
    }
}