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:com.baidu.oped.apm.profiler.errorTest.ConcurrentCall.java

@Test
public void test() throws IOException, InterruptedException {
    ((ThreadPoolExecutor) executorService).prestartAllCoreThreads();

    ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager();
    cm.setMaxTotal(200);//from  w w  w  .  j  a v a2  s.  c  o m
    cm.setDefaultMaxPerRoute(200);

    final HttpClient client = new DefaultHttpClient(cm);
    int call = 400;
    final CountDownLatch latch = new CountDownLatch(call);
    for (int i = 0; i < call; i++) {
        executorService.execute(new Runnable() {
            @Override
            public void run() {
                try {
                    String url = getUrl();
                    logger.info("execute {}", url);
                    final HttpGet httpGet = new HttpGet(url);
                    final HttpResponse execute = client.execute(httpGet);
                    execute.getEntity().getContent().close();

                } catch (ClientProtocolException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } catch (IOException e) {
                    e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
                } finally {
                    latch.countDown();
                }
            }
        });
    }
    latch.await();
    executorService.shutdown();
    cm.shutdown();

}

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

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    String message = "";
    try {//from w  ww  .  j  a va  2 s.  c o m
        message = checkConnection();
    } catch (ClientProtocolException e) {
        message += e.getMessage();
        e.printStackTrace();
    } catch (IOException e) {
        message += e.getMessage();
        e.printStackTrace();
    }
    MessageDialog.open(MessageDialog.INFORMATION, HandlerUtil.getActiveShell(event), "Connection check result",
            message, SWT.SHEET);
    return null;
}

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

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    try {/*from   ww  w.  ja  va 2  s  . c o m*/
        List<SEE> registeredSEEs = new ArrayList<>();
        for (SEE see : SkillproService.getSkillproProvider().getSEERepo()) {
            if (see.getMESNodeID() != null || !see.getMESNodeID().isEmpty()) {
                registeredSEEs.add(see);
            }
        }
        //can actually be done in the first for-loop, but let's just leave it like this for now
        for (SEE see : registeredSEEs) {
            updateSEE(see);
        }
    } 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.alignace.chargeio.net.Requestor.java

private ServerResponse executeRequest(HttpUriRequest request) {

    ServerResponse response = new ServerResponse();
    try {/*from  ww w.ja va  2 s .  c o m*/
        HttpResponse httpResponse = client.execute(request);
        response.setStatusCode(httpResponse.getStatusLine().getStatusCode());
        response.setResponseStream(httpResponse.getEntity().getContent());
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    return response;
}

From source file:org.springframework.ide.eclipse.boot.dash.ngrok.NGROKClient.java

private void shutdownTunnel(NGROKTunnel ngrokTunnel) {
    try {//from  ww  w .  j a  v  a2 s.c  o  m
        String deleteURL = process.getApiURL() + "/api/tunnels/"
                + URLEncoder.encode(ngrokTunnel.getName(), "UTF-8");
        HttpResponse response = Request.Delete(deleteURL).execute().returnResponse();
        if (response.getStatusLine().getStatusCode() != 204) {
            System.err.println("errro closing tunnel");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.megam.deccanplato.provider.box.handler.FolderImpl.java

/**
 * @return/* w ww .  j  a va2  s .co m*/
 */
private Map<String, String> retrive() {

    Map<String, String> outMap = new HashMap<>();
    final String BOX_RETRIVE = "/folders/" + args.get(FOLDER_ID) + "/items";

    Map<String, String> headerMap = new HashMap<String, String>();
    headerMap.put("Authorization", "BoxAuth api_key=" + args.get(API_KEY) + "&auth_token=" + args.get(TOKEN));

    Map<String, String> boxList = new HashMap<>();
    boxList.put("limit", args.get(LIMIT));
    boxList.put("offset", args.get(OFFSET));

    TransportTools tools = new TransportTools(BOX_URI + BOX_RETRIVE, null, headerMap);
    Gson obj = new GsonBuilder().setPrettyPrinting().create();
    tools.setContentType(ContentType.APPLICATION_JSON, obj.toJson(boxList));
    String responseBody = "";
    TransportResponse response = null;
    try {
        response = TransportMachinery.get(tools);
        responseBody = response.entityToString();
        System.out.println("OUTPUT:" + responseBody);
    } catch (ClientProtocolException ce) {
        ce.printStackTrace();
    } catch (IOException ioe) {
        ioe.printStackTrace();
    } catch (URISyntaxException e) {
        e.printStackTrace();
    }
    outMap.put(OUTPUT, responseBody);
    return outMap;
}

From source file:com.suse.studio.api.lib.HttpClient.java

public InputStream get(String path) {
    InputStream content = null;//from   w  w  w  .j  a v  a  2s  .co m
    try {
        startTimer();
        HttpResponse response = httpClient.execute(new HttpGet(baseUrl() + path));
        stopTimer();
        HttpEntity entity = response.getEntity();
        if (entity != null) {
            content = entity.getContent();
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    return content;
}

From source file:conexao.Conexao.java

public PlayerGames getPlayerGames(Long summonerId) {
    PlayerGames example = null;//  w w w  .  j  av  a 2s .  c  om
    try {

        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet getRequest = new HttpGet("https://br.api.pvp.net/api/lol/br/v1.3/game/by-summoner/" + summonerId
                + "/recent?api_key=RGAPI-6b21c1fe-67a3-4222-b713-918d6609f30c");
        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("Output from Server .... \n");
        /*            while ((output = br.readLine()) != null) {
        System.out.println(output);
        }*/

        do {
            output += br.readLine();
        } while (br.readLine() != null);
        // System.out.println("output: " + output);
        example = new Gson().fromJson(output, PlayerGames.class);
        httpClient.getConnectionManager().shutdown();
        // System.out.println("id: " + example.getSummonerId());
    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }
    return example;
}

From source file:com.phonty.improved.Register.java

public boolean process(String phone) {
    String line = null;//  ww  w.ja v  a 2 s .  c o m
    StringBuilder builder = new StringBuilder();
    try {
        String token = Installation.id(context);
        List<NameValuePair> nvps = new ArrayList<NameValuePair>();
        nvps.add(new BasicNameValuePair("phone", phone));
        nvps.add(new BasicNameValuePair("token", token));

        httppost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8));
        HttpResponse response = client.execute(httppost);

        StatusLine statusLine = response.getStatusLine();
        int statusCode = statusLine.getStatusCode();
        if (statusCode == 200) {
            HttpEntity entity = response.getEntity();
            InputStream content = entity.getContent();
            BufferedReader reader = new BufferedReader(new InputStreamReader(content));
            while ((line = reader.readLine()) != null) {
                builder.append(line);
                if (parse(line).equals("OK"))
                    return true;
                else
                    return false;
            }
        } else {
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        return false;
    } catch (IOException e) {
        e.printStackTrace();
        return false;
    }
    return false;
}

From source file:eu.prestoprime.plugin.ltfsarchiver.client.LTFSClient.java

private LTFSResponse executeRequest(LTFSRequest ltfsRequest) throws LTFSException {
    logger.debug("Calling: " + ltfsRequest);

    try {//w ww .  jav a2s. co m
        HttpClient client = new DefaultHttpClient();
        HttpGet request = new HttpGet(ltfsRequest.toURL());
        HttpResponse response = client.execute(request);
        if (response.getStatusLine().getStatusCode() == 200) {
            HttpEntity entity = response.getEntity();
            if (entity != null) {
                BufferedReader reader = new BufferedReader(new InputStreamReader(entity.getContent()));
                StringBuffer sb = new StringBuffer();
                String line;
                while ((line = reader.readLine()) != null)
                    sb.append(line.trim());
                reader.close();
                EntityUtils.consume(entity);

                logger.debug("Received: " + sb);

                LTFSResponse ltfsResponse;
                switch (response.getHeaders("content-Type")[0].getValue()) {
                case "text/plain":
                default:
                    ltfsResponse = new LTFSResponse(sb.toString());
                    break;
                case "application/json":
                    ltfsResponse = new LTFSResponse(new JSONObject(sb.toString()));
                    break;
                }
                return ltfsResponse;
            } else {
                throw new LTFSException("LTFSArchiver returns with empty entity...");
            }
        } else {
            throw new LTFSException(
                    "LTFSArchiver returns with error " + response.getStatusLine().getStatusCode() + "...");
        }
    } catch (ClientProtocolException e) {
        e.printStackTrace();
        throw new LTFSException("Unable to contact the LTFSArchiver Web Service...");
    } catch (IOException e) {
        e.printStackTrace();
        throw new LTFSException("Unable to read the response...");
    } catch (JSONException e) {
        e.printStackTrace();
        throw new LTFSException("Unable to parse JSON response...");
    }
}