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.thinkberg.webdav.PropFindHandler.java

/**
 * Handle a PROPFIND request./*from  w w  w.j  a  v a2  s .  c  o  m*/
 *
 * @param request  the servlet request
 * @param response the servlet response
 * @throws IOException if there is an error that cannot be handled normally
 */
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException {
    SAXReader saxReader = new SAXReader();
    try {
        Document propDoc = saxReader.read(request.getInputStream());
        logXml(propDoc);

        Element propFindEl = propDoc.getRootElement();
        for (Object propElObject : propFindEl.elements()) {
            Element propEl = (Element) propElObject;
            if (VALID_PROPFIND_TAGS.contains(propEl.getName())) {
                FileObject object = VFSBackend.resolveFile(request.getPathInfo());
                if (object.exists()) {
                    // respond as XML encoded multi status
                    response.setContentType("text/xml");
                    response.setCharacterEncoding("UTF-8");
                    response.setStatus(SC_MULTI_STATUS);

                    Document multiStatusResponse = getMultiStatusResponse(object, propEl, getBaseUrl(request),
                            getDepth(request));
                    logXml(multiStatusResponse);

                    // write the actual response
                    XMLWriter writer = new XMLWriter(response.getWriter(), OutputFormat.createCompactFormat());
                    writer.write(multiStatusResponse);
                    writer.flush();
                    writer.close();

                } else {
                    response.sendError(HttpServletResponse.SC_NOT_FOUND);
                }
                break;
            }
        }
    } catch (DocumentException e) {
        LOG.error("invalid request: " + e.getMessage());
        response.sendError(HttpServletResponse.SC_BAD_REQUEST);
    }
}

From source file:com.jaspersoft.jasperserver.rest.services.RESTJob.java

@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    // Get the uri of the resource
    long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo()));

    // get the resources....
    try {/*  w  w  w .j  ava 2s  .  com*/
        reportSchedulerService.deleteJob(jobId);
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage());
    }

    String xml = null; //m.writeResourceDescriptor(job);
    // send the xml...
    restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, "");

}

From source file:gov.nih.nci.ncicb.tcga.dcc.common.web.StaticContentServlet.java

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

    final String rawResourcePath = request.getServletPath() + request.getPathInfo();

    if (log.isDebugEnabled()) {
        log.debug("Attempting to GET resource: " + rawResourcePath);
    }//  w  w  w  .  j a v  a2  s  .  co m
    final URL[] resources = getRequestResourceURLs(request);
    if (resources == null || resources.length == 0) {
        if (log.isDebugEnabled()) {
            log.debug("Resource not found: " + rawResourcePath);
        }
        response.sendError(HttpServletResponse.SC_NOT_FOUND); //Error 404
        return;
    }
    //Render the resource as-is with a stream
    prepareResponse(response, resources, rawResourcePath);
    final OutputStream out = response.getOutputStream();
    try {
        for (int i = 0; i < resources.length; i++) {
            final URLConnection resourceConn = resources[i].openConnection();
            final InputStream in = resourceConn.getInputStream();
            try {
                byte[] buffer = new byte[1024];
                int bytesRead = -1;
                while ((bytesRead = in.read(buffer)) != -1) {
                    out.write(buffer, 0, bytesRead);
                }
            } finally {
                in.close();
            }
        }
    } finally {
        out.close();
    }
}

From source file:org.obm.healthcheck.server.HealthCheckServletDefaultHandlersTest.java

@Test
public void testUnknownUrl() throws Exception {
    assertThat(get("/this/surely/isnt/handled").getStatusLine().getStatusCode())
            .isEqualTo(HttpServletResponse.SC_NOT_FOUND);
}

From source file:com.formtek.dashlets.sitetaskmgr.SiteWFUtil.java

/**
 * Retrieve the workflow path for the specified workflow
 *
 * @param Workflow wfId/*from w w  w.java2s . c om*/
 * @param workflowService workflowService
 * @return WorkflowPath wfPath
 */
public static WorkflowPath getWorkflowPath(String wfId, WorkflowService workflowService) {
    logger.debug("Getting the workflow path from workflow instance: " + wfId);
    List<WorkflowPath> wfPaths = workflowService.getWorkflowPaths(wfId);
    if (wfPaths == null || wfPaths.size() != 1) {
        throw new WebScriptException(HttpServletResponse.SC_NOT_FOUND,
                "Failed to find workflow paths for workflow instance id: " + wfId);
    }
    WorkflowPath wfPath = wfPaths.get(0);
    logger.debug("Retrieved WorkflowPath with id: " + wfPath.getId());
    return wfPath;
}

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

@RequestMapping(value = "/video/{id}/data", method = RequestMethod.POST)
public @ResponseBody VideoStatus setVideoData(@PathVariable("id") long id,
        @RequestParam("data") MultipartFile videoData, HttpServletResponse response) throws IOException {
    VideoStatus status = new VideoStatus(VideoState.READY);
    //don't have the video: return 404 - the client should receive a 404 error and throw an exception
    if (!videos.containsKey(id)) {
        //   response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return status; // if the id is invalid, the status won't be checked by the client
    }/*  w w w.jav  a 2  s.  c o m*/

    videoFileManager = (null == videoFileManager) ? VideoFileManager.get() : videoFileManager;
    videoFileManager.saveVideoData(videos.get(id), videoData.getInputStream());
    //succesful: status.state == VideoState.READY            
    return status;
}

From source file:cc.kune.core.server.rack.filters.rest.CORSServiceFilter.java

@Override
protected void customDoFilter(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws IOException, ServletException {
    final boolean cors = (Boolean) request.getAttribute("cors.isCorsRequest");

    // This part is similar to RESTServiceFilter
    final String methodName = RackHelper.getMethodName(request, pattern);
    final ParametersAdapter parameters = new ParametersAdapter(request);
    LOG.debug((cors ? "" : "NO ") + "CORS METHOD: '" + methodName + "' on: " + serviceClass.getSimpleName());

    response.setCharacterEncoding("utf-8");

    // See: http://software.dzhuvinov.com/cors-filter-tips.html
    response.setContentType("text/plain");

    final RESTResult result = transactionalFilter.doService(serviceClass, methodName, parameters,
            getInstance(serviceClass));//  ww w .j  a v a 2 s. co m
    if (result != null) {
        final Exception exception = result.getException();
        if (exception != null) {
            if (exception instanceof InvocationTargetException && ((InvocationTargetException) exception)
                    .getTargetException() instanceof ContentNotFoundException) {
                printMessage(response, HttpServletResponse.SC_NOT_FOUND, result.getException().getMessage());
            } else {
                printMessage(response, HttpServletResponse.SC_BAD_REQUEST, result.getException().getMessage());
            }
        } else {
            final String output = result.getOutput();
            if (output != null) {
                final PrintWriter writer = response.getWriter();
                writer.print(output);
                writer.flush();
            } else {
                // Is not for us!!!
            }
        }
    }
}

From source file:org.dspace.app.webui.cris.controller.ResearcherPageDetailsController.java

@Override
public ModelAndView handleDetails(HttpServletRequest request, HttpServletResponse response) throws Exception {
    log.debug("Start handleRequest");
    Map<String, Object> model = new HashMap<String, Object>();

    Integer objectId = extractEntityId(request);
    if (objectId == -1) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Researcher page not found");
        return null;
    }//from  www. j  a va2s.com

    ResearcherPage researcher = null;
    try {

        researcher = ((ApplicationService) applicationService).get(ResearcherPage.class, objectId);

    } catch (NumberFormatException e) {
    }

    if (researcher == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "Researcher page not found");
        return null;
    }

    Context context = UIUtil.obtainContext(request);
    EPerson currUser = context.getCurrentUser();

    boolean isAdmin = AuthorizeManager.isAdmin(context);

    if (isAdmin || (currUser != null
            && (researcher.getEpersonID() != null && currUser.getID() == researcher.getEpersonID()))) {
        model.put("researcher_page_menu", new Boolean(true));
        model.put("authority_key", ResearcherPageUtils.getPersistentIdentifier(researcher));

        if (isAdmin) {
            AuthorityDAO dao = AuthorityDAOFactory.getInstance(context);
            long pendingItems = dao.countIssuedItemsByAuthorityValueInAuthority(RPAuthority.RP_AUTHORITY_NAME,
                    ResearcherPageUtils.getPersistentIdentifier(researcher));
            model.put("pendingItems", new Long(pendingItems));
        }
    }

    else if ((researcher.getStatus() == null || researcher.getStatus().booleanValue() == false)) {
        if (context.getCurrentUser() != null || Authenticate.startAuthentication(context, request, response)) {
            // Log the error
            log.info(LogManager.getHeader(context, "authorize_error",
                    "Only system administrator can access to disabled researcher page"));

            JSPManager.showAuthorizeError(request, response,
                    new AuthorizeException("Only system administrator can access to disabled researcher page"));
        }
        return null;
    }

    if (subscribeService != null) {
        boolean subscribed = subscribeService.isSubscribed(currUser, researcher);
        model.put("subscribed", subscribed);
        EPerson eperson = EPerson.findByNetid(context, researcher.getSourceID());
        if (eperson != null) {
            model.put("subscriptions", subscribeService.getSubscriptions(eperson));
        }
    }

    ModelAndView mvc = null;

    try {
        mvc = super.handleDetails(request, response);
    } catch (RuntimeException e) {
        log.error(e.getMessage(), e);
        return null;
    }

    mvc.getModel().putAll(model);
    mvc.getModel().put("researcher", researcher);
    mvc.getModel().put("exportscitations", ConfigurationManager.getProperty("exportcitation.options"));
    mvc.getModel().put("showStatsOnlyAdmin",
            ConfigurationManager.getBooleanProperty(SolrLogger.CFG_STAT_MODULE, "authorization.admin"));

    // Fire usage event.
    request.setAttribute("sectionid", StatsConfig.DETAILS_SECTION);
    new DSpace().getEventService()
            .fireEvent(new UsageEvent(UsageEvent.Action.VIEW, request, context, researcher));

    log.debug("end servlet handleRequest");

    return mvc;
}

From source file:com.springsource.greenhouse.invite.InviteController.java

/**
 * Show the invitee their invite and allow them to accept it.
 *//*from  ww  w .  j  a va  2 s  . c  o  m*/
@RequestMapping(value = "/invite/accept", method = RequestMethod.GET)
public String acceptInvitePage(@RequestParam String token, Model model, HttpServletResponse response)
        throws IOException {
    try {
        Invite invite = inviteRepository.findInvite(token);
        model.addAttribute(invite.getInvitee());
        model.addAttribute("sentBy", invite.getSentBy());
        model.addAttribute(invite.createSignupForm());
        model.addAttribute("token", token);
        return "invite/accept";
    } catch (InviteException e) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }
}

From source file:com.cloud.servlet.StaticResourceServletTest.java

@Test
public void testDirectory() throws ServletException, IOException {
    final HttpServletResponse response = doGetTest("dir");
    Mockito.verify(response).setStatus(HttpServletResponse.SC_NOT_FOUND);
}