Example usage for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE

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

Introduction

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

Prototype

int SC_SERVICE_UNAVAILABLE

To view the source code for javax.servlet.http HttpServletResponse SC_SERVICE_UNAVAILABLE.

Click Source Link

Document

Status code (503) indicating that the HTTP server is temporarily overloaded, and unable to handle the request.

Usage

From source file:org.jboss.web.loadbalancer.LoadbalancerServlet.java

protected void handleRequest(HttpServletRequest request, HttpServletResponse response, int requestMethod)
        throws ServletException, IOException {
    HttpMethod method = null;//from   w  w  w.j a  va 2 s. c o m

    initLoadbalancerDelegate();

    // get target host from scheduler
    try {
        method = loadbalancer.createMethod(request, response, requestMethod);
    } catch (NoHostAvailableException nhae) {
        log.error("We have no host to schedule request - giving up");
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE, nhae.getMessage());
        return;
    }
    loadbalancer.addRequestData(request, method);

    // do handle the request
    loadbalancer.handleRequest(request, response, method);
}

From source file:nl.ctrlaltdev.harbinger.filter.BlacklistFilter.java

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
        throws IOException, ServletException {
    if (!ctx.isBlacklisted(request.getRemoteAddr(), Instant.now())) {
        chain.doFilter(request, response);
    } else if (response instanceof HttpServletResponse) {
        ((HttpServletResponse) response).sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
    }//  ww  w .j  a  v a  2 s  .co m
}

From source file:com.cloudera.oryx.kmeans.serving.web.AssignServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;// w  ww  .  ja v  a  2  s . c om
    }
    String line = pathInfo.subSequence(1, pathInfo.length()).toString();
    Generation generation = getGenerationManager().getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;
    }

    RealVector vec = generation.toVector(DelimitedDataUtils.decode(line));
    if (vec == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
    }

    int assignment = DistanceToNearestServlet.findClosest(generation, vec).getClosestCenterId();
    response.getWriter().write(Integer.toString(assignment));
}

From source file:com.cloudera.oryx.kmeans.serving.web.AddServlet.java

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

    KMeansGenerationManager generationManager = getGenerationManager();
    Generation generation = generationManager.getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;/*from www .  jav  a 2  s .  c  om*/
    }

    for (CharSequence line : CharStreams.readLines(request.getReader())) {
        generationManager.append(line);

        RealVector vec = generation.toVector(DelimitedDataUtils.decode(line));
        if (vec == null) {
            response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
            return;
        }

        // TODO update the centers, along the lines of Meyerson et al.
    }

}

From source file:cn.leancloud.diamond.server.controller.ConfigController.java

public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) {
    response.setHeader("Content-Type", "text/html;charset=UTF-8");
    final String address = getRemortIP(request);
    if (address == null) {
        // ?400//  w  w w. j  a v  a2 s.com
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "400";
    }

    if (GlobalCounter.getCounter().decrementAndGet() >= 0) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return "503";
    }

    String md5 = this.configService.getContentMD5(dataId, group);
    if (md5 == null) {
        return "404";
    }

    response.setHeader(Constants.CONTENT_MD5, md5);

    // 304???double-check??
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    String path = configService.getConfigInfoPath(dataId, group);
    // ?
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    // ?
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache,no-store");
    return "forward:" + path;
}

From source file:com.cloudera.oryx.kmeans.serving.web.DistanceToNearestServlet.java

@Override
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException {
    CharSequence pathInfo = request.getPathInfo();
    if (pathInfo == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "No path");
        return;//ww w.ja  v a 2 s  .  c  om
    }
    String line = pathInfo.subSequence(1, pathInfo.length()).toString();

    Generation generation = getGenerationManager().getCurrentGeneration();
    if (generation == null) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE,
                "API method unavailable until model has been built and loaded");
        return;
    }

    String[] tokens = DelimitedDataUtils.decode(line);
    RealVector vector = generation.toVector(tokens);
    if (vector == null) {
        response.sendError(HttpServletResponse.SC_BAD_REQUEST, "Wrong column count");
        return;
    }
    double distance = findClosest(generation, vector).getSquaredDistance();
    response.getWriter().write(Double.toString(distance));
}

From source file:com.taobao.diamond.server.controller.ConfigController.java

public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) {
    response.setHeader("Content-Type", "text/html;charset=GBK");
    final String address = getRemortIP(request);
    if (address == null) {
        // 400//from ww  w.  ja va 2  s  . c o  m
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "400";
    }

    if (GlobalCounter.getCounter().decrementAndGet() >= 0) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return "503";
    }

    String md5 = this.configService.getContentMD5(dataId, group);
    if (md5 == null) {
        return "404";
    }

    response.setHeader(Constants.CONTENT_MD5, md5);

    // 304double-check
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    String path = configService.getConfigInfoPath(dataId, group);
    // 
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    // 
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache,no-store");
    return "forward:" + path;
}

From source file:com.mengka.diamond.server.controller.ConfigController.java

/**
 * ???//from www.  j  a  v a 2s . c  om
 * 
 * @param request
 * @param dataId
 * @param group
 *            ?
 * @return
 */
@RequestMapping(method = RequestMethod.GET)
public String getConfig(HttpServletRequest request, HttpServletResponse response, String dataId, String group) {
    response.setHeader("Content-Type", "text/html;charset=utf-8");
    final String address = getRemortIP(request);
    if (address == null) {
        // ?400
        response.setStatus(HttpServletResponse.SC_BAD_REQUEST);
        return "400";
    }

    if (GlobalCounter.getCounter().decrementAndGet() >= 0) {
        response.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return "503";
    }

    String md5 = this.configService.getContentMD5(dataId, group);
    if (md5 == null) {
        return "404";
    }

    response.setHeader(Constants.CONTENT_MD5, md5);

    // 304???double-check??
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    String path = configService.getConfigInfoPath(dataId, group);
    // ?
    if (diskService.isModified(dataId, group)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return "304";
    }
    // ?
    response.setHeader("Pragma", "no-cache");
    response.setDateHeader("Expires", 0);
    response.setHeader("Cache-Control", "no-cache,no-store");
    return "forward:" + path;
}

From source file:org.jitsi.rest.AbstractJSONHandler.java

/**
 * Analyzes response IQ returned by {@code AbstractJSONHandler#handle()}
 * method(s) and translates XMPP error into HTTP status code.
 *
 * @param responseIQ the IQ that is not {@link ColibriConferenceIQ} from
 *        which XMPP error will be extracted.
 * @return HTTP status code//from  ww  w  .j a va 2  s.  c  o m
 */
protected static int getHttpStatusCodeForResultIq(IQ responseIQ) {
    String condition = responseIQ.getError().getCondition();

    if (XMPPError.Condition.not_authorized.toString().equals(condition)) {
        return HttpServletResponse.SC_UNAUTHORIZED;
    } else if (XMPPError.Condition.service_unavailable.toString().equals(condition)) {
        return HttpServletResponse.SC_SERVICE_UNAVAILABLE;
    } else {
        return HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
    }
}

From source file:org.apache.camel.component.http.CamelServlet.java

@Override
protected void service(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
    if (log.isTraceEnabled()) {
        log.trace("Service: " + request);
    }/*from   w  ww . j a  va 2  s .  c o m*/

    // Is there a consumer registered for the request.
    HttpConsumer consumer = resolve(request);
    if (consumer == null) {
        response.sendError(HttpServletResponse.SC_NOT_FOUND);
        return;
    }

    // are we suspended?
    if (consumer.isSuspended()) {
        response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
        return;
    }

    // create exchange and set data on it
    Exchange exchange = new DefaultExchange(consumer.getEndpoint(), ExchangePattern.InOut);
    if (consumer.getEndpoint().isBridgeEndpoint()) {
        exchange.setProperty(Exchange.SKIP_GZIP_ENCODING, Boolean.TRUE);
    }
    if (consumer.getEndpoint().isDisableStreamCache()) {
        exchange.setProperty(Exchange.DISABLE_HTTP_STREAM_CACHE, Boolean.TRUE);
    }

    HttpHelper.setCharsetFromContentType(request.getContentType(), exchange);
    exchange.setIn(new HttpMessage(exchange, request, response));

    try {
        if (log.isTraceEnabled()) {
            log.trace("Processing request for exchangeId: " + exchange.getExchangeId());
        }
        // process the exchange
        consumer.getProcessor().process(exchange);
    } catch (Exception e) {
        exchange.setException(e);
    }

    try {
        if (log.isTraceEnabled()) {
            log.trace("Writing response for exchangeId: " + exchange.getExchangeId());
        }

        // now lets output to the response
        consumer.getBinding().writeResponse(exchange, response);
    } catch (IOException e) {
        log.error("Error processing request", e);
        throw e;
    } catch (Exception e) {
        log.error("Error processing request", e);
        throw new ServletException(e);
    }
}