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:uk.ac.ebi.eva.server.ws.FeatureWSServer.java

@RequestMapping(value = "/{featureIdOrName}", method = RequestMethod.GET)
public QueryResponse getFeatureByIdOrName(@PathVariable("featureIdOrName") String featureIdOrName,
        @RequestParam("species") String species, HttpServletResponse response)
        throws IllegalOpenCGACredentialsException, IOException {

    initializeQueryOptions();//from w w  w.  j  ava  2 s  . c  om

    if (species == null || species.isEmpty()) {
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return setQueryResponse("Please specify a species");
    }

    MultiMongoDbFactory.setDatabaseNameForCurrentThread(DBAdaptorConnector.getDBName(species));

    List<FeatureCoordinates> features = featureRepository.findByIdOrName(featureIdOrName, featureIdOrName);

    QueryResult<FeatureCoordinates> queryResult = new QueryResult<>();
    queryResult.setResult(features);
    return setQueryResponse(queryResult);
}

From source file:de.yaio.services.webshot.server.controller.WebshotController.java

@ExceptionHandler(IOExceptionWithCause.class)
public void handleCustomException(final HttpServletRequest request, final IOExceptionWithCause e,
        final HttpServletResponse response) throws IOException {
    LOGGER.info("Exception while running request:" + createRequestLogMessage(request), e);
    response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
    response.getWriter().append("url-get failed while webshoting resource:");
    response.getWriter().append(e.getCause().getMessage());
}

From source file:org.dataconservancy.ui.api.BaseController.java

@ExceptionHandler(InvalidXmlException.class)
public void handleException(InvalidXmlException e, HttpServletRequest req, HttpServletResponse resp) {
    log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]");
    resp.setStatus(HttpStatus.SC_UNSUPPORTED_MEDIA_TYPE);

    try {/*from w ww .  j  a  va  2 s  .  co m*/
        resp.getWriter().print(e.getMessage());
        resp.getWriter().flush();
        resp.getWriter().close();
    } catch (Exception ee) {
        log.debug("Handling exception", e);
    }
}

From source file:org.dataconservancy.ui.api.BaseController.java

@ExceptionHandler(IOException.class)
public void handleException(IOException e, HttpServletRequest req, HttpServletResponse resp) {
    log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]");
    resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);

    try {//from  w ww . j  ava2 s . c om
        resp.getWriter().print(e.getMessage());
        resp.getWriter().flush();
        resp.getWriter().close();
    } catch (Exception ee) {
        log.debug("Handling exception", e);
    }
}

From source file:org.dataconservancy.ui.api.BaseController.java

@ExceptionHandler(ArchiveServiceException.class)
public void handleException(ArchiveServiceException e, HttpServletRequest req, HttpServletResponse resp) {
    log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]");
    resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);

    try {//from   ww w . ja  v  a2  s . c  o  m
        resp.getWriter().print(e.getMessage());
        resp.getWriter().flush();
        resp.getWriter().close();
    } catch (Exception ee) {
        log.debug("Handling exception", e);
    }
}

From source file:au.edu.uq.cmm.benny.Benny.java

private void respond(HttpServletResponse resp, int status, String msg) throws IOException {
    resp.setContentType("text/plain");
    resp.setStatus(status);
    Writer w = resp.getWriter();/*  ww  w  .  ja  v  a  2  s. c o  m*/
    try {
        w.write(msg + "\r\n");
    } finally {
        w.close();
    }
}

From source file:de.otto.jsonhome.registry.controller.RegistriesController.java

/**
 * Returns the registries as a list of URLs.
 *
 * <pre><code>//from   w  w w .j a v  a2  s .  c om
 *     GET /registries
 *
 *     {
 *          "self" : "http://example.org/registries",
 *          "registries" : [
 *              { "href" : "http://example.org/registries/live", "title" : "Live environment" },
 *              { "href" : "http://example.org/registries/test", "title" : "Testing environment" }
 *          ]
 *     }
 * </code></pre>
 * <p/>
 * HTTP status codes returned by this method:
 * <ul>
 *     <li>200 OK: if the resource was successfully returned.</li>
 * </ul>
 * @param response the HttpServletResponse
 */
@Rel("/rel/jsonhome/registries")
@RequestMapping(value = "/registries", method = RequestMethod.GET, produces = "application/json")
@ResponseBody
public Map<String, ?> getRegistries(final HttpServletResponse response) {
    response.setStatus(SC_OK);
    return registriesToJson(applicationBaseUri, registryRepository);
}

From source file:grails.plugin.errorpagesfix.PatchedErrorHandlingServlet.java

private void renderDefaultResponse(HttpServletResponse response, int statusCode, String title, String text)
        throws IOException {
    response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    response.setContentType(TEXT_HTML);

    Writer writer = response.getWriter();

    writer.write("<HTML>\n<HEAD>\n<TITLE>Error " + statusCode + " - " + title);
    writer.write("</TITLE>\n<BODY>\n<H2>Error " + statusCode + " - " + title + ".</H2>\n");
    writer.write(text + "<BR/>");

    for (int i = 0; i < 20; i++) {
        writer.write("\n<!-- Padding for IE                  -->");
    }// ww w. jav  a  2 s. c  o  m

    writer.write("\n</BODY>\n</HTML>\n");
    writer.flush();
}

From source file:photogift.server.filter.AuthenticatedFilter.java

private void filter(FilterChain chain, HttpServletRequest request, HttpServletResponse response) {
    try {//w  ww. ja v a  2  s  . c o m
        chain.doFilter(request, response);
    } catch (IOException e) {
        // Likely a temporary network error
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    } catch (ServletException e) {
        // Something went wrong with Jetty serving requests.
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:org.dataconservancy.ui.api.BaseController.java

@ExceptionHandler(RelationshipConstraintException.class)
public void handleException(RelationshipConstraintException e, HttpServletRequest req,
        HttpServletResponse resp) {
    log.debug("Handling exception [" + e.getClass() + "] [" + e.getMessage() + "]");
    resp.setStatus(HttpStatus.SC_INTERNAL_SERVER_ERROR);

    try {//from  w  w  w.ja  v a 2 s  .co m
        resp.getWriter().print(e.getMessage());
        resp.getWriter().flush();
        resp.getWriter().close();
    } catch (Exception ee) {
        log.debug("Handling exception", e);
    }
}