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:biz.taoconsulting.dominodav.methods.PROPFIND.java

/**
 * (non-Javadoc)/*from   www  . ja va 2  s .  c om*/
 * 
 * @see biz.taoconsulting.dominodav.methods.AbstractDAVMethod#action()
 */
@SuppressWarnings("deprecation")
protected void action() throws Exception { // TODO: cleanup action method by
    // refactoring -- too messy
    boolean withoutChildren = true; // Resource only, no children
    IDAVRepository rep = this.getRepository();
    IDAVResource resource;
    HttpServletResponse resp = this.getResp();

    // Resource-Path is stripped by the repository name!
    String curPath = null;
    String curURI = null;

    try {
        curPath = (String) this.getHeaderValues().get("resource-path");
        if (curPath == null || curPath.equals("")) {
            curPath = "/";
        }
        // If Depth is missing it might throw an error, so we assume 0 then
        String depth = this.getHeaderValues().get("Depth");
        if (depth != null && depth.equals("0")) {
            withoutChildren = true;
        } else {
            withoutChildren = false;
        }
        // uri is the unique identifier on the host includes servlet and
        // repository but not server
        curURI = (String) this.getHeaderValues().get("uri");

    } catch (Exception e) {
        LOGGER.error(e);
        withoutChildren = true; // No recursive call to propfind in a error
        // condition
    }

    LOGGER.info("PROPFIND for path:[" + curPath + "] and URI:" + curURI);

    IDAVXMLResponse xr = DavXMLResponsefactory.getXMLResponse(null, false);
    if (this.redirectedFromGet) {
        // Determine the style
        String xsltStyle = null;
        if (rep instanceof DAVRepositoryMETA) {
            xsltStyle = WebDavManager.getManager(null).getRootPropfindStyle();
        } else {
            xsltStyle = WebDavManager.getManager(null).getPropfindStyle();
        }
        xr = DavXMLResponsefactory.getXMLResponse(xsltStyle, true);

    } else {
        xr = DavXMLResponsefactory.getXMLResponse(null, true);
    }
    // LOGGER.info("xr OK");
    // xr = DavXMLResponsefactory.getXMLResponse(null, false);

    try {

        // Here we need to retrieve the path without the repository name!
        resource = rep.getResource(curURI, withoutChildren);

        if (resource == null) {
            // LOGGER.info("Resource is null");
            this.setErrorMessage("<h1>404 - Resource not found</h1>", HttpServletResponse.SC_NOT_FOUND);

            String result = this.getErrorMessage();
            resp.setContentLength(result.length());
            PrintWriter out = resp.getWriter();
            out.write(result);
            out.close();

        } else {

            if (!resource.isCollection()) {
                // LOGGER.info("Resource is not a collection");
                this.getResp().setHeader("ETag", resource.getETag());
            }
            // Modified by EC
            // LOGGER.info("Further.....");

            java.util.Date dt = new java.util.Date();
            this.getResp().setHeader("Last-Modified", dt.toGMTString());
            this.getResp().setHeader("Cache-Control", "no-cache");
            dt.setYear(70);
            this.getResp().setHeader("Expires", dt.toGMTString());
            this.getResp().setHeader("Server", "Microsoft-IIS/6.0");
            this.getResp().setHeader("Public-Extension", "http://schemas.microsoft.com/repl-2");
            this.getResp().setHeader("MicrosoftSharePointTeamServices", "12.0.0.6210");
            this.getResp().setHeader("Set-Cookie", "WSS_KeepSessionAuthenticated=80; path=" + curURI);

            // End Mody by EC
            xr.openTag("multistatus");
            resource.addToDavXMLResponse(xr);
            xr.auxTag("username", rep.getCredentials().getUserName());
            xr.addComment("Called method : PROPFIND");
            xr.closeDocument();
            // LOGGER.info("Close doc");
            // Ugly hack: Domino closes connections on status 207
            // and Win7 has a problem with it

            /*
             * if (this.redirectedFromGet ||
             * this.cameFromWindows7webDAVredir(this.getReq())) {
             * this.setHTTPStatus(HttpServletResponse.SC_OK);
             * resp.setStatus(HttpServletResponse.SC_OK); } else {
             * this.setHTTPStatus(DAVProperties.STATUS_MULTIPART);
             * resp.setStatus(DAVProperties.STATUS_MULTIPART,
             * DAVProperties.STATUS_MULTIPART_STRING); }
             */

            this.setHTTPStatus(DAVProperties.STATUS_MULTIPART);
            resp.setStatus(DAVProperties.STATUS_MULTIPART, DAVProperties.STATUS_MULTIPART_STRING);
            resp.setHeader("Connection", "keep-alive");

            resp.setContentType(DAVProperties.TYPE_XML);
            // resp.setContentType("text/xml");
            // resp.setHeader("content-encoding", "utf-8");
            // resp.setContentLength(xr.getXMLBytes().length);
            // ServletOutputStream out = this.getOutputStream();
            // out.write(xr.getXMLBytes());
            // out.close();
            String result = xr.toString();
            resp.setContentLength(result.length());
            PrintWriter out = resp.getWriter();
            out.write(result);
            out.close();
        }

    } catch (DAVNotFoundException exc) {
        // LOGGER.error(exc);
        this.setErrorMessage("<h1>404 - Resource not found</h1>", HttpServletResponse.SC_NOT_FOUND);
        String result = this.getErrorMessage();
        resp.setContentLength(result.length());
        PrintWriter out = resp.getWriter();
        out.write(result);
        out.close();
    } catch (IOException e) {
        // LOGGER.error(e);
        this.setErrorMessage("<h1>500 - We screwed up</h1><h2>" + e.getMessage() + "</h2>",
                HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }

}

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

protected void error(HttpServletResponse response) throws IOException {
    if (!response.isCommitted())
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
}

From source file:controller.MunicipiosRestController.java

/**
*
* @param id//from ww  w  . j  a  v  a2s.c  o m
* @param request
* @param response
* @return XML
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/xml")
public String getByIdXML(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) {

    MunicipiosDAO tabla = new MunicipiosDAO();
    XStream XML;
    Municipios elemento;
    try {
        elemento = tabla.selectById(id);
        if (elemento == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id);
            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);
    }

    XML = new XStream();
    XML.alias("municipio", Municipios.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(elemento);
}

From source file:de.mpg.mpdl.inge.pidcache.web.MainServlet.java

protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {

    logger.info("PID cache POST request");

    if (req.getParameter("url") == null) {
        resp.sendError(HttpServletResponse.SC_NO_CONTENT, "URL parameter failed.");
    }/*from w ww.jav a 2s. co  m*/
    try {

        if (!authenticate(req, resp)) {
            logger.warn("Unauthorized request from " + req.getRemoteHost());
            return;
        }

        PidCacheService cacheService = new PidCacheService();
        String xmlOutput = null;

        if (GwdgPidService.GWDG_PIDSERVICE_CREATE.equals(req.getPathInfo())) {
            xmlOutput = cacheService.create(req.getParameter("url"));
        } else if (GwdgPidService.GWDG_PIDSERVICE_EDIT.equals(req.getPathInfo())) {
            if (req.getParameter("pid") == null) {
                resp.sendError(HttpServletResponse.SC_NO_CONTENT, "PID parameter failed.");
            }
            xmlOutput = cacheService.update(req.getParameter("pid"), req.getParameter("url"));
        } else {
            resp.sendError(HttpServletResponse.SC_NOT_FOUND, req.getPathInfo());
        }

        resp.setStatus(cacheService.getStatus());
        resp.encodeRedirectURL(cacheService.getLocation());
        resp.addHeader("Location", cacheService.getLocation());
        resp.getWriter().append(xmlOutput);
    } catch (Exception e) {
        throw new ServletException("Error processing request", e);
    }
}

From source file:com.carolinarollergirls.scoreboard.jetty.XmlScoreBoardServlet.java

protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    super.doPost(request, response);

    try {/*from   w  ww . ja v a  2 s.co  m*/
        if ("/set".equals(request.getPathInfo()))
            set(request, response);
        else if (!response.isCommitted())
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
    } catch (JDOMException jE) {
        ScoreBoardManager.printMessage("XmlScoreBoardServlet ERROR: " + jE.getMessage());
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }
}

From source file:controller.IndicadoresRestController.java

/**
*
* @param id/*from  w  w w . j  a  v  a  2 s.c  o  m*/
* @param request
* @param response
* @return XML
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/xml")
public String getByIdXML(@PathVariable("id") String id, HttpServletRequest request,
        HttpServletResponse response) {

    IndicadoresDAO tabla = new IndicadoresDAO();
    XStream XML;
    Indicadores elemento;
    try {
        elemento = tabla.selectById(id);
        if (elemento == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id);
            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);
    }

    XML = new XStream();
    XML.alias("indicador", Indicadores.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(elemento);
}

From source file:com.eryansky.modules.sys.web.ProxyController.java

/**
 * ?/*from   w ww.  j  a va 2  s  .  c  o  m*/
 * @param nativeWebRequest
 * @throws IOException
 */
@RequestMapping(value = { "**" })
public ModelAndView proxy(NativeWebRequest nativeWebRequest) throws Exception {
    CustomHttpServletRequestWrapper request = nativeWebRequest
            .getNativeRequest(CustomHttpServletRequestWrapper.class);
    String requestUrl = request.getRequestURI();

    String contentUrl = StringUtils.substringAfterLast(requestUrl, AppConstants.getAdminPath() + "/proxy/");
    String param = AppUtils.joinParasWithEncodedValue(WebUtils.getParametersStartingWith(request, null));//?
    String url = contentUrl + "?" + param;
    logger.debug("proxy url{}", url);
    HttpServletResponse response = nativeWebRequest.getNativeResponse(HttpServletResponse.class);
    HttpCompoents httpCompoents = HttpCompoents.getInstance();//?? ?Cookie?
    Response remoteResponse = httpCompoents.getResponse(url);
    try {
        // 
        if (remoteResponse == null) {
            String errorMsg = "?" + contentUrl;
            logger.error(errorMsg);
            if (WebUtils.isAjaxRequest(request)) {
                WebUtils.renderJson(response, Result.errorResult().setObj(errorMsg));
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND, errorMsg);
            }
            return null;
        }
        HttpResponse httpResponse = remoteResponse.returnResponse();
        HttpEntity entity = httpResponse.getEntity();
        // 
        if (httpResponse.getStatusLine().getStatusCode() >= 400) {
            String errorMsg = "?" + contentUrl;
            logger.error(errorMsg);
            logger.error(httpResponse.getStatusLine().getStatusCode() + "");
            logger.error(EntityUtils.toString(entity, "utf-8"));
            if (WebUtils.isAjaxRequest(request)) {
                WebUtils.renderJson(response, Result.errorResult().setObj(errorMsg));
            } else {
                response.sendError(HttpServletResponse.SC_NOT_FOUND, errorMsg);
            }
            return null;
        }

        // Header
        response.setContentType(entity.getContentType().getValue());
        if (entity.getContentLength() > 0) {
            response.setContentLength((int) entity.getContentLength());
        }
        // 
        InputStream input = entity.getContent();
        OutputStream output = response.getOutputStream();
        // byte?InputStreamOutputStream, ?4k.
        IOUtils.copy(input, output);
        output.flush();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
    }
    return null;
}

From source file:controller.TemasNivel2RestController.java

/**
*
* @param id/*w w w .jav a2 s  .c  om*/
* @param request
* @param response
* @return XML
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/xml")
public String getByIdXML(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) {

    TemasNivel2DAO tabla = new TemasNivel2DAO();
    XStream XML;
    TemasNivel2 elemento;
    try {
        elemento = tabla.selectById(id);
        if (elemento == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id);
            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);
    }

    XML = new XStream();
    XML.alias("Tema-Nivel-2", TemasNivel2.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(elemento);
}

From source file:controller.TemasNivel1RestController.java

/**
*
* @param id/*from ww w .jav  a2s .c  o m*/
* @param request
* @param response
* @return XML
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/xml")
public String getByIdXML(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) {

    TemasNivel1DAO tabla = new TemasNivel1DAO();
    XStream XML;
    TemasNivel1 elemento;
    try {
        elemento = tabla.selectById(id);
        if (elemento == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id);
            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);
    }

    XML = new XStream();
    XML.alias("Tema-Nivel-1", TemasNivel1.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(elemento);
}

From source file:controller.TemasNivel3RestController.java

/**
*
* @param id//from w  w w.  java  2s  . c o m
* @param request
* @param response
* @return XML
*/
@RequestMapping(value = "/{id}", method = RequestMethod.GET, produces = "application/xml")
public String getByIdXML(@PathVariable("id") int id, HttpServletRequest request, HttpServletResponse response) {

    TemasNivel3DAO tabla = new TemasNivel3DAO();
    XStream XML;
    TemasNivel3 elemento;
    try {
        elemento = tabla.selectById(id);
        if (elemento == null) {
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            Error e = new Error();
            e.setTypeAndDescription("Warning", "No existe el elemeto solicitado con id:" + id);
            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);
    }

    XML = new XStream();
    XML.alias("Tema-Nivel-3", TemasNivel3.class);
    response.setStatus(HttpServletResponse.SC_OK);
    return XML.toXML(elemento);
}