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

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

Introduction

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

Prototype

@Override
@Nullable
public String getMessage() 

Source Link

Document

Return the detail message, including the message from the nested exception if there is one.

Usage

From source file:com.appglu.impl.SyncTemplate.java

/**
 * {@inheritDoc}//from ww w  .j  a  v a 2 s .  c om
 */
public void downloadChangesForTables(final List<TableVersion> tables,
        final InputStreamCallback inputStreamCallback) throws AppGluRestClientException {
    RequestCallback requestCallback = new RequestCallback() {
        public void doWithRequest(ClientHttpRequest request) throws IOException {
            HttpEntity<Object> requestEntity = new HttpEntity<Object>(new TableVersionBody(tables));

            HttpHeaders requestHeaders = requestEntity.getHeaders();
            if (!requestHeaders.isEmpty()) {
                request.getHeaders().putAll(requestHeaders);
            }

            jsonMessageConverter.write(requestEntity.getBody(), requestHeaders.getContentType(), request);
        }
    };

    ResponseExtractor<Object> responseExtractor = new ResponseExtractor<Object>() {
        public Object extractData(ClientHttpResponse response) throws IOException {
            inputStreamCallback.doWithInputStream(response.getBody());
            return null;
        }
    };

    try {
        this.restOperations.execute(CHANGES_FOR_TABLES_URL, HttpMethod.POST, requestCallback,
                responseExtractor);
    } catch (RestClientException e) {
        throw new AppGluRestClientException(e.getMessage(), e);
    }
}

From source file:com.formulaone.controller.merchant.MerchantControllerTest.java

/**
 * Test successful user deletion//from  w w w . jav  a 2  s . c o  m
 */
@Test
public void test_4_SuccessMerchantDeletion() {
    Map<String, Long> vars = new HashMap<String, Long>();
    vars.put("id", createdId);

    try {
        ResponseEntity<String> resp = restTemplate.exchange(base + "/{id}", HttpMethod.DELETE,
                new HttpEntity<String>(httpHeaders), String.class, vars);

        assertThat(resp.getStatusCode(), equalTo(HttpStatus.OK));
    } catch (RestClientException e) {
        fail("Unexpected exception happened: " + e.getMessage());
    }
}

From source file:eu.cloudwave.wp5.feedback.eclipse.base.infrastructure.rest.RestClientImpl.java

private void handleErrors(final RestClientException exception) {
    // handle 404 NOT FOUND error
    if (exception instanceof ResourceAccessException) {
        throw new RequestException(ErrorType.FEEDBACK_HANDLER_NOT_AVAILABLE, exception.getMessage());
    } else if (exception instanceof HttpStatusCodeException) {
        final HttpStatusCodeException httpException = (HttpStatusCodeException) exception;

        // handle 404 NOT FOUND error
        if (httpException.getStatusCode().equals(HttpStatus.NOT_FOUND)) {
            throw new RequestException(ErrorType.FEEDBACK_HANDLER_NOT_AVAILABLE, exception.getMessage());
        }//w  w  w .  ja v a  2s  .  c om

        // handle other errors
        final ObjectMapper mapper = new ObjectMapper();
        try {
            final RestRequestErrorDto error = mapper.readValue(httpException.getResponseBodyAsString(),
                    RestRequestErrorDto.class);
            throw new RequestException(error.getType(), error.getMessage());
        } catch (final IOException e) {
        }
    }
    throw new RuntimeException(READ_SERVER_ERROR_EXCEPTION, exception);
}

From source file:com.formulaone.controller.merchant.MerchantControllerTest.java

/**
 * Test Merchant retrieval by Id//from w w w . j ava 2 s  .co  m
 */
@Test
public void test_2_SuccessfulMerchantRetrievalById() {
    Map<String, Long> vars = new HashMap<String, Long>();
    vars.put("id", createdId);
    try {
        ResponseEntity<MerchantResponse> response = restTemplate.exchange(base + "/{id}", HttpMethod.GET,
                new HttpEntity<MerchantResponse>(httpHeaders), MerchantResponse.class, vars);

        MerchantResponse merchantResponse = response.getBody();
        assertThat(merchantResponse, notNullValue());
        assertThat(merchantResponse.getCompanyName(), equalTo(request.getCompany().getName()));
        assertThat(merchantResponse.getDescription(), equalTo(request.getBusinessDescription()));
        assertThat(merchantResponse.getFirstName(), equalTo(request.getOwnershipDetails().getFirstName()));
        assertThat(merchantResponse.getLastName(), equalTo(request.getOwnershipDetails().getLastName()));
        assertThat(merchantResponse.getMid(), notNullValue());
        assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

    } catch (RestClientException e) {
        fail("Unexpected exception happened: " + e.getMessage());
    }
}

From source file:com.formulaone.controller.merchant.MerchantControllerTest.java

/**
 * test successful all mnerchants retrieval
 * // www.  j  a  va2 s .  co m
 * @throws IOException
 * @throws JsonMappingException
 * @throws JsonParseException
 */
@Test
public void test_3_SuccessfulAllMerchantsRetrieval()
        throws JsonParseException, JsonMappingException, IOException {
    try {
        @SuppressWarnings("unchecked")
        ResponseEntity<List<MerchantResponse>> response = restTemplate.exchange(base + "", HttpMethod.GET,
                new HttpEntity<List<MerchantResponse>>(httpHeaders),
                new ParameterizedTypeReference<List<MerchantResponse>>() {
                });

        assertThat(response, notNullValue());
        assertThat(response.getBody(), notNullValue());
        assertThat(response.getStatusCode(), equalTo(HttpStatus.OK));

        List<MerchantResponse> merchantResponses = response.getBody();
        assertThat(merchantResponses, notNullValue());
        assertThat(merchantResponses.size(), equalTo(Integer.valueOf(1)));

        for (MerchantResponse merchantResponse : merchantResponses) {
            assertThat(merchantResponse.getCompanyName(), equalTo(request.getCompany().getName()));
            assertThat(merchantResponse.getDescription(), equalTo(request.getBusinessDescription()));
            assertThat(merchantResponse.getFirstName(), equalTo(request.getOwnershipDetails().getFirstName()));
            assertThat(merchantResponse.getLastName(), equalTo(request.getOwnershipDetails().getLastName()));
            assertThat(merchantResponse.getMid(), notNullValue());

        }

    } catch (RestClientException e) {
        fail("Unexpected exception happened: " + e.getMessage());
    }
}

From source file:com.thecorpora.qbo.androidapk.rest.RESTClient.java

/**
 * We give the IP to the robot//from  w  w  w.j av a2 s .  c  o m
 * 
 * @param ip4Linphone The IP given by the user in the Login activity is sent to the robot in order to properly configurate Linphone
 */
public int post_ip4sip(String ip4Linphone) {
    try {
        mRest.ip4sip(ip4Linphone);
        return 0;
    } catch (RestClientException e) {
        Log.e(TAG, e.getMessage(), e);
        return -1;
    }
}

From source file:com.thecorpora.qbo.androidapk.rest.RESTClient.java

/**
 * Start SIP Server//from w  w w  . j  av a2 s  .c  o m
 */
public int startSIPServer() {
    try {
        mRest.startSIPServer();
        return 0;
    } catch (RestClientException e) {
        Log.e(TAG, e.getMessage(), e);
        return -1;
    }
}

From source file:com.thecorpora.qbo.androidapk.rest.RESTClient.java

/**
 * Stop SIP Sever/*w w w . j  ava  2  s  .com*/
 */
public int stopSIPServer() {
    try {
        mRest.stopSIPServer();
        return 0;
    } catch (RestClientException e) {
        Log.e(TAG, e.getMessage(), e);
        return -1;
    }
}