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

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

Introduction

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

Prototype

public String toString() 

Source Link

Document

Returns a short description of this throwable.

Usage

From source file:org.openmrs.module.dhisreport.web.controller.LocationMappingController.java

public Metadata getDHIS2OrganizationUnits() throws Exception {
    String username = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2UserName");
    String password = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2Password");
    String dhisurl = Context.getAdministrationService().getGlobalProperty("dhisreport.dhis2URL");
    String url = dhisurl + "/api/organisationUnits.xml?fields=name,code&paging=false";
    // String url = "https://play.dhis2.org/demo/api/dataSets";
    // String referer = webRequest.getHeader( "Referer" );

    DefaultHttpClient httpClient = new DefaultHttpClient();
    HttpGet getRequest = new HttpGet(url);
    getRequest.addHeader("accept", "application/xml");
    getRequest.addHeader(//from  w  ww  . j ava 2 s  . com
            BasicScheme.authenticate(new UsernamePasswordCredentials(username, password), "UTF-8", false));
    HttpResponse response;
    InputStream is = null;
    Metadata metadata = null;
    try {
        response = httpClient.execute(getRequest);
        is = response.getEntity().getContent();
        // String result = getStringFromInputStream( is );
        // System.out.println( result + "\n" );
        JAXBContext jaxbContext = JAXBContext.newInstance(Metadata.class);
        javax.xml.bind.Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        metadata = (Metadata) jaxbUnmarshaller.unmarshal(is);

        return metadata;
    } catch (ClientProtocolException e) {
        log.debug("ClientProtocolException occured : " + e.toString());
        e.printStackTrace();
    } finally {
        is.close();
    }
    return metadata;

}

From source file:com.phildatoon.weather.WOEIDUtils.java

private String fetchWOEIDxmlString(Context context, String queryString) {
    MyLog.d("fetch WOEID xml string");
    String qResult = "";

    HttpClient httpClient = new DefaultHttpClient();

    HttpGet httpGet = new HttpGet(queryString);

    try {//from   w  w  w.  j  av a  2  s  .  c om
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            Reader in = new InputStreamReader(inputStream);
            BufferedReader bufferedreader = new BufferedReader(in);
            StringBuilder stringBuilder = new StringBuilder();

            String readLine = null;

            while ((readLine = bufferedreader.readLine()) != null) {
                MyLog.d(readLine);
                stringBuilder.append(readLine + "\n");
            }

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return qResult;
}

From source file:com.example.apis.ifashion.WOEIDUtils.java

private String fetchWOEIDxmlString(Context context, String queryString) {
    YahooWeatherLog.d("fetch WOEID xml string");
    String qResult = "";

    HttpClient httpClient = NetworkUtils.createHttpClient();

    HttpGet httpGet = new HttpGet(queryString);

    try {/*ww  w  .j a  v  a 2s .  c  o m*/
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            Reader in = new InputStreamReader(inputStream);
            BufferedReader bufferedreader = new BufferedReader(in);
            StringBuilder stringBuilder = new StringBuilder();

            String readLine = null;

            while ((readLine = bufferedreader.readLine()) != null) {
                YahooWeatherLog.d(readLine);
                stringBuilder.append(readLine + "\n");
            }

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (ConnectTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return qResult;
}

From source file:info.androidhive.androidsplashscreentimer.WOEIDUtils.java

private String fetchWOEIDxmlString(Context context, String queryString) {
    MyLog.d("fetch WOEID xml string");
    String qResult = "";

    HttpClient httpClient = NetworkUtils.createHttpClient();

    HttpGet httpGet = new HttpGet(queryString);

    try {// w ww .  ja va 2 s  .c  om
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            Reader in = new InputStreamReader(inputStream);
            BufferedReader bufferedreader = new BufferedReader(in);
            StringBuilder stringBuilder = new StringBuilder();

            String readLine = null;

            while ((readLine = bufferedreader.readLine()) != null) {
                MyLog.d(readLine);
                stringBuilder.append(readLine + "\n");
            }

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (ConnectTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (SocketTimeoutException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } finally {
        httpClient.getConnectionManager().shutdown();
    }

    return qResult;
}

From source file:org.cloudsimulator.controller.BusinessConfigurationController.java

public void sendXmlRdfOfBusinessConfigurationToKB() {
    ResponseMessageString responseMessage;
    hideSendForm();/*from www  .j ava 2 s.  co  m*/
    try {
        responseMessage = KBDAO.sendXMLToKB("PUT", this.ipOfKB, "businessConfiguration",
                this.businessConfiguration.getLocalUri(), this.createdXmlRdfBusinessConfiguration);

        if (responseMessage != null) {
            if (responseMessage.getResponseCode() < 400) {
                this.sendDone = "done";
            } else {
                this.sendDone = "error";
            }

            if (responseMessage.getResponseBody() != null) {
                this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode()
                        + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />"
                        + responseMessage.getResponseBody().replace("\n", "<br />");
            } else {
                this.alertMessage = "<strong>Response Code </strong>: " + responseMessage.getResponseCode()
                        + " <strong>Reason</strong>: " + responseMessage.getReason() + "<br />";
            }
        }
    } catch (ClientProtocolException e) {
        LOGGER.error(e.getMessage(), e);
        this.sendDone = "exception";
        this.alertMessage = e.toString();
    } catch (IOException e) {
        LOGGER.error(e.getMessage(), e);
        this.sendDone = "exception";
        this.alertMessage = e.toString();
    }
}

From source file:com.michael.feng.utils.YahooWeather4a.YahooWeatherUtils.java

private String getWeatherString(Context context, String woeidNumber) {
    String qResult = "";
    String queryString = "http://weather.yahooapis.com/forecastrss?w=" + woeidNumber;

    HttpClient httpClient = new DefaultHttpClient();
    HttpGet httpGet = new HttpGet(queryString);

    try {/*from   ww  w. j a  v  a  2s  .co  m*/
        HttpEntity httpEntity = httpClient.execute(httpGet).getEntity();

        if (httpEntity != null) {
            InputStream inputStream = httpEntity.getContent();
            Reader in = new InputStreamReader(inputStream);
            BufferedReader bufferedreader = new BufferedReader(in);
            StringBuilder stringBuilder = new StringBuilder();

            String stringReadLine = null;

            while ((stringReadLine = bufferedreader.readLine()) != null) {
                stringBuilder.append(stringReadLine + "\n");
            }

            qResult = stringBuilder.toString();
        }

    } catch (ClientProtocolException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    } catch (IOException e) {
        e.printStackTrace();
        Toast.makeText(context, e.toString(), Toast.LENGTH_LONG).show();
    }

    return qResult;
}

From source file:org.ubicompforall.BusTUC.Queries.Browser.java

public StringBuffer getRequestStandard(String buf) {
    StringBuffer html_string = new StringBuffer();
    String foo = "";
    Long time = System.nanoTime();
    try {/*from   ww  w  .  ja  v  a2  s  . co  m*/
        HttpPost m_post = new HttpPost(
                "http://busstjener.idi.ntnu.no/busstuc/oracle?q=" + URLEncoder.encode(buf, "ISO8859-1"));
        //HttpResponse m_response = m_client.execute(m_post);
        System.out.println("Wanted String: " + buf);
        // quick hax
        foo = EntityUtils.toString(m_client.execute(m_post).getEntity(), "UTF-8");
        ;
        html_string.append(foo);
        // Will fail if server is busy or down
        Log.v("html_string", "Returned html: " + html_string);
    } catch (ClientProtocolException e) {
        Log.v("CLIENTPROTOCOL EX", "e:" + e.toString());
    } catch (IOException e) {
        Log.v("IO EX", "e:" + e.toString());

    } catch (NullPointerException e) {
        Log.v("NULL", "NullPointer");
    } catch (StringIndexOutOfBoundsException e) {
        Log.v("StringIndexOutOfBounds", "Exception");
    } catch (Exception e) {
        e.printStackTrace();
    }
    return html_string;
}

From source file:org.droidkit.app.UpdateService.java

private boolean updateVersion(String apk) {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(apk);
    boolean result = false;

    try {/*from  w ww.ja v  a 2 s  . co  m*/
        HttpResponse response = client.execute(get);
        InputStream in = response.getEntity().getContent();

        File localFile = new File(
                Environment.getExternalStorageDirectory() + "/" + apk.substring(apk.lastIndexOf("/") + 1));
        FileOutputStream out = new FileOutputStream(localFile);
        int count;
        byte[] buffer = new byte[8196];

        while ((count = in.read(buffer)) > 0) {
            out.write(buffer, 0, count);
        }

        out.close();
        in.close();
        result = true;
    } catch (ClientProtocolException e) {
        Log.e("DroidKit", "Error retrieving updated apk: " + e.toString());
    } catch (IOException e) {
        Log.e("DroidKit", "Error retrieving updated apk: " + e.toString());
    }

    client.getConnectionManager().shutdown();
    return result;
}

From source file:org.droidkit.app.UpdateService.java

private void queryServer() {
    DefaultHttpClient client = new DefaultHttpClient();
    HttpGet get = new HttpGet(mUpdateServer + "?foobar=boo");
    StringBuffer obj = new StringBuffer();

    Log.i("DroidKit", "Checking updates: " + mUpdateServer);

    try {/*ww w.  j ava2  s  .c  om*/
        HttpResponse response = client.execute(get);
        InputStream in = response.getEntity().getContent();

        BufferedReader reader = new BufferedReader(new InputStreamReader(in),
                (int) response.getEntity().getContentLength());

        String line = "";

        while ((line = reader.readLine()) != null) {
            obj.append(line);
            obj.append("\n");
        }
    } catch (ClientProtocolException e) {
        Log.e("DroidKit", "Error contacting update server: " + e.toString());
    } catch (IOException e) {
        Log.e("DroidKit", "Error contacting update server: " + e.toString());
    }

    client.getConnectionManager().shutdown();

    parseJSONResponse(obj.toString());
}

From source file:org.ubicompforall.BusTUC.Queries.Browser.java

public String getRequestServer(String stop, Boolean formated, Location location, int numStops, int dist,
        Context context) {/*w  w w  .j ava2  s .co  m*/
    String html_string = null;
    HttpGet m_get = new HttpGet();
    try {
        stop = URLEncoder.encode(stop, "UTF-8");
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // HttpPost m_post= new
    // HttpPost("http://m.atb.no/xmlhttprequest.php?service=routeplannerOracle.getOracleAnswer&question=");
    try {
        final TelephonyManager tm = (TelephonyManager) context.getSystemService(Context.TELEPHONY_SERVICE);
        String t_id = tm.getDeviceId();
        String tmp = "TABuss";
        String p_id = Secure.getString(context.getContentResolver(), Secure.ANDROID_ID);
        m_get.setURI(new URI("http://busstjener.idi.ntnu.no/MultiBRISserver/MBServlet?dest=" + stop + "&lat="
                + location.getLatitude() + "&long=" + location.getLongitude() + "&type=json&nStops=" + numStops
                + "&maxWalkDist=" + dist + "&key=" + tmp + p_id));
        HttpResponse m_response = m_client.execute(m_get);
        // Request
        html_string = httpF.requestServer(m_response);
        // Will fail if server is busy or down
        Log.v("html_string", "Returned html: " + html_string);
        // Long newTime = System.nanoTime() - time;
        // System.out.println("TIMEEEEEEEEEEEEEEEEEEEEE: " +
        // newTime/1000000000.0);
    } catch (ClientProtocolException e) {
        Log.v("CLIENTPROTOCOL EX", "e:" + e.toString());
    } catch (IOException e) {
        Log.v("IO EX", "e:" + e.toString());

    } catch (NullPointerException e) {
        Log.v("NULL", "NullPointer");
    } catch (StringIndexOutOfBoundsException e) {
        Log.v("StringIndexOutOfBounds", "Exception");
    } catch (Exception e) {
        e.printStackTrace();
    }

    return html_string;
}