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:eionet.gdem.web.struts.stylesheet.EditStylesheetFormActionTest.java

@Test
public void testNonExistingStylesheet() {
    super.setRequestPathInfo("/stylesheetViewForm?stylesheetId=9999999");

    try {/*w w w .j  a va2 s  .  c o m*/
        super.actionPerform();
    } catch (AssertionError err) {
    }

    assertEquals(super.getMockResponse().getStatusCode(), HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.carolinarollergirls.scoreboard.jetty.StreamServlet.java

protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doGet(request, response);

    if (request.getPathInfo().equals("/list"))
        list(request, response);/*w w  w. j a  va  2s. c o  m*/
    else
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.googlecode.commonspringaspects.servlets.PerformanceHttpRequestHandler.java

public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (!enabled) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from  w  w w  . jav  a2 s  .  c o m
    }

    if (request.getMethod().equals("POST")) {

        MonitorFactory.reset();
        response.sendRedirect(request.getRequestURI());

    } else {

        response.setContentType("text/html");
        PrintWriter writer = response.getWriter();
        writer.print("<html>");
        writer.print("<body><form action='' method='post'> <input type='submit' value='Reset JAMon'> </form>");
        writer.print(MonitorFactory.getRootMonitor().getReport(3, "desc"));
        writer.print("</body></html>");

    }
}

From source file:cn.featherfly.web.spring.servlet.view.NotFoundView.java

/**
 * {@inheritDoc}//from  w w w . j  a va  2 s  . c  o  m
 */
@Override
protected void renderMergedOutputModel(Map<String, Object> model, HttpServletRequest request,
        HttpServletResponse response) throws Exception {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
}

From source file:com.telefonica.iot.perseo.RulesManager.java

/**
 * Get a rule by name/* w  ww  .jav  a  2s .  c  o  m*/
 *
 * @param epService Esper provider containing rules
 * @param ruleName Name of the rule
 *
 * @return Result object with a code and a JSON response
 */
public static synchronized Result get(EPServiceProvider epService, String ruleName) {
    try {

        logger.debug("rule asked for: " + ruleName);
        ruleName = ruleName == null ? "" : ruleName;
        EPAdministrator epa = epService.getEPAdministrator();

        if (ruleName.length() != 0) {
            EPStatement st = epa.getStatement(ruleName);
            if (st == null) {
                return new Result(HttpServletResponse.SC_NOT_FOUND,
                        String.format("{\"error\":\"%s not found\"}\n", ruleName));
            } else {
                return new Result(HttpServletResponse.SC_OK, Utils.Statement2JSONObject(st).toString());
            }
        } else {
            String[] sttmntNames = epa.getStatementNames();
            JSONArray ja = new JSONArray();
            for (String name : sttmntNames) {
                logger.debug("getting rule " + name);
                EPStatement st = epa.getStatement(name);
                ja.put(Utils.Statement2JSONObject(st));
            }
            return new Result(HttpServletResponse.SC_OK, ja.toString());
        }

    } catch (EPException epe) {
        logger.error("getting statement" + epe);
        return new Result(HttpServletResponse.SC_BAD_REQUEST,
                String.format("{\"error\":%s}\n", JSONObject.valueToString(epe.getMessage())));
    }
}

From source file:eu.trentorise.game.api.rest.ExceptionHandler.java

@org.springframework.web.bind.annotation.ExceptionHandler(ResourceNotFoundException.class)
public void handleResourceNotFound(HttpServletResponse res, Exception e) throws IOException {
    res.sendError(HttpServletResponse.SC_NOT_FOUND, e.getMessage());
}

From source file:com.thinkberg.moxo.dav.HeadHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = getResourceManager().getFileObject(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {//from ww  w . ja  v a 2  s .c  o  m
            setHeader(response, object.getContent());
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:org.bonitasoft.web.designer.controller.utils.HttpFile.java

public static void writeFileInResponse(HttpServletRequest request, HttpServletResponse response, Path filePath)
        throws IOException {
    if (!isExistingFilePath(response, filePath)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//  ww  w  .  j  a  v a  2s . c  om
    }
    writeFileInResponse(response, filePath,
            request.getServletContext().getMimeType(filePath.getFileName().toString()), "inline");
}

From source file:com.thinkberg.webdav.HeadHandler.java

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    FileObject object = VFSBackend.resolveFile(request.getPathInfo());

    if (object.exists()) {
        if (FileType.FOLDER.equals(object.getType())) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN);
        } else {/*  w  w  w  .j a v  a2s  . co m*/
            setHeader(response, object.getContent());
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:foam.nanos.blob.FileService.java

@Override
protected void download(X x) {
    OutputStream os = null;//from  w w w  .ja va 2  s . com
    HttpServletRequest req = x.get(HttpServletRequest.class);
    HttpServletResponse resp = x.get(HttpServletResponse.class);

    try {
        String path = req.getRequestURI();
        String id = path.replaceFirst("/service/" + nspec_.getName() + "/", "");

        // find file from file dao
        File file = (File) fileDAO_.find_(x, id);
        if (file == null || file.getData() == null) {
            resp.setStatus(HttpServletResponse.SC_NOT_FOUND);
            return;
        }

        // check to see if current user has access to file owner
        if (userDAO_.find_(x, file.getOwner()) == null) {
            resp.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
            return;
        }

        // get blob and blob size
        // TODO: figure out why delegate is not being set for IdentifiedBlob
        String blobId = ((IdentifiedBlob) file.getData()).getId();
        Blob blob = getDelegate().find_(x, blobId);
        long size = blob.getSize();

        // set response status, content type, content length
        resp.setStatus(HttpServletResponse.SC_OK);
        resp.setContentType(file.getMimeType());
        resp.setHeader("Content-Length", Long.toString(size, 10));
        resp.setHeader("Cache-Control", "public");

        // output data to response
        os = resp.getOutputStream();
        blob.read(os, 0, size);
        os.close();
    } catch (Throwable t) {
        t.printStackTrace();
        throw new RuntimeException(t);
    } finally {
        IOUtils.closeQuietly(os);
    }
}