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:at.ac.univie.isc.asio.insight.ExplorerPageRedirectFilter.java

@Override
protected void doFilterInternal(final HttpServletRequest request, final HttpServletResponse response,
        final FilterChain chain) throws ServletException, IOException {
    final String redirect = template.findRedirectTarget(request);
    final String original = request.getRequestURI();

    if (redirect == null) { // skip redirect
        log.debug(Scope.REQUEST.marker(), "not an explorer request ({}) - skip redirecting", original);
        chain.doFilter(request, response);
        return;/*  w  w w  .  ja v a  2s  .  c o  m*/
    }

    assert redirect.startsWith("/") : "redirect target is not an absolute path";
    final RequestDispatcher dispatcher = request.getRequestDispatcher(redirect);
    if (dispatcher == null) { // redirect cannot be handled
        final String message = Pretty.format("no handler for request to <%s> (redirected from <%s>) found",
                redirect, original);
        log.debug(Scope.REQUEST.marker(), message);
        if (!response.isCommitted()) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, message);
        }
        return;
    }

    log.debug(Scope.REQUEST.marker(), "redirect request from {} to {}", original, redirect);
    dispatcher.forward(request, response);
}

From source file:com.esri.gpt.control.arcims.ServletConnectorProxy.java

/**
 * Handles a GET request. <p/> The default behavior is the execute the doGet
 * method./*  ww w  . j ava 2 s  . c om*/
 * 
 * @param request
 *          the servlet request
 * @param response
 *          the servlet response
 * @throws ServletException
 * @throws IOException
 *           if an exception occurs
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {

    /* if(true){
       doPost(request,response);
       return;
     }*/

    /*if(!_redirectURL.startsWith("http"))
       setURL(request);
            
    response.sendRedirect(_redirectURL + "?" + request.getQueryString());*/

    Principal p = request.getUserPrincipal();
    if (p != null) {
        LOGGER.finer("UserName : " + p.getName());
    }

    LOGGER.finer("Query string=" + request.getQueryString());
    if ("ping".equalsIgnoreCase(request.getParameter("Cmd"))) {
        response.getWriter().write("IMS v9.3.0");
    } else if ("ping".equalsIgnoreCase(request.getParameter("cmd"))) {
        response.getWriter().write("IMS v9.3.0");
    } else if ("getVersion".equalsIgnoreCase(request.getParameter("Cmd"))) {
        response.getWriter().write("Version=9.3.0\nBuild_Number=514.2159");
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:eu.dasish.annotation.backend.rest.TargetResource.java

/**
 * //from  w  ww.j  a v  a  2 s .c  o m
 * @param externalIdentifier the external UUId of a target.
 * @return a {@link Target} element representing a target object with "externalIdentifier".
 * @throws IOException if sending an error fails.
 */
@GET
@Produces(MediaType.TEXT_XML)
@Path("{targetid: " + BackendConstants.regExpIdentifier + "}")
@Transactional(readOnly = true)
public JAXBElement<Target> getTarget(@PathParam("targetid") String externalIdentifier) throws IOException {
    Map params = new HashMap();
    try {
        Target result = (Target) (new RequestWrappers(this)).wrapRequestResource(params, new GetTarget(),
                Resource.TARGET, Access.READ, externalIdentifier);
        if (result != null) {
            return new ObjectFactory().createTarget(result);
        } else {
            return new ObjectFactory().createTarget(new Target());
        }
    } catch (NotInDataBaseException e1) {
        httpServletResponse.sendError(HttpServletResponse.SC_NOT_FOUND, e1.getMessage());
        return new ObjectFactory().createTarget(new Target());
    } catch (ForbiddenException e2) {
        httpServletResponse.sendError(HttpServletResponse.SC_FORBIDDEN, e2.getMessage());
        return new ObjectFactory().createTarget(new Target());
    }
}

From source file:io.wcm.caconfig.editor.impl.ConfigPersistServlet.java

@Override
@SuppressWarnings("null")
protected void doPost(SlingHttpServletRequest request, SlingHttpServletResponse response)
        throws ServletException, IOException {
    if (!editorConfig.isEnabled()) {
        sendForbiddenWithMessage(response, "Configuration editor is disabled.");
        return;//from  w w  w . j a  v a 2  s .  c  om
    }

    // get parameters
    String configName = request.getParameter(RP_CONFIGNAME);
    if (StringUtils.isBlank(configName)) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }
    boolean collection = BooleanUtils.toBoolean(request.getParameter(RP_COLLECTION));

    ConfigurationMetadata configMetadata = configManager.getConfigurationMetadata(configName);
    if (configMetadata != null && configMetadata.isCollection() != collection) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Collection parameter mismatch.");
        return;
    }

    // parse JSON parameter data
    ConfigurationPersistData persistData = null;
    ConfigurationCollectionPersistData collectionPersistData = null;
    try {
        String jsonDataString = IOUtils.toString(request.getInputStream(), CharEncoding.UTF_8);
        JSONObject jsonData = new JSONObject(jsonDataString);
        if (collection) {
            collectionPersistData = parseCollectionConfigData(jsonData, configMetadata);
        } else {
            persistData = parseConfigData(jsonData, configMetadata);
        }
    } catch (JSONException ex) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid JSON data: " + ex.getMessage());
        return;
    }

    // persist data
    try {
        if (collection) {
            configManager.persistConfigurationCollection(request.getResource(), configName,
                    collectionPersistData);
        } else {
            configManager.persistConfiguration(request.getResource(), configName, persistData);
        }
    } catch (ConfigurationPersistenceAccessDeniedException ex) {
        sendForbiddenWithMessage(response, ex.getMessage());
    } catch (ConfigurationPersistenceException ex) {
        log.warn("Unable to persist data for " + configName + (collection ? "[col]" : ""), ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR,
                "Unable to persist data: " + ex.getMessage());
    }
    /*CHECKSTYLE:OFF*/ catch (Exception ex) { /*CHECKSTYLE:ON*/
        log.error("Error getting configuration for " + configName + (collection ? "[col]" : ""), ex);
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, ex.getMessage());
    }
}

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

@RequestMapping(value = "/log/{file:[a-zA-Z0-9\\.\\-_]+}", method = RequestMethod.GET)
public void getLogFile(HttpServletResponse response, @RequestParam(value = "s") String sessionId,
        @RequestParam(value = "full", required = false) Boolean downloadFull,
        @PathVariable(value = "file") String logFileName) throws IOException {
    UserSession userSession = getSession(sessionId, response);
    if (userSession == null)
        return;/*  w  ww.j a v a2 s. c o  m*/

    if (!userSession.isSpecificPermitted("cuba.gui.administration.downloadlogs")) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;
    }

    // security check, handle only valid file name
    String filename = FilenameUtils.getName(logFileName);

    try {
        File logFile = logControl.getLogFile(filename);

        response.setHeader("Cache-Control", "no-cache");
        response.setHeader("Pragma", "no-cache");
        response.setDateHeader("Expires", 0);
        response.setHeader("Content-Type", "application/zip");
        response.setHeader("Pragma", "no-cache");

        response.setHeader("Content-Disposition", "attachment; filename=" + filename);

        OutputStream outputStream = null;
        try {
            outputStream = response.getOutputStream();

            if (BooleanUtils.isTrue(downloadFull)) {
                LogArchiver.writeArchivedLogToStream(logFile, outputStream);
            } else {
                LogArchiver.writeArchivedLogTailToStream(logFile, outputStream);
            }
        } catch (RuntimeException | IOException ex) {
            log.error("Unable to download file", ex);
            response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        } finally {
            IOUtils.closeQuietly(outputStream);
        }

    } catch (LogFileNotFoundException e) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }
}

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

@Test
public void testWebInf() throws ServletException, IOException {
    final HttpServletResponse response = doGetTest("WEB-INF/web.xml");
    Mockito.verify(response).setStatus(HttpServletResponse.SC_NOT_FOUND);
}

From source file:org.jboss.as.test.integration.web.response.DefaultResponseCodeAtRootTestCase.java

@Test
public void testNormalOpMode() throws Exception {
    deployer.deploy("test");
    try {/*from  w ww  . j  av  a 2 s .  com*/
        HttpGet httpget = new HttpGet(url.toString());
        HttpResponse response = this.httpclient.execute(httpget);
        //403 apparently
        Assert.assertEquals(HttpServletResponse.SC_FORBIDDEN, response.getStatusLine().getStatusCode());
        httpget = new HttpGet(url.toString() + URL_PATTERN + "xxx");
        response = this.httpclient.execute(httpget);
        Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, response.getStatusLine().getStatusCode());
    } finally {
        deployer.undeploy("test");
    }
}

From source file:de.thm.arsnova.controller.UserController.java

@RequestMapping(value = { "/{username}" }, method = RequestMethod.DELETE)
public void activate(@PathVariable final String username, final HttpServletRequest request,
        final HttpServletResponse response) {
    if (null == userService.deleteDbUser(username)) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
    }// w  w  w  .  j av  a 2s .c  o  m
}

From source file:com.sg.rest.SpringSecurityTest.java

@Test
public void testNonExistentResource() throws Exception {
    mockMvc.perform(get(PATH_DO_NOT_EXIST)).andExpect(status().is(HttpServletResponse.SC_NOT_FOUND))
            .andExpect(content().bytes(new byte[0]));
}

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    String searchCriteria = getUserSearchInformation(req.getPathInfo());
    WSUser[] users = null;/*from  ww  w  .j  a  v  a  2  s  .co  m*/
    WSUserSearchCriteria wsUserSearchCriteria = restUtils.getWSUserSearchCriteria(searchCriteria);

    try {
        // get the resources....
        users = userAndRoleManagementService.findUsers(wsUserSearchCriteria);
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, "could not locate users in uri: "
                + wsUserSearchCriteria.getName() + axisFault.getLocalizedMessage());
    }
    if (log.isDebugEnabled()) {
        log.debug("" + users.length + " users were found");
    }

    String marshal = generateSummeryReport(users);
    if (log.isDebugEnabled()) {
        log.debug("Marshaling OK");
    }
    restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, marshal);
}