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:ch.entwine.weblounge.kernel.security.SecurityFilter.java

/**
 * {@inheritDoc}//from   w ww.  j a va  2  s .  c  om
 * 
 * @see javax.servlet.Filter#doFilter(javax.servlet.ServletRequest,
 *      javax.servlet.ServletResponse, javax.servlet.FilterChain)
 */
@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {

    Site site = null;
    if (!(request instanceof HttpServletRequest)) {
        logger.warn("Received plain servlet request and don't know what to do with it");
        return;
    }

    // Try to map the request to a site
    HttpServletRequest httpRequest = (HttpServletRequest) request;
    URL url = UrlUtils.toURL(httpRequest, false, false);
    site = sites.findSiteByURL(url);
    if (site == null) {
        logger.debug("Request for {} cannot be mapped to any site", httpRequest.getRequestURL());
        ((HttpServletResponse) response).sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // Set the site in the security service
    try {
        logger.trace("Request to {} mapped to site '{}'", httpRequest.getRequestURL(), site.getIdentifier());
        securityService.setSite(site);

        // Select appropriate security filter and apply it
        Filter siteSecurityFilter = siteFilters.get(site);
        if (siteSecurityFilter != null) {
            logger.trace("Security for '{}' is handled by site specific security configuration");
            siteSecurityFilter.doFilter(request, response, chain);
        } else {
            logger.trace("Security for '{}' is handled by default security configuration");
            defaultSecurityFilter.doFilter(request, response, chain);
        }
    } finally {
        securityService.setSite(null);
    }

}

From source file:be.iminds.aiolos.ui.CommonServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // Not necessary for plugin only as standalone app.
    // doGetPlugin allways needed.
    // check whether we are not at .../{webManagerRoot}
    final String pathInfo = request.getPathInfo();
    if (pathInfo == null || pathInfo.equals("/")) {
        String path = request.getRequestURI();
        if (!path.endsWith("/")) {
            path = path.concat("/");
        }//w w  w  . jav  a  2 s.  c o  m
        path = path.concat(LABEL);
        response.sendRedirect(path);
        return;
    }

    int slash = pathInfo.indexOf("/", 1);
    if (slash < 2) {
        slash = pathInfo.length();
    }

    final String label = pathInfo.substring(1, slash);
    if (label != null && label.startsWith(LABEL)) {
        final RequestInfo reqInfo = new RequestInfo(request, LABEL);
        if (reqInfo.extension.equals("html")) {
            doGetPlugin(request, response);
        } else if (reqInfo.extension.equals("json")) {
            renderJSON(response, request.getLocale());
        }
    } else {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
    }
}

From source file:net.triptech.buildulator.web.ProjectController.java

/**
 * Display the edit project form.//  www  .  java2s.  c o  m
 *
 * @param id the id
 * @param uiModel the ui model
 * @param request the request
 * @param response the response
 * @return the string
 */
@RequestMapping(value = "/{id}", params = "edit", method = RequestMethod.GET)
public String editForm(@PathVariable("id") Long id, Model uiModel, final HttpServletRequest request,
        final HttpServletResponse response) {

    String page = "projects/edit";

    Project project = Project.findProject(id);

    if (checkProjectPermission(project, request)) {
        uiModel.addAttribute("project", project);
    } else {
        response.setStatus(HttpServletResponse.SC_NOT_FOUND);
        page = "resourceNotFound";
    }
    return page;
}

From source file:jp.or.openid.eiwg.scim.servlet.Users.java

/**
 * GET?/* ww  w . j  a v a  2 s  . c om*/
 *
 * @param request 
 * @param response ?
 * @throws ServletException
 * @throws IOException
 */
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    // ?
    ServletContext context = getServletContext();

    // ??
    Operation op = new Operation();
    boolean result = op.Authentication(context, request);

    if (!result) {
        // 
        this.errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage());
    } else {
        // ?
        String targetId = request.getPathInfo();
        String attributes = request.getParameter("attributes");
        String filter = request.getParameter("filter");
        String sortBy = request.getParameter("sortBy");
        String sortOrder = request.getParameter("sortOrder");
        String startIndex = request.getParameter("startIndex");
        String count = request.getParameter("count");

        if (targetId != null && !targetId.isEmpty()) {
            // ?'/'???
            targetId = targetId.substring(1);
        }

        // 
        ArrayList<LinkedHashMap<String, Object>> resultList = op.searchUserInfo(context, request, targetId,
                attributes, filter, sortBy, sortOrder, startIndex, count);
        if (resultList != null) {
            ObjectMapper mapper = new ObjectMapper();
            StringWriter writer = new StringWriter();

            // ??
            if (targetId != null && !targetId.isEmpty()) {
                if (!resultList.isEmpty()) {
                    LinkedHashMap<String, Object> resultObject = resultList.get(0);
                    // javaJSON??
                    mapper.writeValue(writer, resultObject);
                    response.setContentType("application/scim+json;charset=UTF-8");
                    response.setHeader("Location", request.getRequestURL().toString());
                    PrintWriter out = response.getWriter();
                    out.println(writer);
                } else {
                    // id?????????
                    this.errorResponse(response, HttpServletResponse.SC_NOT_FOUND, null,
                            MessageConstants.ERROR_NOT_FOUND);
                }
            } else {
                // javaJSON??
                mapper.writeValue(writer, resultList);
                String listResponse = "{\"schemas\":[\"urn:ietf:params:scim:api:messages:2.0:ListResponse\"],";
                listResponse += "\"totalResults\":" + Integer.toString(resultList.size());
                if (resultList.size() > 0) {
                    listResponse += ",\"Resources\":";
                    listResponse += writer.toString();
                }
                listResponse += "}";
                response.setContentType("application/scim+json;charset=UTF-8");
                PrintWriter out = response.getWriter();
                out.println(listResponse);
            }
        } else {
            // 
            this.errorResponse(response, op.getErrorCode(), op.getErrorType(), op.getErrorMessage());
        }
    }

}

From source file:com.oneops.cms.ws.rest.CmRestController.java

@ExceptionHandler(OpsException.class)
public void handleOpsException(OpsException e, HttpServletResponse response) throws IOException {
    sendError(response, HttpServletResponse.SC_NOT_FOUND, e);
}

From source file:com.erudika.para.security.RestAuthFilter.java

private boolean userAuthRequestHandler(HttpServletRequest request, HttpServletResponse response) {
    Authentication userAuth = SecurityContextHolder.getContext().getAuthentication();
    User user = SecurityUtils.getAuthenticatedUser(userAuth);
    String reqUri = request.getRequestURI();
    String method = request.getMethod();
    if (user != null && user.getActive()) {
        App parentApp;//from  w  ww .j ava2s .co  m
        if (userAuth instanceof JWTAuthentication) {
            parentApp = ((JWTAuthentication) userAuth).getApp();
        } else {
            parentApp = Para.getDAO().read(App.id(user.getAppid()));
        }
        if (parentApp != null) {
            String resource = RestUtils.extractResourceName(request);
            if (!parentApp.isAllowedTo(user.getId(), resource, request.getMethod())) {
                RestUtils
                        .returnStatusResponse(response, HttpServletResponse.SC_FORBIDDEN,
                                Utils.formatMessage(
                                        "You don't have permission to access this resource. "
                                                + "[user: {0}, resource: {1} {2}]",
                                        user.getId(), method, reqUri));
                return false;
            }
        } else {
            RestUtils.returnStatusResponse(response, HttpServletResponse.SC_NOT_FOUND, "App not found.");
            return false;
        }
    } else {
        RestUtils.returnStatusResponse(response, HttpServletResponse.SC_UNAUTHORIZED, Utils
                .formatMessage("You don't have permission to access this resource. [{0} {1}]", method, reqUri));
        return false;
    }
    return true;
}

From source file:com.centurylink.mdw.hub.servlet.SoapServlet.java

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

    if (logger.isMdwDebugEnabled()) {
        logger.mdwDebug("SOAP Listener GET Request:\n" + request.getRequestURI()
                + (request.getQueryString() == null ? "" : ("?" + request.getQueryString())));
    }/*  ww  w . j  a v  a 2 s  . c om*/

    if (request.getServletPath().endsWith(RPC_SERVICE_PATH) || RPC_SERVICE_PATH.equals(request.getPathInfo())) {
        Asset rpcWsdlAsset = AssetCache.getAsset(Package.MDW + "/MdwRpcWebService.wsdl", Asset.WSDL);
        response.setContentType("text/xml");
        response.getWriter().print(substituteRuntimeWsdl(rpcWsdlAsset.getStringContent()));
    } else if (request.getPathInfo() == null || request.getPathInfo().equalsIgnoreCase("mdw.wsdl")) {
        // forward to general wsdl
        RequestDispatcher requestDispatcher = request.getRequestDispatcher("/mdw.wsdl");
        requestDispatcher.forward(request, response);
    } else if (request.getPathInfo().toUpperCase().endsWith(Asset.WSDL)) {
        String wsdlAsset = request.getPathInfo().substring(1);
        Asset asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        if (asset == null) {
            // try trimming file extension
            wsdlAsset = wsdlAsset.substring(0, wsdlAsset.length() - 5);
            asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        }
        if (asset == null) {
            // try with lowercase extension
            wsdlAsset = wsdlAsset + ".wsdl";
            asset = AssetCache.getAsset(wsdlAsset, Asset.WSDL);
        }
        if (asset == null) {
            String message = "No WSDL resource found: " + request.getPathInfo().substring(1);
            logger.severe(message);
            response.setStatus(HttpServletResponse.SC_NOT_FOUND);
            response.getWriter().print(message);
        } else {
            response.setContentType("text/xml");
            response.getWriter().print(substituteRuntimeWsdl(asset.getStringContent()));
        }
    } else {
        ServletException ex = new ServletException(
                "HTTP GET not supported for URL: " + request.getRequestURL());
        logger.severeException(ex.getMessage(), ex);
        throw ex;
    }
}

From source file:net.siegmar.japtproxy.JaptProxyServlet.java

/**
 * Check the requested data and forward the request to internal sender.
 *
 * @param req the HttpServletRequest object
 * @param res the HttpServletResponse object
 * @throws ServletException {@inheritDoc}
 * @throws IOException      {@inheritDoc}
 *///from  ww  w  .ja  v  a2s.  c o  m
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse res)
        throws ServletException, IOException {
    res.setBufferSize(Util.DEFAULT_BUFFER_SIZE);

    MDC.put("REQUEST_ID", DigestUtils.md5Hex(Long.toString(System.currentTimeMillis())));

    LOG.debug("Incoming request from IP '{}', " + "User-Agent '{}'", req.getRemoteAddr(),
            req.getHeader(HttpHeaderConstants.USER_AGENT));

    if (LOG.isDebugEnabled()) {
        logHeader(req);
    }

    try {
        japtProxy.handleRequest(req, res);
    } catch (final InvalidRequestException e) {
        LOG.warn(e.getMessage());
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Invalid request");
        return;
    } catch (final UnknownBackendException e) {
        LOG.info(e.getMessage());
        res.sendError(HttpServletResponse.SC_BAD_REQUEST, "Unknown backend");
        return;
    } catch (final ResourceUnavailableException e) {
        LOG.debug(e.getMessage(), e);
        res.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    } catch (final HandlingException e) {
        LOG.error("HandlingException", e);
        res.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
        return;
    } finally {
        MDC.clear();
    }

    res.flushBuffer();
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_TITLE_SEARCH_PATH, method = RequestMethod.GET)
public @ResponseBody Collection<Video> findByTitle(@RequestParam(VideoSvcApi.TITLE_PARAMETER) String title,
        HttpServletResponse response) {//  w  ww .  ja v  a 2 s.  c o m
    Collection<Video> v = videos.findByName(title);
    if (v == null) {
        sendError(response, HttpServletResponse.SC_NOT_FOUND, "Video not found");
    }
    return v;
}

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

@RequestMapping(value = VideoSvcApi.VIDEO_DATA_PATH, method = RequestMethod.GET)
public @ResponseBody void getVideoData(@PathVariable("id") long id, HttpServletResponse response)
        throws IOException {

    try {//from w  w  w  .  ja  va  2 s . c om
        VideoFileManager vfm = VideoFileManager.get();
        if (!videos.containsKey(id))
            response.setStatus(404);
        else if (vfm.hasVideoData(videos.get(id))) {
            Video v = videos.get(id);
            //response.addHeader("Content-Type", v.getContentType ());
            vfm.copyVideoData(v, response.getOutputStream());
        } else {
            response.setStatus(404);
        }
    } catch (IndexOutOfBoundsException e) {

        response.setStatus(HttpServletResponse.SC_NOT_FOUND);

    }

}