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

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

Introduction

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

Prototype

public void printStackTrace() 

Source Link

Document

Prints this throwable and its backtrace to the standard error stream.

Usage

From source file:net.duckling.ddl.util.RESTClient.java

public JsonObject httpPost(String url, List<NameValuePair> params) throws IOException {
    CloseableHttpClient httpclient = HttpClients.createDefault();
    try {/*  w  w w. j a v a  2 s  .c om*/
        HttpPost httppost = new HttpPost(url);
        httppost.setEntity(new UrlEncodedFormEntity(params, Consts.UTF_8));
        httppost.setHeader("accept", "application/json");
        CloseableHttpResponse response = httpclient.execute(httppost);
        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        }
        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));
        JsonParser jp = new JsonParser();
        JsonElement je = jp.parse(br);
        return je.getAsJsonObject();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    } finally {
        httpclient.close();
    }
    return null;
}

From source file:org.megam.deccanplato.provider.maluuba.handler.InterpretEndpointImpl.java

@Override
public Map<String, String> run() {
    Map<String, String> outMap = new HashMap<String, String>();
    final String NORMALIZE_URL = "http://napi.maluuba.com/v0/interpret?" + PHRASE + "=" + args.get(PHRASE) + "&"
            + APIKEY + "=" + args.get(APIKEY);

    TransportTools tst = new TransportTools(NORMALIZE_URL, null, null);
    String responseBody = null;//from  w  ww  . jav a 2s. c  om

    TransportResponse response = null;

    try {
        response = TransportMachinery.get(tst);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    responseBody = response.entityToString();

    outMap.put(OUTPUT, responseBody);
    return outMap;
}

From source file:es.warp.desktop_droid.TelephonyEventService.java

public void connectHTTP() {
    // TODO Check if internet is available
    String server = Util.retrieveServerConf(this);
    String id = Util.retrieveIdConf(this);
    String http = "http://" + server + "/notify-call/" + id;
    Log.d("TelephonyEventService", "Connecting to " + http);

    HttpClient httpclient = new DefaultHttpClient();
    HttpGet httpget = new HttpGet(http);
    try {//from   w  ww .  j  a va 2 s.  c  o  m
        httpclient.execute(httpget);
    } catch (ClientProtocolException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    } catch (IOException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
}

From source file:org.megam.deccanplato.provider.maluuba.handler.NormalizeEndpointImpl.java

@Override
public Map<String, String> run() {

    Map<String, String> outMap = new HashMap<String, String>();
    final String NORMALIZE_URL = "http://napi.maluuba.com/v0/normalize?" + PHRASE + "=" + args.get(PHRASE) + "&"
            + TYPE + "=" + args.get(TYPE) + "&" + APIKEY + "=" + args.get(APIKEY) + "&" + TIMEZONE + "="
            + args.get(TIMEZONE);//from   w  ww.  j a  v a2s . c o  m

    TransportTools tst = new TransportTools(NORMALIZE_URL, null, null);
    String responseBody = null;

    TransportResponse response = null;

    try {
        response = TransportMachinery.get(tst);
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (URISyntaxException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    responseBody = response.entityToString();

    outMap.put(OUTPUT, responseBody);
    return outMap;
}

From source file:org.semanticscience.PDBAptamerRetriever.shared.URLReader.java

private String getStringFromURLGET(String scheme, String host, String path, String query) {
    String returnMe;//from   w  w w.j  a va  2 s  .  c o  m
    try {
        URI uri = new URI(scheme, host, path, query, null);
        DefaultHttpClient client = new DefaultHttpClient();
        HttpGet get = new HttpGet(uri);
        try {
            HttpResponse response = client.execute(get, localContext);
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                InputStream is = entity.getContent();
                String s = convertinputStreamToString(is);
                returnMe = s;
                // Do not need the rest
                get.abort();
                return returnMe;
            }
        } catch (ClientProtocolException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:DefinitionObject.java

/*** Calls for server output ***/

public void fetch_output(String word) {
    entry = word;/*  w  w w  .j a v a2 s.  c o  m*/
    System.out.print("----------------\n" + "Word to be defined:\t " + word + "\n----------------");

    try {

        HttpClient httpClient = HttpClientBuilder.create().build();
        HttpGet getRequest = new HttpGet(
                "https://api.pearson.com:443/v2/dictionaries/entries?headword=" + word); //Here is word!
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

        if (response.getStatusLine().getStatusCode() != 200) {
            throw new RuntimeException(
                    "Failed : HTTP error code : " + response.getStatusLine().getStatusCode());
        }

        BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent())));

        String output;
        System.out.println("\nOutput from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            serverOutput = output;
        }

        httpClient.getConnectionManager().shutdown();
    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:de.unistuttgart.ipvs.pmp.apps.vhike.tools.JSonRequestReaderWS.java

/**
 * Announce a trip to the webservice/*from  w w  w  .  ja v a 2s.co  m*/
 * 
 * @return true if succeeded
 */
public static String announceTrip(String session_id, String destination, float current_lat, float current_lon,
        int avail_seats) {
    listToParse.clear();
    listToParse.add(new ParamObject("sid", session_id, false));

    listToParse.add(new ParamObject("destination", destination, true));
    listToParse.add(new ParamObject("current_lat", String.valueOf(current_lat), true));
    listToParse.add(new ParamObject("current_lon", String.valueOf(current_lon), true));
    listToParse.add(new ParamObject("avail_seats", String.valueOf(avail_seats), true));

    JsonObject object = null;
    try {
        object = JSonRequestProvider.doRequest(listToParse, "trip_announce.php");
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    boolean suc = false;
    int tripId = 0;
    String status = null;
    if (object != null) {
        suc = object.get("successful").getAsBoolean();
        if (suc) {
            status = object.get("status").getAsString();
            if (status.equals("announced")) {
                tripId = object.get("id").getAsInt();
                Model.getInstance().setTripId(tripId);
                Log.i(TAG, String.valueOf(Model.getInstance().getTripId()));
            }
        } else {
            return status = object.get("msg").getAsString();
        }

    }

    return status;
}

From source file:edu.lternet.pasta.client.ProvenanceFactoryClient.java

/**
 * Returns the EML provenance metadata fragment as an XML string enclosed
 * by a <methodStep> element for the provided package identifier.
 * //w ww .j ava  2 s.  c om
 * @param packageId The packageId of the parent data package whose provenance
 *                  metadata is being generated and returned.
 * @return an XML string containing the generated provenance metadata inside
 *         a <methodStep> element
 * @throws PastaEventException 
 */
public String getProvenanceByPid(String packageId) throws Exception {
    String provenanceXml = null;
    Integer statusCode = null;
    HttpEntity responseEntity = null;
    CloseableHttpClient httpClient = HttpClientBuilder.create().build();
    HttpResponse response = null;
    String urlFragment = packageId.replace('.', '/');
    String provenanceURL = String.format("%s/%s", BASE_URL, urlFragment);
    HttpGet httpGet = new HttpGet(provenanceURL);

    // Set header content
    if (this.token != null) {
        httpGet.setHeader("Cookie", "auth-token=" + this.token);
    }

    try {
        response = httpClient.execute(httpGet);
        statusCode = (Integer) response.getStatusLine().getStatusCode();
        responseEntity = response.getEntity();

        if (responseEntity != null) {
            provenanceXml = EntityUtils.toString(responseEntity);
        }
    } catch (ClientProtocolException e) {
        logger.error(e);
        e.printStackTrace();
    } catch (IOException e) {
        logger.error(e);
        e.printStackTrace();
    } finally {
        closeHttpClient(httpClient);
    }

    if (statusCode != HttpStatus.SC_OK) {
        // Something went wrong; return message from the response entity
        String gripe = String.format("The Metadata Factory responded with response code %d and message '%s'.\n",
                statusCode, provenanceXml);
        throw new PastaEventException(gripe);
    }

    return provenanceXml;
}

From source file:eu.skillpro.ams.pscm.connector.amsservice.ui.GetConfigurationHandler.java

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    knownFactoryNodes = new HashMap<AssetTO, FactoryNode>();
    try {/*from ww  w  .  java 2 s  . c  o m*/
        for (FactoryNode node : getConfigurations()) {
            SkillproService.getSkillproProvider().updateFactoryNode(node);
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.sigimera.app.android.backend.network.LoginHttpHelper.java

@Override
protected Boolean doInBackground(String... params) {
    HttpClient httpclient = new MyHttpClient(ApplicationController.getInstance().getApplicationContext());
    HttpPost request = new HttpPost(HOST);
    request.addHeader("Host", "api.sigimera.org:443");

    /**/*from w  ww .j a v  a  2s  .  c  o  m*/
     * Basic Authentication for the auth_token fetching:
     * 
     * Authorization: Basic QWxhZGluOnNlc2FtIG9wZW4=
     */
    StringBuffer authString = new StringBuffer();
    authString.append(params[0]);
    authString.append(":");
    authString.append(params[1]);
    String basicAuthentication = "Basic "
            + Base64.encodeToString(authString.toString().getBytes(), Base64.DEFAULT);
    request.addHeader("Authorization", basicAuthentication);

    try {
        HttpResponse result = httpclient.execute(request);

        JSONObject json_response = new JSONObject(
                new BufferedReader(new InputStreamReader(result.getEntity().getContent())).readLine());
        if (json_response.has("auth_token")) {
            SharedPreferences.Editor editor = ApplicationController.getInstance().getSharedPreferences().edit();
            editor.putString("auth_token", json_response.getString("auth_token"));
            return editor.commit();
        } else if (json_response.has("error")) {
            return false;
        }
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (JSONException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } finally {
        httpclient.getConnectionManager().shutdown();
    }
    return false;
}