Example usage for javax.servlet.http HttpServletResponse getStatus

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

Introduction

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

Prototype

public int getStatus();

Source Link

Document

Gets the current status code of this response.

Usage

From source file:com.yoho.core.trace.instrument.web.TraceInterceptor.java

/**
 * Override to add annotations not defined in {@link TraceKeys}.
 */// w w w  .  j a va  2  s.c  o m
protected void addResponseTags(HttpServletResponse response, Throwable e) {
    int httpStatus = response.getStatus();
    if (httpStatus == HttpServletResponse.SC_OK && e != null) {
        // Filter chain threw exception but the response status may not have been set
        // yet, so we have to guess.
        this.tracer.addTag(this.traceKeys.getHttp().getStatusCode(),
                String.valueOf(HttpServletResponse.SC_INTERNAL_SERVER_ERROR));
    } else if ((httpStatus < 200) || (httpStatus > 299)) {
        this.tracer.addTag(this.traceKeys.getHttp().getStatusCode(), String.valueOf(response.getStatus()));
    }
}

From source file:fragment.web.LogoControllerTest.java

private void checkCorrectnessOfMethod(HttpServletResponse response) {
    Assert.assertTrue(response.getContentType().contains("image/"));
    Assert.assertEquals(HttpServletResponse.SC_OK, response.getStatus());
}

From source file:org.springframework.boot.autoconfigure.web.BasicErrorController.java

@ExceptionHandler(Exception.class)
public void handle(HttpServletRequest request, HttpServletResponse response, Exception e) throws Exception {
    this.resolver.resolveException(request, response, null, e);
    if (response.getStatus() == HttpServletResponse.SC_OK) {
        response.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
    }/*w  w w . j ava2 s. co m*/
    // There's only one exception so it's easier for the error controller to identify
    // it this way...
    request.setAttribute(ErrorController.class.getName(), e);
    if (e instanceof BindException) {
        // ... but other error pages might be looking for it here as well
        request.setAttribute(BindingResult.MODEL_KEY_PREFIX + ((BindException) e).getObjectName(), e);
    }
}

From source file:com.netflix.spinnaker.gate.ratelimit.RateLimitingInterceptor.java

@Override
public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler,
        ModelAndView modelAndView) throws Exception {
    // Hystrix et-al can return 429's, which we'll want to intercept to provide a reset header
    if (response.getStatus() == 429 && !response.getHeaderNames().contains(Rate.RESET_HEADER)) {
        response.setIntHeader(Rate.CAPACITY_HEADER, -1);
        response.setIntHeader(Rate.REMAINING_HEADER, 0);
        response.setDateHeader(Rate.RESET_HEADER, ZonedDateTime.now().plusSeconds(5).toEpochSecond());
        response.setHeader(Rate.LEARNING_HEADER, "false");
    }/*from   ww w . j a  v a 2 s  .c o  m*/
}

From source file:com.hp.autonomy.frontend.find.core.web.CustomErrorController.java

@RequestMapping(DispatcherServletConfiguration.NOT_FOUND_ERROR_PATH)
public ModelAndView notFoundError(final HttpServletRequest request, final HttpServletResponse response) {
    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode(MESSAGE_CODE_NOT_FOUND_MAIN).setSubMessageCode(MESSAGE_CODE_NOT_FOUND_SUB)
            .setStatusCode(response.getStatus()).setContactSupport(true).setButtonHref(getErrorUrl(request))
            .build());//  w  w  w  .  j av  a  2 s .  c o m
}

From source file:com.codename1.corsproxy.CORSProxy.java

@Override
protected void service(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
        throws ServletException, IOException {
    super.service(servletRequest, servletResponse);
    if (servletResponse.getStatus() >= 300 && servletResponse.getStatus() < 400) {
        // XMLHTTPRequest automatically follows redirects.  We don't want that, so we'll
        // convert 3xx status to non-standard header that we will parse on the other side.
        servletResponse.setIntHeader("X-CN1-Status", servletResponse.getStatus());
        servletResponse.setStatus(200);/* w  w w . java2s.c om*/
    }
}

From source file:org.openrepose.powerfilter.PowerFilterChain.java

private boolean isResponseOk(HttpServletResponse response) {
    return response.getStatus() < HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
}

From source file:com.hp.autonomy.frontend.find.core.web.CustomErrorController.java

@RequestMapping(DispatcherServletConfiguration.AUTHENTICATION_ERROR_PATH)
public ModelAndView authenticationErrorPage(final HttpServletRequest request,
        final HttpServletResponse response) {
    return controllerUtils.buildErrorModelAndView(new ErrorModelAndViewInfo.Builder().setRequest(request)
            .setMainMessageCode(MESSAGE_CODE_AUTHENTICATION_ERROR_MAIN)
            .setSubMessageCode(MESSAGE_CODE_AUTHENTICATION_ERROR_SUB).setStatusCode(response.getStatus())
            .setButtonHref(getAuthenticationErrorUrl(request)).setAuthError(true).build());
}

From source file:com.netflix.spinnaker.gate.interceptors.RequestLoggingInterceptor.java

@Override
public void afterCompletion(HttpServletRequest request, HttpServletResponse response, Object handler,
        Exception ex) throws Exception {
    // 127.0.0.1 "GET /limecat.jpg HTTP/1.0" 200 2326
    log.debug(String.format("%s \"%s %s %s\" %d %d", sourceIpAddress(request), request.getMethod(),
            getRequestEndpoint(request), request.getProtocol(), response.getStatus(),
            getResponseSize(response)));
}

From source file:de.chludwig.websec.saml2sp.controller.Saml2SPErrorController.java

@RequestMapping(ERROR_PAGE_PATH)
public ModelAndView errorPage(HttpServletRequest request, HttpServletResponse response,
        @CurrentUser ApplicationUser currentUser) {
    ModelAndView modelAndView = Saml2SpController.createModelAndView("error", currentUser);
    modelAndView.addObject("forwardedFrom", request.getAttribute("javax.servlet.forward.request_uri"));
    modelAndView.addObject("statusCode", response.getStatus());
    return modelAndView;
}