List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.RetrieveSEEHandler.java
@Override public Object execute(ExecutionEvent event) throws ExecutionException { try {/* w w w.ja v a 2 s. c om*/ if (SkillproService.getSkillproProvider().getSEERepo().isEmpty()) { getAllSEE(); } else { getNewSEE(); } } catch (ClientProtocolException e) { e.printStackTrace(); MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "Protocol exception", e.getMessage(), SWT.SHEET); } catch (IOException e) { e.printStackTrace(); MessageDialog.open(MessageDialog.ERROR, HandlerUtil.getActiveShell(event), "IOException exception", e.getMessage(), SWT.SHEET); } return null; }
From source file:com.osafe.services.sagepay.SagePayTokenServices.java
public static Map<String, Object> paymentRefund(DispatchContext ctx, Map<String, Object> context) { Debug.logInfo("SagePay Token - Entered paymentRefund", module); // Debug.logInfo("SagePay Token - paymentRefund 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 relatedVPSTxId = (String) context.get("relatedVPSTxId"); String relatedVendorTxCode = (String) context.get("relatedVendorTxCode"); String relatedSecurityKey = (String) context.get("relatedSecurityKey"); String relatedTxAuthNo = (String) context.get("relatedTxAuthNo"); String amount = (String) context.get("amount"); String token = (String) context.get("token"); 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"); HttpClient httpClient = SagePayUtil.getHttpClient(); HttpHost host = SagePayUtil.getHost(props); //start - refund parameters Map<String, String> parameters = new HashMap<String, String>(); String vpsProtocol = props.get("protocolVersion"); String vendor = props.get("vendor"); String txType = props.get("refundTransType"); parameters.put("VPSProtocol", vpsProtocol); parameters.put("TxType", txType); parameters.put("Vendor", vendor); parameters.put("VendorTxCode", vendorTxCode); parameters.put("Amount", amount); parameters.put("Description", description); parameters.put("RelatedVPSTxId", relatedVPSTxId); parameters.put("RelatedVendorTxCode", relatedVendorTxCode); parameters.put("RelatedSecurityKey", relatedSecurityKey); parameters.put("RelatedTxAuthNo", relatedTxAuthNo); parameters.put("Token", token); parameters.put("Currency", currency); if (description != null) { parameters.put("Description", description); }//from w w w . j av a 2s . c om if (billingSurname != null) { parameters.put("BillingSurname", billingSurname); } if (billingFirstnames != null) { parameters.put("BillingFirstnames", billingFirstnames); } if (billingAddress != null) { parameters.put("BillingAddress1", 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 - refund parameters try { String successMessage = null; HttpPost httpPost = SagePayUtil.getHttpPost(props.get("refundUrl"), parameters); HttpResponse response = httpClient.execute(host, httpPost); Map<String, String> responseData = SagePayUtil.getResponseData(response); Debug.logInfo("response data -> " + responseData, module); String status = responseData.get("Status"); String statusDetail = responseData.get("StatusDetail"); resultMap.put("status", status); resultMap.put("statusDetail", statusDetail); //start - payment refunded if ("OK".equals(status)) { resultMap.put("vpsTxId", responseData.get("VPSTxId")); resultMap.put("txAuthNo", responseData.get("TxAuthNo")); successMessage = "Payment Refunded"; } //end - payment refunded //start - refund not authorized by the acquiring bank if ("NOTAUTHED".equals(status)) { successMessage = "Refund not authorized by the acquiring bank"; } //end - refund not authorized by the acquiring bank //start - refund request not formed properly or parameters missing if ("MALFORMED".equals(status)) { successMessage = "Refund request not formed properly or parameters missing"; } //end - refund request not formed properly or parameters missing //start - invalid information passed in parameters if ("INVALID".equals(status)) { successMessage = "Invalid information passed in parameters"; } //end - invalid information passed in parameters //start - problem at Sagepay if ("ERROR".equals(status)) { successMessage = "Problem at SagePay"; } //end - problem at Sagepay 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:com.radioactiveyak.location_best_practices.services.PlaceCheckinService.java
/** * Performs a checkin for the specified venue at the specified time. * TODO Add additional checkin / ratings / review details as appropriate for your service. * @param timeStamp Checkin timestamp// ww w . j av a 2 s. co m * @param reference Checkin venue reference * @param id Checkin venue unique identifier * @return Successfully checked in */ protected boolean checkin(long timeStamp, String reference, String id) { if (reference != null) { try { // Construct the URI required to perform a checkin. // TODO Replace this with the checkin URI for your own web service. URI uri = new URI(PlacesConstants.PLACES_CHECKIN_URI + PlacesConstants.PLACES_API_KEY); // Construct the payload // TODO Replace with your own payload StringBuilder postData = new StringBuilder("<CheckInRequest>\n"); postData.append(" <reference>"); postData.append(URLEncoder.encode(reference, "UTF-8")); postData.append("</reference>\n"); postData.append("</CheckInRequest>"); // Construct and execute the HTTP Post HttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uri); httppost.setEntity(new StringEntity(postData.toString())); HttpResponse response = httpClient.execute(httppost); // If the post was successful, check if this is the newest checkin, and if so save it and broadcast // an Intent to notify the application. if (response.getStatusLine().getReasonPhrase().equals(PlacesConstants.PLACES_CHECKIN_OK_STATUS)) { long lastCheckin = sharedPreferences.getLong(PlacesConstants.SP_KEY_LAST_CHECKIN_TIMESTAMP, 0); if (timeStamp > lastCheckin) { sharedPreferencesEditor.putLong(PlacesConstants.SP_KEY_LAST_CHECKIN_TIMESTAMP, timeStamp); sharedPreferencesEditor.putString(PlacesConstants.SP_KEY_LAST_CHECKIN_ID, id); sharedPreferenceSaver.savePreferences(sharedPreferencesEditor, false); Intent intent = new Intent(PlacesConstants.NEW_CHECKIN_ACTION); intent.putExtra(PlacesConstants.EXTRA_KEY_ID, id); sendBroadcast(intent); } return true; } // If the checkin fails return false. else return false; } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } catch (URISyntaxException e) { Log.e(TAG, e.getMessage()); } } return false; }
From source file:org.flowable.rest.dmn.service.api.BaseSpringDmnRestTestCase.java
protected CloseableHttpResponse internalExecuteRequest(HttpUriRequest request, int expectedStatusCode, boolean addJsonContentType) { CloseableHttpResponse response = null; try {//from w ww . j a v a 2 s . co m if (addJsonContentType && request.getFirstHeader(HttpHeaders.CONTENT_TYPE) == null) { // Revert to default content-type request.addHeader(new BasicHeader(HttpHeaders.CONTENT_TYPE, "application/json")); } response = client.execute(request); Assert.assertNotNull(response.getStatusLine()); int responseStatusCode = response.getStatusLine().getStatusCode(); if (expectedStatusCode != responseStatusCode) { log.info("Wrong status code : {}, but should be {}", responseStatusCode, expectedStatusCode); log.info("Response body: {}", IOUtils.toString(response.getEntity().getContent())); } Assert.assertEquals(expectedStatusCode, responseStatusCode); httpResponses.add(response); return response; } catch (ClientProtocolException e) { Assert.fail(e.getMessage()); } catch (IOException e) { Assert.fail(e.getMessage()); } return null; }
From source file:com.android.transmart.services.PlaceCheckinService.java
/** * Performs a checkin for the specified venue at the specified time. * TODO Add additional checkin / ratings / review details as appropriate for your service. * @param timeStamp Checkin timestamp//from ww w. jav a 2 s .com * @param reference Checkin venue reference * @param id Checkin venue unique identifier * @return Successfully checked in */ protected boolean checkin(long timeStamp, String reference, String id) { if (reference != null) { try { // Construct the URI required to perform a checkin. // TODO Replace this with the checkin URI for your own web service. URI uri = new URI(LocationConstants.PLACES_CHECKIN_URI + LocationConstants.PLACES_API_KEY); // Construct the payload // TODO Replace with your own payload StringBuilder postData = new StringBuilder("<CheckInRequest>\n"); postData.append(" <reference>"); postData.append(URLEncoder.encode(reference, "UTF-8")); postData.append("</reference>\n"); postData.append("</CheckInRequest>"); // Construct and execute the HTTP Post HttpClient httpClient = new DefaultHttpClient(); HttpPost httppost = new HttpPost(uri); httppost.setEntity(new StringEntity(postData.toString())); HttpResponse response = httpClient.execute(httppost); // If the post was successful, check if this is the newest checkin, and if so save it and broadcast // an Intent to notify the application. if (response.getStatusLine().getReasonPhrase().equals(LocationConstants.PLACES_CHECKIN_OK_STATUS)) { long lastCheckin = sharedPreferences.getLong(LocationConstants.SP_KEY_LAST_CHECKIN_TIMESTAMP, 0); if (timeStamp > lastCheckin) { sharedPreferencesEditor.putLong(LocationConstants.SP_KEY_LAST_CHECKIN_TIMESTAMP, timeStamp); sharedPreferencesEditor.putString(LocationConstants.SP_KEY_LAST_CHECKIN_ID, id); sharedPref.savePreferences(sharedPreferencesEditor, false); Intent intent = new Intent(LocationConstants.NEW_CHECKIN_ACTION); intent.putExtra(LocationConstants.EXTRA_KEY_ID, id); sendBroadcast(intent); } return true; } // If the checkin fails return false. else return false; } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } catch (URISyntaxException e) { Log.e(TAG, e.getMessage()); } } return false; }
From source file:com.tomdignan.android.opencnam.library.teststub.test.OpenCNAMRequestTestCase.java
public void testJSONRequest() { mOpenCNAMRequest.setSerializationFormat(OpenCNAMRequest.FORMAT_JSON); String response = null;/*from w w w. j a v a 2 s .co m*/ try { response = (String) mOpenCNAMRequest.execute(); } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException: " + e.getMessage()); } catch (IOException e) { Log.e(TAG, "ClientProtocolException: " + e.getMessage()); } assertNotNull(response); JSONObject object = null; try { object = new JSONObject(response); } catch (JSONException e) { e.printStackTrace(); } assertNotNull(object); String cnam = null; String number = null; try { cnam = object.getString("cnam"); } catch (JSONException e) { e.printStackTrace(); } assertNotNull(cnam); cnam = cnam.trim(); try { number = object.getString("number"); } catch (JSONException e) { e.printStackTrace(); } assertNotNull(number); number = number.trim(); assertEquals(cnam, CNAM); assertEquals(number, NUMBER); }
From source file:net.evecom.androidecssp.activity.ProjectListActivity.java
/** * /*from w w w .jav a 2 s .c o m*/ */ private void initlist() { new Thread(new Runnable() { @Override public void run() { Message message = new Message(); try { HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("eventId", eventInfo.get("id").toString()); resutArray = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/getAllProjectByeventId", hashMap); } catch (ClientProtocolException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } catch (IOException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } if (resutArray.length() > 0) { try { projectInfos = getObjsInfo(resutArray); if (null == projectInfos) { message.what = MESSAGETYPE_02; } else { message.what = MESSAGETYPE_01; } } catch (JSONException e) { message.what = MESSAGETYPE_02; Log.e("mars", e.getMessage()); } } else { message.what = MESSAGETYPE_02; } Log.v("mars", resutArray); projectListHandler.sendMessage(message); } }).start(); }
From source file:com.liato.bankdroid.banking.banks.Nordea.Nordea.java
@Override public Urllib login() throws LoginException, BankException { try {/*from www.ja va2s .co m*/ LoginPackage lp = preLogin(); String response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("felaktiga uppgifter")) { throw new LoginException(res.getText(R.string.invalid_username_password).toString()); } else if (response.contains("nloggningar med ditt personnummer idag")) { Matcher matcher = reCSRF.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " CSRF token."); } String csrftoken = matcher.group(1); Iterator<NameValuePair> it = lp.getPostData().iterator(); while (it.hasNext()) { NameValuePair nv = it.next(); if (nv.getName().equals("_csrf_token")) { it.remove(); break; } } lp.getPostData().add(new BasicNameValuePair("_csrf_token", csrftoken)); //Too many logins, we need to solve a captcha. Bitmap bm = BitmapFactory.decodeStream( urlopen.openStream("https://mobil.nordea.se/banking-nordea/nordea-c3/captcha.png")); String captcha = CaptchaBreaker.iMustBreakYou(bm); bm.recycle(); bm = null; lp.getPostData().add(new BasicNameValuePair("captcha", captcha)); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); if (response.contains("felaktiga uppgifter")) { 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.cerberus.servlet.publi.ExecuteNextInQueue.java
/** * Executes the next test case represented by the given * {@link TestCaseExecutionInQueue}/*from w ww. j av a 2 s . c om*/ * * @param lastInQueue * @param req * @param resp * @throws IOException */ private void executeNext(TestCaseExecutionInQueue lastInQueue, HttpServletRequest req, HttpServletResponse resp) throws IOException { String charset = resp.getCharacterEncoding(); String query = ""; try { ParamRequestMaker paramRequestMaker = makeParamRequestfromLastInQueue(lastInQueue); // TODO : Prefer use mkString(charset) instead of mkString(). // However the RunTestCase servlet does not decode parameters, // then we have to mkString() without using charset query = paramRequestMaker.mkString(); } catch (UnsupportedEncodingException uee) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, uee.getMessage()); return; } catch (IllegalArgumentException iae) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, iae.getMessage()); return; } catch (IllegalStateException ise) { resp.sendError(HttpServletResponse.SC_BAD_REQUEST, ise.getMessage()); return; } CloseableHttpClient httpclient = null; HttpGet httpget = null; try { httpclient = HttpClients.createDefault(); URI uri = new URIBuilder().setScheme(req.getScheme()).setHost(req.getServerName()) .setPort(req.getServerPort()).setPath(req.getContextPath() + RunTestCase.SERVLET_URL) .setCustomQuery(query).build(); httpget = new HttpGet(uri); } catch (URISyntaxException use) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, use.getMessage()); return; } CloseableHttpResponse response = null; try { response = httpclient.execute(httpget); if (response.getStatusLine().getStatusCode() != HttpServletResponse.SC_OK) { resp.sendError(response.getStatusLine().getStatusCode(), response.getStatusLine().getReasonPhrase()); } } catch (ClientProtocolException cpe) { resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, cpe.getMessage()); } finally { if (response != null) { response.close(); } } }
From source file:immf.growl.GrowlApiClient.java
public GrowlApiResult callApi(HttpPost post) { if (GrowlApiClientState.EXCEEDED == this.state) { return GrowlApiResult.EXCEEDED; } else if (GrowlApiClientState.ERROR == this.state) { return GrowlApiResult.ERROR; }/* w ww. j a va2s .c om*/ try { GrowlApiResult result = this.analyzeResponse(this.httpClient.execute(post)); if (this.internalServerErrorCount > MAX_INTERNAL_SERVER_ERROR_COUNT) { this.setState(GrowlApiClientState.ERROR); log.error("Internal server error count is exceeded."); } else { log.info("Remaining:" + this.getRemaining() + ", Reset Date:" + this.getResetTimeStamp()); } return result; } catch (ClientProtocolException e) { GrowlNotifier.log.error(e.getMessage()); } catch (IOException e) { GrowlNotifier.log.error(e.getMessage()); } finally { post.abort(); } return GrowlApiResult.ERROR; }