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:com.nabla.dc.server.ImageService.java

@Override
public void doGet(final HttpServletRequest request, final HttpServletResponse response) throws IOException {
    final String imageId = request.getParameter("id");
    if (imageId == null || imageId.isEmpty()) {
        if (log.isTraceEnabled())
            log.trace("missing image ID");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {/* www  . j av  a2  s .  co  m*/
        try {
            if (exportImage(imageId, response)) {
                //   response.setStatus(HttpServletResponse.SC_OK);
            } else
                response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (final SQLException e) {
            if (log.isErrorEnabled())
                log.error("SQL error " + e.getErrorCode() + "-" + e.getSQLState(), e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } catch (final Throwable e) {
            if (log.isErrorEnabled())
                log.error("unexpected error", e);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        }
    }
}

From source file:com.javaetmoi.core.spring.vfs.Vfs2ResourceHttpRequestHandler.java

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

    checkAndPrepare(request, response, true);

    // check whether a matching resource exists
    Resource resource = getResource(request);
    if (resource == null) {
        logger.debug("No matching resource found - returning 404");
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/*from  w ww .  j  a va 2  s.  c o m*/
    }

    // check the resource's media type
    MediaType mediaType = getMediaType(resource);
    if (mediaType != null) {
        if (logger.isDebugEnabled()) {
            logger.debug("Determined media type '" + mediaType + "' for " + resource);
        }
    } else {
        if (logger.isDebugEnabled()) {
            logger.debug("No media type found for " + resource + " - not sending a content-type header");
        }
    }

    // header phase
    // Use a Vfs2Resource when asset are probided by the JBoss 5 Virtaul File System
    URL url = resource.getURL();
    if (url.getProtocol().startsWith(ResourceUtils.URL_PROTOCOL_VFS)) {
        resource = new Vfs2Resource(Vfs2Utils.getRoot(url));
    }

    if (new ServletWebRequest(request, response).checkNotModified(resource.lastModified())) {
        logger.debug("Resource not modified - returning 304");
        return;
    }
    setHeaders(response, resource, mediaType);

    // content phase
    if (METHOD_HEAD.equals(request.getMethod())) {
        logger.trace("HEAD request - skipping content");
        return;
    }
    writeContent(response, resource);
}

From source file:jp.or.openid.eiwg.filter.InitFilter.java

/**
 * ????//from  w ww.jav  a 2 s. com
 *
 * @param request 
 * @param response ?
 * @param chain ?
 * @throws ServletException
 * @throws IOException
 */
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    try {

        // ??
        String path = ((HttpServletRequest) request).getServletPath();
        if (path == null || StringUtils.isEmpty(path)) {
            // 
            this.errorResponse((HttpServletResponse) response, HttpServletResponse.SC_NOT_FOUND, null,
                    MessageConstants.ERROR_NOT_FOUND);
        } else {
            // ?????????
            if (!"/scim/ServiceProviderConfigs".equalsIgnoreCase(path)
                    && !"/scim/ResourceTypes".equalsIgnoreCase(path) && !"/scim/Schemas".equalsIgnoreCase(path)
                    && !"/scim/Users".equalsIgnoreCase(path)) {
                // 
                this.errorResponse((HttpServletResponse) response, HttpServletResponse.SC_NOT_FOUND, null,
                        MessageConstants.ERROR_NOT_FOUND);
            } else {
                // ??
                chain.doFilter(request, response);
            }
        }
    } catch (Throwable e) {
        // 
        e.printStackTrace();
        this.errorResponse((HttpServletResponse) response, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, null,
                MessageConstants.ERROR_UNKNOWN);
    }
}

From source file:io.wcm.handler.media.impl.AbstractMediaFileServlet.java

@Override
protected void doGet(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {

    // get binary data resource
    Resource resource = getBinaryDataResource(request);
    if (resource == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;/* w  w  w.ja v  a2s .  c o  m*/
    }

    // check if the resource was modified since last request
    if (isNotModified(resource, request, response)) {
        return;
    }

    // get binary data and send to client
    byte[] binaryData = getBinaryData(resource, request);
    if (binaryData == null || binaryData.length == 0) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } else {
        String contentType = getContentType(resource, request);
        sendBinaryData(binaryData, contentType, request, response);
    }

}

From source file:com.novartis.pcs.ontology.rest.servlet.GraphServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String pathInfo = StringUtils.trimToNull(request.getPathInfo());
    String orientation = StringUtils.trimToNull(request.getParameter("orientation"));
    String callback = StringUtils.trimToNull(request.getParameter("callback"));
    String mediaType = getExpectedMediaType(request);

    if (pathInfo != null && pathInfo.length() > 1) {
        String termRefId = pathInfo.substring(1);
        graph(termRefId, mediaType, orientation, callback, response);
    } else {/*from   ww  w  . ja  v a2  s.  c o  m*/
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentLength(0);
    }
}

From source file:org.ngrinder.infra.spring.Redirect404DispatcherServlet.java

/**
 * Redirect to error 404 when the /svn/ is not included in the path.
 *
 * @param request  current HTTP requests
 * @param response current HTTP response
 * @throws Exception if preparing the response failed
 *///from   w w  w .j a v a  2 s  .c  o  m
protected void noHandlerFound(HttpServletRequest request, HttpServletResponse response) throws Exception {
    if (!request.getPathInfo().startsWith("/svn/")) {
        if (request.getPathInfo().contains("/api")) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.setContentType("application/json; charset=UTF-8");
            String requestUri = urlPathHelper.getRequestUri(request);
            JsonObject object = new JsonObject();

            object.addProperty(JSON_SUCCESS, false);
            object.addProperty(JSON_CAUSE,
                    "API URL " + requestUri + " [" + request.getMethod() + "] does not exist.");
            response.getWriter().write(gson.toJson(object));
            response.flushBuffer();
        } else {
            if (pageNotFoundLogger.isWarnEnabled()) {
                String requestUri = urlPathHelper.getRequestUri(request);
                pageNotFoundLogger.warn("No mapping found for HTTP request with URI [" + requestUri
                        + "] in DispatcherServlet with name '" + getServletName() + "'");
            }
            response.sendRedirect("/error_404");
        }
    }
}

From source file:eionet.cr.web.action.ExportTriplesActionBean.java

@DefaultHandler
public Resolution defaultHandler() {

    if (StringUtils.isBlank(uri)) {

        if (Util.isWebBrowser(getContext().getRequest())) {
            getContext().getRequest().setAttribute(StripesExceptionHandler.EXCEPTION_ATTR,
                    new CRException("Graph URI not specified in the request!"));
            return new ForwardResolution(StripesExceptionHandler.ERROR_PAGE);
        } else {/*from   w w w  . jav  a  2s . co  m*/
            return new ErrorResolution(HttpServletResponse.SC_NOT_FOUND);
        }
    }

    return (new StreamingResolution("application/rdf+xml") {

        public void stream(HttpServletResponse response) throws Exception {
            RDFGenerator.generate(uri, response.getOutputStream());
        }
    });
}

From source file:com.github.rabid_fish.proxy.servlet.SoapServlet.java

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

    PrintWriter writer = response.getWriter();

    if (request.getQueryString() != null && request.getQueryString().equals("wsdl")) {
        response.setStatus(HttpServletResponse.SC_OK);
        response.setContentType("text/xml");
        writeWsdl(writer);/*ww  w .ja  va2 s. com*/
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentType("text/html");
        writer.append("404: page not found");
    }

    writer.flush();
    writer.close();
}

From source file:com.evolveum.midpoint.web.boot.StaticWebServlet.java

protected void serveResource(HttpServletRequest request, HttpServletResponse response, boolean content)
        throws IOException, ServletException {
    String relativePath = request.getPathInfo();
    LOGGER.trace("Serving relative path {}", relativePath);

    String requestUri = request.getRequestURI();
    if (relativePath == null || relativePath.length() == 0 || "/".equals(relativePath)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, requestUri);
        return;/*from ww w . j  a  v  a 2  s  . co  m*/
    }

    File file = new File(base, relativePath);
    if (!file.exists() || !file.isFile()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, requestUri);
        return;
    }

    String contentType = getServletContext().getMimeType(file.getName());
    if (contentType == null) {
        contentType = "application/octet-stream";
    }
    response.setContentType(contentType);
    response.setHeader("Content-Length", String.valueOf(file.length()));

    LOGGER.trace("Serving file {}", file.getPath());

    ServletOutputStream outputStream = response.getOutputStream();
    FileInputStream fileInputStream = new FileInputStream(file);

    try {
        IOUtils.copy(fileInputStream, outputStream);
    } catch (IOException e) {
        throw e;
    } finally {
        fileInputStream.close();
        outputStream.close();
    }

}

From source file:net.sourceforge.fenixedu.presentationTier.Action.publico.rss.InformaRSSAction.java

@Override
public ActionForward execute(final ActionMapping mapping, final ActionForm form,
        final HttpServletRequest request, final HttpServletResponse response) throws Exception {
    final String encoding = System.getProperty("file.encoding", Charset.defaultCharset().name());
    final ChannelIF channel = getRSSChannel(request);
    if (channel != null) {
        response.setContentType("text/xml; charset=" + encoding);
        final PrintWriter writer = response.getWriter();
        final ChannelExporterIF exporter = new RSS_2_0_Exporter(writer, encoding);
        exporter.write(channel);//  www. j a  va  2  s.co m
        response.flushBuffer();
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.getWriter().write(HttpStatus.getStatusText(HttpStatus.SC_NOT_FOUND));
        response.getWriter().close();
    }
    return null;
}