Example usage for org.apache.http.client ClientProtocolException getMessage

List of usage examples for org.apache.http.client ClientProtocolException getMessage

Introduction

In this page you can find the example usage for org.apache.http.client ClientProtocolException getMessage.

Prototype

public String getMessage() 

Source Link

Document

Returns the detail message string of this throwable.

Usage

From source file:net.evecom.androidecssp.activity.TaskListActivity.java

/**
 * /* w ww.  j  a  v  a 2 s .com*/
 */
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());
                hashMap.put("projectId", projectInfo.get("id").toString());
                System.out.println(hashMap.values().toArray().toString());
                resutArray = connServerForResultPost(
                        "jfs/ecssp/mobile/taskresponseCtr/getTaskByEventIdAndProjectId", 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 {
                    taskInfos = getObjsInfo(resutArray);
                    if (null == taskInfos) {
                        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);
            eventListHandler.sendMessage(message);

        }
    }).start();

}

From source file:net.orpiske.ssps.common.resource.HttpResourceExchange.java

public ResourceInfo info(URI uri) throws ResourceExchangeException {
    HttpHead httpHead = new HttpHead(uri);
    HttpResponse response;//from  w ww  . j  a v a2  s.co  m
    try {
        response = httpClient.execute(httpHead);

        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode == HttpStatus.SC_OK) {
            long length = getContentLength(response);
            logger.debug("Reading " + length + " bytes from the server");

            ResourceInfo ret = new ResourceInfo();

            ret.setSize(length);
            ret.setLastModified(getLastModified(response));

            return ret;
        } else {
            switch (statusCode) {
            case HttpStatus.SC_NOT_FOUND:
                throw new ResourceExchangeException("Remote file not found");
            case HttpStatus.SC_BAD_REQUEST:
                throw new ResourceExchangeException("The client sent a bad request");
            case HttpStatus.SC_FORBIDDEN:
                throw new ResourceExchangeException("Accessing the resource is forbidden");
            case HttpStatus.SC_UNAUTHORIZED:
                throw new ResourceExchangeException("Unauthorized");
            case HttpStatus.SC_INTERNAL_SERVER_ERROR:
                throw new ResourceExchangeException("Internal server error");
            default:
                throw new ResourceExchangeException("Unable to download file: http status code " + statusCode);
            }
        }
    } catch (ClientProtocolException e) {
        throw new ResourceExchangeException("Unhandled protocol error: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new ResourceExchangeException("I/O error: " + e.getMessage(), e);
    }
}

From source file:org.arquillian.droidium.native_.selendroid.SelendroidServerManager.java

/**
 * Waits for the start of Selendroid server.
 *
 * After installation and execution of instrumentation command, we repeatedly send HTTP request to status page to get
 * response code of 200 - server is up and running and we can proceed safely to testing process.
 *
 * @param port port to wait on the communication from installed Selendroid server
 * @throws InvalidSelendroidPortException if {@code port} is invalid
 *///from  w ww  .  j ava  2s.  c  o  m
private void waitUntilSelendroidServerCommunication(int port) {
    validatePort(port);

    RequestConfig config = RequestConfig.custom().setConnectTimeout(CONNECTION_TIME_OUT_SECONDS * 1000)
            .setConnectionRequestTimeout(CONNECTION_TIME_OUT_SECONDS * 1000)
            .setSocketTimeout(SOCKET_TIME_OUT_SECONDS * 1000).build();

    CloseableHttpClient client = HttpClients.custom().setDefaultRequestConfig(config)
            .disableContentCompression().build();

    HttpGet httpGet = new HttpGet(getSelendroidStatusURI(port));

    boolean connectionSuccess = false;

    for (int i = NUM_CONNECTION_RETIRES; i > 0; i--) {
        try {
            HttpResponse response = client.execute(httpGet);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode == 200) {
                connectionSuccess = true;
                break;
            }
            logger.log(Level.INFO,
                    i + ": Response was not 200 from port " + port + ", response was: " + statusCode);
        } catch (ClientProtocolException e) {
            logger.log(Level.WARNING, e.getMessage());
        } catch (IOException e) {
            logger.log(Level.WARNING, e.getMessage());
        }
    }

    try {
        client.close();
    } catch (IOException e) {
        logger.log(Level.WARNING, e.getMessage());
    }

    if (!connectionSuccess) {
        throw new AndroidExecutionException("Unable to get successful connection from Selendroid http server.");
    }
}

From source file:com.liato.bankdroid.banking.banks.seb.SEB.java

@Override
public Urllib login() throws LoginException, BankException {
    try {//  ww  w.  ja v a 2 s.c  o m
        urlopen = new Urllib(context,
                CertificateReader.getClientCertificate(context, R.raw.cert_client_seb, "openbankdata"),
                CertificateReader.getCertificates(context, R.raw.cert_seb));
        urlopen.setFollowRedirects(false);
        List<NameValuePair> postData = new ArrayList<NameValuePair>();
        postData.add(new BasicNameValuePair("A1", username));
        postData.add(new BasicNameValuePair("A2", password));
        HttpResponse hr = urlopen.openAsHttpResponse(
                "https://mP.seb.se/nauth2/Authentication/Auth?SEB_Referer=/priv/ServiceFactory-pw", postData,
                true);
        if (hr.getStatusLine().getStatusCode() == 200) {
            throw new LoginException(res.getString(R.string.invalid_username_password));
        } else if (hr.getStatusLine().getStatusCode() != 302) {
            throw new BankException(res.getString(R.string.unable_to_login));
        }
        urlopen.setFollowRedirects(true);
    } catch (ClientProtocolException e) {
        throw new BankException(e.getMessage());
    } catch (IOException e) {
        e.printStackTrace();
        throw new BankException(e.getMessage());
    }
    return urlopen;
}

From source file:com.nextgis.firereporter.ScanexHttpLogin.java

@Override
protected Void doInBackground(String... urls) {
    if (HttpGetter.IsNetworkAvailible(mContext)) {
        String sUser = urls[0];//from www  . j  a  v a 2s.  c  o m
        String sPass = urls[1];

        try {

            // Create a new HttpClient
            HttpClient httpclient = new DefaultHttpClient();

            // step 1. open login dialog
            String sRedirect = "http://fires.kosmosnimki.ru/SAPI/oAuthCallback.html&authServer=MyKosmosnimki";
            String sURL = "http://fires.kosmosnimki.ru/SAPI/LoginDialog.ashx?redirect_uri="
                    + Uri.encode(sRedirect);
            HttpGet httpget = new HttpGet(sURL);
            HttpParams params = httpget.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httpget.setParams(params);
            HttpResponse response = httpclient.execute(httpget);

            //2 get cookie and params            
            Header head = response.getFirstHeader("Set-Cookie");
            String sCookie = head.getValue();

            head = response.getFirstHeader("Location");
            String sLoc = head.getValue();

            Uri uri = Uri.parse(sLoc);
            String sClientId = uri.getQueryParameter("client_id");
            String sScope = uri.getQueryParameter("scope");
            String sState = uri.getQueryParameter("state");

            String sPostUri = "http://my.kosmosnimki.ru/Account/LoginDialog?redirect_uri="
                    + Uri.encode(sRedirect) + "&client_id=" + sClientId + "&scope=" + sScope + "&state="
                    + sState;

            HttpPost httppost = new HttpPost(sPostUri);

            params = httppost.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httppost.setHeader("Cookie", sCookie);

            List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>();
            nameValuePairs.add(new BasicNameValuePair("email", sUser));
            nameValuePairs.add(new BasicNameValuePair("password", sPass));
            nameValuePairs.add(new BasicNameValuePair("IsApproved", "true"));
            httppost.setEntity(new UrlEncodedFormEntity(nameValuePairs));

            response = httpclient.execute(httppost);
            head = response.getFirstHeader("Set-Cookie");

            if (head == null) {
                mError = mContext.getString(R.string.noNetwork);
                return null;
            }

            sCookie += "; " + head.getValue();
            head = response.getFirstHeader("Location");
            sLoc = head.getValue();

            uri = Uri.parse(sLoc);
            String sCode = uri.getQueryParameter("code");
            sState = uri.getQueryParameter("state");

            //3 get 
            String sGetUri = "http://fires.kosmosnimki.ru/SAPI/Account/logon/?authServer=MyKosmosnimki&code="
                    + sCode + "&state=" + sState;
            httpget = new HttpGet(sGetUri);
            httpget.setHeader("Cookie", sCookie);
            params = httpget.getParams();
            params.setParameter(ClientPNames.HANDLE_REDIRECTS, Boolean.FALSE);
            httpget.setParams(params);
            response = httpclient.execute(httpget);

            head = response.getFirstHeader("Set-Cookie");
            if (head == null) {
                mError = mContext.getString(R.string.noNetwork);
                return null;
            }
            sCookie += "; " + head.getValue();

            Bundle bundle = new Bundle();
            if (sCookie.length() > 0) {
                //if(bGetCookie){
                bundle.putBoolean(GetFiresService.ERROR, false);
                bundle.putString(GetFiresService.JSON, sCookie);
                //bundle.putString("json", mContent);
            } else {
                bundle.putBoolean(GetFiresService.ERROR, true);
            }

            bundle.putInt(GetFiresService.SOURCE, mnType);
            Message msg = new Message();
            msg.setData(bundle);
            if (mEventReceiver != null) {
                mEventReceiver.sendMessage(msg);
            }

        } catch (ClientProtocolException e) {
            mError = e.getMessage();
            return null;
        } catch (IOException e) {
            mError = e.getMessage();
            return null;
        } catch (Exception e) {
            mError = e.getMessage();
            return null;
        }
    } else {
        Bundle bundle = new Bundle();
        bundle.putBoolean(GetFiresService.ERROR, true);
        bundle.putString(GetFiresService.ERR_MSG, mContext.getString(R.string.noNetwork));
        bundle.putInt(GetFiresService.SOURCE, mnType);

        Message msg = new Message();
        msg.setData(bundle);
        if (mEventReceiver != null) {
            mEventReceiver.sendMessage(msg);
        }
    }
    return null;
}

From source file:uk.co.uwcs.choob.modules.HttpModule.java

private synchronized String execute(final HttpRequestBase method) {
    String response = null;/*from www  .j  av  a 2s  .co  m*/
    // execute method returns?!? (rather than async) - do it here sync, and
    // wrap async elsewhere
    try {
        response = HttpModule.client.execute(method, responseHandler);
    } catch (ClientProtocolException e) {
        response = HttpModule.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
        // e.printStackTrace();
    } catch (IOException e) {
        response = HttpModule.HTTP_RESPONSE_ERROR + " - " + e.getClass().getSimpleName() + " " + e.getMessage();
        // e.printStackTrace();
    }
    return response;
}

From source file:com.liato.bankdroid.banking.banks.Nordea.Nordea.java

@Override
public void update() throws BankException, LoginException, BankChoiceException {
    super.update();
    if (username == null || password == null || username.length() == 0 || password.length() == 0) {
        throw new LoginException(res.getText(R.string.invalid_username_password).toString());
    }// w ww . ja va2 s. c  om

    urlopen = login();
    String response = null;
    Matcher matcher;
    try {
        response = urlopen.open("https://mobil.nordea.se/banking-nordea/nordea-c3/accounts.html");
        matcher = reAccounts.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3)), matcher.group(1).trim()));
        }
        /*
         * Capture groups:
         * GROUP                EXAMPLE DATA
         * 1: Currency          SEK
         * 2: Amount            56,78  
         *   
         */
        matcher = reBalance.matcher(response);
        String currency = "SEK";
        if (matcher.find()) {
            balance = Helpers.parseBalance(matcher.group(2));
            currency = Html.fromHtml(matcher.group(1)).toString().trim();
        }
        this.setCurrency(currency);

        response = urlopen.open("https://mobil.nordea.se/banking-nordea/nordea-c3/funds/portfolio/funds.html");
        matcher = reFundsLoans.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3)), "f:" + matcher.group(1).trim(), -1L,
                    Account.FUNDS));
        }

        response = urlopen.open("https://mobil.nordea.se/banking-nordea/nordea-c3/accounts.html?type=lan");
        matcher = reFundsLoans.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3)), "l:" + matcher.group(1).trim(), -1L,
                    Account.LOANS));
        }

        response = urlopen.open("https://mobil.nordea.se/banking-nordea/nordea-c3/card/list.html");
        matcher = reCards.matcher(response);
        while (matcher.find()) {
            accounts.add(new Account(Html.fromHtml(matcher.group(2)).toString().trim(),
                    Helpers.parseBalance(matcher.group(3)), "c:" + matcher.group(1).trim(), -1L,
                    Account.CCARD));
        }

        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();
    }

    // Demo account to use with screenshots
    //accounts.add(new Account("Personkonto", Helpers.parseBalance("7953.37"), "1"));
    //accounts.add(new Account("Kapitalkonto", Helpers.parseBalance("28936.08"), "0"));

}

From source file:net.orpiske.ssps.common.resource.HttpResourceExchange.java

public Resource<InputStream> get(URI uri) throws ResourceExchangeException {
    HttpGet httpget = new HttpGet(uri);
    HttpResponse response;/*from  w w w .  j  a  v  a  2  s. c o m*/
    try {

        response = httpClient.execute(httpget);

        int statusCode = response.getStatusLine().getStatusCode();

        if (statusCode == HttpStatus.SC_OK) {
            HttpEntity entity = response.getEntity();

            if (entity != null) {
                logger.debug("Reading " + entity.getContentLength() + " bytes from the server");

                Resource<InputStream> ret = new Resource<InputStream>();

                ret.setPayload(entity.getContent());

                ResourceInfo info = new ResourceInfo();

                info.setSize(entity.getContentLength());
                info.setLastModified(getLastModified(response));
                ret.setResourceInfo(info);

                return ret;
            }
        } else {
            switch (statusCode) {
            case HttpStatus.SC_NOT_FOUND:
                throw new ResourceExchangeException("Remote file not found");
            case HttpStatus.SC_BAD_REQUEST:
                throw new ResourceExchangeException("The client sent a bad request");
            case HttpStatus.SC_FORBIDDEN:
                throw new ResourceExchangeException("Accessing the resource is forbidden");
            case HttpStatus.SC_UNAUTHORIZED:
                throw new ResourceExchangeException("Unauthorized");
            case HttpStatus.SC_INTERNAL_SERVER_ERROR:
                throw new ResourceExchangeException("Internal server error");
            default:
                throw new ResourceExchangeException("Unable to download file: http status code " + statusCode);
            }
        }
    } catch (ClientProtocolException e) {
        throw new ResourceExchangeException("Unhandled protocol error: " + e.getMessage(), e);
    } catch (IOException e) {
        throw new ResourceExchangeException("I/O error: " + e.getMessage(), e);
    }

    return null;
}

From source file:com.buession.cas.client.RestfulAuthentication.java

/**
 * ? Service Ticket/* www  .  j  a va2  s .c o  m*/
 * 
 * @param ticketGrantingTicket
 *        Ticket Granting Ticket
 * @param service
 * @return Service Ticket
 */
@SuppressWarnings("deprecation")
public String getServiceTicket(final String ticketGrantingTicket, final String service) {
    Validate.notBlank(ticketGrantingTicket, "TicketGrantingTicket could not be null or empty");

    final String url = configuration.getServer() + "/v1/tickets/" + ticketGrantingTicket;
    final HttpPost httpPost = new HttpPost(url);

    httpPost.setConfig(requestConfig);

    List<NameValuePair> params = new ArrayList<NameValuePair>();
    params.add(new BasicNameValuePair("service", service));

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(params, HTTP.UTF_8));
        try {
            HttpResponse response = httpClient.execute(httpPost);
            int statusCode = response.getStatusLine().getStatusCode();
            if (statusCode >= 200 && statusCode < 300) {
                final String content = EntityUtils.toString(response.getEntity());

                logger.debug("get Service Ticket: {}", content);
                return content;
            } else {
                logger.warn("Invalid response code \"{}\" from CASServer", statusCode);
            }
        } catch (ClientProtocolException e) {
            logger.error(e.getMessage());
        } catch (IOException e) {
            logger.error(e.getMessage());
        } finally {
            httpPost.releaseConnection();
        }
    } catch (UnsupportedEncodingException e) {
        logger.warn("Encoding {} could noe support", HTTP.UTF_8);
    } finally {
        httpPost.releaseConnection();
    }

    return null;
}

From source file:org.openbmap.soapclient.CheckServerTask.java

/**
 * Sends a https request to website to check if server accepts user name and password
 * @return true if server confirms credentials
 *//*from ww  w  .  j a  v a2  s  .co  m*/
private boolean credentialsAccepted(String user, String password) {

    if (user == null || password == null) {
        return false;
    }

    final DefaultHttpClient httpclient = new DefaultHttpClient();
    final HttpPost httppost = new HttpPost(Preferences.PASSWORD_VALIDATION_URL);
    try {
        final String authorizationString = "Basic "
                + Base64.encodeToString((user + ":" + password).getBytes(), Base64.NO_WRAP);
        httppost.setHeader("Authorization", authorizationString);
        final HttpResponse response = httpclient.execute(httppost);

        final int reply = response.getStatusLine().getStatusCode();
        if (reply == 200) {
            Log.v(TAG, "Server accepted credentials");
            return true;
        } else if (reply == 401) {
            Log.e(TAG, "Server authentication failed");
            return false;
        } else {
            Log.w(TAG, "Generic error: server reply " + reply);
            return false;
        }
        // TODO: redirects (301, 302) are NOT handled here
        // thus if something changes on the server side we're dead here
    } catch (final ClientProtocolException e) {
        Log.e(TAG, e.getMessage(), e);
    } catch (final IOException e) {
        Log.e(TAG, "I/O exception while checking credentials " + e.getMessage(), e);
    }
    return false;
}