List of usage examples for java.lang Exception getLocalizedMessage
public String getLocalizedMessage()
From source file:cz.zcu.kiv.eeg.mobile.base.ws.asynctask.FetchScenarios.java
/** * Method, where all scenarios are read from server. * All heavy lifting is made here.// w ww . j av a2s.co m * * @param params omitted here * @return list of fetched scenarios */ @Override protected List<Scenario> 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_SCENARIOS + qualifier; setState(RUNNING, R.string.working_ws_scenarios); 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<ScenarioList> response = restTemplate.exchange(url, HttpMethod.GET, entity, ScenarioList.class); ScenarioList body = response.getBody(); if (body != null) { return body.getScenarios(); } } catch (Exception e) { Log.e(TAG, e.getLocalizedMessage(), e); setState(ERROR, e); } finally { setState(DONE); } return Collections.emptyList(); }
From source file:com.difference.historybook.proxy.ProxyTest.java
@Test public void testSmallFetch() { String body = "<html><head></head><body>Hello World!</body></html>"; stubFor(get(urlEqualTo("/some/page")) .willReturn(aResponse().withStatus(200).withHeader("Content-Type", "text/html").withBody(body))); Proxy proxy = getProxy().setPort(PROXY_PORT); try {//w ww . j av a2s . c o m proxy.start(); java.net.Proxy proxyServer = new java.net.Proxy(java.net.Proxy.Type.HTTP, new InetSocketAddress("127.0.0.1", PROXY_PORT)); HttpURLConnection connection = (HttpURLConnection) new URL( "http://localhost:" + DUMMY_SERVER_PORT + "/some/page").openConnection(proxyServer); byte[] fetchedContent = IOUtils.toByteArray(connection.getInputStream()); assertArrayEquals(body.getBytes(Charsets.UTF_8), fetchedContent); proxy.stop(); } catch (Exception e) { fail(e.getLocalizedMessage()); } }
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 w w w. j av a 2 s . c o m*/ * * @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.// w w w. ja v a2 s .c om * * @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.//ww w .j a v a 2 s . co m * * @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./* ww w .j a va 2 s . c o m*/ * * @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.// w ww .j a v a2 s. 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 ww w . j a va 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./*from ww w. j a va2 s . c o m*/ * * @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.//ww w. j a va2 s.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(); }