Example usage for org.springframework.web.client RestClientException RestClientException

List of usage examples for org.springframework.web.client RestClientException RestClientException

Introduction

In this page you can find the example usage for org.springframework.web.client RestClientException RestClientException.

Prototype

public RestClientException(String msg) 

Source Link

Document

Construct a new instance of RestClientException with the given message.

Usage

From source file:com.mc.printer.model.layout.ws.WebSender.java

public <T extends Object> T getForObject(String url, Class<T> responseType) throws RestClientException {
    try {/* w  w  w.  ja va  2s  . c  om*/
        T obj = super.getForObject(url, responseType);
        return obj;
    } catch (Exception e) {
        throw new RestClientException("" + e.getLocalizedMessage());
    }

}

From source file:com.mc.printer.model.layout.ws.WebSender.java

public <T extends Object> T postForObject(String url, Object request, Class<T> responseType)
        throws RestClientException {
    try {/*from  ww w . ja  va  2s . c o m*/
        T obj = super.postForObject(url, request, responseType);
        ;
        return obj;
    } catch (Exception e) {
        throw new RestClientException("" + e.getLocalizedMessage());
    }

}

From source file:org.energyos.espi.thirdparty.mocks.MockRestTemplate.java

@SuppressWarnings("unchecked")
public <T> T getForObject(String url, Class<T> responseType, Object... urlVariables)
        throws RestClientException {
    ClassPathResource sourceFile = new ClassPathResource("/fixtures/test_usage_data.xml");
    String inputStreamString;//from   www.  ja  v a 2s .co m
    try {
        inputStreamString = new Scanner(sourceFile.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        return (T) inputStreamString;
    } catch (IOException e) {
        e.printStackTrace();
        throw new RestClientException("The file import broke.");
    }

}

From source file:com.mc.printer.model.layout.ws.WebSender.java

public URI postForLocation(String url, Object request) throws RestClientException {
    try {//from   www.  j  a v  a  2 s. c om
        URI uri = super.postForLocation(url, request);
        return uri;
    } catch (Exception e) {
        throw new RestClientException("" + e.getLocalizedMessage());
    }

}

From source file:com.oneops.amq.plugins.CMSClientTest.java

@SuppressWarnings("unchecked")
@BeforeClass/*from   w w  w.ja  v a 2 s .c om*/
public void setUp() {

    //a mocked rest template used when we need simulated exception response
    //it is used two times so lets init it here once
    restTemplateThrows = mock(RestTemplate.class);
    when(restTemplateThrows.getForObject(anyString(), any(Class.class), anyString(), anyString(), anyString()))
            .thenThrow(new RestClientException(this.getClass().getName()));

    this.cmsClient.setServiceUrl(SERVICE_URL);

}

From source file:com.mc.printer.model.layout.ws.WebSender.java

public <T extends Object> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
        ParameterizedTypeReference<T> responseType) throws RestClientException {
    try {//from w  w  w . ja  va2 s  .c  o  m
        ResponseEntity<T> res = super.exchange(url, method, requestEntity, responseType);
        return res;
    } catch (Exception e) {
        throw new RestClientException("" + e.getLocalizedMessage());
    }
}

From source file:org.energyos.espi.thirdparty.mocks.MockRestTemplate.java

@SuppressWarnings("unchecked")
@Override/*ww w  . jav a 2  s .com*/
public <T> ResponseEntity<T> exchange(String url, HttpMethod method, HttpEntity<?> requestEntity,
        Class<T> responseType, Object... uriVariables) throws RestClientException {
    ClassPathResource sourceFile = new ClassPathResource("/fixtures/test_usage_data.xml");
    String inputStreamString;
    try {
        inputStreamString = new Scanner(sourceFile.getInputStream(), "UTF-8").useDelimiter("\\A").next();
        return new ResponseEntity<>((T) inputStreamString, HttpStatus.OK);
    } catch (IOException e) {
        e.printStackTrace();
        throw new RestClientException("The file import broke.");
    }
}

From source file:org.zalando.riptide.Callback.java

@Override
public void doWithRequest(final ClientHttpRequest request) throws IOException {
    final HttpHeaders headers = entity.getHeaders();
    request.getHeaders().putAll(headers);

    @Nullable/*from   w w w. ja va  2  s .c  o  m*/
    final T body = entity.getBody();

    if (body == null) {
        return;
    }

    final Class<?> type = body.getClass();
    @Nullable
    final MediaType contentType = headers.getContentType();

    final Optional<HttpMessageConverter<T>> match = converters.stream()
            .filter(c -> c.canWrite(type, contentType)).map(this::cast).findFirst();

    if (match.isPresent()) {
        final HttpMessageConverter<T> converter = match.get();

        converter.write(body, contentType, request);
    } else {
        final String message = format(
                "Could not write request: no suitable HttpMessageConverter found for request type [%s]",
                type.getName());

        if (contentType == null) {
            throw new RestClientException(message);
        } else {
            throw new RestClientException(format("%s and content type [%s]", message, contentType));
        }
    }
}

From source file:de.codecentric.boot.admin.services.SpringBootAdminRegistratorTest.java

@Test
public void register_failed() {
    AdminProperties adminProps = new AdminProperties();
    adminProps.setUrl("http://sba:8080");
    AdminClientProperties clientProps = new AdminClientProperties();
    clientProps.setUrl("http://localhost:8080");
    clientProps.setName("AppName");

    RestTemplate restTemplate = mock(RestTemplate.class);
    when(restTemplate.postForEntity(isA(String.class), isA(Application.class), eq(Application.class)))
            .thenThrow(new RestClientException("Error"));

    SpringBootAdminRegistrator registrator = new SpringBootAdminRegistrator(restTemplate, adminProps,
            clientProps);/*  w  w w  . j  a  v a  2  s.  c om*/
    boolean result = registrator.register();

    assertFalse(result);
}

From source file:nl.gridshore.nosapi.impl.NosApiResponseErrorHandler.java

@Override
public void handleError(ClientHttpResponse response) throws IOException {
    logger.debug("Handle error '{}' received from the NOS server.", response.getStatusCode().name());
    HttpStatus statusCode = response.getStatusCode();
    MediaType contentType = response.getHeaders().getContentType();
    Charset charset = contentType != null ? contentType.getCharSet() : null;
    byte[] body = FileCopyUtils.copyToByteArray(response.getBody());

    switch (statusCode) {
    case BAD_REQUEST:
    case UNAUTHORIZED:
    case FORBIDDEN:
        throwClientException(charset, body);
    default:/*from   w  w  w.ja  v  a  2s  .c o m*/
        // do nothing, let the series resolving do it' work
    }

    switch (statusCode.series()) {
    case CLIENT_ERROR:
        throw new HttpClientErrorException(statusCode, response.getStatusText(), body, charset);
    case SERVER_ERROR:
        throw new HttpServerErrorException(statusCode, response.getStatusText(), body, charset);
    default:
        throw new RestClientException("Unknown status code [" + statusCode + "]");
    }
}