List of usage examples for org.apache.http.client.utils URIUtils createURI
@Deprecated public static URI createURI(final String scheme, final String host, final int port, final String path, final String query, final String fragment) throws URISyntaxException
From source file:org.mahasen.client.Upload.java
/** * @param uploadFile//from w ww . j a va 2 s.com * @param tags * @param folderStructure * @param addedProperties * @throws IOException */ public void upload(File uploadFile, String tags, String folderStructure, List<NameValuePair> addedProperties) throws IOException, MahasenClientException, URISyntaxException { httpclient = new DefaultHttpClient(); if (addedProperties != null) { this.customProperties = addedProperties; } try { System.out.println(" Is Logged : " + clientLoginData.isLoggedIn()); if (clientLoginData.isLoggedIn() == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); File file = uploadFile; if (file.exists()) { if (!folderStructure.equals("")) { customProperties.add(new BasicNameValuePair("folderStructure", folderStructure)); } customProperties.add(new BasicNameValuePair("fileName", file.getName())); customProperties.add(new BasicNameValuePair("tags", tags)); URI uri = URIUtils.createURI("https", clientLoginData.getHostNameAndPort(), -1, "/mahasen/upload_ajaxprocessor.jsp", URLEncodedUtils.format(customProperties, "UTF-8"), null); HttpPost httppost = new HttpPost(uri); InputStreamEntity reqEntity = new InputStreamEntity(new FileInputStream(file), -1); reqEntity.setContentType("binary/octet-stream"); reqEntity.setChunked(true); httppost.setEntity(reqEntity); httppost.setHeader("testHeader", "testHeadervalue"); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(resEntity); if (response.getStatusLine().getStatusCode() == 900) { throw new MahasenClientException(String.valueOf(response.getStatusLine())); } } } else { System.out.println("User has to be logged in to perform this function"); } } finally { httpclient.getConnectionManager().shutdown(); } }
From source file:de.topicmapslab.couchtm.internal.utils.SysDB.java
/** * Query the server, not a specific database. * /*from w w w . j a va 2 s . c o m*/ * @param query * @return result */ protected String getTopLevel(String query) { String responseBody = "{}"; try { URI uri = URIUtils.createURI("http", url, port, query, null, null); get = new HttpGet(uri); responseBody = client.execute(get, responseHandler); } catch (Exception e) { e.printStackTrace(); } return responseBody; }
From source file:net.neoturbine.autolycus.internal.BusTimeAPI.java
/** * Requests the XML data for a given action and parameters. Matches the * <code>system</code> input with a hard-coded internal list to know which * server to use. Note that this MUST not be run in the UI thread. * /*from w w w. j a v a 2s . c o m*/ * @param context * Currently unused, but needed for analytics. * @param verb * The string in the last part of the Base URL within the API * documentation. * @param system * One of the internally supported transit systems. * @param params * a Bundle containing the parameters to be passed within its * extras. * @return an XmlPullParser with the XML tree resulting from this API call. * * @throws ClientProtocolException * @throws IOException * @throws XmlPullParserException */ private static XmlPullParser loadData(Context context, String verb, String system, Bundle params) throws ClientProtocolException, IOException, XmlPullParserException { ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); if (params != null) { for (String name : params.keySet()) { qparams.add(new BasicNameValuePair(name, params.getString(name))); } } String server = ""; String key = ""; if (system.equals("Chicago Transit Authority")) { server = "www.ctabustracker.com"; key = "HeDbySM4CUDgRDsrGnRGZmD6K"; } else if (system.equals("Ohio State University TRIP")) { server = "trip.osu.edu"; key = "auixft7SWR3pWAcgkQfnfJpXt"; } else if (system.equals("MTA New York City Transit")) { server = "bustime34.mta.info"; key = "t7YxRNCmvVCfrZzrcMFeYegjp"; } qparams.add(new BasicNameValuePair("key", key)); // assemble the url URI uri; try { uri = URIUtils.createURI("http", // Protocol server, // server 80, // specified in API documentation "/bustime/api/v1/" + verb, // path URLEncodedUtils.format(qparams, "UTF-8"), null); } catch (URISyntaxException e) { // shouldn't happen throw new RuntimeException(e); } // assemble our request HttpClient httpClient = new DefaultHttpClient(); HttpGet httpget = new HttpGet(uri); Log.i(TAG, "Retrieving " + httpget.getURI().toString()); // from localytics recordEvent(context,system,verb,false); // ah, the blocking HttpResponse response = httpClient.execute(httpget); if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) { throw new RuntimeException(response.getStatusLine().toString()); } InputStream content = response.getEntity().getContent(); XmlPullParserFactory factory = XmlPullParserFactory.newInstance(); XmlPullParser xpp = factory.newPullParser(); xpp.setInput(content, null); return xpp; }
From source file:org.mahasen.util.DeleteUtil.java
/** * @param fileToDelete/*from w w w. j a va2 s .c om*/ * @throws MalformedURLException * @throws RegistryException */ public void delete(String fileToDelete) throws MalformedURLException, RegistryException, MahasenConfigurationException, MahasenException { Id resourceId = Id.build(String.valueOf(fileToDelete.hashCode())); String currentFileName = null; try { MahasenResource mahasenResource = mahasenManager.lookupDHT(resourceId); if (mahasenManager.lookupDHT(resourceId) == null) { throw new MahasenException("File not found"); } String fileName = mahasenResource.getProperty(MahasenConstants.FILE_NAME).toString(); Hashtable<String, Vector<String>> iptable = mahasenResource.getSplittedPartsIpTable(); int totalNoOfParts = 0; for (String partName : mahasenResource.getPartNames()) { totalNoOfParts += iptable.get(partName).size(); } setStoredNoOfParts(totalNoOfParts); for (String partName : mahasenResource.getPartNames()) { currentFileName = fileName + "." + partName; for (int i = 0; i < iptable.get(partName).size(); i++) { String nodeIp = iptable.get(partName).get(i); ArrayList<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair(MahasenConstants.FILE_NAME, fileName + "." + partName)); URI uri = null; try { uri = URIUtils.createURI("https", nodeIp + ":" + MahasenConstants.SERVER_PORT, -1, "/mahasen/delete_request_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); MahasenDeleteWorker mahasenDeleteWorker = new MahasenDeleteWorker(uri); Thread deleteThread = new Thread(mahasenDeleteWorker); deleteThread.start(); } catch (URISyntaxException e) { log.info("URI not found"); return; } } } final BlockFlag blockFlag = new BlockFlag(true, 1500); while (true) { if (storedNoOfParts.intValue() == 0) { MahasenResource resourceToDelete = mahasenManager.lookupDHT(resourceId); mahasenManager.deletePropertyFromTreeMap(resourceId, resourceToDelete); mahasenManager.deleteContent(resourceId); blockFlag.unblock(); break; } if (blockFlag.isBlocked()) { mahasenManager.getNode().getEnvironment().getTimeSource().sleep(10); } else { throw new MahasenException("Time out in delete operation for " + fileName); } } } catch (InterruptedException e) { log.error("Error deleting file : " + currentFileName); } }
From source file:es.eucm.eadventure.tracking.prv.service.TrackingPoster.java
public String openSession() { if (baseURL != null) return baseURL; try {// w ww . j av a2s . c o m HttpClient httpclient = new DefaultHttpClient(); URI uri = URIUtils.createURI("http", serviceURL, -1, "", null, null); HttpPost httppost = new HttpPost(uri); HttpResponse response; response = httpclient.execute(httppost); if (Integer.toString(response.getStatusLine().getStatusCode()).startsWith("2")) { HttpEntity entity = response.getEntity(); if (entity != null) { InputStream instream = entity.getContent(); StringWriter strWriter = new StringWriter(); char[] buffer = new char[1024]; try { Reader reader = new BufferedReader(new InputStreamReader(instream, "UTF-8")); int n; while ((n = reader.read(buffer)) != -1) { strWriter.write(buffer, 0, n); } } finally { instream.close(); } baseURL = strWriter.toString(); } } } catch (ClientProtocolException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException e) { e.printStackTrace(); } return baseURL; }
From source file:org.mahasen.client.Delete.java
/** * @param fileName//from w ww. j a v a2 s . c o m * @param hostIP * @throws IOException */ public void delete(String fileName, String hostIP) throws IOException, AuthenticationExceptionException, URISyntaxException, MahasenClientException { httpclient = new DefaultHttpClient(); clientLogin = new ClientLogin(); ClientConfiguration clientConfiguration = ClientConfiguration.getInstance(); try { System.setProperty("javax.net.ssl.trustStore", clientConfiguration.getTrustStorePath()); System.setProperty("javax.net.ssl.trustStorePassword", "wso2carbon"); System.setProperty("javax.net.ssl.trustStoreType", "JKS"); String userName = clientConfiguration.getUserName(); String passWord = clientConfiguration.getPassWord(); String hostAndPort = hostIP + ":" + clientConfiguration.getPort(); ClientLoginData loginData = clientLogin.remoteLogin(hostAndPort, userName, passWord); String logincookie = loginData.getCookie(); Boolean isLogged = loginData.isLoggedIn(); System.out.println("Login Cookie : " + logincookie + " Is Logged : " + isLogged); if (isLogged == true) { httpclient = WebClientSSLWrapper.wrapClient(httpclient); List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("fileName", fileName)); URI uri = URIUtils.createURI("https", hostAndPort, -1, "/mahasen/delete_ajaxprocessor.jsp", URLEncodedUtils.format(qparams, "UTF-8"), null); HttpPost httppost = new HttpPost(uri); System.out.println("executing request " + httppost.getRequestLine()); HttpResponse response = httpclient.execute(httppost); HttpEntity resEntity = response.getEntity(); System.out.println("----------------------------------------"); System.out.println(response.getStatusLine()); EntityUtils.consume(resEntity); if (response.getStatusLine().getStatusCode() == 900) { throw new MahasenClientException(String.valueOf(response.getStatusLine())); } } else { System.out.println("User has to be logged in to perform this function"); } } 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:com.leclercb.taskunifier.gui.plugins.PluginLicense.java
private URI getCheckSerialUri() throws Exception { List<NameValuePair> parameters = new ArrayList<NameValuePair>(); parameters.add(new BasicNameValuePair("plugin", this.pluginId)); parameters.add(new BasicNameValuePair("email", this.email)); return URIUtils.createURI("http", "www.taskunifier.com", -1, "/plugins/paypal/checklicense.php", URLEncodedUtils.format(parameters, "UTF-8"), null); }
From source file:org.craftercms.social.util.UGCHttpClient.java
private HttpPost manageAttachments(String[] attachments, String ticket, String target, String textContent) throws UnsupportedEncodingException, URISyntaxException { List<NameValuePair> qparams = new ArrayList<NameValuePair>(); qparams.add(new BasicNameValuePair("ticket", ticket)); URI uri = URIUtils.createURI(scheme, host, port, appPath + "/api/2/ugc/" + "create.json", URLEncodedUtils.format(qparams, HTTP.UTF_8), null); HttpPost httppost = new HttpPost(uri); if (attachments.length > 0) { MultipartEntity me = new MultipartEntity(HttpMultipartMode.BROWSER_COMPATIBLE); File file;// w w w . jav a 2 s .c o m FileBody fileBody; for (String f : attachments) { file = new File(f); fileBody = new FileBody(file, "application/octect-stream"); me.addPart("attachments", fileBody); } //File file = new File(attachments[0]); //FileBody fileBody = new FileBody(file, "application/octect-stream") ; //me.addPart("attachments", fileBody) ; me.addPart("target", new StringBody(target)); me.addPart("textContent", new StringBody(textContent)); httppost.setEntity(me); } return httppost; }
From source file:com.jzboy.couchdb.http.URITemplates.java
/** * URI used in bulk document operations//from w w w .j av a 2s . c o m */ public static URI bulkDocs(String host, int port, String dbName) throws URISyntaxException { return URIUtils.createURI("http", host, port, dbName + "/_bulk_docs", null, null); }
From source file:org.epop.dataprovider.msacademic.MicrosoftAcademicSearch.java
@Override protected Reader getHTMLDoc(String htmlParams, int pageTurnLimit, boolean initialWait) { // http://academic.research.microsoft.com/Search/?query=author:(%22Angelo%20gargantini%22)&start=1&end=10000 // List<NameValuePair> qparams = new ArrayList<NameValuePair>(); // qparams.add(new BasicNameValuePair("query","author:(\""+ // q.getCompleteAuthorName()+"\")"));//with quotation marks // qparams.add(new BasicNameValuePair("query", "author:(" // + q.getCompleteAuthorName() + ")"));// without quotation marks // qparams.add(new BasicNameValuePair("start", "1")); // qparams.add(new BasicNameValuePair("end", // String.valueOf(searchStep))); URI uri;//www .java 2s . c om String responseBody = ""; try { if (initialWait) Thread.sleep(DELAY); uri = URIUtils.createURI("http", MS_ACADEMIC_SEARCH, -1, "", htmlParams, null); HttpGet httpget = new HttpGet(uri); System.out.println(httpget.getURI()); HttpClient httpclient = new DefaultHttpClient(); ResponseHandler<String> responseHandler = new BasicResponseHandler(); responseBody = httpclient.execute(httpget, responseHandler); if (pageTurnLimit == 0) return new StringReader(responseBody); int counter = 1; String newResponseBody = responseBody; while (newResponseBody.contains( "<a id=\"ctl00_MainContent_PaperList_Next\" title=\"Go to Next Page\" class=\"nextprev\"")) { Thread.sleep(DELAY); URI newUri = URIUtils.createURI("http", MS_ACADEMIC_SEARCH, -1, "", htmlParams + "&start=" + String.valueOf((counter * searchStep) + 1) + "&end=" + String.valueOf((counter + 1) * searchStep), null); httpget = new HttpGet(newUri); System.out.println(httpget.getURI()); httpclient = new DefaultHttpClient(); newResponseBody = httpclient.execute(httpget, responseHandler); // System.out.println(newResponseBody); responseBody = responseBody + newResponseBody; if (pageTurnLimit == counter) return new StringReader(responseBody); counter++; } } catch (URISyntaxException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } // return the result as string return new StringReader(responseBody); }