List of usage examples for org.apache.http.client ClientProtocolException getMessage
public String getMessage()
From source file:com.walmart.retailtech.move.innovationte.startersprestplus.listeners.LogWriterInterceptor.java
public void handleMessage(Message message) throws Fault { /*//from www. ja v a2s.c o m * Validate the requestor */ // Begin by parsing the header. String method = message.get(Message.HTTP_REQUEST_METHOD).toString(); if (method.equals("OPTIONS") || method.equals("HEAD")) return; JsonObject jsonHeaders = new JsonObject(); try { String headers = new Gson().toJson(message.get(Message.PROTOCOL_HEADERS)); jsonHeaders = new Gson().fromJson(headers, JsonObject.class); } catch (Exception e) { throw new Fault("Access Absolutely Denied!" + e.getMessage(), LOG); } String user = jsonHeaders.get("userid").getAsString(); if (user.trim().equals("") || user.equals(null)) throw new Fault("Access Absolutely Denied!", LOG); // Validate user credentials HttpClient httpClient = HttpClientBuilder.create().build(); // add the auth URL here HttpGet get = new HttpGet(""); HttpResponse response = null; try { response = httpClient.execute(get); StatusLine status = response.getStatusLine(); if (status.getStatusCode() != 200) throw new Fault("Access Absolutely Denied!", LOG); //throw new RuntimeException( "Access Denied" ); //( "**** DATA ****" ); //HttpEntity ent = response.getEntity(); //System.out.println( "Entity: " + EntityUtils.toString( ent ) ); } catch (ClientProtocolException cpe) { throw new Fault(cpe.getMessage(), LOG); //throw new RuntimeException( cpe ); } catch (IOException ioe) { throw new Fault(ioe.getMessage(), LOG); //throw new RuntimeException( ioe ); } /* * Uncomment the below code if you need to * do something with the incoming payload. */ // Parse the request message payload /* String payload = null; Logger logger = getMessageLogger( message ); if ( writer != null || logger.isLoggable(Level.INFO) ) { payload = logging(logger, message).toString().replaceAll("\n", ""); // Do something with the payload... } */ }
From source file:org.opencastproject.workflow.handler.HttpNotificationWorkflowOperationHandler.java
/** * Execute the given notification request. If the target is not responding, retry as many time as the maxAttampts * parameter with in between each try a sleep time. * * @param request// www. ja v a 2 s. c o m * The request to execute * @param maxAttempts * The number of attempts in case of error * @param timeout * The wait time in milliseconds at which a connection attempt will throw * @return true if the request has been executed successfully */ private boolean executeRequest(HttpUriRequest request, int maxAttempts, int timeout, int sleepTime) { logger.debug(format("Executing notification request on target %s, %d attemps left", request.getURI(), maxAttempts)); DefaultHttpClient httpClient = new DefaultHttpClient(); httpClient.getParams().setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, timeout); HttpResponse response; try { response = httpClient.execute(request); } catch (ClientProtocolException e) { logger.error(format("Protocol error during execution of query on target %s: %s", request.getURI(), e.getMessage())); return false; } catch (IOException e) { logger.error(format("I/O error during execution of query on target %s: %s", request.getURI(), e.getMessage())); return false; } Integer statusCode = response.getStatusLine().getStatusCode(); if (statusCode == SC_OK || statusCode == SC_NO_CONTENT || statusCode == SC_ACCEPTED) { logger.debug(format("Request successfully executed on target %s, status code: %d", request.getURI(), statusCode)); return true; } else if (maxAttempts > 1) { logger.debug(format("Request failed on target %s, status code: %d, will retry in %d seconds", request.getURI(), statusCode, sleepTime / 1000)); try { Thread.sleep(sleepTime); return executeRequest(request, --maxAttempts, timeout, sleepTime * SLEEP_SCALE_FACTOR); } catch (InterruptedException e) { logger.error("Error during sleep time before new notification request try: {}", e.getMessage()); return false; } } else { logger.warn(format("Request failed on target %s, status code: %d, no more attempt.", request.getURI(), statusCode)); return false; } }
From source file:net.evecom.androidecssp.activity.taskresponse.TaskAndResponsesInfoActivity.java
@Override protected void onResume() { super.onResume(); if (ifloadresponselist) { ifloadresponselist = false;/*from ww w . j a va2s . com*/ new Thread(new Runnable() { @Override public void run() { Message message = new Message(); HashMap<String, String> hashMap = new HashMap<String, String>(); hashMap.put("taskId", taskInfo.get("id").toString()); try { resPonsesresutArray = connServerForResultPost( "jfs/ecssp/mobile/taskresponseCtr/getTaskResponseByTaskId", 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 (resPonsesresutArray.length() > 0) { try { taskResponseInfos = getObjsInfo(resPonsesresutArray); if (null == taskResponseInfos) { 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", resPonsesresutArray); responseListHandler.sendMessage(message); } }).start(); } }
From source file:com.liato.bankdroid.banking.banks.Lansforsakringar.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()); }/*from w w w . j a v a2 s.c om*/ urlopen = login(); String response = null; Matcher matcher; try { if (accountsUrl == null) { Log.d(TAG, "accountsUrl is null, unable to update."); return; } response = urlopen.open(accountsUrl); matcher = reAccountsReg.matcher(response); while (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Account number 125486547 * 2: Name Personkonto * 3: Amount 25 000 000 * */ accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(), Helpers.parseBalance(matcher.group(3).trim()), matcher.group(1).trim())); balance = balance.add(Helpers.parseBalance(matcher.group(3))); } matcher = reAccountsFunds.matcher(response); while (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Name Fonder * 2: ID idJsp165 * 3: Amount 0,00 * */ accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(3).trim()), matcher.group(2).trim(), Account.FUNDS)); } matcher = reAccountsLoans.matcher(response); while (matcher.find()) { /* * Capture groups: * GROUP EXAMPLE DATA * 1: Name Privatlån * 2: ID idJsp207 * 3: Amount 25 000 000 * 4: Debt 1,00 * */ accounts.add(new Account(Html.fromHtml(matcher.group(1)).toString().trim(), Helpers.parseBalance(matcher.group(4).trim()), matcher.group(2).trim(), Account.LOANS)); } // Save token for next request matcher = reToken.matcher(response); if (!matcher.find()) { throw new BankException(res.getText(R.string.unable_to_find).toString() + " token."); } mRequestToken = matcher.group(1); 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.adam.aslfms.service.Handshaker.java
/** * Connects to Last.fm servers and tries to handshake/authenticate. A * successful handshake is needed for all other submission requests. If an * error occurs, exceptions are thrown.//from ww w. j a va 2 s. c o m * * @return the result of a successful handshake, {@link HandshakeResult} * @throws BadAuthException * means that the username/password provided by the user was * wrong, or that the user requested his/her credentials to be * cleared. * @throws TemporaryFailureException * @throws UnknownResponseException * {@link UnknownResponseException} * @throws ClientBannedException * this version of the client has been banned */ public HandshakeResult handshake() throws BadAuthException, TemporaryFailureException, ClientBannedException { Log.d(TAG, "Handshaking: " + getNetApp().getName()); String username = settings.getUsername(getNetApp()); String pwdMd5 = settings.getPwdMd5(getNetApp()); if (username.length() == 0) { Log.d(TAG, "Invalid (empty) username for: " + getNetApp().getName()); throw new BadAuthException(getContext().getString(R.string.auth_bad_auth)); } // ----------------------------------------------------------------------- // ------------ for debug // ------------------------------------------------ // use these values if you are testing or developing a new app // String clientid = "tst"; // String clientver = "1.0"; // ----------------------------------------------------------------------- // ------------ for this app // --------------------------------------------- // ----------------------------------------------------------------------- // These values should only be used for SLS. If other code // misbehaves using these values, this app might get banned. // You can ask Last.fm for your own ids. String clientid = getContext().getString(R.string.client_id); String clientver = getContext().getString(R.string.client_ver); // ------------ end // ------------------------------------------------------ // ----------------------------------------------------------------------- String time = new Long(Util.currentTimeSecsUTC()).toString(); String authToken = MD5.getHashString(pwdMd5 + time); String uri = getNetApp().getHandshakeUrl() + "&p=1.2.1&c=" + clientid + "&v=" + clientver + "&u=" + enc(username) + "&t=" + time + "&a=" + authToken; DefaultHttpClient http = new DefaultHttpClient(); HttpGet request = new HttpGet(uri); try { ResponseHandler<String> handler = new BasicResponseHandler(); String response = http.execute(request, handler); String[] lines = response.split("\n"); if (lines.length == 4 && lines[0].equals("OK")) { // handshake succeeded Log.i(TAG, "Handshake succeeded!: " + getNetApp().getName()); HandshakeResult hi = new HandshakeResult(lines[1], lines[2], lines[3]); return hi; } else if (lines.length == 1) { if (lines[0].startsWith("BANNED")) { Log.e(TAG, "Handshake fails: client banned: " + getNetApp().getName()); throw new ClientBannedException(getContext().getString(R.string.auth_client_banned)); } else if (lines[0].startsWith("BADAUTH")) { Log.i(TAG, "Handshake fails: bad auth: " + getNetApp().getName()); throw new BadAuthException(getContext().getString(R.string.auth_bad_auth)); } else if (lines[0].startsWith("BADTIME")) { Log.e(TAG, "Handshake fails: bad time: " + getNetApp().getName()); throw new TemporaryFailureException(getContext().getString(R.string.auth_timing_error)); } else if (lines[0].startsWith("FAILED")) { String reason = lines[0].substring(7); Log.e(TAG, "Handshake fails: FAILED " + reason + ": " + getNetApp().getName()); throw new TemporaryFailureException( getContext().getString(R.string.auth_server_error).replace("%1", reason)); } } else { throw new TemporaryFailureException( "Weird response from handskake-req: " + response + ": " + getNetApp().getName()); } } catch (ClientProtocolException e) { throw new TemporaryFailureException(TAG + ": " + e.getMessage()); } catch (IOException e) { throw new TemporaryFailureException(TAG + ": " + e.getMessage()); } finally { http.getConnectionManager().shutdown(); } return null; }
From source file:net.evecom.androidecssp.activity.taskresponse.TaskAddActivity.java
/** * //from w w w .j av a2 s . c om * * * @author Mars zhang * @created 2015-11-25 2:06:28 * @param entity */ private void postdata(final HashMap<String, String> entity) { new Thread(new Runnable() { @Override public void run() { Message message = new Message(); try { saveResult = connServerForResultPost("jfs/ecssp/mobile/taskresponseCtr/taskadd", entity); } 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 (saveResult.length() > 0) { message.what = MESSAGETYPE_01; } else { message.what = MESSAGETYPE_02; } Log.v("mars", saveResult); saveHandler.sendMessage(message); } }).start(); }
From source file:com.liato.bankdroid.banking.banks.CSN.java
@Override public Urllib login() throws LoginException, BankException { try {//from w w w .j av a2s . c om LoginPackage lp = preLogin(); response = urlopen.open(lp.getLoginTarget(), lp.getPostData()); Matcher matcher = reLoginError.matcher(response); if (matcher.find()) { throw new LoginException(Html.fromHtml(matcher.group(1)).toString().trim()); } if (!response.contains("Inloggad som")) { throw new BankException(res.getText(R.string.unable_to_login).toString()); } } catch (ClientProtocolException e) { throw new BankException("login:CPE:" + e.getCause().getMessage()); } catch (IOException e) { e.printStackTrace(); throw new BankException("login:IOE:" + e.getMessage()); } return urlopen; }
From source file:com.osafe.services.sagepay.SagePayTokenServices.java
public static Map<String, Object> paymentAuthentication(DispatchContext ctx, Map<String, Object> context) { Debug.logInfo("SagePay Token - Entered paymentAuthentication", module); // Debug.logInfo("SagePay Token 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 token = (String) context.get("token"); 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"); String storeToken = props.get("storeToken"); if (UtilValidate.isEmpty(storeToken)) { storeToken = "0"; }/*from www .j av a 2 s . c om*/ //start - required parameters parameters.put("VPSProtocol", vpsProtocol); parameters.put("TxType", txType); parameters.put("Vendor", vendor); // parameters.put("StoreToken", storeToken); if (vendorTxCode != null) { parameters.put("VendorTxCode", vendorTxCode); } if (amount != null) { parameters.put("Amount", amount); } if (currency != null) { parameters.put("Currency", currency); } //GBP/USD if (description != null) { parameters.put("Description", description); } if (token != null) { parameters.put("Token", token); } if (storeToken != null) { parameters.put("StoreToken", storeToken); } //start - billing details 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 ("USA".equals(billingCountry) || "CAN".equals(billingCountry)) { if (UtilValidate.isNotEmpty(billingState)) { 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("DeliveryAddress1", 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("DeliveryAddress1", 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 ("USA".equals(deliveryCountry) || "CAN".equals(deliveryCountry)) { if (UtilValidate.isNotEmpty(deliveryState)) { 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:com.liato.bankdroid.banking.Bank.java
public SessionPackage getSessionPackage(Context context) { String preloader = "Error..."; try {/* w ww . j a v a 2 s .c o m*/ preloader = IOUtils.toString(context.getResources().openRawResource(R.raw.loading)); } catch (NotFoundException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } catch (IOException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } try { LoginPackage lp = preLogin(); if (lp == null) { throw new BankException( "No automatic login for this bank. preLogin() is not implemented or has failed."); } String html = String.format(preloader, "function go(){document.getElementById('submitform').submit(); }", // Javascript function Helpers.renderForm(lp.getLoginTarget(), lp.getPostData()) + "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML ); CookieStore cookies = urlopen.getHttpclient().getCookieStore(); return new SessionPackage(html, cookies); } catch (ClientProtocolException e) { Log.e(TAG, e.getMessage()); } catch (IOException e) { Log.e(TAG, e.getMessage()); } catch (BankException e) { Log.e(TAG, e.getMessage()); } String html = String.format(preloader, String.format("function go(){window.location=\"%s\" }", this.URL), // Javascript function "<script type=\"text/javascript\">setTimeout('go()', 1000);</script>" // HTML ); return new SessionPackage(html, null); }
From source file:de.dan_nrw.android.followerstat.dao.folllowers.TwitterFollowerDAO.java
@Override public long getFollowerCount(String userName) throws TwitterUserAccountNotFoundException, TwitterRequestException { try {//from w w w.j a v a2 s .com String json = this.sendRequest( URI.create(String.format("http://twitter.com/users/show/%s.json", userName)), new StringResponseHandler(), true); JSONObject jsonObject = new JSONObject(json); return jsonObject.getLong("followers_count"); } catch (ClientProtocolException ex) { throw new TwitterRequestException(ex); } catch (SecurityException ex) { throw new TwitterAuthException(ex.getCause()); } catch (IOException ex) { if (ex.getMessage().equals("404")) { throw new TwitterUserAccountNotFoundException(); } throw new TwitterRequestException(ex); } catch (JSONException ex) { throw new TwitterResponseParsingException(ex); } catch (OAuthExpectationFailedException ex) { throw new TwitterAuthException(ex); } catch (OAuthException ex) { throw new TwitterAuthException(ex); } }