List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:org.envirocar.server.event.HTTPPushListener.java
private synchronized void pushNewTrack(Track track) { HttpResponse resp = null;// ww w . j a v a 2s. c om try { ObjectNode jsonTrack = encoder.encodeJSON(track, DEFAULT_ACCESS_RIGHTS, MediaTypes.TRACK_TYPE); String content = writer.writeValueAsString(jsonTrack); logger.debug("Entity: {}", content); HttpEntity entity = new StringEntity(content, ContentType.create(MediaTypes.TRACK)); HttpPost hp = new HttpPost(host); hp.setEntity(entity); resp = this.client.execute(hp); } catch (ClientProtocolException e) { logger.warn(e.getMessage(), e); } catch (IOException e) { logger.warn(e.getMessage(), e); } finally { if (resp != null) { try { EntityUtils.consume(resp.getEntity()); } catch (IOException e) { logger.warn(e.getMessage()); } } } }
From source file:com.normalexception.app.rx8club.task.DeletePmTask.java
@Override protected Void doInBackground(Void... params) { try {//from w w w . j av a 2s. com HtmlFormUtils.deletePM(this.token, this.pmid); } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(), e); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:de.schneider.dev.poi.service.OpenStreetMapGeoService.java
public void getGeoCoordinate(String location) throws EncoderException { LOG.info("Start GeoCoordination OpenStreetMap"); // create default HttpClient HttpClient httpClient = new DefaultHttpClient(); // get data from URI URLCodec urlCodec = new URLCodec("UTF-8"); HttpGet httpGet = new HttpGet(URI_String + urlCodec.encode(location) + "&format=json"); LOG.info("HttpGet: " + httpGet); LOG.debug(httpGet.toString());/*from w w w . ja v a2 s . c o m*/ LOG.debug("HttpGetURI: " + httpGet.getURI()); // get response try { HttpResponse httpResponse = httpClient.execute(httpGet); LOG.info("HttpResponse: " + httpResponse); LOG.info("Status Code: " + httpResponse.getStatusLine().getStatusCode()); LOG.info("Status Phrase: " + httpResponse.getStatusLine().getReasonPhrase()); HttpEntity httpEntity = httpResponse.getEntity(); LOG.info("HttpEntity: " + httpEntity); LOG.info("HttpEntity Streaming: " + httpEntity.isStreaming()); if (httpEntity.isStreaming()) { InputStream inputStream = httpEntity.getContent(); String content = EntityUtils.toString(httpEntity); LOG.info(content); inputStream.close(); } } catch (ClientProtocolException cpe) { LOG.error(cpe.getMessage()); } catch (IOException ioe) { LOG.error(ioe.getMessage()); } }
From source file:com.normalexception.app.rx8club.task.PmTask.java
@Override protected Void doInBackground(Void... params) { try {// w w w . j ava2 s. c o m HtmlFormUtils.submitPM(doType, token, text, title, recipients, pmid); } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(), e); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:com.normalexception.app.rx8club.task.NewThreadTask.java
@Override protected Void doInBackground(Void... arg0) { try {/* w w w . j a v a 2 s .c om*/ HtmlFormUtils.newThread(forumId, s, token, posthash, subject, post); } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(), e); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } return null; }
From source file:nl.raja.niruraji.pa.domain.RestClientApacheHttpClient.java
@Override public String getString(String url) { if (url == null || url.isEmpty()) { String errorMsg = "The url can't be NULL or empty"; LOGGER.error(errorMsg);/*from ww w .ja v a2 s. c o m*/ throw (new IllegalArgumentException(errorMsg)); } String result = null; try { // create HTTP Client HttpClient httpClient = HttpClientBuilder.create().build(); // Create new getRequest with below mentioned URL HttpGet getRequest = new HttpGet(url); // Add additional header to getRequest which accepts application/xml data getRequest.addHeader(HttpHeaders.ACCEPT, MediaType.APPLICATION_JSON); // Execute your request and catch response HttpResponse response = httpClient.execute(getRequest); // Check for HTTP response code: 200 = success if (response.getStatusLine().getStatusCode() != 200) { String msg = "API call failed : HTTP error code : " + response.getStatusLine().getStatusCode(); LOGGER.warn(msg); throw new RuntimeException(msg); } result = EntityUtils.toString(response.getEntity()); } catch (ClientProtocolException e) { String msg = "API call failed : " + e.getMessage(); LOGGER.warn(msg); } catch (IOException e) { String msg = "Error reading api response : " + e.getMessage(); LOGGER.error(msg); } return result; }
From source file:org.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"); HttpClient httpClient = SagePayUtil.getHttpClient(); 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 w w. j av a 2s .com 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 { 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 String errorMsg = "Error occured in encoding parameters for HttpPost (" + uee.getMessage() + ")"; Debug.logError(uee, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } catch (ClientProtocolException cpe) { //from httpClient execute String errorMsg = "Error occured in HttpClient execute(" + cpe.getMessage() + ")"; Debug.logError(cpe, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } catch (IOException ioe) { //from httpClient execute or getResponsedata String errorMsg = "Error occured in HttpClient execute or getting response (" + ioe.getMessage() + ")"; Debug.logError(ioe, errorMsg, module); resultMap = ServiceUtil.returnError(errorMsg); } finally { httpClient.getConnectionManager().shutdown(); } return resultMap; }
From source file:org.jenkinsci.plugins.kubernetesworkflowsteps.KubeStepExecution.java
protected <T extends HttpRequestBase> CloseableHttpResponse makeCall(T request) throws ClientProtocolException, IOException, KeyManagementException, NoSuchAlgorithmException, KeyStoreException { CloseableHttpResponse response;/*from w ww. j a va 2 s.c o m*/ try { response = getClient().execute(host, request); } catch (ClientProtocolException e) { System.err.println(e.getMessage()); throw e; } return response; }
From source file:com.aegiswallet.tasks.SendShamirValueTask.java
@Override protected Object doInBackground(Object[] objects) { httpclient = new DefaultHttpClient(); httppost = new HttpPost(Constants.AEGIS_SITE); Log.d(TAG, "sending shamir"); try {/* ww w. j a v a 2s . c o m*/ // Add your data TelephonyManager tManager = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE); String uid = tManager.getDeviceId(); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(2); nameValuePairs.add(new BasicNameValuePair("device", uid)); nameValuePairs.add(new BasicNameValuePair("message", x3Value)); httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); // Execute HTTP Post Request HttpResponse response = httpclient.execute(httppost); int statusCode = response.getStatusLine().getStatusCode(); Log.d(TAG, "response for shamir: " + statusCode); if (statusCode != 200) { //TODO: did not succeed } else { //Means we have successfully exported the key to BitcoinSecurityProject.org application.getPrefs().edit().remove(Constants.SHAMIR_EXPORTED_KEY).commit(); } } catch (ClientProtocolException e) { Log.d(TAG, e.getMessage()); } catch (IOException e) { Log.d(TAG, e.getMessage()); } return null; }
From source file:com.normalexception.app.rx8club.task.UpdateTask.java
@Override protected Void doInBackground(Void... params) { try {//w w w .j a v a 2s. c om if (delete) { HtmlFormUtils.submitDelete(securitytoken, p); } else { HtmlFormUtils.submitEdit(securitytoken, p, posthash, poststarttime, msg); } } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage(), e); } catch (IOException e) { Log.e(TAG, e.getMessage(), e); } return null; }