List of usage examples for org.apache.http.client HttpClient getParams
@Deprecated HttpParams getParams();
From source file:com.cloudhopper.sxmp.PostMO.java
static public void main(String[] args) throws Exception { String URL = "https://sms.twitter.com/receive/cloudhopper"; String text = "HELP"; String srcAddr = "+16504304922"; String ticketId = System.currentTimeMillis() + ""; String operatorId = "20"; StringBuilder string0 = new StringBuilder(200).append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<operation type=\"deliver\">\n") .append(" <account username=\"customer1\" password=\"password1\"/>\n").append(" <deliverRequest>\n") .append(" <operatorId>" + operatorId + "</operatorId>\n") .append(" <sourceAddress type=\"international\">" + srcAddr + "</sourceAddress>\n") .append(" <destinationAddress type=\"network\">40404</destinationAddress>\n") .append(" <text encoding=\"ISO-8859-1\">" + HexUtil.toHexString(text.getBytes()) + "</text>\n") .append(" </deliverRequest>\n").append("</operation>\n").append(""); HttpClient client = new DefaultHttpClient(); client.getParams().setBooleanParameter("http.protocol.expect-continue", false); long start = System.currentTimeMillis(); // execute request try {/* ww w .j a v a 2 s. c o m*/ HttpPost post = new HttpPost(URL); StringEntity entity = new StringEntity(string0.toString(), "ISO-8859-1"); entity.setContentType("text/xml; charset=\"ISO-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); logger.debug("----------------------------------------"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } long end = System.currentTimeMillis(); logger.debug("Response took " + (end - start) + " ms"); }
From source file:bundestagswahl.benchmark.BWBenchmark.java
public static void main(String[] args) throws Exception { resultTime = new double[6]; Scanner scanner = new Scanner(System.in); System.out.print("Please enter URL: "); serverUrl = scanner.nextLine();/*from ww w. j ava2 s . c o m*/ System.out.print("Please enter number of terminals: "); numberTerminals = scanner.nextInt(); System.out.print("Please enter number of requests: "); numberRequests = scanner.nextInt(); System.out.print("Please enter delay between two requests in seconds: "); requestDelay = scanner.nextDouble(); scanner.close(); PoolingClientConnectionManager cm = new PoolingClientConnectionManager(); cm.setMaxTotal(numberTerminals); HttpClient httpclient = new DefaultHttpClient(cm); httpclient.getParams().setIntParameter(CoreConnectionPNames.SO_TIMEOUT, 300000) .setIntParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, 300000) .setIntParameter(CoreConnectionPNames.SOCKET_BUFFER_SIZE, 8 * 1024) .setBooleanParameter(CoreConnectionPNames.TCP_NODELAY, true); try { final CountDownLatch latch = new CountDownLatch(numberTerminals); for (int i = 0; i < numberTerminals; i++) { BenchmarkTerminal terminal = new BenchmarkTerminal(httpclient, latch, serverUrl, numberRequests, requestDelay); terminal.start(); } latch.await(); httpclient.getConnectionManager().shutdown(); } finally { } printResultTimes(); System.out.println(" "); System.out.println("Done"); }
From source file:com.cloudhopper.sxmp.PostUTF8MO.java
static public void main(String[] args) throws Exception { String URL = "https://sms-staging.twitter.com/receive/cloudhopper"; // this is a Euro currency symbol //String text = "\u20AC"; // shorter arabic //String text = "\u0623\u0647\u0644\u0627"; // even longer arabic //String text = "\u0623\u0647\u0644\u0627\u0020\u0647\u0630\u0647\u0020\u0627\u0644\u062a\u062c\u0631\u0628\u0629\u0020\u0627\u0644\u0623\u0648\u0644\u0649"; String text = ""; for (int i = 0; i < 140; i++) { text += "\u0623"; }/* w w w . j a v a2 s . c om*/ String srcAddr = "+14159129228"; String ticketId = System.currentTimeMillis() + ""; String operatorId = "23"; //text += " " + ticketId; StringBuilder string0 = new StringBuilder(200).append("<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n") .append("<operation type=\"deliver\">\n") .append(" <account username=\"customer1\" password=\"password1\"/>\n").append(" <deliverRequest>\n") .append(" <ticketId>" + ticketId + "</ticketId>\n") .append(" <operatorId>" + operatorId + "</operatorId>\n") .append(" <sourceAddress type=\"international\">" + srcAddr + "</sourceAddress>\n") .append(" <destinationAddress type=\"network\">40404</destinationAddress>\n") .append(" <text encoding=\"UTF-8\">" + HexUtil.toHexString(text.getBytes("UTF-8")) + "</text>\n") .append(" </deliverRequest>\n").append("</operation>\n").append(""); HttpClient client = new DefaultHttpClient(); client.getParams().setBooleanParameter("http.protocol.expect-continue", false); long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(URL); StringEntity entity = new StringEntity(string0.toString(), "ISO-8859-1"); entity.setContentType("text/xml; charset=\"ISO-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); logger.debug("----------------------------------------"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } long end = System.currentTimeMillis(); logger.debug("Response took " + (end - start) + " ms"); }
From source file:com.cloudhopper.sxmp.SubmitMain.java
static public void main(String[] args) throws Exception { String url = "http://localhost:9080/api/sxmp/1.0"; // create a submit request SubmitRequest submit = new SubmitRequest(); submit.setAccount(new Account("customer1", "password1")); submit.setDeliveryReport(Boolean.TRUE); MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404"); submit.setSourceAddress(sourceAddr); submit.setOperatorId(24);// ww w . jav a 2 s . c om MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+14155551212"); submit.setDestinationAddress(destAddr); submit.setText( "Test abcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijjabcdefghijbcdefghij", TextEncoding.UTF_8); //submit.setText("Hello World"); // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); long totalStart = System.currentTimeMillis(); int count = 1; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(submit)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:com.cloudhopper.sxmp.demo.SubmitMain.java
static public void main(String[] args) throws Exception { String url = "http://127.0.0.1:8080/api/sxmp/1.0"; String phone = "+14155551212"; int operator = 1; if (args.length > 0) url = args[0];/*from w w w. j a v a 2s .co m*/ if (args.length > 1) phone = args[1]; if (args.length > 2) operator = Integer.parseInt(args[2]); // create a submit request SubmitRequest submit = new SubmitRequest(); submit.setAccount(new Account("customer1", "password1")); submit.setDeliveryReport(Boolean.TRUE); MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.NETWORK, "40404"); submit.setSourceAddress(sourceAddr); submit.setOperatorId(operator); submit.setPriority(Priority.URGENT); MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.INTERNATIONAL, phone); submit.setDestinationAddress(destAddr); submit.setText("Hello World"); // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); long totalStart = System.currentTimeMillis(); int count = 1; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(submit)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:com.cloudhopper.sxmp.DeliverMain.java
static public void main(String[] args) throws Exception { // create a deliver request DeliverRequest deliver = new DeliverRequest(); deliver.setAccount(new Account("customer1", "password1")); deliver.setOperatorId(2);//from w w w. ja v a2 s .c o m MobileAddress sourceAddr = new MobileAddress(); sourceAddr.setAddress(MobileAddress.Type.INTERNATIONAL, "+13135551212"); deliver.setSourceAddress(sourceAddr); MobileAddress destAddr = new MobileAddress(); destAddr.setAddress(MobileAddress.Type.NETWORK, "55555"); deliver.setDestinationAddress(destAddr); deliver.setText( "This is a new message that I want to send that's a little larger than normal &!#@%20*()$#@!~"); // target url //String url = "http://localhost:9080/api/sxmp/1.0"; //String url = "http://lyn-stratus-001/api/sxmp/1.0"; //String url = "http://localhost:9080/api/sxmp/1.0"; //String strURL = "http://sfd-twtr-gw.cloudhopper.com/api/sxmp/1.0"; String url = "http://lyn-stratus-lab5:9080/api/sxmp/1.0"; // Get file to be posted HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); client.getParams().setParameter(CoreProtocolPNames.USE_EXPECT_CONTINUE, Boolean.FALSE); // convert request into a byte array //byte[] data = SxmpWriter.createByteArray(submit); //logger.debug(StringUtil.toHexString(data)); long totalStart = System.currentTimeMillis(); int count = 5000; for (int i = 0; i < count; i++) { long start = System.currentTimeMillis(); // execute request try { HttpPost post = new HttpPost(url); //ByteArrayEntity entity = new ByteArrayEntity(data); StringEntity entity = new StringEntity(SxmpWriter.createString(deliver)); entity.setContentType("text/xml; charset=\"iso-8859-1\""); post.setEntity(entity); ResponseHandler<String> responseHandler = new BasicResponseHandler(); String responseBody = client.execute(post, responseHandler); long stop = System.currentTimeMillis(); logger.debug("----------------------------------------"); logger.debug("Response took " + (stop - start) + " ms"); logger.debug(responseBody); logger.debug("----------------------------------------"); } finally { // do nothing } } long totalEnd = System.currentTimeMillis(); logger.debug("Response took " + (totalEnd - totalStart) + " ms for " + count + " requests"); double seconds = ((double) (totalEnd - totalStart)) / 1000; double smspersec = ((double) count) / seconds; logger.debug("SMS / Sec: " + DecimalUtil.toString(smspersec, 2)); }
From source file:uk.co.techblue.docusign.client.DocuSignClient.java
public static void main(String[] args) throws ClientProtocolException, IOException { ThreadSafeClientConnManager cm = new ThreadSafeClientConnManager(); int maxPerRoute = 50; cm.setDefaultMaxPerRoute(maxPerRoute); cm.setMaxTotal(maxPerRoute);// w w w .ja va 2s . c o m HttpClient client = new DefaultHttpClient(cm); HttpParams params = client.getParams(); // Allowable time between packets HttpConnectionParams.setSoTimeout(params, 6000); // Allowable time to get a connection HttpConnectionParams.setConnectionTimeout(params, 6000); HttpGet request = new HttpGet( "https://demo.docusign.net/restapi/v2/accounts/672084/envelopes/e266ddb9-b293-4013-98fd-c121b7832d4a/audit_events"); request.setHeader("Authorization", "bearer D/rZd4fBhOpg2r0VTipQC105ARE="); HttpResponse response = client.execute(request); System.out.println(response); }
From source file:com.threadswarm.imagefeedarchiver.driver.CommandLineDriver.java
public static void main(String[] args) throws InterruptedException, ExecutionException, ParseException { // define available command-line options Options options = new Options(); options.addOption("h", "help", false, "display usage information"); options.addOption("u", "url", true, "RSS feed URL"); options.addOption("a", "user-agent", true, "User-Agent header value to use when making HTTP requests"); options.addOption("o", "output-directory", true, "output directory for downloaded images"); options.addOption("t", "thread-count", true, "number of worker threads, defaults to cpu-count + 1"); options.addOption("d", "delay", true, "delay between image downloads (in milliseconds)"); options.addOption("p", "notrack", false, "tell websites that you don't wish to be tracked (DNT)"); options.addOption("s", "https", false, "Rewrite image URLs to leverage SSL/TLS"); CommandLineParser commandLineParser = new BasicParser(); CommandLine commandLine = commandLineParser.parse(options, args); // print usage information if 'h'/'help' or no-args were given if (args.length == 0 || commandLine.hasOption("h")) { HelpFormatter helpFormatter = new HelpFormatter(); helpFormatter.printHelp("java -jar ImageFeedArchiver.jar", options); return; //abort execution }/*from w w w. ja va 2 s . co m*/ URI rssFeedUri = null; if (commandLine.hasOption("u")) { String rssFeedUrlString = commandLine.getOptionValue("u"); try { rssFeedUri = FeedUtils.getUriFromUrlString(rssFeedUrlString); } catch (MalformedURLException | URISyntaxException e) { LOGGER.error("The Feed URL you supplied was malformed or violated syntax rules.. exiting", e); System.exit(1); } LOGGER.info("Target RSS feed URL: {}", rssFeedUri); } else { throw new IllegalStateException("RSS feed URL was not specified!"); } File outputDirectory = null; if (commandLine.hasOption("o")) { outputDirectory = new File(commandLine.getOptionValue("o")); if (!outputDirectory.isDirectory()) throw new IllegalArgumentException("output directory must be a *directory*!"); LOGGER.info("Using output directory: '{}'", outputDirectory); } else { throw new IllegalStateException("output directory was not specified!"); } String userAgentString = null; if (commandLine.hasOption("a")) { userAgentString = commandLine.getOptionValue("a"); LOGGER.info("Setting 'User-Agent' header value to '{}'", userAgentString); } int threadCount; if (commandLine.hasOption("t")) { threadCount = Integer.parseInt(commandLine.getOptionValue("t")); } else { threadCount = Runtime.getRuntime().availableProcessors() + 1; } LOGGER.info("Using {} worker threads", threadCount); long downloadDelay = 0; if (commandLine.hasOption("d")) { String downloadDelayString = commandLine.getOptionValue("d"); downloadDelay = Long.parseLong(downloadDelayString); } LOGGER.info("Using a download-delay of {} milliseconds", downloadDelay); boolean doNotTrackRequested = commandLine.hasOption("p"); boolean forceHttps = commandLine.hasOption("s"); ApplicationContext context = new ClassPathXmlApplicationContext("META-INF/applicationContext.xml"); ((ConfigurableApplicationContext) context).registerShutdownHook(); HttpClient httpClient = (HttpClient) context.getBean("httpClient"); if (userAgentString != null) httpClient.getParams().setParameter(CoreProtocolPNames.USER_AGENT, userAgentString); ProcessedRssItemDAO processedRssItemDAO = (ProcessedRssItemDAO) context.getBean("processedRssItemDAO"); CommandLineDriver.Builder driverBuilder = new CommandLineDriver.Builder(rssFeedUri); driverBuilder.setDoNotTrackRequested(doNotTrackRequested).setOutputDirectory(outputDirectory) .setDownloadDelay(downloadDelay).setThreadCount(threadCount).setHttpClient(httpClient) .setForceHttps(forceHttps).setProcessedRssItemDAO(processedRssItemDAO); CommandLineDriver driver = driverBuilder.build(); driver.run(); }
From source file:Technique.PostFile.java
public static void upload(String files) throws Exception { String userHome = System.getProperty("user.home"); HttpClient httpclient = new DefaultHttpClient(); httpclient.getParams().setParameter(CoreProtocolPNames.PROTOCOL_VERSION, HttpVersion.HTTP_1_1); HttpPost httppost = new HttpPost("http://localhost/image/up.php"); File file = new File(files); MultipartEntity mpEntity = new MultipartEntity(); ContentBody contentFile = new FileBody(file); mpEntity.addPart("userfile", contentFile); httppost.setEntity(mpEntity);/* ww w .j a va 2s. c o m*/ System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); if (!(response.getStatusLine().toString()).equals("HTTP/1.1 200 OK")) { // Successfully Uploaded } else { // Did not upload. Add your logic here. Maybe you want to retry. } System.out.println(response.getStatusLine()); if (resEntity != null) { System.out.println(EntityUtils.toString(resEntity)); } if (resEntity != null) { resEntity.consumeContent(); } httpclient.getConnectionManager().shutdown(); }
From source file:org.eclipse.epp.internal.mpc.core.util.HttpUtil.java
public static HttpClient createHttpClient(String baseUri) { HttpClient client = new DefaultHttpClient(); client.getParams().setParameter(CoreProtocolPNames.USER_AGENT, MarketplaceClientCore.BUNDLE_ID); if (baseUri != null) { configureProxy(client, baseUri); }/*from w w w. j av a 2 s . c o m*/ return client; }