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:cz.cas.lib.proarc.authentication.utils.AuthUtils.java

/**
 * Writes the authentication required status to the HTTP response.
 * @param response response//  w  w w . jav a2  s  .  c  o  m
 * @throws IOException failure
 * @see #HEADER_AUTHENTICATE_TYPE
 * @see <a href='http://www.smartclient.com/smartgwt/javadoc/com/smartgwt/client/docs/Relogin.html'>SmartGWT Relogin</a>
 */
public static void setLoginRequiredResponse(HttpServletResponse response) throws IOException {
    response.setHeader(HEADER_AUTHENTICATE_TYPE, Authenticators.getInstance().getLoginType());
    response.setStatus(HttpServletResponse.SC_FORBIDDEN);
    response.setContentType(MediaType.TEXT_HTML);
    InputStream res = ProarcAuthFilter.class.getResourceAsStream("loginRequiredMarker.html");
    try {
        IOUtils.copy(res, response.getOutputStream());
        res.close();
    } finally {
        IOUtils.closeQuietly(res);
    }
}

From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java

/**
 * respond with given status code//w  ww.j a  v  a  2  s. co  m
 *
 * @param message
 * @param status
 * @param response
 * @throws IOException
 */
private static void error(String message, int status, HttpServletResponse response) throws IOException {
    response.setStatus(status);
    response.setContentType("application/json");
    response.getWriter().println("{ \"error\" : \"" + message + "\", " + "\"status\" : " + status + "}");
}

From source file:org.ambraproject.wombat.util.ReproxyUtil.java

/**
 * Apply reproxying information for a requested asset to a response.
 * <p/>/*  w w  w  . j  a  va 2  s. c o m*/
 * The request may not support the reproxying protocol, and there may not be any reproxy URLs for the asset. In either
 * case, the response is not touched. The return value indicates this.
 * <p/>
 * Note that both {@code request} and {@code response} are for the client. Neither is for the service that reproxies
 * the asset. It is assumed that the caller has already queried the service that reproxies the asset, which provides
 * the {@code reproxyUrls} argument.
 *
 * @param request     a request from the client
 * @param response    a response to the client
 * @param reproxyUrls a list of available reproxy URLs for the requested asset (empty and {@code null} are allowed,
 *                    indicating none are available)
 * @param cacheFor    number of seconds to instruct the client to cache the reproxy information
 * @return {@code true} if the response was filled with reproxy information, in which case nothing should be written
 * to the response body; {@code false} if not, in which case the response body should be written
 */
public static boolean applyReproxy(HttpServletRequest request, HttpServletResponse response,
        List<String> reproxyUrls, int cacheFor) {
    if (reproxyUrls != null && !reproxyUrls.isEmpty() && supportsReproxy(request)) {
        response.setStatus(HttpStatus.SC_OK);
        response.setHeader(X_REPROXY_URL, REPROXY_URL_JOINER.join(reproxyUrls));
        response.setHeader(X_REPROXY_CACHE_FOR, cacheFor + "; Last-Modified Content-Type Content-Disposition");
        return true;
    }
    return false;
}

From source file:cc.kune.core.server.manager.file.FileDownloadManagerUtils.java

/**
 * Return not found404.//from w ww . jav  a  2s  .c o m
 * 
 * @param resp
 *          the resp
 * @throws IOException
 *           Signals that an I/O exception has occurred.
 */
public static void returnNotFound404(final HttpServletResponse resp) throws IOException {
    resp.getWriter().println("Content not found");
    resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:org.eclipse.jgit.lfs.server.fs.FileLfsServlet.java

/**
 * Send an error response./*  w ww  .  j ava2s . c  o m*/
 *
 * @param rsp
 *            the servlet response
 * @param status
 *            HTTP status code
 * @param message
 *            error message
 * @throws IOException
 *             on failure to send the response
 * @since 4.6
 */
protected static void sendError(HttpServletResponse rsp, int status, String message) throws IOException {
    rsp.setStatus(status);
    PrintWriter writer = rsp.getWriter();
    gson.toJson(new Error(message), writer);
    writer.flush();
    writer.close();
    rsp.flushBuffer();
}

From source file:gov.nist.appvet.tool.sigverifier.util.ReportUtil.java

/**
 * This method returns report information to the AppVet ToolAdapter as ASCII
 * text and cannot attach a file to the response.
 *///www.  ja  v  a 2s .  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("toolrisk", reportStatus.name());
        PrintWriter out = response.getWriter();
        out.println(reportText);
        out.flush();
        out.close();
        log.debug("Returned report");
        return true;
    } catch (IOException e) {
        log.error(e.toString());
        return false;
    }
}

From source file:de.xwic.appkit.webbase.modules.ModuleProviderServlet.java

/**
 * 200 and send content/* w w  w.  j  a v a 2  s.  c o  m*/
 *
 * @param content
 * @param response
 * @throws IOException
 * @throws JSONException
 */
private static void ok(JSONObject content, HttpServletResponse response) throws IOException, JSONException {
    response.setStatus(HttpServletResponse.SC_OK);
    response.setContentType("application/json");
    response.getWriter().println(content.toString(2));
}

From source file:com.meltmedia.cadmium.servlets.ErrorPageFilterSelectionTest.java

/**
 * Creates a filter chain that sends a 200 response.
 * //from  ww w .  java2  s  .c om
 * @param content the content to write to the res object.
 * @return a filter chain that simulates a 200 response.
 */
public static FilterChain successFilterChain(final String content) {
    return new FilterChain() {
        @Override
        public void doFilter(ServletRequest req, ServletResponse res) throws IOException, ServletException {
            HttpServletResponse httpRes = (HttpServletResponse) res;
            httpRes.setStatus(200);
            OutputStream out = null;
            InputStream in = null;
            try {
                out = res.getOutputStream();
                in = new ByteArrayInputStream(content.getBytes());
                IOUtils.copy(in, out);
            } finally {
                IOUtils.closeQuietly(out);
                IOUtils.closeQuietly(in);
            }
        }
    };
}

From source file:org.jasig.cas.support.oauth.OAuthUtils.java

/**
 * Write to the output the text and return a null view.
 *
 * @param response http response// w w  w  .j a  v a 2 s  .co m
 * @param text output text
 * @param status status code
 * @return a null view
 */
public static ModelAndView writeText(final HttpServletResponse response, final String text, final int status) {
    try (PrintWriter printWriter = response.getWriter()) {
        response.setStatus(status);
        printWriter.print(text);
    } catch (final IOException e) {
        LOGGER.error("Failed to write to response", e);
    }
    return null;
}

From source file:net.sourceforge.vulcan.web.JstlFunctions.java

public static void setStatus(HttpServletResponse response, int code) {
    response.setStatus(code);
}