List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:gov.nih.nci.caxchange.messaging.SpecimenLoadTest.java
private void sendMessage() { try {/*from w ww. jav a 2s . co m*/ final HttpClient httpclient = new DefaultHttpClient(); final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl); final StringEntity reqentity = new StringEntity(getInsertInvalidAvailableQuantityXMLStr()); httppost.setEntity(reqentity); httppost.setHeader(HttpHeaders.CONTENT_TYPE, "text/xml"); final HttpResponse response = httpclient.execute(httppost); final HttpEntity entity = response.getEntity(); if (entity != null) { final String output = EntityUtils.toString(entity); Assert.assertNotNull(output); Assert.assertEquals(true, output.contains("FAILURE")); } } catch (ClientProtocolException e) { Assert.fail(e.getMessage()); } catch (IllegalStateException e) { Assert.fail(e.getMessage()); } catch (IOException e) { Assert.fail(e.getMessage()); } }
From source file:com.liato.bankdroid.banking.banks.PlusGirot.java
@Override public Urllib login() throws LoginException, BankException { try {/* w ww . j a va 2 s . co m*/ LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("elaktigt kontonummer")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.vsct.dt.strowgr.admin.repository.consul.ConsulReaderTest.java
@Test public void should_throw_exception_when_status_out_of_range_200_299() { for (int status = 100; status < 600; status++) { if (status >= 200 && status < 300) continue; // skip // given/*from w w w .jav a 2s . c o m*/ HttpResponse httpResponse = mock(HttpResponse.class); when(httpResponse.getStatusLine()) .thenReturn(new BasicStatusLine(new ProtocolVersion("http1.1", 1, 1), status, "")); BasicHttpEntity givenHttpEntity = new BasicHttpEntity(); givenHttpEntity.setContent(new ByteArrayInputStream("".getBytes(StandardCharsets.UTF_8))); when(httpResponse.getEntity()).thenReturn(givenHttpEntity); // test try { new ConsulReader(null).parseHttpResponse(httpResponse, this::getHttpEntity); // check fail("can't reach this point for status " + status); } catch (ClientProtocolException e) { // check assertThat(e.getMessage()).contains(String.valueOf(status)); } } }
From source file:com.liato.bankdroid.banking.banks.Nordnet.java
@Override public Urllib login() throws LoginException, BankException { try {// w ww .j a v a 2 s . c o m LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("fel vid inloggningen")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.emobc.android.utils.RetreiveFileContentTask.java
@Override protected String doInBackground(URL... params) { URL url = params[0];/* w ww . j a va 2 s. co m*/ HttpClient httpclient = HttpUtils .getHttpClient(url.getProtocol().equalsIgnoreCase(HttpUtils.HTTPS_PROTOCOL)); HttpUriRequest httpUriRequest = createUriRequest(url); try { // Execute HTTP Post Request HttpResponse response = httpclient.execute(httpUriRequest); if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { String str = EntityUtils.toString(response.getEntity()); return str; } else { Log.w("RetreiveFileContentTask: ", "HttpStatus Code: " + String.valueOf(response.getStatusLine().getStatusCode())); } } catch (ClientProtocolException e) { Log.e("RetreiveFileContentTask: ClientProtocolException: ", e.getMessage()); // Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } catch (IOException e) { Log.e("RetreiveFileContentTask: IOException: ", e.getMessage()); // Toast.makeText(context, e.getMessage(), Toast.LENGTH_SHORT).show(); } return ""; }
From source file:com.ubikod.urbantag.UrbanTagApplication.java
@Override protected void onApplicationProcessCreate() { Log.i(UrbanTag.TAG, "Launching App !"); /* re initiate wifi message display */ SharedPreferences pref = getApplicationContext().getSharedPreferences("URBAN_TAG_PREF", Context.MODE_PRIVATE); pref.edit().putBoolean("notifiedWifi", false).commit(); /* Fetch tags list */ AsyncTask<Void, Void, List<Tag>> updateTagList = new AsyncTask<Void, Void, List<Tag>>() { @Override// ww w .ja v a2s . c o m protected List<Tag> doInBackground(Void... v) { List<Tag> res = new ArrayList<Tag>(); HttpClient client = new DefaultHttpClient(); HttpGet request = new HttpGet(UrbanTag.API_URL + ACTION_FETCH_TAGS_LIST); Log.i(UrbanTag.TAG, "Fetching tags list on : " + request.getURI().toString()); try { HttpResponse response = client.execute(request); BufferedReader rd = new BufferedReader( new InputStreamReader(response.getEntity().getContent())); String textResponse = ""; String line = ""; while ((line = rd.readLine()) != null) { textResponse += line; } Log.i(UrbanTag.TAG, "Received :" + textResponse); JSONArray jsonTagsArray = new JSONArray(textResponse); for (int i = 0; i < jsonTagsArray.length(); i++) { Tag t = TagManager.createTag(jsonTagsArray.getJSONObject(i)); if (t != null) { res.add(t); } } } catch (ClientProtocolException cpe) { Log.e(UrbanTag.TAG, cpe.getMessage()); } catch (IOException ioe) { Log.e(UrbanTag.TAG, ioe.getMessage()); } catch (JSONException je) { Log.e(UrbanTag.TAG, je.getMessage()); } return res; } @Override protected void onPostExecute(List<Tag> list) { TagManager tagManager = new TagManager(new DatabaseHelper(getApplicationContext(), null)); if (list.size() > 0) tagManager.update(list); } }; updateTagList.execute(); }
From source file:fr.redteam.dressyourself.plugins.weather.yahooWeather.WOEIDUtils.java
private String queryYahooWeather(String queryString) { Log.d(TAG, "QueryYahooWeather"); String qResult = ""; HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(queryString); try {//w w w. j av a 2 s . c o m HttpEntity httpEntity = httpClient.execute(httpGet).getEntity(); if (httpEntity != null) { InputStream inputStream = httpEntity.getContent(); Reader in = new InputStreamReader(inputStream); BufferedReader bufferedreader = new BufferedReader(in); StringBuilder stringBuilder = new StringBuilder(); String stringReadLine = null; while ((stringReadLine = bufferedreader.readLine()) != null) { stringBuilder.append(stringReadLine + "\n"); } qResult = stringBuilder.toString(); } } catch (ClientProtocolException e) { Log.d(TAG_ERREUR_METEO, e.getMessage()); } catch (IOException e) { Log.d(TAG_ERREUR_METEO, e.getMessage()); } return qResult; }
From source file:gov.nih.nci.caxchange.messaging.RegisterConsentIntegrationTest.java
/** * Testcase for registerConsents when Specimen doesn't exist */// w w w . j a v a2 s. c o m @Test public void registerConsentsSpecimenNotExist() { try { final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl); final StringEntity reqentity = new StringEntity(getRegisterConsentSpecimenNotExistXMLStr()); httppost.setEntity(reqentity); httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT); final HttpResponse response = httpclient.execute(httppost); final HttpEntity entity = response.getEntity(); String createdXML = null; if (entity != null) { createdXML = EntityUtils.toString(entity); Assert.assertEquals(true, createdXML.contains("<errorCode>1090</errorCode>")); } } catch (ClientProtocolException e) { Assert.fail(e.getMessage()); } catch (IllegalStateException e) { Assert.fail(e.getMessage()); } catch (IOException e) { Assert.fail(e.getMessage()); } }
From source file:gov.nih.nci.caxchange.messaging.RegisterConsentIntegrationTest.java
private void createSpecimen() { try {/*from w ww. j a v a 2s. c om*/ final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl); String xmlString = getInsertSpecimenXMLStr(); xmlString = xmlString.replaceAll("102", "102_Consent"); final StringEntity reqentity = new StringEntity(xmlString); httppost.setEntity(reqentity); httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT); final HttpResponse response = httpclient.execute(httppost); final HttpEntity entity = response.getEntity(); String createdXML = null; if (entity != null) { createdXML = EntityUtils.toString(entity); Assert.assertEquals(true, createdXML.contains("<responseStatus>SUCCESS</responseStatus>")); } } catch (ClientProtocolException e) { Assert.fail(e.getMessage()); } catch (IllegalStateException e) { Assert.fail(e.getMessage()); } catch (IOException e) { Assert.fail(e.getMessage()); } }
From source file:gov.nih.nci.caxchange.messaging.AdverseEventIntegrationTest.java
/** * TestCase for Creating Adverse Event in caAERS *///from w w w . j a va 2 s . co m @Test public void createAdverseEvent() { try { final HttpPost httppost = new HttpPost(transcendCaxchangeServiceUrl); final StringEntity reqentity = new StringEntity(getCreateAdverseEventXMLStr()); httppost.setEntity(reqentity); httppost.setHeader(HttpHeaders.CONTENT_TYPE, XMLTEXT); final HttpResponse response = httpclient.execute(httppost); final HttpEntity entity = response.getEntity(); String createdXML = null; if (entity != null) { createdXML = EntityUtils.toString(entity); Assert.assertEquals(true, createdXML.contains("<responseStatus>SUCCESS</responseStatus>")); } } catch (ClientProtocolException e) { Assert.fail(e.getMessage()); } catch (IllegalStateException e) { Assert.fail(e.getMessage()); } catch (IOException e) { Assert.fail(e.getMessage()); } }