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.acc.storefront.controllers.pages.GuestOrderController.java

@RequestMapping(value = "/order/" + ORDER_GUID_PATH_VARIABLE_PATTERN, method = RequestMethod.GET)
public String order(@PathVariable("orderGUID") final String orderGUID, final Model model,
        final HttpServletResponse response) throws CMSItemNotFoundException {
    try {/*from  ww w.j av a 2s  . co  m*/
        storeCmsPageInModel(model, getContentPageForLabelOrId(ORDER_DETAIL_CMS_PAGE));
        model.addAttribute("metaRobots", "no-index,no-foollow");
        setUpMetaDataForContentPage(model, getContentPageForLabelOrId(ORDER_DETAIL_CMS_PAGE));
        final OrderData orderDetails = orderFacade.getOrderDetailsForGUID(orderGUID);
        model.addAttribute("orderData", orderDetails);
    } catch (final UnknownIdentifierException e) {
        LOG.warn("Attempted to load a order that does not exist or is not visible");
        model.addAttribute("metaRobots", "no-index,no-follow");
        GlobalMessages.addErrorMessage(model, "system.error.page.not.found");
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        return ControllerConstants.Views.Pages.Error.ErrorNotFoundPage;
    } catch (final IllegalArgumentException ae) {
        return REDIRECT_ORDER_EXPIRED;

    }
    return ControllerConstants.Views.Pages.Guest.GuestOrderPage;
}

From source file:org.keycloak.secretstore.boundary.QRCodeServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String tokenIdAsString = req.getParameter("tokenId");
    String sizeAsString = req.getParameter("size");
    Principal principal = req.getUserPrincipal();

    int size = 250;

    if (null != sizeAsString && !sizeAsString.isEmpty()) {
        try {//from  www.  j a  va2s .  com
            size = Integer.parseInt(req.getParameter("size"));
        } catch (Throwable t) {
            resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Size is invalid.");
            return;
        }
    }

    if (null == tokenIdAsString || tokenIdAsString.isEmpty()) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Token key is missing.");
        return;
    }

    UUID tokenId;
    try {
        tokenId = UUID.fromString(tokenIdAsString);
    } catch (Throwable t) {
        resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Token key is invalid.");
        return;
    }

    Token token = tokenService.getByIdForDistribution(tokenId);
    if (null == token) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Token could not be found.");
        return;
    }

    if (!principal.getName().equals(token.getPrincipal())) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND, "Token could not be found for principal.");
        return;
    }

    String response = token.getId().toString() + "," + token.getSecret();

    if (null != token.getExpiresAt()) {
        response += "," + token.getExpiresAt().toString();
    }

    BitMatrix bitMatrix;
    try {
        QRCodeWriter writer = new QRCodeWriter();
        bitMatrix = writer.encode(response, BarcodeFormat.QR_CODE, size, size);
    } catch (WriterException e) {
        resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Error while generating the QR Code.");
        return;
    }

    ByteArrayOutputStream pngOut = new ByteArrayOutputStream();
    MatrixToImageWriter.writeToStream(bitMatrix, "PNG", pngOut);
    byte[] pngData = pngOut.toByteArray();

    resp.setStatus(HttpServletResponse.SC_OK);
    resp.setContentType("image/png");
    resp.getOutputStream().write(pngData);
}

From source file:com.kixeye.chassis.transport.swagger.SwaggerServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    // figure out the real path
    String pathInfo = StringUtils.trimToEmpty(req.getPathInfo());

    while (pathInfo.endsWith("/")) {
        pathInfo = StringUtils.removeEnd(pathInfo, "/");
    }/*from  ww w .j  a v  a2 s.  com*/

    while (pathInfo.startsWith("/")) {
        pathInfo = StringUtils.removeStart(pathInfo, "/");
    }

    if (StringUtils.isBlank(pathInfo)) {
        resp.sendRedirect(rootContextPath + "/" + WELCOME_PAGE);
    } else {
        // get the resource
        AbstractFileResolvingResource resource = (AbstractFileResolvingResource) resourceLoader
                .getResource(SWAGGER_DIRECTORY + "/" + pathInfo);

        // send it to the response
        if (resource.exists()) {
            StreamUtils.copy(resource.getInputStream(), resp.getOutputStream());
            resp.setStatus(HttpServletResponse.SC_OK);
            resp.flushBuffer();
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        }
    }
}

From source file:controller.MunicipiosRestController.java

/**
 *
 * @param request/*from w ww .  ja va 2 s . c o  m*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    MunicipiosDAO tabla = new MunicipiosDAO();
    XStream XML;
    List<Municipios> lista;

    try {
        lista = tabla.selectAll();

        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<Municipios> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("municipio", Municipios.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}

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

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    String mediaType = getExpectedMediaType(request);
    String pathInfo = StringUtils.trimToNull(request.getPathInfo());
    if (mediaType == null || !MEDIA_TYPE_JSON.equals(mediaType)) {
        response.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
        response.setContentLength(0);/*from ww w .java 2s  .  com*/
    } else if (pathInfo == null || pathInfo.length() == 1) {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        response.setContentLength(0);
    } else {
        String datasourceAcronym = null;
        String vocabRefId = null;
        boolean pending = Boolean.parseBoolean(request.getParameter("pending"));
        int i = pathInfo.indexOf('/', 1);
        if (i != -1) {
            datasourceAcronym = pathInfo.substring(1, i);
            vocabRefId = pathInfo.substring(i + 1);
        } else {
            datasourceAcronym = pathInfo.substring(1);
        }
        serialize(datasourceAcronym, vocabRefId, pending, response);
    }
}

From source file:controller.IndicadoresRestController.java

/**
 *
 * @param request/* www.j av a  2  s .  c  o  m*/
 * @param response
 * @return XML
 */
@RequestMapping(method = RequestMethod.GET, produces = "application/xml")
public String getXML(HttpServletRequest request, HttpServletResponse response) {
    IndicadoresDAO tabla = new IndicadoresDAO();
    XStream XML;
    List<Indicadores> lista;

    try {
        lista = tabla.selectAll();

        if (lista.isEmpty()) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existen elementos");
            XML = new XStream();
            XML.alias("message", Error.class);
            return XML.toXML(e);
        }
    } catch (HibernateException ex) {
        response.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        Error e = new Error();
        e.setTypeAndDescription("errorServerError", ex.getMessage());
        XML = new XStream();
        XML.alias("message", Error.class);
        return XML.toXML(e);
    }

    Datos<Indicadores> datos = new Datos<>();
    datos.setDatos(lista);
    XML = new XStream();
    XML.alias("indicador", Indicadores.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(lista);
}

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

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServiceException {
    try {//from  w ww .java2  s.  c om
        // Get the uri of the resource
        long jobId = getJobId(restUtils.extractRepositoryUri(req.getPathInfo()));

        // get the resources....
        Job job = reportSchedulerService.getJob(jobId);

        StringWriter sw = new StringWriter();
        // create JAXB context and instantiate marshaller

        restUtils.getMarshaller(Job.class).marshal(job, sw);

        restUtils.setStatusAndBody(HttpServletResponse.SC_OK, resp, sw.toString());

    } catch (JAXBException e) {
        throw new ServiceException(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e.getMessage());
    } catch (AxisFault axisFault) {
        throw new ServiceException(HttpServletResponse.SC_NOT_FOUND, axisFault.getMessage());
    }
}

From source file:io.liuwei.web.StaticContentServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ??//from  w  ww .  j  av a 2  s . com
    String contentPath = request.getPathInfo();
    if (StringUtils.isBlank(contentPath) || "/".equals(contentPath)) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "contentPath parameter is required.");
        return;
    }

    // ??.
    ContentInfo contentInfo = getContentInfo(contentPath);
    if (!contentInfo.file.exists()) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, "file not found.");
        return;
    }

    // ?EtagModifiedSince Header?, ??304,.
    if (!Servlets.checkIfModifiedSince(request, response, contentInfo.lastModified)
            || !Servlets.checkIfNoneMatchEtag(request, response, contentInfo.etag)) {
        return;
    }

    // Etag/
    Servlets.setExpiresHeader(response, Servlets.ONE_YEAR_SECONDS);
    Servlets.setLastModifiedHeader(response, contentInfo.lastModified);
    Servlets.setEtag(response, contentInfo.etag);

    // MIME
    response.setContentType(contentInfo.mimeType);

    // ?Header
    if (request.getParameter("download") != null) {
        Servlets.setFileDownloadHeader(response, contentInfo.fileName);
    }

    // OutputStream
    OutputStream output;
    if (checkAccetptGzip(request) && contentInfo.needGzip) {
        // outputstream, http1.1 trunked??content-length.
        output = buildGzipOutputStream(response);
    } else {
        // outputstream, content-length.
        response.setContentLength(contentInfo.length);
        output = response.getOutputStream();
    }

    // ?,?input file
    FileUtils.copyFile(contentInfo.file, output);
    output.flush();
}

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

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

    setSpecificPartPath(Utils.getSpecificPath(request, null));
    ResearchObject dyn = extractDynamicObject(request);

    if (dyn == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND, getSpecificPartPath() + " page not found");
        return null;
    }/*from   w  ww . ja va 2 s . c  o m*/

    Context context = UIUtil.obtainContext(request);
    EPerson currentUser = context.getCurrentUser();
    if ((dyn.getStatus() == null || dyn.getStatus().booleanValue() == false)
            && !AuthorizeManager.isAdmin(context)) {

        if (currentUser != 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 (AuthorizeManager.isAdmin(context)) {
        model.put("do_page_menu", new Boolean(true));
    }

    ModelAndView mvc = null;

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

    if (subscribeService != null) {
        boolean subscribed = subscribeService.isSubscribed(currentUser, dyn);
        model.put("subscribed", subscribed);
    }

    request.setAttribute("sectionid", StatsConfig.DETAILS_SECTION);
    new DSpace().getEventService().fireEvent(new UsageEvent(UsageEvent.Action.VIEW, request, context, dyn));

    mvc.getModel().putAll(model);
    mvc.getModel().put("entity", dyn);
    return mvc;
}

From source file:com.thoughtworks.go.domain.ChecksumFileHandlerTest.java

@Test
public void shouldHandleResultIfHttpCodeSaysFileNotFound() {
    StubGoPublisher goPublisher = new StubGoPublisher();
    assertThat(checksumFileHandler.handleResult(HttpServletResponse.SC_NOT_FOUND, goPublisher), is(true));
    assertThat(goPublisher.getMessage(), containsString(String.format(
            "[WARN] The md5checksum property file was not found on the server. Hence, Go can not verify the integrity of the artifacts.",
            file)));//from   w ww.  j av  a 2  s. c o  m
}