List of usage examples for java.util List get
E get(int index);
From source file:net.securnetwork.itebooks.downloader.EbookDownloader.java
/** * Program main method.//from ww w. ja v a 2 s . co m * * @param args the program arguments */ public static void main(String[] args) { if (validateArguments(args)) { int start = MIN_EBOOK_INDEX; int end = getLastEbookIndex(); String destinationFolder = null; // Check if resume mode if (args.length == 1 && args[0].equals(RESUME_ARG)) { start = Integer.parseInt(prefs.get(LAST_SAVED_EBOOK_PREF, MIN_EBOOK_INDEX - 1 + "")) + 1; //$NON-NLS-1$ destinationFolder = prefs.get(OUTPUT_FOLDER_PREF, null); } else { destinationFolder = getDestinationFolder(args); } if (destinationFolder == null) { System.err.println(Messages.getString("EbookDownloader.NoDestinationFolderFound")); //$NON-NLS-1$ return; } else { // Possibly fix the destination folder path destinationFolder = destinationFolder.replace("\\", "/"); if (!destinationFolder.endsWith("/")) { destinationFolder += "/"; } prefs.put(OUTPUT_FOLDER_PREF, destinationFolder); } if (args.length == 3) { start = getStartIndex(args); end = getEndIndex(args); } try { for (int i = start; i <= end; i++) { String ebookPage = BASE_EBOOK_URL + i + SLASH; Source sourceHTML = new Source(new URL(ebookPage)); List<Element> allTables = sourceHTML.getAllElements(HTMLElementName.TABLE); Element detailsTable = allTables.get(0); // Try to build an info bean for the ebook String bookTitle = EbookPageParseUtils.getTitle(detailsTable); if (bookTitle != null) { EbookInfo ebook = createEbookInfo(bookTitle, i, detailsTable); String filename = destinationFolder + Misc.getValidFilename(ebook.getTitle(), ebook.getSubTitle(), ebook.getYear(), ebook.getFileFormat()); System.out.print(MessageFormat.format(Messages.getString("EbookDownloader.InfoDownloading"), //$NON-NLS-1$ new Object[] { ebook.getSiteId() })); try { URL ebookPageURL = new URL(ebook.getDownloadLink()); HttpURLConnection con = (HttpURLConnection) ebookPageURL.openConnection(); con.setRequestMethod("GET"); con.setRequestProperty("Referer", ebookPage); InputStream conIS = con.getInputStream(); FileUtils.copyInputStreamToFile(conIS, new File(filename)); System.out.println(Messages.getString("EbookDownloader.DownloadingOK")); //$NON-NLS-1$ prefs.put(LAST_SAVED_EBOOK_PREF, i + ""); //$NON-NLS-1$ conIS.close(); } catch (Exception e) { System.out.println(Messages.getString("EbookDownloader.DownloadingKO")); //$NON-NLS-1$ } } } } catch (Exception e) { System.err.println(Messages.getString("EbookDownloader.FatalError")); //$NON-NLS-1$ e.printStackTrace(); } } else { printHelp(); } }
From source file:com.mtea.macrotea_httpclient_study.ClientFormLogin.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*w w w . ja v a 2 s. c om*/ HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); //?? EntityUtils.consume(entity); System.out.println("?cookies:"); List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken2", "password")); //? httpost.setEntity(new UrlEncodedFormEntity(nvps, "UTF-8")); response = httpclient.execute(httpost); entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { //??httpclient??? httpclient.getConnectionManager().shutdown(); } }
From source file:com.dlmu.heipacker.crawler.client.ClientFormLogin.java
public static void main(String[] args) throws Exception { DefaultHttpClient httpclient = new DefaultHttpClient(); try {/*from www . j a va2 s . com*/ HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt"); HttpResponse response = httpclient.execute(httpget); HttpEntity entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken2", "password")); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); response = httpclient.execute(httpost); entity = response.getEntity(); System.out.println("Login form get: " + response.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); cookies = httpclient.getCookieStore().getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } 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:edu.uci.ics.crawler4j.weatherCrawler.BasicCrawlController.java
public static void main(String[] args) { String folder = ConfigUtils.getFolder(); String crawlerCount = ConfigUtils.getCrawlerCount(); args = new String[2]; if (StringUtils.isBlank(folder) || StringUtils.isBlank(crawlerCount)) { args[0] = "weather"; args[1] = "10"; System.out.println("No parameters in config.properties ......."); System.out.println("[weather] will be used as rootFolder (it will contain intermediate crawl data)"); System.out.println("[10] will be used as numberOfCralwers (number of concurrent threads)"); } else {/*from w ww.j a v a2s . c om*/ args[0] = folder; args[1] = crawlerCount; } /* * crawlStorageFolder is a folder where intermediate crawl data is * stored. */ String crawlStorageFolder = args[0]; /* * numberOfCrawlers shows the number of concurrent threads that should * be initiated for crawling. */ int numberOfCrawlers = Integer.parseInt(args[1]); CrawlConfig config = new CrawlConfig(); if (crawlStorageFolder != null && IO.deleteFolderContents(new File(crawlStorageFolder))) System.out.println(""); config.setCrawlStorageFolder(crawlStorageFolder + "/d" + System.currentTimeMillis()); /* * Be polite: Make sure that we don't send more than 1 request per * second (1000 milliseconds between requests). */ config.setPolitenessDelay(1000); config.setConnectionTimeout(1000 * 60); // config1.setPolitenessDelay(1000); /* * You can set the maximum crawl depth here. The default value is -1 for * unlimited depth */ config.setMaxDepthOfCrawling(StringUtils.isBlank(ConfigUtils.getCrawlerDepth()) ? 40 : Integer.valueOf(ConfigUtils.getCrawlerDepth())); // config1.setMaxDepthOfCrawling(0); /* * You can set the maximum number of pages to crawl. The default value * is -1 for unlimited number of pages */ config.setMaxPagesToFetch(100000); // config1.setMaxPagesToFetch(10000); /* * Do you need to set a proxy? If so, you can use: * config.setProxyHost("proxyserver.example.com"); * config.setProxyPort(8080); * * If your proxy also needs authentication: * config.setProxyUsername(username); config.getProxyPassword(password); */ if (ConfigUtils.getValue("useProxy", "false").equalsIgnoreCase("true")) { System.out.println("?============"); List<ProxySetting> proxys = ConfigUtils.getProxyList(); ProxySetting proxy = proxys.get(RandomUtils.nextInt(proxys.size() - 1)); /* test the proxy is alaviable or not */ while (!TestProxy.testProxyAvailable(proxy)) { proxy = proxys.get(RandomUtils.nextInt(proxys.size() - 1)); } System.out.println("??" + proxy.getIp() + ":" + proxy.getPort()); config.setProxyHost(proxy.getIp()); config.setProxyPort(proxy.getPort()); // config.setProxyHost("127.0.0.1"); // config.setProxyPort(8087); } else { System.out.println("??============"); } /* * This config parameter can be used to set your crawl to be resumable * (meaning that you can resume the crawl from a previously * interrupted/crashed crawl). Note: if you enable resuming feature and * want to start a fresh crawl, you need to delete the contents of * rootFolder manually. */ config.setResumableCrawling(false); // config1.setResumableCrawling(false); /* * Instantiate the controller for this crawl. */ PageFetcher pageFetcher = new PageFetcher(config); // PageFetcher pageFetcher1 = new PageFetcher(config1); RobotstxtConfig robotstxtConfig = new RobotstxtConfig(); RobotstxtServer robotstxtServer = new RobotstxtServer(robotstxtConfig, pageFetcher); try { /* * For each crawl, you need to add some seed urls. These are the * first URLs that are fetched and then the crawler starts following * links which are found in these pages */ CrawlController controller = new CrawlController(config, pageFetcher, robotstxtServer); controller.addSeed(StringUtils.isBlank(ConfigUtils.getSeed()) ? "http://www.tianqi.com/chinacity.html" : ConfigUtils.getSeed()); // controller.addSeed("http://www.ics.uci.edu/~lopes/"); // controller.addSeed("http://www.ics.uci.edu/~welling/"); /* * Start the crawl. This is a blocking operation, meaning that your * code will reach the line after this only when crawling is * finished. */ String isDaily = null; isDaily = ConfigUtils.getValue("isDaily", "true"); System.out .println("?=======" + ConfigUtils.getValue("table", "weather_data") + "======="); if (isDaily.equalsIgnoreCase("true")) { System.out.println("???=============="); controller.start(BasicDailyCrawler.class, numberOfCrawlers); } else { System.out.println("???=============="); controller.start(BasicCrawler.class, numberOfCrawlers); } } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } }
From source file:com.SSOserver.common.ClientFormLogin.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); try {//from ww w. j av a 2 s . c o m HttpGet httpget = new HttpGet("http://127.0.0.1:8080/SSOserver/Userlogin.action"); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("?Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("? cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("?- " + cookies.get(i).toString()); } } } finally { response1.close(); } // params.add(new BasicNameValuePair("username", "1")); // params.add(new BasicNameValuePair("userpwd", "1")); HttpUriRequest login = RequestBuilder.post() .setUri(new URI("http://127.0.0.1:8080/SSOserver/Userlogin.action")) .addParameter("username", "1").addParameter("userpwd", "1").build(); CloseableHttpResponse response2 = httpclient.execute(login); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("?Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("?- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:com.bhc.test.ClientFormLogin.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); URI uri = null;//from w ww . ja va 2 s . c om try { uri = new URIBuilder().setScheme("https").setHost("user.qunar.com").setPath("/captcha/api/image") .setParameter("k", "{en7mni(z").setParameter("p", "ucenter_login") .setParameter("c", "ef7d278eca6d25aa6aec7272d57f0a9a") .setParameter("t", String.valueOf(new Date().getTime())).build(); HttpGet httpget = new HttpGet(uri); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } HttpUriRequest login = RequestBuilder.post().setUri(new URI("https://someportal/")) .addParameter("IDToken1", "username").addParameter("IDToken2", "password").build(); CloseableHttpResponse response2 = httpclient.execute(login); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:at.gv.egiz.pdfas.web.client.test.SimpleTest.java
public static void main(String[] args) { try {//w w w .j ava 2 s . c o m FileInputStream fis = new FileInputStream("/home/afitzek/simple.pdf"); byte[] inputData = IOUtils.toByteArray(fis); PDFASSignParameters signParameters = new PDFASSignParameters(); signParameters.setConnector(Connector.JKS); signParameters.setPosition(null); signParameters.setProfile("SIGNATURBLOCK_SMALL_DE"); signParameters.setQRCodeContent("TEST CONTENT"); //signParameters.setKeyIdentifier("test"); PDFASSignRequest request = new PDFASSignRequest(); request.setInputData(inputData); request.setParameters(signParameters); request.setRequestID("SOME TEST ID"); //URL endpoint = new //URL("http://demo.egiz.gv.at/demoportal-pdf_as/wssign?wsdl"); //URL endpoint = new // URL("http://www.buergerkarte.at/pdf-as-extern-4/wssign?wsdl"); String baseUrl = "http://demo.egiz.gv.at/demoportal-pdf_as/services/"; //String baseUrl = "http://localhost:8080/pdf-as-web/services/"; //URL endpoint = new URL( // "http://192.168.56.10/pdf-as-web/wssign?wsdl"); URL signEndpoint = new URL(baseUrl + "wssign?wsdl"); URL verifyEndpoint = new URL(baseUrl + "wsverify?wsdl"); RemotePDFSigner signer = new RemotePDFSigner(signEndpoint, true); RemotePDFVerifier verifier = new RemotePDFVerifier(verifyEndpoint, true); PDFASSignRequest signrequest = new PDFASSignRequest(); signrequest.setInputData(inputData); signrequest.setParameters(signParameters); signParameters.setTransactionId("MYID ...."); System.out.println("Simple Request:"); PDFASSignResponse response = signer.signPDFDokument(signrequest); System.out.println("Sign Error: " + response.getError()); PDFASVerifyRequest verifyRequest = new PDFASVerifyRequest(); verifyRequest.setInputData(response.getSignedPDF()); verifyRequest.setVerificationLevel(VerificationLevel.INTEGRITY_ONLY); PDFASVerifyResponse verifyResponse = verifier.verifyPDFDokument(verifyRequest); List<PDFASVerifyResult> results = verifyResponse.getVerifyResults(); for (int i = 0; i < results.size(); i++) { PDFASVerifyResult result = results.get(i); printVerifyResult(result); } /* * System.out.println("Simple Request:"); byte[] outputFile = * signer.signPDFDokument(inputData, signParameters); * * FileOutputStream fos = new FileOutputStream( * "/home/afitzek/simple_request_signed.pdf"); * fos.write(outputFile); fos.close(); * * System.out.println("Simple Request Obj:"); PDFASSignResponse * response = signer.signPDFDokument(request); * * if (response.getSignedPDF() != null) { FileOutputStream fos2 = * new FileOutputStream( * "/home/afitzek/simple_request_obj_signed.pdf"); * fos2.write(response.getSignedPDF()); fos2.close(); } * * if(response.getError() != null) { System.out.println("ERROR: " + * response.getError()); } */ /* List<PDFASSignRequest> bulk = new ArrayList<PDFASSignRequest>(); for (int i = 0; i < 10; i++) { bulk.add(request); } PDFASBulkSignRequest bulkRequest = new PDFASBulkSignRequest(); bulkRequest.setSignRequests(bulk); for (int j = 0; j < 10; j++) { System.out.println("Bulk Request:"); PDFASBulkSignResponse responses = signer .signPDFDokument(bulkRequest); for (int i = 0; i < responses.getSignResponses().size(); i++) { PDFASSignResponse bulkresponse = responses .getSignResponses().get(i); System.out.println("ID: " + bulkresponse.getRequestID()); if (bulkresponse.getError() != null) { System.out.println("ERROR: " + bulkresponse.getError()); } else { System.out.println("OK"); } } } */ System.out.println("Done!"); } catch (Throwable e) { e.printStackTrace(); } }
From source file:net.jcreate.home.dict.DictService.java
public static void main(String[] args) { DictService service = DictService.getInstance(); DictItem dictItem1 = new DictItem(); dictItem1.setOid(KeyGenerator.getKey()); dictItem1.setDictOID("e34028818317d572f80117d573bf4b0003"); dictItem1.setDictItemCode("a"); dictItem1.setDictItemName("dddddddddddddd"); try {// ww w . ja v a 2s . c o m service.test(dictItem1); } catch (BusinessException e) { // TODO Auto-generated catch block e.printStackTrace(); } List dictItems = null; try { dictItems = service.getDictItems("vv"); } catch (BusinessException e1) { e1.printStackTrace(); } for (int i = 0; i < dictItems.size(); i++) { DictItem dictItem = (DictItem) dictItems.get(i); System.out.println(dictItem); } }
From source file:PostMethodMyExample.java
public static void main(String[] args) throws Exception { BasicCookieStore cookieStore = new BasicCookieStore(); CloseableHttpClient httpclient = HttpClients.custom().setDefaultCookieStore(cookieStore).build(); try {//from w w w.j a v a 2s . co m HttpGet httpget = new HttpGet("https://portal.sun.com/portal/dt"); CloseableHttpResponse response1 = httpclient.execute(httpget); try { HttpEntity entity = response1.getEntity(); System.out.println("Login form get: " + response1.getStatusLine()); EntityUtils.consume(entity); System.out.println("Initial set of cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response1.close(); } HttpPost httpost = new HttpPost("https://portal.sun.com/amserver/UI/Login?" + "org=self_registered_users&" + "goto=/portal/dt&" + "gotoOnFail=/portal/dt?error=true"); List<NameValuePair> nvps = new ArrayList<NameValuePair>(); nvps.add(new BasicNameValuePair("IDToken1", "username")); nvps.add(new BasicNameValuePair("IDToken2", "password")); httpost.setEntity(new UrlEncodedFormEntity(nvps, Consts.UTF_8)); CloseableHttpResponse response2 = httpclient.execute(httpost); try { HttpEntity entity = response2.getEntity(); System.out.println("Login form get: " + response2.getStatusLine()); EntityUtils.consume(entity); System.out.println("Post logon cookies:"); List<Cookie> cookies = cookieStore.getCookies(); if (cookies.isEmpty()) { System.out.println("None"); } else { for (int i = 0; i < cookies.size(); i++) { System.out.println("- " + cookies.get(i).toString()); } } } finally { response2.close(); } } finally { httpclient.close(); } }
From source file:com.boundary.aws.kinesis.Sample.java
public static void main(String[] args) throws Exception { init();//from w w w . jav a 2 s . c om final String myStreamName = "boundary-test-stream"; final Integer myStreamSize = 1; // Create a stream. The number of shards determines the provisioned // throughput. CreateStreamRequest createStreamRequest = new CreateStreamRequest(); createStreamRequest.setStreamName(myStreamName); createStreamRequest.setShardCount(myStreamSize); kinesisClient.createStream(createStreamRequest); // The stream is now being created. LOG.info("Creating Stream : " + myStreamName); waitForStreamToBecomeAvailable(myStreamName); // list all of my streams ListStreamsRequest listStreamsRequest = new ListStreamsRequest(); listStreamsRequest.setLimit(10); ListStreamsResult listStreamsResult = kinesisClient.listStreams(listStreamsRequest); List<String> streamNames = listStreamsResult.getStreamNames(); while (listStreamsResult.isHasMoreStreams()) { if (streamNames.size() > 0) { listStreamsRequest.setExclusiveStartStreamName(streamNames.get(streamNames.size() - 1)); } listStreamsResult = kinesisClient.listStreams(listStreamsRequest); streamNames.addAll(listStreamsResult.getStreamNames()); } LOG.info("Printing my list of streams : "); // print all of my streams. if (!streamNames.isEmpty()) { System.out.println("List of my streams: "); } for (int i = 0; i < streamNames.size(); i++) { System.out.println(streamNames.get(i)); } LOG.info("Putting records in stream : " + myStreamName); // Write 10 records to the stream for (int j = 0; j < 100; j++) { PutRecordRequest putRecordRequest = new PutRecordRequest(); putRecordRequest.setStreamName(myStreamName); putRecordRequest.setData(ByteBuffer.wrap(String.format("testData-%d", j).getBytes())); putRecordRequest.setPartitionKey(String.format("partitionKey-%d", j)); PutRecordResult putRecordResult = kinesisClient.putRecord(putRecordRequest); System.out.println("Successfully putrecord, partition key : " + putRecordRequest.getPartitionKey() + ", ShardID : " + putRecordResult.getShardId()); } // Delete the stream. LOG.info("Deleting stream : " + myStreamName); DeleteStreamRequest deleteStreamRequest = new DeleteStreamRequest(); deleteStreamRequest.setStreamName(myStreamName); kinesisClient.deleteStream(deleteStreamRequest); // The stream is now being deleted. LOG.info("Stream is now being deleted : " + myStreamName); }