Example usage for org.springframework.http HttpStatus valueOf

List of usage examples for org.springframework.http HttpStatus valueOf

Introduction

In this page you can find the example usage for org.springframework.http HttpStatus valueOf.

Prototype

public static HttpStatus valueOf(int statusCode) 

Source Link

Document

Return the enum constant of this type with the specified numeric value.

Usage

From source file:de.qucosa.spring.ResourceExceptionHandler.java

@ExceptionHandler(FedoraClientException.class)
public ResponseEntity fedoraClientExceptionHandler(FedoraClientException fe) {
    log.warn(fe);//from  w  w  w. j  a  v  a  2  s.com
    return new ResponseEntity(HttpStatus.valueOf(fe.getStatus()));
}

From source file:com.epam.ta.reportportal.commons.exception.rest.RestErrorDefinition.java

public RestErrorDefinition(int httpStatus, ErrorType error,
        ExceptionMessageBuilder<T> exceptionMessageBuilder) {
    this(HttpStatus.valueOf(httpStatus), error, exceptionMessageBuilder);
}

From source file:com.example.NettyClientController.java

private Mono<HttpStatus> fetch(int value) {
    return this.client.get(url).map(inbound -> HttpStatus.valueOf(inbound.status().code()));
}

From source file:ar.com.aleatoria.ue.rest.SimpleClientHttpResponse.java

@Override
public HttpStatus getStatusCode() throws IOException {
    try {//from  w ww .  j  a v a  2 s  . c  o m
        return HttpStatus.valueOf(getRawStatusCode());
    } catch (IOException ex) {
        /* 
         * If credentials are incorrect or not provided for Basic Auth, then 
         * Android throws this exception when an HTTP 401 is received. Checking 
         * for this response and returning the proper status.
         */
        if (ex.getLocalizedMessage().equals(AUTHENTICATION_ERROR)) {
            return HttpStatus.UNAUTHORIZED;
        } else {
            throw ex;
        }
    }
}

From source file:com.github.ljtfreitas.restify.http.spring.client.call.exec.ResponseEntityConverter.java

@Override
public ResponseEntity<T> convert(EndpointResponse<T> source) {
    return new ResponseEntity<T>(source.body(), headersOf(source.headers()),
            HttpStatus.valueOf(source.code().value()));
}

From source file:marytts.http.controllers.MaryErrorController.java

private HttpStatus getStatus(HttpServletRequest request) {
    Integer statusCode = (Integer) request.getAttribute("javax.servlet.error.status_code");
    if (statusCode == null) {
        return HttpStatus.INTERNAL_SERVER_ERROR;
    }//  www .  ja va2  s  .  c  om
    return HttpStatus.valueOf(statusCode);
}

From source file:org.frat.common.controller.ErrorController.java

private String getExceptionMessage(Throwable throwable, Integer statusCode) {
    if (throwable != null) {
        return throwable.getMessage();
    }//from  ww  w. j a  v  a  2  s . c  o  m
    HttpStatus httpStatus = HttpStatus.valueOf(statusCode);
    return httpStatus.getReasonPhrase();
}

From source file:UrlEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    System.setProperty("http.keepAlive", "true");

    ResponseEntity<String> responseEntity = null;
    URL obj = new URL(requestOptions.getUrl());

    for (int i = 0; i < requestOptions.getCount(); i++) {
        HttpURLConnection con = (HttpURLConnection) obj.openConnection();

        // add request header
        con.setRequestMethod("GET");
        con.setConnectTimeout(2000);//  w  w  w  .  jav a  2s .c om
        for (Map.Entry<String, String> e : requestOptions.getHeaderMap().entrySet()) {
            con.setRequestProperty(e.getKey(), e.getValue());
        }

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        con.connect();

        int responseCode = con.getResponseCode();
        System.out.println("Response Code : " + responseCode);

        final InputStream is = con.getInputStream();
        String response = IOUtils.toString(is);
        is.close();

        //print result
        System.out.println(response);

        responseEntity = new ResponseEntity<String>(response, HttpStatus.valueOf(responseCode));
    }
    return responseEntity;
}

From source file:OkHttpEngine.java

@Override
public ResponseEntity<String> submit(JCurlRequestOptions requestOptions) throws Exception {
    OkHttpClient client = new OkHttpClient.Builder().connectTimeout(2000, TimeUnit.MILLISECONDS)
            .sslSocketFactory(SSLContext.getDefault().getSocketFactory()).followSslRedirects(true).build();

    ResponseEntity<String> responseEntity = null;

    for (int i = 0; i < requestOptions.getCount(); i++) {
        final Request.Builder requestBuilder = new Request.Builder().url(requestOptions.getUrl())
                .headers(Headers.of(requestOptions.getHeaderMap())).get();
        Request request = requestBuilder.build();

        System.out.println("\nSending 'GET' request to URL : " + requestOptions.getUrl());
        Response response = client.newCall(request).execute();

        int responseCode = response.code();
        System.out.println("Response Code : " + responseCode);

        final InputStream is = response.body().byteStream();
        String responseContent = IOUtils.toString(is);
        is.close();/*w  w w.  j  a  v  a2s .co  m*/

        //print result
        System.out.println(responseContent);

        responseEntity = new ResponseEntity<String>(responseContent, HttpStatus.valueOf(responseCode));
    }
    return responseEntity;
}

From source file:fr.esiea.esieaddress.controllers.exception.ExceptionHandlerCtrl.java

@ExceptionHandler(value = { RestException.class })
protected ResponseEntity<Object> handleException(RestException ex, WebRequest request) {
    LOGGER.info("An exception was catch by spring mvc :" + ex.getClass() + " : " + ex.getMessage());
    Object model = ex.getModel();
    return new ResponseEntity<Object>(model, HttpStatus.valueOf(ex.getStatus()));
}