List of usage examples for org.springframework.web.client RestTemplate getMessageConverters
public List<HttpMessageConverter<?>> getMessageConverters()
From source file:won.protocol.rest.LinkedDataRestClientHttpsServerOnly.java
private RestTemplate createRestTemplateForReadingLinkedData() throws Exception { RestTemplate template = CryptographyUtils.createSslRestTemplate(this.trustStrategy, readTimeout, connectionTimeout);/* w w w . ja va2 s . c o m*/ template.getMessageConverters().add(datasetConverter); return template; }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchDiseases.java
/** * Method, where all diseases are read from server. * All heavy lifting is made here.//from www . j a v a2 s . c om * * @param params omitted here * @return list of fetched diseases */ @Override protected List<Disease> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_DISEASES; setState(RUNNING, R.string.working_ws_disease); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<DiseaseList> response = restTemplate.exchange(url, HttpMethod.GET, entity, DiseaseList.class); DiseaseList body = response.getBody(); if (body != null) { return body.getDiseases(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeFixes.java
/** * Method, where all electrodeTypes are read from server. * All heavy lifting is made here./*from ww w . ja va 2 s. c o m*/ * * @param params omitted here * @return list of fetched electrodeFixes */ @Override protected List<ElectrodeFix> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_FIXLIST; setState(RUNNING, R.string.working_ws_electrode_fix); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<ElectrodeFixList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ElectrodeFixList.class); ElectrodeFixList body = response.getBody(); if (body != null) { return body.getElectrodeFixList(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeLocations.java
/** * Method, where all electrodeLocations are read from server. * All heavy lifting is made here./*from ww w. j a v a 2s .c om*/ * * @param params omitted here * @return list of fetched electrodeLocations */ @Override protected List<ElectrodeLocation> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_LOCATIONS; setState(RUNNING, R.string.working_ws_electrode_location); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<ElectrodeLocationList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ElectrodeLocationList.class); ElectrodeLocationList body = response.getBody(); if (body != null) { return body.getElectrodeLocations(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeSystems.java
/** * Method, where all electrodeSystems are read from server. * All heavy lifting is made here./*from w ww . ja va 2 s . c om*/ * * @param params omitted here * @return list of fetched electrodeSystems */ @Override protected List<ElectrodeSystem> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_SYSTEMS; setState(RUNNING, R.string.working_ws_electrode_system); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<ElectrodeSystemList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ElectrodeSystemList.class); ElectrodeSystemList body = response.getBody(); if (body != null) { return body.getElectrodeSystems(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchElectrodeTypes.java
/** * Method, where all electrodeTypes are read from server. * All heavy lifting is made here./*from w w w. ja v a2s .c o m*/ * * @param params omitted here * @return list of fetched electrodeTypes */ @Override protected List<ElectrodeType> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_ELECTRODE_TYPES; setState(RUNNING, R.string.working_ws_electrode_type); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<ElectrodeTypeList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ElectrodeTypeList.class); ElectrodeTypeList body = response.getBody(); if (body != null) { return body.getElectrodeTypes(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchHardwareList.java
/** * Method, where all hardwareList are read from server. * All heavy lifting is made here./*from w ww .j a v a 2 s. c o m*/ * * @param params omitted here * @return list of fetched hardware */ @Override protected List<Hardware> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_HARDWARE; setState(RUNNING, R.string.working_ws_hardware); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<HardwareList> response = restTemplate.exchange(url, HttpMethod.GET, entity, HardwareList.class); HardwareList body = response.getBody(); if (body != null) { return body.getHardwareList(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchPharmaceuticals.java
/** * Method, where all pharmaceuticals are read from server. * All heavy lifting is made here.// w w w. ja va 2 s . c om * * @param params omitted here * @return list of fetched pharmaceuticals */ @Override protected List<Pharmaceutical> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_PHARMACEUTICAL; setState(RUNNING, R.string.working_ws_pharmaceutical); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<PharmaceuticalList> response = restTemplate.exchange(url, HttpMethod.GET, entity, PharmaceuticalList.class); PharmaceuticalList body = response.getBody(); if (body != null) { return body.getPharmaceuticals(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchSoftwareList.java
/** * Method, where all softwareList are read from server. * All heavy lifting is made here./*from w ww . ja v a 2s . c o m*/ * * @param params omitted here * @return list of fetched software */ @Override protected List<Software> doInBackground(Void... params) { SharedPreferences credentials = getCredentials(); String username = credentials.getString("username", null); String password = credentials.getString("password", null); String url = credentials.getString("url", null) + Values.SERVICE_SOFTWARE; setState(RUNNING, R.string.working_ws_software); HttpAuthentication authHeader = new HttpBasicAuthentication(username, password); HttpHeaders requestHeaders = new HttpHeaders(); requestHeaders.setAuthorization(authHeader); requestHeaders.setAccept(Collections.singletonList(MediaType.APPLICATION_XML)); HttpEntity<Object> entity = new HttpEntity<Object>(requestHeaders); SSLSimpleClientHttpRequestFactory factory = new SSLSimpleClientHttpRequestFactory(); // Create a new RestTemplate instance RestTemplate restTemplate = new RestTemplate(factory); restTemplate.getMessageConverters().add(new SimpleXmlHttpMessageConverter()); try { // Make the network request Log.d(TAG, url); ResponseEntity<SoftwareList> response = restTemplate.exchange(url, HttpMethod.GET, entity, SoftwareList.class); SoftwareList body = response.getBody(); if (body != null) { return body.getSoftwareList(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:org.starfishrespect.myconsumption.android.tasks.ConfigUpdater.java
public void refreshDB() { AsyncTask<Void, List, Void> task = new AsyncTask<Void, List, Void>() { @Override// w w w.j a va 2s . c o m protected Void doInBackground(Void... params) { DatabaseHelper db = SingleInstance.getDatabaseHelper(); RestTemplate template = new RestTemplate(); template.getMessageConverters().add(new MappingJacksonHttpMessageConverter()); try { String url = SingleInstance.getServerUrl() + "configs/co2"; Double co2 = template.getForObject(url, Double.class); int id = db.getIdForKey("config_co2"); KeyValueData valueData = new KeyValueData("config_co2", co2.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + co2); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config co2", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } try { String url = SingleInstance.getServerUrl() + "configs/day"; Double day = template.getForObject(url, Double.class); int id = db.getIdForKey("config_day"); KeyValueData valueData = new KeyValueData("config_day", day.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + day); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config day", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } try { String url = SingleInstance.getServerUrl() + "configs/night"; Double night = template.getForObject(url, Double.class); int id = db.getIdForKey("config_night"); KeyValueData valueData = new KeyValueData("config_night", night.toString()); valueData.setId(id); LOGD(TAG, "writing stat in local db: " + night); db.getKeyValueDao().createOrUpdate(valueData); } catch (SQLException e) { LOGD(TAG, "Cannot create config night", e); } catch (ResourceAccessException | HttpClientErrorException e) { LOGE(TAG, "Cannot access server ", e); } return null; } @Override protected void onPostExecute(Void aVoid) { if (configUpdateFinishedCallback != null) { configUpdateFinishedCallback.onConfigUpdateFinished(); } } }; task.execute(); }