Example usage for javax.servlet.http HttpServletResponse sendError

List of usage examples for javax.servlet.http HttpServletResponse sendError

Introduction

In this page you can find the example usage for javax.servlet.http HttpServletResponse sendError.

Prototype

public void sendError(int sc) throws IOException;

Source Link

Document

Sends an error response to the client using the specified status code and clears the buffer.

Usage

From source file:ru.mystamps.web.controller.CategoryController.java

@GetMapping(Url.INFO_CATEGORY_BY_ID_PAGE)
public View showInfoById(@Category @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }//from  w  w w  . j  a v  a2  s  .  co m

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_CATEGORY_PAGE);

    return view;
}

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:de.mpg.escidoc.pubman.sword.PubManServiceDocumentServlet.java

/** 
 * Process the POST request. This will return an unimplemented response.
 * @param HttpServletRequest//from   w  w w. ja  v  a 2  s  .co m
 * @param HttpServletResponse
 * @throws ServletException
 * @throws IOException
 */
protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    response.sendError(HttpServletResponse.SC_NOT_IMPLEMENTED);
}

From source file:fr.norad.servlet.sample.html.template.IndexTemplateServlet.java

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    if (template == null) {
        resp.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;//from   ww  w  .  j  ava 2 s  .  c  o  m
    }

    HashMap<String, String> hashMap = new HashMap<>(properties);
    String contextPath = req.getContextPath();
    if (contextPathSuffix != null && !contextPathSuffix.equals("")) {
        contextPath += contextPathSuffix;
    }
    hashMap.put("contextPath", contextPath);
    hashMap.put("fullWebPath", req.getRequestURL().toString().replace(req.getRequestURI(), contextPath));

    String response = StrSubstitutor.replace(template, hashMap);

    resp.setStatus(200);
    resp.setContentType("text/html; charset=utf-8");
    resp.getWriter().write(response);
}

From source file:com.enonic.cms.web.CmsDispatcherServlet.java

protected void doService(HttpServletRequest req, HttpServletResponse res) throws Exception {
    final HttpMethod requestMethod = HttpMethod.valueOf(req.getMethod());

    if (!ALLOWED_HTTP_METHODS.contains(requestMethod)) {
        res.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
        return;//w ww.j  a  v a 2s.c o  m
    }

    ServletRequestAccessor.setRequest(req);
    OriginalUrlResolver.resolveOriginalUrl(req);

    super.doService(req, res);
}

From source file:ru.mystamps.web.controller.CountryController.java

/**
 * @author Aleksander Parkhomenko/*from w  w w.j a v a2  s  .  c o m*/
 */
@GetMapping(Url.INFO_COUNTRY_BY_ID_PAGE)
public View showInfoById(@Country @PathVariable("slug") LinkEntityDto country, HttpServletResponse response)
        throws IOException {

    if (country == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return null;
    }

    RedirectView view = new RedirectView();
    view.setStatusCode(HttpStatus.MOVED_PERMANENTLY);
    view.setUrl(Url.INFO_COUNTRY_PAGE);

    return view;
}

From source file:ee.ria.xroad.proxy.testsuite.testcases.ServerProxyHttpError.java

@Override
public AbstractHandler getServerProxyHandler() {
    return new AbstractHandler() {
        @Override//from  w ww.java2s  . c o  m
        public void handle(String target, Request baseRequest, HttpServletRequest request,
                HttpServletResponse response) throws IOException {
            // Read all of the request.
            IOUtils.readLines(request.getInputStream());

            response.sendError(HttpServletResponse.SC_BAD_GATEWAY);
            baseRequest.setHandled(true);
        }
    };
}

From source file:net.incrementalism.tooter.ProfileServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    User currentUser = getCurrentUser(request);
    if (currentUser == null) {
        response.sendError(HttpServletResponse.SC_FORBIDDEN);
        return;//www  .j a  v a2  s . co  m
    }
    displayProfile(currentUser, request, response);
}

From source file:net.duckling.ddl.web.api.APIAndroidMessagePullController.java

@RequestMapping
public void init(HttpServletRequest req, HttpServletResponse resp) throws IOException {
    String uid = findUser(req);//from   ww w  . j av a2 s  . com
    if (StringUtils.isEmpty(uid) || "Guest".equals(uid)) {
        resp.sendError(401);
        JSONObject obj = new JSONObject();
        obj.put("error", "!");
        JsonUtil.writeJSONObject(resp, obj);
        return;
    }
    String sessionId = req.getSession().getId();
    AndroidMessageBean bean = androidNoticeHandler.getUserMessage(uid, sessionId);
    JSONObject obj = new JSONObject();
    addMessage(bean, obj);
    if (bean.getLatestMessageTeamId() > 0) {
        Team team = teamService.getTeamByID(bean.getLatestMessageTeamId());
        if (team != null) {
            obj.put("latestMesageTeamCode", team.getName());
            obj.put("latestMesageTeamName", team.getDisplayName());
        }
    }
    JsonUtil.writeJSONObject(resp, obj);
}

From source file:grails.plugin.springsecurity.web.filter.IpAddressFilter.java

protected void deny(final HttpServletRequest req, final HttpServletResponse res) throws IOException {
    // send 404 to hide the existence of the resource
    res.sendError(HttpServletResponse.SC_NOT_FOUND);
}