Example usage for javax.servlet.http HttpServletResponse SC_NOT_FOUND

List of usage examples for javax.servlet.http HttpServletResponse SC_NOT_FOUND

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse SC_NOT_FOUND.

Prototype

int SC_NOT_FOUND

To view the source code for javax.servlet.http HttpServletResponse SC_NOT_FOUND.

Click Source Link

Document

Status code (404) indicating that the requested resource is not available.

Usage

From source file:uk.org.iay.mdq.server.ResultRawView.java

@Override
public void render(final Map<String, ?> model, final HttpServletRequest request,
        final HttpServletResponse response) throws Exception {
    final Result result = (Result) model.get("result");
    log.debug("rendering as {}", getContentType());

    if (result.isNotFound()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from w w w  .  j a  v a2 s . c om
    }

    // select the representation to provide
    Representation rep = null;
    final String acceptEncoding = request.getHeader(HttpHeaders.ACCEPT_ENCODING);
    if (acceptEncoding != null) {
        if (acceptEncoding.contains("gzip")) {
            rep = result.getGZIPRepresentation();
        } else if (acceptEncoding.contains("compress")) {
            rep = result.getDeflateRepresentation();
        }
    }

    // default to the normal representation
    if (rep == null) {
        rep = result.getRepresentation();
    }

    // Set response headers
    String contentEncoding = rep.getContentEncoding();
    if (contentEncoding != null) {
        response.setHeader(HttpHeaders.CONTENT_ENCODING, contentEncoding);
    } else {
        // for logging only
        contentEncoding = "normal";
    }
    response.setContentType(getContentType());
    response.setContentLength(rep.getBytes().length);
    response.setHeader(HttpHeaders.ETAG, rep.getETag());

    log.debug("selected ({}) representation is {} bytes", contentEncoding, rep.getBytes().length);

    response.getOutputStream().write(rep.getBytes());
}

From source file:controller.TemasNivel1RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel1DAO tabla = new TemasNivel1DAO();
    Gson JSON;/*  www.j  a v a  2s .  co  m*/
    List<TemasNivel1> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel1> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:controller.TemasNivel2RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel2DAO tabla = new TemasNivel2DAO();
    Gson JSON;//from  w  ww  .ja v  a2s .  c om
    List<TemasNivel2> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel2> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:controller.TemasNivel3RestController.java

@RequestMapping(method = RequestMethod.GET, produces = "application/json")
public String getJSON(HttpServletRequest request, HttpServletResponse response) {
    TemasNivel3DAO tabla = new TemasNivel3DAO();
    Gson JSON;/*from  w w w .  j  a v  a 2s.c o  m*/
    List<TemasNivel3> lista;
    try {
        lista = tabla.selectAll();
        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            JSON = new Gson();
            return JSON.toJson(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServer", ex.getMessage());
        JSON = new Gson();
        return JSON.toJson(e);
    }

    Datos<TemasNivel3> datos = new Datos<>();
    datos.setDatos(lista);
    JSON = new Gson();
    response.setStatus(HttpServletResponse.SC_OK);
    return JSON.toJson(datos);
}

From source file:libs.foundation.components.logo.img_GET.java

protected void writeLayer(SlingHttpServletRequest req, SlingHttpServletResponse resp, ImageContext c,
        Layer layer) throws IOException, RepositoryException {

    Image image = new Image(c.resource);
    image.setItemName(Image.NN_FILE, "image");
    image.setItemName(Image.PN_REFERENCE, "imageReference");
    if (!image.hasContent()) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from  www  .  j  a  va2  s.  c o m*/
    }

    // get style and set constraints
    image.set(Image.PN_MIN_WIDTH, c.properties.get("minWidth", ""));
    image.set(Image.PN_MIN_HEIGHT, c.properties.get("minHeight", ""));
    image.set(Image.PN_MAX_WIDTH, c.properties.get("maxWidth", ""));
    image.set(Image.PN_MAX_HEIGHT, c.properties.get("maxHeight", ""));

    // get pure layer
    layer = image.getLayer(false, false, false);

    // crop
    boolean modified = image.crop(layer) != null;

    // resize
    modified |= image.resize(layer) != null;

    // rotate
    modified |= image.rotate(layer) != null;

    if (modified) {
        resp.setContentType(c.requestImageType);
        layer.write(c.requestImageType, 1.0, resp.getOutputStream());
    } else {
        // do not re-encode layer, just spool
        Property data = image.getData();
        InputStream in = data.getStream();
        resp.setContentLength((int) data.getLength());
        String contentType = image.getMimeType();
        if (contentType.equals("application/octet-stream")) {
            contentType = c.requestImageType;
        }
        resp.setContentType(contentType);
        IOUtils.copy(in, resp.getOutputStream());
        in.close();
    }
    resp.flushBuffer();
}

From source file:libs.foundation.components.parbase.img_GET.java

@Override
protected void writeLayer(SlingHttpServletRequest req, SlingHttpServletResponse resp, ImageContext c,
        Layer layer) throws IOException, RepositoryException {

    Image image = new Image(c.resource);
    if (!image.hasContent()) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from w  w w.  j a v a2 s . c  o m
    }

    // get style and set constraints
    image.loadStyleData(c.style);

    // get pure layer
    layer = image.getLayer(false, false, false);
    boolean modified = false;

    if (layer != null) {
        // crop
        modified = image.crop(layer) != null;

        // rotate
        modified |= image.rotate(layer) != null;

        // resize
        modified |= image.resize(layer) != null;

        // apply diff if needed (because we create the layer inline)
        modified |= applyDiff(layer, c);
    }

    if (modified) {
        String mimeType = image.getMimeType();
        if (ImageHelper.getExtensionFromType(mimeType) == null) {
            // get default mime type
            mimeType = "image/png";
        }
        resp.setContentType(mimeType);
        layer.write(mimeType, mimeType.equals("image/gif") ? 255 : 1.0, resp.getOutputStream());
    } else {
        // do not re-encode layer, just spool
        Property data = image.getData();
        InputStream in = data.getStream();
        resp.setContentLength((int) data.getLength());
        resp.setContentType(image.getMimeType());
        IOUtils.copy(in, resp.getOutputStream());
        in.close();
    }
    resp.flushBuffer();
}

From source file:com.thoughtworks.go.remote.work.HttpServiceStub.java

@Override
public int download(String url, FetchHandler handler) throws IOException {
    byte[] body = downloadFiles.get(url);
    if (body == null) {
        return HttpServletResponse.SC_NOT_FOUND;
    }/*from  w  w w .  j a  v a 2 s .  co  m*/
    handler.handle(new ByteArrayInputStream(body));
    return returnCode;
}

From source file:org.openmrs.module.openhmis.cashier.web.controller.ReceiptController.java

@RequestMapping(method = RequestMethod.GET)
public void get(@RequestParam(value = "billId", required = false) Integer billId, HttpServletResponse response)
        throws IOException {
    if (billId == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from  w w w  .  j  a va2 s  . c o m
    }

    IBillService service = Context.getService(IBillService.class);
    Bill bill = service.getById(billId);
    if (!validateBill(billId, bill, response)) {
        return;
    }

    JasperReport report = ModuleSettings.getReceiptReport();
    if (report == null) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Configuration error: need to specify global " + "option for default report ID.");
        return;
    }

    if (generateReport(billId, response, bill, report)) {
        bill.setReceiptPrinted(true);
        service.save(bill);
    }
}

From source file:com.kappaware.logtrawler.adminserver.requesthandler.StatsRequestHandler.java

@Override
protected Object handleJsonRequest(HttpServletRequest request, String[] groups, HttpServletResponse response)
        throws HttpServerException {
    if (groups.length == 2) {
        Stats.Mode mode;/*from  w  w  w .  j a  v a 2 s .c o  m*/
        try {
            mode = Stats.Mode.valueOf(groups[1]);
        } catch (Exception e) {
            throw new HttpServerException(HttpServletResponse.SC_NOT_FOUND,
                    String.format("Unknow mode '%s'", groups[1]));
        }
        Stats stats = new Stats();
        if ("*".equals(groups[0])) {
            for (AgentHandler ah : this.agentHandlerByName.values()) {
                stats.getAgents().add(new Stats.Agent(ah, mode));
            }
        } else {
            AgentHandler ah = this.agentHandlerByName.get(groups[0]);
            if (ah != null) {
                stats.getAgents().add(new Stats.Agent(ah, mode));
            } else {
                throw new HttpServerException(HttpServletResponse.SC_NOT_FOUND,
                        String.format("Unknow agent '%s'", groups[0]));
            }
        }
        return stats;
    } else {
        log.error(String.format("groups[].length = %d", groups.length));
        throw new HttpServerException(HttpServletResponse.SC_NOT_FOUND, null);
    }
}

From source file:de.otto.mongodb.profiler.web.AbstractController.java

@ExceptionHandler(ResourceNotFoundException.class)
public void onResourceNotFound(HttpServletResponse response) throws IOException {

    response.sendError(HttpServletResponse.SC_NOT_FOUND, "Resource not found!");
}