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:GetSearchResults.java

/**
 * @param args/*from w w w  .j  a  v  a2s . c o m*/
 * @throws ParseException
 */
public static void main(final String[] args) throws ParseException {

    // you can either set the 2 strings above, or pass them in to this program
    if (args.length == 2) {
        USER_NAME = args[0];
        API_KEY = args[1];
    }

    // make sure the credentials got set
    if (USER_NAME.equals("<YOUR USER NAME>") || API_KEY.equals("<YOUR API KEY>")) {
        System.err.println(
                "You must either edit this example file and put in your username and apikey OR pass them in as program arguments");
        System.exit(1);
    }

    final ApiCredentials credentials = new ApiCredentials(USER_NAME, API_KEY);
    final NZBMatrixApi api = new NZBMatrixApi(credentials);

    try {
        final String searchTerm = "fedora";
        // makes the search request to the nzbMatrixAPI
        final SearchResultsResponse searchResponse = api.getSearchResults(searchTerm);

        System.out.println("Got first " + searchResponse.getResults().size() + " results for the search term '"
                + searchTerm + "'\n");

        // print out information about each result (see all of the methods attached to the result object.)
        for (final SearchResult result : searchResponse.getResults()) {
            System.out.println("\nNzb Name : " + result.getNzbName());
            System.out.println("\tNzb ID     : " + result.getNzbID());
            System.out.println("\tNzb Url    : " + result.getDetailsURL());
            System.out.println("\tCategory   : " + result.getCategory());
            System.out.println("\tAge        : " + result.getAgeInDays() + " days");
            System.out.println("\tPost Date  : " + result.getDatePosted());
            System.out.println("\tIndex Date : " + result.getDateIndexed());
            // see the rest of the methods attached to the SearchResult object
        }

    } catch (final ClientProtocolException e) {
        e.printStackTrace();
    } catch (final IOException e) {
        e.printStackTrace();
    } catch (final NZBMatrixApiException e) {
        e.printStackTrace();
    }
}

From source file:hydrograph.server.service.HydrographServiceClient.java

public static void main(String[] args) {
    HydrographServiceClient client = new HydrographServiceClient();
    try {//from   w  w  w  . j a va2 s. c  o  m
        System.out.println("+++ Start: " + new Timestamp((new Date()).getTime()));
        // client.calltoReadService();
        // client.calltoFilterService();
        //  client.calltoReadMetastore();
        client.chcekConnectionStatus();
        // client.calltoDeleteLocalDebugService();

        System.out.println("done:");
        System.out.println("+++ End: " + new Timestamp((new Date()).getTime()));
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:org.jboss.pnc.auth.client.SimpleOAuthConnect.java

public static void main(String[] args) {
    try {/*  www .ja v a 2s. co m*/
        System.out.println(
                ">>> Access token: " + SimpleOAuthConnect.getAccessToken(args[0], args[1], args[2], args[3]));
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

From source file:GetAllConnectedWlanDevices.java

public static void main(String[] args) {
    //Create a new FritzConnection with username and password
    FritzConnection fc = new FritzConnection(ip, user, password);
    try {/*from  ww  w. ja  v a 2  s .c o m*/
        //The connection has to be initiated. This will load the tr64desc.xml respectively igddesc.xml 
        //and all the defined Services and Actions. 
        fc.init();
    } catch (ClientProtocolException e2) {
        //Any HTTP related error.
        e2.printStackTrace();
    } catch (IOException e2) {
        //Any Network related error.
        e2.printStackTrace();
    } catch (JAXBException e2) {
        //Any xml violation.
        e2.printStackTrace();
    }

    for (int i = 1; i <= 3; i++) {
        //Get the Service. In this case WLANConfiguration:X 
        Service service = fc.getService("WLANConfiguration:" + i);
        //Get the Action. in this case GetTotalAssociations
        Action action = service.getAction("GetTotalAssociations");
        Response response1 = null;
        try {
            //Execute the action without any In-Parameter.
            response1 = action.execute();
        } catch (UnsupportedOperationException | IOException e1) {

            e1.printStackTrace();
        }
        int deviceCount = -1;
        try {
            //Get the value from the field NewTotalAssociations as an integer. Values can have the Types: String, Integer, Boolean, DateTime and UUID
            deviceCount = response1.getValueAsInteger("NewTotalAssociations");
        } catch (ClassCastException | NoSuchFieldException e) {
            e.printStackTrace();
        }
        System.out.println("WLAN " + i + ":" + deviceCount);
        for (int j = 0; j < deviceCount; j++) {
            //Create a map for the arguments of an action. You have to do this, if the action has IN-Parameters.
            HashMap<String, Object> arguments = new HashMap<String, Object>();
            //Set the argument NewAssociatedDeviceIndex to an integer value.
            arguments.put("NewAssociatedDeviceIndex", j);
            try {
                Response response2 = fc.getService("WLANConfiguration:" + i)
                        .getAction("GetGenericAssociatedDeviceInfo").execute(arguments);
                System.out.println("    " + response2.getData());
            } catch (UnsupportedOperationException e) {
                e.printStackTrace();
            } catch (IOException e) {
                e.printStackTrace();
            }

        }

    }

}

From source file:com.quix.aia.cn.imo.mapper.UrlForUserData.java

public static void main(String[] args) {
    // TODO Auto-generated method stub
    UserAuthResponds userAuth = new UserAuthResponds();
    try {/*  ww  w .  j  a va  2 s.com*/

        GsonBuilder builder = new GsonBuilder();
        DefaultHttpClient httpClient = new DefaultHttpClient();
        String username = "", psw = "", co = "";
        username = "NSNP306";
        psw = "A111111A";
        co = "0986";

        HttpGet getRequest = new HttpGet("http://211.144.219.243/isp/rest/index.do?isAjax=true&account="
                + username + "&co=" + co + "&password=" + psw + "");
        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);
            Gson googleJson = new Gson();
            userAuth = googleJson.fromJson(output, UserAuthResponds.class);
            System.out.println("Success " + userAuth.getSuccess());
            if (userAuth.getSuccess().equals("1")) {
                System.out.println("Login successfully Done");
            } else {

                System.out.println("Login Failed ");
            }

        }
        httpClient.getConnectionManager().shutdown();

        //           googleJson = builder.create();
        //           Type listType = new TypeToken<List<UserAuthResponds>>() {}.getType();

    } catch (ClientProtocolException e) {
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
    } catch (IOException e) {
        log.log(Level.SEVERE, e.getMessage());
        e.printStackTrace();
    }

}

From source file:test1.ApacheHttpRestClient2.java

public final static void main(String[] args) {

    HttpClient httpClient = new DefaultHttpClient();
    try {/*from  w  w w  .  j  a  v  a 2s. co m*/
        // this ona api call returns results in a JSON format
        HttpGet httpGetRequest = new HttpGet("https://api.ona.io/api/v1/users");

        // Execute HTTP request
        HttpResponse httpResponse = httpClient.execute(httpGetRequest);

        System.out.println("------------------HTTP RESPONSE----------------------");
        System.out.println(httpResponse.getStatusLine());
        System.out.println("------------------HTTP RESPONSE----------------------");

        // Get hold of the response entity
        HttpEntity entity = httpResponse.getEntity();

        // If the response does not enclose an entity, there is no need
        // to bother about connection release
        byte[] buffer = new byte[1024];
        if (entity != null) {
            InputStream inputStream = entity.getContent();
            try {
                int bytesRead = 0;
                BufferedInputStream bis = new BufferedInputStream(inputStream);
                while ((bytesRead = bis.read(buffer)) != -1) {
                    String chunk = new String(buffer, 0, bytesRead);
                    FileWriter file = new FileWriter("C:\\Users\\fred\\Desktop\\webicons\\output.txt");
                    //file.write(chunk.toJSONString());
                    file.write(chunk.toCharArray());
                    file.flush();
                    file.close();

                    System.out.print(chunk);
                    System.out.println(chunk);
                }
            } catch (IOException ioException) {
                // In case of an IOException the connection will be released
                // back to the connection manager automatically
                ioException.printStackTrace();
            } catch (RuntimeException runtimeException) {
                // In case of an unexpected exception you may want to abort
                // the HTTP request in order to shut down the underlying
                // connection immediately.
                httpGetRequest.abort();
                runtimeException.printStackTrace();
            }
            //          try {
            //              FileWriter file = new FileWriter("C:\\Users\\fred\\Desktop\\webicons\\output.json");
            //                file.write(bis.toJSONString());
            //                file.flush();
            //                file.close();
            //
            //                System.out.print(bis);
            //          } catch (Exception e) {
            //          }

            finally {
                // Closing the input stream will trigger connection release
                try {
                    inputStream.close();
                } catch (Exception ignore) {
                }
            }
        }
    } catch (ClientProtocolException e) {
        // thrown by httpClient.execute(httpGetRequest)
        e.printStackTrace();
    } catch (IOException e) {
        // thrown by entity.getContent();
        e.printStackTrace();
    } finally {
        // When HttpClient instance is no longer needed,
        // shut down the connection manager to ensure
        // immediate deallocation of all system resources
        httpClient.getConnectionManager().shutdown();
    }
}

From source file:no.uib.tools.OnthologyHttpClient.java

public static void main(String[] args) {
    try {/*w w  w  .  j a va  2s  .com*/
        CloseableHttpClient httpClient = HttpClients.createDefault();
        HttpGet getRequest = new HttpGet(
                "http://www.ebi.ac.uk/ols/api/ontologies/mod/terms/http%253A%252F%252Fpurl.obolibrary.org%252Fobo%252FMOD_00861/descendants?size=2002");
        getRequest.addHeader("accept", "application/json");

        HttpResponse response = httpClient.execute(getRequest);

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

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

        String output;
        FileWriter fw = new FileWriter("./mod.json");
        System.out.println("Output from Server .... \n");
        while ((output = br.readLine()) != null) {
            System.out.println(output);
            fw.write(output);
        }

        fw.close();
        httpClient.close();

    } catch (ClientProtocolException e) {

        e.printStackTrace();

    } catch (IOException e) {

        e.printStackTrace();
    }

}

From source file:org.springside.examples.schedule.TransferOaDataToGx.java

public static void main(String[] args) {
    //      //from   w w w  .j  av  a  2  s .  c o  m
    //      // ?
    //      HttpPost httpPost = new HttpPost("http://gxoa.cc/login!login.do?userName=&userPassword=gxuser&loginState=1");
    //      
    //      // ?connection poolclient
    //      RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20 * 1000)
    //            .setConnectTimeout(20 * 1000).build();
    //
    //      CloseableHttpClient  httpClient = HttpClientBuilder.create().setMaxConnTotal(20).setMaxConnPerRoute(20)
    //            .setDefaultRequestConfig(requestConfig).build();
    //      try {
    //         CloseableHttpResponse  closeableHttpResponse = httpClient.execute(httpPost);
    //         System.out.println(IOUtils.toString(closeableHttpResponse.getEntity().getContent(), "UTF-8"));
    //         HttpGet httpGet = new HttpGet("http://gxoa.cc/attachmentDownload.do?filePath=2010-07/2010-07-28-4bdd9279-c09e-4b68-80fc-c9d049c6bdfc-GXTC-1005124--??20091062.rar");
    //         CloseableHttpResponse closeableHttpResponseFile = httpClient.execute(httpGet);
    //         //FileOutputStream fileOutputStream = new FileOutputStream(new File("D:\"));
    //         System.out.println(IOUtils.toString(closeableHttpResponseFile.getEntity().getContent(), "UTF-8"));
    //
    //         
    //      } catch (ClientProtocolException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      } catch (IOException e) {
    //         // TODO Auto-generated catch block
    //         e.printStackTrace();
    //      }

    //      

    HttpPost httpPost = new HttpPost("http://219.239.33.123:9090/quickstart/api/getFileFromFTP");

    List<NameValuePair> nvps = new ArrayList<NameValuePair>();

    nvps.add(new BasicNameValuePair("filePath",
            "2015-04/2015-04-28-718f376f-b725-4e18-87e2-43e30124b2b5-GXTC-1506112-&-.rar"));

    String salt = "GXCX_OA_SALT";
    long currentTime = ((new Date().getTime() * 4 + 2) * 5 - 1) * 8 + 3;// by yucy
    String key = salt + currentTime;
    nvps.add(new BasicNameValuePair("key", Base64.encodeBase64String(key.getBytes())));

    try {
        httpPost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8"));
    } catch (UnsupportedEncodingException e1) {
        // TODO Auto-generated catch block
        e1.printStackTrace();
    }
    // ?connection poolclient
    RequestConfig requestConfig = RequestConfig.custom().setSocketTimeout(20 * 1000)
            .setConnectTimeout(20 * 1000).build();
    CloseableHttpClient httpClient = HttpClientBuilder.create().setMaxConnTotal(20).setMaxConnPerRoute(20)
            .setDefaultRequestConfig(requestConfig).build();
    try {
        CloseableHttpResponse closeableHttpResponseFile = httpClient.execute(httpPost);

        FileUtils.writeByteArrayToFile(new File("D:/upload/templateBulletin.rar"),
                IOUtils.toByteArray(closeableHttpResponseFile.getEntity().getContent()));
    } catch (ClientProtocolException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    //TODO  ?
    //FileUtils.writeByteArrayToFile( file, FileUtils.readFileToByteArray( new File("D:/upload/templateBulletin.zip") ) );

}

From source file:com.da.img.CityInfoList.java

public static void main(String[] args) {
    CityInfoList cfl = new CityInfoList();
    try {/* w w w.  j  a  va2  s. c o m*/
        cfl.executeURL(args[0]);
    } 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();
    }
}

From source file:com.da.img.BoradList.java

public static void main(String[] args) {
    BoradList cfl = new BoradList();
    try {// w  ww .  ja v a2  s. co m
        cfl.executeURL(args[0]);
    } 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();
    }
}