Example usage for org.springframework.http HttpStatus toString

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

Introduction

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

Prototype

@Override
public String toString() 

Source Link

Document

Return a string representation of this status code.

Usage

From source file:ch.wisv.areafiftylan.utils.ResponseEntityBuilder.java

/**
 * Create a standard response for all requests to the API
 *
 * @param httpStatus  The HTTP Status of the response
 * @param httpHeaders Optional Http Headers for the response.
 * @param message     The message in human readable String format
 * @param object      Optional object related to the request (like a created User)
 *
 * @return The ResponseEntity in standard Area FiftyLAN format.
 *///w  w  w.j a  v a 2  s.com
public static ResponseEntity<?> createResponseEntity(HttpStatus httpStatus, HttpHeaders httpHeaders,
        String message, Object object) {
    Map<String, Object> responseBody = new LinkedHashMap<>();
    responseBody.put("status", httpStatus.toString());
    responseBody.put("timestamp", LocalDateTime.now().toString());
    responseBody.put("message", message);
    responseBody.put("object", object);

    if (httpHeaders == null) {
        httpHeaders = new HttpHeaders();
    }
    return new ResponseEntity<>(responseBody, httpHeaders, httpStatus);
}

From source file:org.ega_archive.elixircore.controller.exception.CustomErrorController.java

@RequestMapping(value = "${error.path:/error}")
@ResponseBody/*from   w  w w. j  a v a2 s. c om*/
public Base<String> error(HttpServletRequest request) {
    Map<String, Object> body = getErrorAttributes(request, getTraceParameter(request));
    HttpStatus status = getStatus(request);

    return new Base<String>(status.toString(), new Exception((String) body.get("message")));
}

From source file:de.hybris.platform.marketplaceintegrationbackoffice.utils.MarketplaceintegrationbackofficeHttpClientImpl.java

@Override
public boolean redirectRequest(final String requestUrl) throws IOException {

    final boolean result = true;
    final RestTemplate restTemplate = new RestTemplate();

    final java.net.URI uri = java.net.URI.create(requestUrl);
    final java.awt.Desktop dp = java.awt.Desktop.getDesktop();
    if (dp.isSupported(java.awt.Desktop.Action.BROWSE)) {
        dp.browse(uri);//from  w  w  w  .j  ava 2  s.  c  om
    }
    restTemplate.execute(requestUrl, HttpMethod.GET, new RequestCallback() {
        @Override
        public void doWithRequest(final ClientHttpRequest request) throws IOException {
            // empty block should be documented
        }
    }, new ResponseExtractor<Object>() {
        @Override
        public Object extractData(final ClientHttpResponse response) throws IOException {
            final HttpStatus statusCode = response.getStatusCode();
            LOG.debug("Response status: " + statusCode.toString());
            return response.getStatusCode();
        }
    });
    return result;
}

From source file:org.openwms.core.http.AbstractWebController.java

/**
 * Build a response object that signals a not-okay response with a given status {@code code}.
 *
 * @param <T> Some type extending the AbstractBase entity
 * @param code The status code to set as response code
 * @param msg The error message passed to the caller
 * @param msgKey The error message key passed to the caller
 * @param params A set of Serializable objects that are passed to the caller
 * @return A ResponseEntity with status {@code code}
 *//*from  ww  w  . j a v a2s. c om*/
protected <T extends AbstractBase> ResponseEntity<Response<T>> buildResponse(HttpStatus code, String msg,
        String msgKey, T... params) {
    Response result = new Response(msg, msgKey, code.toString(), params);
    //result.add(linkTo(this.getClass()).withSelfRel());
    return new ResponseEntity<>(result, code);
}

From source file:org.openwms.core.http.AbstractWebController.java

/**
 * Build a response object that signals a not-okay response with a given status {@code code} and with given http headers.
 *
 * @param <T> Some type extending the AbstractBase entity
 * @param code The status code to set as response code
 * @param msg The error message passed to the caller
 * @param msgKey The error message key passed to the caller
 * @param headers The map of headers.//  ww  w . j av  a 2s  .c  o m
 * @param params A set of Serializable objects that are passed to the caller
 * @return A ResponseEntity with status {@code code}
 */
protected <T extends AbstractBase> ResponseEntity<Response<T>> buildResponse(HttpStatus code, String msg,
        String msgKey, MultiValueMap<String, String> headers, T... params) {
    Response result = new Response(msg, msgKey, code.toString(), params);
    return new ResponseEntity<>(result, headers, code);
}

From source file:com.kth.baasio.exception.BaasioException.java

public BaasioException(HttpStatus status, String errorBody) {
    super();/*from w  w w . j  av  a  2  s. c o m*/

    statusCode = status.toString();
    try {
        otherCauses = JsonUtils.parse(errorBody, BaasioOtherCauses.class);
    } catch (BaasioRuntimeException e) {
        otherCauses.setProperty("error", errorBody);
    } catch (Exception e) {
        e.printStackTrace();
    }

    otherCauses.setProperty("statusCode", status.toString());
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

@Override
public String checkStatus(final InstanceConfig config, final URI triggerUrl) throws ResponseStatusException {
    Preconditions.checkArgument(config != null);
    Preconditions.checkArgument(triggerUrl != null);

    final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(),
            config.getUsername(), config.getPassword());
    final URI url = triggerUrl.resolve(triggerUrl.getPath() + STATUS_PATH);

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    final HttpEntity<String> httpEntity = new HttpEntity<>(headers);

    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.GET, httpEntity,
            String.class);
    final HttpStatus status = response.getStatusCode();
    if (status.equals(HttpStatus.OK)) {
        return response.getBody();
    } else {/*from  w ww  .ja  va2  s .  c om*/
        throw new ResponseStatusException(
                "HttpStatus " + status.toString() + " response received. Load trigger monitoring failed.");
    }
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

@Override
public String uploadDataSet(final InstanceConfig config, final File file) throws ResponseStatusException {
    Preconditions.checkArgument(config != null);
    Preconditions.checkArgument(file != null);

    final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(),
            config.getUsername(), config.getPassword());
    final String checkSum = createCheckSum(file);

    final List<NameValuePair> params = Arrays
            .asList(new NameValuePair[] { new BasicNameValuePair("checksum", checkSum) });
    final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(),
            UPLOAD_PATH, params);// w  w w.j  a v  a  2s.  c om

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.valueOf("application/zip"));
    final HttpEntity<Resource> httpEntity = new HttpEntity<>(new FileSystemResource(file), headers);

    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity,
            String.class);

    final HttpStatus status = response.getStatusCode();
    if (status.equals(HttpStatus.CREATED)) {
        return response.getBody().trim();
    } else {
        throw new ResponseStatusException(
                "HttpStatus " + status.toString() + " response received. File upload failed.");
    }
}

From source file:com.fredhopper.core.connector.index.upload.impl.RestPublishingStrategy.java

@Override
public URI triggerDataLoad(final InstanceConfig config, final String dataId) throws ResponseStatusException {
    Preconditions.checkArgument(config != null);
    Preconditions.checkArgument(StringUtils.isNotBlank(dataId));

    final RestTemplate restTemplate = restTemplateProvider.createTemplate(config.getHost(), config.getPort(),
            config.getUsername(), config.getPassword());

    final URI url = createUri(config.getScheme(), config.getHost(), config.getPort(), config.getServername(),
            TRIGGER_PATH, Collections.emptyList());

    final HttpHeaders headers = new HttpHeaders();
    headers.setContentType(MediaType.TEXT_PLAIN);
    final HttpEntity<String> httpEntity = new HttpEntity<>(dataId, headers);

    final ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.PUT, httpEntity,
            String.class);
    final HttpStatus status = response.getStatusCode();
    if (status.equals(HttpStatus.CREATED)) {
        return response.getHeaders().getLocation();
    } else {/*from  w w w .ja  v  a 2  s.  co m*/
        throw new ResponseStatusException(
                "HttpStatus " + status.toString() + " response received. Load trigger creation failed.");
    }
}

From source file:eu.freme.eservices.pipelines.core.PipelineService.java

private PipelineResponse execute(final SerializedRequest request, final String body)
        throws UnirestException, IOException, ServiceException {
    switch (request.getMethod()) {
    case GET://from   w  w w. java  2  s.  c  o m
        throw new UnsupportedOperationException("GET is not supported at this moment.");
    default:
        HttpRequestWithBody req = Unirest.post(request.getEndpoint());
        if (request.getHeaders() != null && !request.getHeaders().isEmpty()) {
            req.headers(request.getHeaders());
        }
        if (request.getParameters() != null && !request.getParameters().isEmpty()) {
            req.queryString(request.getParameters()); // encode as POST parameters
        }

        HttpResponse<String> response;
        if (body != null) {
            response = req.body(body).asString();
        } else {
            response = req.asString();
        }
        if (!HttpStatus.Series.valueOf(response.getStatus()).equals(HttpStatus.Series.SUCCESSFUL)) {
            String errorBody = response.getBody();
            HttpStatus status = HttpStatus.valueOf(response.getStatus());
            if (errorBody == null || errorBody.isEmpty()) {
                throw new ServiceException(new PipelineResponse(
                        "The service \"" + request.getEndpoint() + "\" reported HTTP status "
                                + status.toString() + ". No further explanation given by service.",
                        RDFConstants.RDFSerialization.PLAINTEXT.contentType()), status);
            } else {
                throw new ServiceException(
                        new PipelineResponse(errorBody, response.getHeaders().getFirst("content-type")),
                        status);
            }
        }
        return new PipelineResponse(response.getBody(), response.getHeaders().getFirst("content-type"));
    }
}