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.tdclighthouse.prototype.components.json.ValueListAjax.java

protected JSON getValueListAsJson(HstRequest request, HstResponse response, String path,
        BlackListChecker blackListChecker) {
    try {/*from  w  w  w .j  a  v  a  2  s.c o m*/
        JSONObject json = new JSONObject();
        Object object = request.getRequestContext().getObjectBeanManager().getObject(path);
        if (object instanceof ValueList) {
            ValueList bean = (ValueList) object;
            if (!blackListChecker.isBlackListed(bean)) {
                List<ValueListItem> listItem = bean.getItems();
                for (ValueListItem listItemBean : listItem) {
                    json.put(listItemBean.getKey(), listItemBean.getLabel());
                }
            } else {
                setErrorMessage(json, "Forbidden");
                response.setStatus(HttpServletResponse.SC_FORBIDDEN);
            }
        } else {
            setErrorMessage(json, "Not Found");
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        }
        return json;
    } catch (ObjectBeanManagerException e) {
        throw new HstComponentException(e);
    }
}

From source file:org.ngrinder.script.controller.SvnDavController.java

/**
 * Request Handler.// ww  w.j a va2 s .c o m
 *
 * @param request  request
 * @param response response
 * @throws ServletException occurs when servlet has a problem.
 * @throws IOException      occurs when file system has a problem.
 */
@Override
public void handleRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    if (LOGGER.isTraceEnabled()) {
        logRequest(request);
    }
    try {
        // To make it understand Asian Language..
        request = new MyHttpServletRequestWrapper(request);
        DAVRepositoryManager repositoryManager = new DAVRepositoryManager(getDAVConfig(), request);
        ServletDAVHandler handler = DAVHandlerFactory.createHandler(repositoryManager, request, response);
        handler.execute();
    } catch (DAVException de) {
        response.setContentType(XML_CONTENT_TYPE);
        handleError(de, response);
    } catch (SVNException svne) {
        StringWriter sw = new StringWriter();
        svne.printStackTrace(new PrintWriter(sw));

        /**
         * truncate status line if it is to long
         */
        String msg = sw.getBuffer().toString();
        if (msg.length() > 128) {
            msg = msg.substring(0, 128);
        }
        SVNErrorCode errorCode = svne.getErrorMessage().getErrorCode();
        if (errorCode == SVNErrorCode.FS_NOT_DIRECTORY || errorCode == SVNErrorCode.FS_NOT_FOUND
                || errorCode == SVNErrorCode.RA_DAV_PATH_NOT_FOUND) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, msg);
        } else if (errorCode == SVNErrorCode.NO_AUTH_FILE_PATH) {
            response.sendError(HttpServletResponse.SC_FORBIDDEN, msg);
        } else if (errorCode == SVNErrorCode.RA_NOT_AUTHORIZED) {
            response.sendError(HttpServletResponse.SC_UNAUTHORIZED, msg);
        } else {
            String errorBody = generateStandardizedErrorBody(errorCode.getCode(), null, null,
                    svne.getMessage());
            response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            response.setContentType(XML_CONTENT_TYPE);
            response.getWriter().print(errorBody);
        }
    } catch (Throwable th) {
        StringWriter sw = new StringWriter();
        th.printStackTrace(new PrintWriter(sw));
        String msg = sw.getBuffer().toString();
        LOGGER.debug("Error in DavSVN Controller", th);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, msg);
    } finally {
        response.flushBuffer();
    }
}

From source file:org.magnum.dataup.VideoCrt.java

@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.POST)

public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id,
        @RequestParam(value = "data") MultipartFile videoData, HttpServletResponse response)
        throws IOException {
    VideoFileManager vfm = VideoFileManager.get();

    try {//from www. j  a v  a  2s .c om
        if (!videos.containsKey(id))
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        else {
            Video v = videos.get(id);
            //response.addHeader("Content-Type", v.getContentType ());
            vfm.saveVideoData(v, videoData.getInputStream());
        }
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    VideoStatus state = new VideoStatus(VideoState.READY);
    return state;
}

From source file:org.paxml.selenium.rc.FileServer.java

public static AbstractHandler newFileHandler() {
    return new AbstractHandler() {
        @Override//w ww  . j  av  a  2 s .  c o  m
        public void handle(String path, HttpServletRequest request, HttpServletResponse res, int arg3)
                throws IOException, ServletException {
            if (path.startsWith("/")) {
                path = path.substring(1);
            }
            String tmpFile = null;
            InputStream in = null;
            try {
                if (path.startsWith(IN_MEM_IDENT)) {
                    // let a file be read for only once, otherwise memory
                    // could explode
                    String content = memFiles.remove(path);
                    in = new ByteArrayInputStream(content.getBytes("UTF-8"));
                } else if (path.startsWith(TMP_FILE_IDENT)) {
                    tmpFile = path.substring(TMP_FILE_IDENT.length());
                    in = new FileInputStream(new File(TMP_DIR, tmpFile));
                } else if (path.startsWith(CLASSPATH_IDENT)) {
                    in = new ClassPathResource(path.substring(CLASSPATH_IDENT.length())).getInputStream();
                } else {
                    throw new IOException("Path with unknown identifier: " + path);
                }

                res.setStatus(HttpServletResponse.SC_OK);
                res.setContentType("binary/x-paxml");
                res.setHeader("Content-Disposition", "attachment; filename=\"" + path + "\"");
                res.setHeader("Pragma", "");
                res.setHeader("Cache-control", "");

                IOUtils.copy(in, res.getOutputStream());

                ((Request) request).setHandled(true);

            } catch (Exception e) {
                if (log.isErrorEnabled()) {
                    log.error("Cannot resolve path: " + path, e);
                }
                res.setStatus(HttpServletResponse.SC_NOT_FOUND);

                return;
            } finally {
                IOUtils.closeQuietly(in);
                if (tmpFile != null) {
                    new File(tmpFile).delete();
                }
            }

        }

    };
}

From source file:com.haulmont.cuba.core.controllers.FileDownloadController.java

public File getFile(HttpServletRequest request, HttpServletResponse response) throws IOException {
    String filePath = URLEncodeUtils.decodeUtf8(request.getParameter("p"));
    if (filePath != null) {
        if (isPermittedDirectory(filePath)) {
            return new File(filePath);
        } else {/*w w  w . j  a v  a  2s.  c om*/
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    } else {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
    return null;
}

From source file:cz.zcu.kiv.eegdatabase.webservices.rest.datafile.DataFileServiceController.java

/**
 * Exception handler for RestNotFoundException.class.
 * Writes exception message into HTTP response.
 *
 * @param ex       exception body//from  w  w  w  . ja  v a2s . com
 * @param response HTTP response
 * @throws IOException error while writing into response
 */
@ExceptionHandler(RestNotFoundException.class)
public void handleException(RestNotFoundException ex, HttpServletResponse response) throws IOException {
    response.sendError(HttpServletResponse.SC_NOT_FOUND, ex.getMessage());
    log.error(ex);
}

From source file:com.jaspersoft.jasperserver.remote.services.impl.ResourcesManagementRemoteServiceImpl.java

/**
 * Return a descriptor/*  w w w  .jav  a  2 s.c om*/
 * Attachments, if requested, are placed inside the attachments list.
 * If the list is null, no attachment is returned.
 * the local should be true ONLY if the first call from RESTResource is for a local resource
 *
 * @throws com.jaspersoft.jasperserver.api.JSException
 *
 */
public ResourceDescriptor getResource(String resourceURI, Map<String, Object> options) throws ServiceException {
    Resource resource = locateResource(resourceURI);

    if (resource == null) {
        if (log.isWarnEnabled()) {
            log.warn("Get: null resourceDescriptor for " + resourceURI);
        }
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND,
                "Could not locate resource at URI: " + resourceURI);
    } else {
        ResourceDescriptor rd = createResourceDescriptor(resource, processDescriptorOptions(options));
        return rd;
    }
}

From source file:org.magnum.mobilecloud.video.VideoSvcCtrl.java

@PreAuthorize("hasRole(USER)")
@RequestMapping(method = RequestMethod.GET, value = VideoSvcApi.VIDEO_SVC_PATH + "/{id}/likedby")
public @ResponseBody Collection<String> getUsersWhoLikedVideo(@PathVariable("id") long id,
        HttpServletResponse response) {/*from w w  w . ja v  a  2s.  co  m*/
    Collection<String> ret = null;
    Video v = videoRepo.findOne(id);
    if (v != null) {
        ret = Lists.newArrayList(v.getLikers());
        response.setStatus(HttpServletResponse.SC_OK);
    } else
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);

    return ret;
}

From source file:org.jamwiki.servlets.ImageServlet.java

/**
 * Serve a file from the filesystem.  This is less efficient than serving the file
 * directly via Tomcat or Apache, but allows files to be stored outside of the
 * webapp and thus keeps wiki data (files) separate from application code.
 *//*from   ww  w.j  a  v a2 s .  co  m*/
private void streamFileFromFileSystem(File file, HttpServletResponse response)
        throws ServletException, IOException {
    ServletOutputStream out = null;
    InputStream in = null;
    if (file.isDirectory() || !file.canRead()) {
        logger.debug("File does not exist: " + file.getAbsolutePath());
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    String mimeType = getServletContext().getMimeType(file.getAbsolutePath());
    if (mimeType == null) {
        mimeType = WikiFile.UNKNOWN_MIME_TYPE;
    }
    try {
        response.setContentType(mimeType);
        response.setContentLength((int) file.length());
        out = response.getOutputStream();
        in = new FileInputStream(file);
        IOUtils.copy(in, out);
        out.flush();
    } finally {
        IOUtils.closeQuietly(in);
        IOUtils.closeQuietly(out);
    }
}