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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:com.athena.dolly.controller.module.couchbase.CouchbaseClient.java

public static void main(String[] args) {
    CouchbaseClient client = new CouchbaseClient("http://127.0.0.1:8091/pools", "gamesim-sample", "");

    try {//  w w  w .j  ava2  s. c  o m
        client.init();
        System.out.println(client.getMemoryUsage());
        System.out.println(client.getCpuUsage());
        //System.err.println(client.getDesigndocs());
        //System.err.println(client.deleteDesignDoc("test"));
        //System.err.println(client.deleteView("test", "test"));
        //System.err.println(client.createView("test", "test"));
    } catch (RestClientException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (Exception e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        client.shutdown();
    }
}

From source file:org.starfishrespect.myconsumption.android.tasks.UserUpdater.java

@Override
protected Void doInBackground(Void... params) {
    RestTemplate template = new RestTemplate();
    HttpHeaders httpHeaders = CryptoUtils.createHeaders(username, password);
    template.getMessageConverters().add(new MappingJacksonHttpMessageConverter());
    try {//from  www .  ja  v  a2s.c om
        ResponseEntity<UserDTO> response = template.exchange(
                SingleInstance.getServerUrl() + "users/" + username, HttpMethod.GET,
                new HttpEntity<>(httpHeaders), UserDTO.class);
        UserDTO user = response.getBody();
        UserData userData = new UserData(user);
        for (String sensor : user.getSensors()) {
            try {
                ResponseEntity<SensorDTO> responseSensor = template.exchange(
                        SingleInstance.getServerUrl() + "sensors/" + sensor, HttpMethod.GET,
                        new HttpEntity<>(httpHeaders), SensorDTO.class);
                SensorDTO SensorDTO = responseSensor.getBody();
                userData.addSensor(new SensorData(SensorDTO));
            } catch (RestClientException e) {
                e.printStackTrace();
            }
        }
        publishProgress(userData);
    } catch (RestClientException e) {
        e.printStackTrace();
        publishProgress(null);
    }
    return null;
}

From source file:com.skipjaq.awspricing.pricing.AwsPricing.java

private AwsOffer getAwsOffer(String awsOffersUrl) {
    RestTemplate restTemplate = new RestTemplate();
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    converter.setSupportedMediaTypes(/* w ww . ja v a2s. c  o m*/
            Arrays.asList(new MediaType[] { MediaType.APPLICATION_JSON, MediaType.APPLICATION_OCTET_STREAM }));
    restTemplate.setMessageConverters(Arrays.asList(converter, new FormHttpMessageConverter()));
    try {
        return restTemplate.getForObject(awsOffersUrl, AwsOffer.class);
    } catch (RestClientException e) {
        e.printStackTrace();
        return null;
    }
}

From source file:org.projecthdata.weight.service.SyncService.java

@Override
protected void onHandleIntent(Intent intent) {
    Connection<HData> connection = connectionRepository.getPrimaryConnection(HData.class);

    this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.WORKING.toString()).commit();
    //get all readings that are not synced
    try {//from  www  .j  a v  a  2  s  .c om
        Dao<WeightReading, Integer> dao = ormManager.getDatabaseHelper().getWeightDao();
        //TODO: query the database instead of iterating over the whole table

        String url = this.prefs.getString(Constants.PREF_EHR_URL, "");
        Uri uri = Uri.parse(url);
        uri = uri.buildUpon().appendPath("vitalsigns").appendPath("bodyweight").build();
        RestTemplate template = connection.getApi().getRootOperations().getRestTemplate();

        HttpHeaders requestHeaders = new HttpHeaders();
        requestHeaders.setContentType(MediaType.APPLICATION_XML);

        for (WeightReading reading : dao) {

            if (!reading.isSynched()) {
                Result result = new Result();
                //date and time
                result.setResultDateTime(new DateTime(reading.getDateTime().getTime()).toString(dateFormatter));
                //narrative
                result.setNarrative(NARRATIVE);
                //result id
                result.setResultId(UUID.randomUUID().toString());
                //result type code
                result.getResultType().setCode(CODE);
                //result type code system
                result.getResultType().setCodeSystem(CODE_SYSTEM);
                //status code
                result.setResultStatusCode(RESULT_STATUS_CODE);
                //value
                result.setResultValue(reading.getResultValue().toString());
                //value unit
                result.setResultValueUnit(UNITS);

                try {

                    HttpEntity<Result> requestEntity = new HttpEntity<Result>(result, requestHeaders);
                    template.exchange(uri.toString(), HttpMethod.POST, requestEntity, String.class);
                } catch (RestClientException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }

                reading.setSynched(true);
                dao.update(reading);
            }
        }
    } catch (SQLException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    this.prefs.edit().putString(Constants.PREF_SYNC_STATE, SyncState.READY.toString()).commit();

}

From source file:info.smartkit.hairy_batman.query.KJsonApiQuery.java

public void query() {
    // KJSON API testing using RestTemplate.
    RestTemplate restTemplate = new RestTemplate();
    // restTemplate.getMessageConverters().add(new
    // StringHttpMessageConverter());
    MappingJackson2HttpMessageConverter converter = new MappingJackson2HttpMessageConverter();
    // @see:// www.  j  a  v  a2s  . c o m
    // http://stackoverflow.com/questions/22329368/spring-android-rest-template-parse-json-data-with-content-type-text-html
    converter.setSupportedMediaTypes(Collections.singletonList(MediaType.TEXT_HTML));
    restTemplate.getMessageConverters().add(converter);
    // Spring batch for CSV reading.
    //
    WxBar api_query_resutls = new WxBar();

    try {
        /*System.out.println("this.getParameters():" + this.getParameters());
        api_query_resutls = restTemplate.postForObject(
              GlobalConsts.KJSON_API_URI, this.getParameters(),
              WxBar.class);*/
    } catch (RestClientException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }

    if (api_query_resutls.getData() != null) {// FIXME: null JSON
        // exception handler
        // here.

        // WxBar returns =
        // restTemplate.getForObject(GlobalConsts.KJSON_API_URI,
        // WxBar.class);
        ArrayList<WxKJson> api_query_resutls_data = api_query_resutls.getData();
        // System.out.println("ApiQuery result data:  " +
        // api_query_resutls_data);
        LOG.info("ApiQuery result data:  " + api_query_resutls_data.toString());
        WxKJson wxKJson = api_query_resutls_data.get(0);
        // System.out.println("Parsed ApiQuery results,articleReadNum:" +
        // wxKJson.getRead() + ",articleLikeNum: "
        // + wxKJson.getLike());
        LOG.info("Parsed ApiQuery results,articleReadNum:" + wxKJson.getRead() + ",articleLikeNum: "
                + wxKJson.getLike());
        //
        this.readNum = Long.parseLong(wxKJson.getRead());
        this.likeNum = Long.parseLong(wxKJson.getLike());
        this.queriedSubscriber.setArticleReadNum(wxKJson.getRead());
        this.queriedSubscriber.setArticleLikeNum(wxKJson.getLike());
        double likeRate = (double) likeNum / readNum * 100;
        java.math.BigDecimal bigLikeRate = new java.math.BigDecimal(likeRate);
        String bigLikeRateStr = bigLikeRate
                .setScale(GlobalConsts.DEFINITION_PRECISION, java.math.BigDecimal.ROUND_HALF_UP).doubleValue()
                + "%";
        this.queriedSubscriber.setArticleLikeRate(bigLikeRateStr);
        //
        this.queriedSubscriber.setMoniterTime(GlobalVariables.now());
        this.queriedSubscriber.setArticleUrl(wxKJson.getUrl());
        //
        GlobalVariables.wxFooListWithOpenIdArticleReadLike.add(this.queriedSubscriber);
        // File reporting...
        new FileReporter(GlobalConsts.REPORT_FILE_OUTPUT_OPENID_ARITICLE_READ_LIKE,
                GlobalVariables.wxFooListWithOpenIdArticleReadLike,
                FileReporter.REPORTER_TYPE.R_T_OPENID_ARTICLE_READ_LIKE, FileReporter.REPORTER_FILE_TYPE.EXCEL)
                        .write();
        // Save to DB.
        Object[] params = { likeNum.intValue(), readNum.intValue(), this.queriedSubscriber.getArticleLikeRate(),
                this.queriedSubscriber.getArticleUrl() };
        int[] types = { Types.INTEGER, Types.INTEGER, Types.VARCHAR, Types.VARCHAR };
        int rows = GlobalVariables.jdbcTempate.update(GlobalConsts.JDBC_QUERY_UPDATE_OPENID_ARTICLE_READ_LIKE,
                params, types);
        LOG.info("rows(s): " + rows + " updated." + ",likeNum: " + likeNum + ",readNum: " + readNum
                + ",bigLikeRateStr: " + bigLikeRateStr + ",articleUrl: "
                + this.queriedSubscriber.getArticleUrl());
        //
        LOG.info("GlobalVariables.wxFooListWithOpenIdArticleReadLike(size):"
                + GlobalVariables.wxFooListWithOpenIdArticleReadLike.size() + ",raw: "
                + GlobalVariables.wxFooListWithOpenIdArticleReadLike.toString());
        //
        if (this.subscribers.size() > 0) {
            this.query();// Recursively call.
            GlobalVariables.kjsonQueryCounter++;
            if (GlobalVariables.kjsonQueryCounter >= GlobalConsts.KJSON_API_QPM) {
                try {
                    Thread.sleep(30000);
                    GlobalVariables.kjsonQueryCounter = 0;
                } catch (InterruptedException e) {
                    LOG.error(e.toString());
                }
            }
        } else {
            //
        }
    }
}