List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:com.moarub.kipptapi.KipptAPIToken.java
@Override protected StringBuilder doInBackground(String... u) { String username = u[0];/* w w w. jav a2 s .c o m*/ String password = u[1]; DefaultHttpClient client = new DefaultHttpClient(); Credentials creds = new UsernamePasswordCredentials(username, password); client.getCredentialsProvider().setCredentials(new AuthScope(AuthScope.ANY_HOST, AuthScope.ANY_PORT), creds); try { HttpGet request = new HttpGet(reqTokenUrl); HttpResponse response = client.execute(request); return ShareMoreUtils.getResponseString(response); } catch (ClientProtocolException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } catch (IOException e) { Log.d("ApiTokenFailure", "Can't fetch API Token " + e.getMessage()); return null; } }
From source file:org.vsearchd.crawler.backend.BackendSessionHTTP.java
private void handleOutputMessage() { try {//from ww w.j a va2s. co m para.clear(); for (OutputField field : this.message.getFields()) { para.add(new BasicNameValuePair(field.getName(), URLEncoder.encode(field.getValue(), "UTF-8"))); } formEntity = new UrlEncodedFormEntity(para); httppost.setURI(new URI("http://" + this.getBackendServer().getHost() + ":" + String.valueOf(this.getBackendServer().getPort()) + "/" + this.getBackendServer().getFilePath())); httppost.setEntity(formEntity); response = httpclient.execute(httppost); entity = response.getEntity(); instr = entity.getContent(); while (instr.read() > -1) ; instr.close(); } catch (ClientProtocolException e) { log.error(e.getMessage()); } catch (IOException e) { log.error(e.getMessage()); } catch (URISyntaxException e) { log.error(e.getMessage()); } }
From source file:com.aware.utils.Http.java
/** * Request a GET from an URL. //from w ww . j ava 2 s . c o m * @param url * @return HttpEntity with the content of the reply. Use EntityUtils to get content. */ public HttpResponse dataGET(String url) { try { HttpClient httpClient = new DefaultHttpClient(); HttpGet httpGet = new HttpGet(url); HttpResponse httpResponse = httpClient.execute(httpGet); int statusCode = httpResponse.getStatusLine().getStatusCode(); if (statusCode != 200) { if (Aware.DEBUG) { Log.d(TAG, "Status: " + statusCode); Log.e(TAG, "URL:" + url); Log.e(TAG, EntityUtils.toString(httpResponse.getEntity())); } } return httpResponse; } catch (ClientProtocolException e) { if (Aware.DEBUG) Log.e(TAG, e.getMessage()); return null; } catch (IOException e) { if (Aware.DEBUG) Log.e(TAG, e.getMessage()); return null; } }
From source file:lets.code.project.conectividad.BasicWebService.java
public void postData() { httpPost = new HttpPost(webServiceUrl); try {/*from w w w . j a va 2 s.co m*/ List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("id", "1")); nameValuePairs.add(new BasicNameValuePair("name", "crf")); nameValuePairs.add(new BasicNameValuePair("course", "android")); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); httpClient.execute(httpPost); } catch (ClientProtocolException e) { Log.e("WebService:", " ClientProtocolException " + e.getMessage()); } catch (IOException e) { Log.e("WebService:", " IOException " + e.getMessage()); } }
From source file:org.apache.ofbiz.accounting.thirdparty.sagepay.SagePayServices.java
public static Map<String, Object> paymentAuthentication(DispatchContext ctx, Map<String, Object> context) { Debug.logInfo("SagePay - Entered paymentAuthentication", module); Debug.logInfo("SagePay paymentAuthentication context : " + context, module); Delegator delegator = ctx.getDelegator(); Map<String, Object> resultMap = new HashMap<String, Object>(); Map<String, String> props = buildSagePayProperties(context, delegator); String vendorTxCode = (String) context.get("vendorTxCode"); String cardHolder = (String) context.get("cardHolder"); String cardNumber = (String) context.get("cardNumber"); String expiryDate = (String) context.get("expiryDate"); String cardType = (String) context.get("cardType"); String cv2 = (String) context.get("cv2"); String amount = (String) context.get("amount"); String currency = (String) context.get("currency"); String description = (String) context.get("description"); String billingSurname = (String) context.get("billingSurname"); String billingFirstnames = (String) context.get("billingFirstnames"); String billingAddress = (String) context.get("billingAddress"); String billingAddress2 = (String) context.get("billingAddress2"); String billingCity = (String) context.get("billingCity"); String billingPostCode = (String) context.get("billingPostCode"); String billingCountry = (String) context.get("billingCountry"); String billingState = (String) context.get("billingState"); String billingPhone = (String) context.get("billingPhone"); Boolean isBillingSameAsDelivery = (Boolean) context.get("isBillingSameAsDelivery"); String deliverySurname = (String) context.get("deliverySurname"); String deliveryFirstnames = (String) context.get("deliveryFirstnames"); String deliveryAddress = (String) context.get("deliveryAddress"); String deliveryAddress2 = (String) context.get("deliveryAddress2"); String deliveryCity = (String) context.get("deliveryCity"); String deliveryPostCode = (String) context.get("deliveryPostCode"); String deliveryCountry = (String) context.get("deliveryCountry"); String deliveryState = (String) context.get("deliveryState"); String deliveryPhone = (String) context.get("deliveryPhone"); String startDate = (String) context.get("startDate"); String issueNumber = (String) context.get("issueNumber"); String basket = (String) context.get("basket"); String clientIPAddress = (String) context.get("clientIPAddress"); Locale locale = (Locale) context.get("locale"); HttpHost host = SagePayUtil.getHost(props); //start - authentication parameters Map<String, String> parameters = new HashMap<String, String>(); String vpsProtocol = props.get("protocolVersion"); String vendor = props.get("vendor"); String txType = props.get("authenticationTransType"); //start - required parameters parameters.put("VPSProtocol", vpsProtocol); parameters.put("TxType", txType); parameters.put("Vendor", vendor); if (vendorTxCode != null) { parameters.put("VendorTxCode", vendorTxCode); }//from w ww.ja v a 2 s. c om if (amount != null) { parameters.put("Amount", amount); } if (currency != null) { parameters.put("Currency", currency); } //GBP/USD if (description != null) { parameters.put("Description", description); } if (cardHolder != null) { parameters.put("CardHolder", cardHolder); } if (cardNumber != null) { parameters.put("CardNumber", cardNumber); } if (expiryDate != null) { parameters.put("ExpiryDate", expiryDate); } if (cardType != null) { parameters.put("CardType", cardType); } //start - billing details if (billingSurname != null) { parameters.put("BillingSurname", billingSurname); } if (billingFirstnames != null) { parameters.put("BillingFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("BillingAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("BillingAddress2", billingAddress2); } if (billingCity != null) { parameters.put("BillingCity", billingCity); } if (billingPostCode != null) { parameters.put("BillingPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("BillingCountry", billingCountry); } if (billingState != null) { parameters.put("BillingState", billingState); } if (billingPhone != null) { parameters.put("BillingPhone", billingPhone); } //end - billing details //start - delivery details if (isBillingSameAsDelivery != null && isBillingSameAsDelivery) { if (billingSurname != null) { parameters.put("DeliverySurname", billingSurname); } if (billingFirstnames != null) { parameters.put("DeliveryFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("DeliveryAddress", billingAddress); } if (billingAddress2 != null) { parameters.put("DeliveryAddress2", billingAddress2); } if (billingCity != null) { parameters.put("DeliveryCity", billingCity); } if (billingPostCode != null) { parameters.put("DeliveryPostCode", billingPostCode); } if (billingCountry != null) { parameters.put("DeliveryCountry", billingCountry); } if (billingState != null) { parameters.put("DeliveryState", billingState); } if (billingPhone != null) { parameters.put("DeliveryPhone", billingPhone); } } else { if (deliverySurname != null) { parameters.put("DeliverySurname", deliverySurname); } if (deliveryFirstnames != null) { parameters.put("DeliveryFirstnames", deliveryFirstnames); } if (deliveryAddress != null) { parameters.put("DeliveryAddress", deliveryAddress); } if (deliveryAddress2 != null) { parameters.put("DeliveryAddress2", deliveryAddress2); } if (deliveryCity != null) { parameters.put("DeliveryCity", deliveryCity); } if (deliveryPostCode != null) { parameters.put("DeliveryPostCode", deliveryPostCode); } if (deliveryCountry != null) { parameters.put("DeliveryCountry", deliveryCountry); } if (deliveryState != null) { parameters.put("DeliveryState", deliveryState); } if (deliveryPhone != null) { parameters.put("DeliveryPhone", deliveryPhone); } } //end - delivery details //end - required parameters //start - optional parameters if (cv2 != null) { parameters.put("CV2", cv2); } if (startDate != null) { parameters.put("StartDate", startDate); } if (issueNumber != null) { parameters.put("IssueNumber", issueNumber); } if (basket != null) { parameters.put("Basket", basket); } if (clientIPAddress != null) { parameters.put("ClientIPAddress", clientIPAddress); } //end - optional parameters //end - authentication parameters try (CloseableHttpClient httpClient = SagePayUtil.getHttpClient()) { String successMessage = null; HttpPost httpPost = SagePayUtil.getHttpPost(props.get("authenticationUrl"), parameters); HttpResponse response = httpClient.execute(host, httpPost); Map<String, String> responseData = SagePayUtil.getResponseData(response); String status = responseData.get("Status"); String statusDetail = responseData.get("StatusDetail"); resultMap.put("status", status); resultMap.put("statusDetail", statusDetail); //returning the below details back to the calling code, as it not returned back by the payment gateway resultMap.put("vendorTxCode", vendorTxCode); resultMap.put("amount", amount); resultMap.put("transactionType", txType); //start - transaction authorized if ("OK".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("txAuthNo", responseData.get("TxAuthNo")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment authorized"; } //end - transaction authorized if ("NOTAUTHED".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); successMessage = "Payment not authorized"; } if ("MALFORMED".equals(status)) { //request not formed properly or parameters missing resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("INVALID".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } if ("REJECTED".equals(status)) { //invalid information in request resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("securityKey", responseData.get("SecurityKey")); resultMap.put("avsCv2", responseData.get("AVSCV2")); resultMap.put("addressResult", responseData.get("AddressResult")); resultMap.put("postCodeResult", responseData.get("PostCodeResult")); resultMap.put("cv2Result", responseData.get("CV2Result")); } resultMap.put(ModelService.RESPONSE_MESSAGE, ModelService.RESPOND_SUCCESS); resultMap.put(ModelService.SUCCESS_MESSAGE, successMessage); } catch (UnsupportedEncodingException uee) { //exception in encoding parameters in httpPost Debug.logError(uee, "Error occurred in encoding parameters for HttpPost (" + uee.getMessage() + ")", module); resultMap = ServiceUtil .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorEncodingParameters", UtilMisc.toMap("errorString", uee.getMessage()), locale)); } catch (ClientProtocolException cpe) { //from httpClient execute Debug.logError(cpe, "Error occurred in HttpClient execute(" + cpe.getMessage() + ")", module); resultMap = ServiceUtil .returnError(UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecute", UtilMisc.toMap("errorString", cpe.getMessage()), locale)); } catch (IOException ioe) { //from httpClient execute or getResponsedata Debug.logError(ioe, "Error occurred in HttpClient execute or getting response (" + ioe.getMessage() + ")", module); resultMap = ServiceUtil.returnError( UtilProperties.getMessage(resource, "AccountingSagePayErrorHttpClientExecuteOrGettingResponse", UtilMisc.toMap("errorString", ioe.getMessage()), locale)); } return resultMap; }
From source file:com.liato.bankdroid.banking.banks.McDonalds.java
@Override public Urllib login() throws LoginException, BankException { try {//from w w w . j a v a 2 s.co m LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("felaktigt kortnummer")) { throw new LoginException(res.getText(R.string.invalid_card_number).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }
From source file:com.liato.bankdroid.banking.banks.AvanzaMini.java
@Override public void update() throws BankException, LoginException { super.update(); if (username == null || password == null || username.length() == 0 || password.length() == 0) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); }/* ww w.j a v a 2s . co m*/ urlopen = login(); String response = null; Matcher matcher; try { response = urlopen.open("https://www.avanza.se/mini/mitt_konto/index.html"); matcher = reAvanzaMini.matcher(response); if (matcher.find()) { int count = 1; Matcher submatcher = accountsAvanzaMini.matcher(matcher.group(1)); while (submatcher.find()) { accounts.add(new Account(Html.fromHtml(submatcher.group(1)).toString().trim(), Helpers.parseBalance(submatcher.group(2)), Integer.toString(count))); balance = balance.add(Helpers.parseBalance(submatcher.group(2))); count++; } } if (accounts.isEmpty()) { throw new BankException(res.getText(R.string.no_accounts_found).toString()); } } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } finally { super.updateComplete(); } }
From source file:com.liato.bankdroid.banking.banks.SevenDay.java
@Override public Urllib login() throws LoginException, BankException { try {/*from w w w .j a v a 2 s . co m*/ LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("Logga in med personnummer") || response.contains("kommer automatiskt till startsidan")) { 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:org.yaoha.OsmNodeRetrieverTask.java
@Override protected Void doInBackground(Void... params) { while (!queue.isEmpty()) { URI uri = null;//from ww w.jav a 2 s .c om synchronized (queue) { uri = queue.remove(); } Log.d(OsmNodeRetrieverTask.class.getSimpleName(), "Queue holds " + queue.size() + " tasks"); ApiConnector connector = new ApiConnector(); InputStream in; try { in = connector.getNodes(uri).getEntity().getContent(); } catch (ClientProtocolException e) { Log.d(OsmNodeRetrieverTask.class.getSimpleName(), e.getMessage()); continue; } catch (IOException e) { Log.d(OsmNodeRetrieverTask.class.getSimpleName(), e.getMessage()); continue; } OsmXmlParser parser = new OsmXmlParser(); parser.parse(in, this.nodeReceiver); } callListenersAllRequestsDone(); return null; }
From source file:com.liato.bankdroid.banking.banks.Rikslunchen.java
@Override public Urllib login() throws LoginException, BankException { try {/*from www . j a v a2 s .c o m*/ LoginPackage lp = preLogin(); if (lp.getResponse().contains("Ange giltigt kortnummer.")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } myResponse = lp.getResponse(); } catch (ClientProtocolException e) { throw new BankException(e.getMessage()); } catch (IOException e) { throw new BankException(e.getMessage()); } return urlopen; }