List of usage examples for java.net URISyntaxException printStackTrace
public void printStackTrace()
From source file:org.hfoss.posit.android.sync.Communicator.java
/** * Sends a HttpPost request to the given URL. Any JSON * /* w ww .jav a 2 s. co m*/ * @param Uri, the URL to send to/receive from * @param pairs, a list of attribute/value pairs * @return the response from the URL */ public static String doHTTPPost(String Uri, List<NameValuePair> pairs) { BasicHttpParams mHttpParams = new BasicHttpParams(); // Set the timeout in milliseconds until a connection is established. HttpConnectionParams.setConnectionTimeout(mHttpParams, CONNECTION_TIMEOUT); // Set the default socket timeout (SO_TIMEOUT) // in milliseconds which is the timeout for waiting for data. HttpConnectionParams.setSoTimeout(mHttpParams, SOCKET_TIMEOUT); SchemeRegistry registry = new SchemeRegistry(); registry.register(new Scheme("http", new PlainSocketFactory(), 80)); ThreadSafeClientConnManager mConnectionManager = new ThreadSafeClientConnManager(mHttpParams, registry); DefaultHttpClient mHttpClient = new DefaultHttpClient(mConnectionManager, mHttpParams); if (Uri == null) throw new NullPointerException("The URL has to be passed"); String responseString = null; HttpPost post = new HttpPost(); Log.i(TAG, "doHTTPPost() URI = " + Uri); try { post.setURI(new URI(Uri)); } catch (URISyntaxException e) { Log.e(TAG, "URISyntaxException " + e.getMessage()); e.printStackTrace(); return "[Error] " + e.getMessage(); } ResponseHandler<String> responseHandler = new BasicResponseHandler(); try { post.setEntity(new UrlEncodedFormEntity(pairs, HTTP.UTF_8)); } catch (UnsupportedEncodingException e) { Log.e(TAG, "UnsupportedEncodingException " + e.getMessage()); return "[Error] " + e.getMessage(); } try { responseString = mHttpClient.execute(post, responseHandler); Log.d(TAG, "doHTTPpost responseString = " + responseString); } catch (ClientProtocolException e) { Log.e(TAG, "ClientProtocolException" + e.getMessage()); e.printStackTrace(); return "[Error] " + e.getMessage(); } catch (IOException e) { Log.e(TAG, "IOException " + e.getMessage()); e.printStackTrace(); return "[Error] " + e.getMessage(); } catch (IllegalStateException e) { Log.e(TAG, "IllegalStateException: " + e.getMessage()); e.printStackTrace(); return "[Error] " + e.getMessage(); } catch (Exception e) { Log.e(TAG, "Exception on HttpPost " + e.getMessage()); e.printStackTrace(); return "[Error] " + e.getMessage(); } Log.i(TAG, "doHTTPpost response = " + responseString); return responseString; }
From source file:app.HadoopImporterWindowTopComponent.java
public static String[] loadQueriesForNetworkLayer(String networkName, String layerName, HadoopImporterWindowTopComponent comp) { String[] q = new String[2]; CloseableHttpClient httpClient = null; HttpGet httpGet = null;//from w w w. jav a2 s .c o m CloseableHttpResponse response = null; try { httpClient = HttpClients.createDefault(); httpGet = new HttpGet(); String query = "[[Modification date::+]]|?Modification date|sort=Modification date|order=Ddesc"; String queryForLayerSQL = "[[Category:TMN_layer]][[TMN_layer_name::" + layerName + "]][[belongs_to_TMN::" + networkName + "]]|?TMN_layer_nlq|?TMN_layer_elq"; URI uri = new URI("http://semanpix.de/oldtimer/wiki/api.php?action=ask&format=json&query=" + encodeQuery(queryForLayerSQL)); //"); String uri2 = "http://semanpix.de/oldtimer/wiki/api.php?action=ask&format=json&query=" + queryForLayerSQL; httpGet.setURI(uri); System.out.println("[Request:]\n" + uri2); if (comp != null) { comp.setQuery(uri2); } // ArrayList<NameValuePair> nvps; // nvps = new ArrayList<NameValuePair>(); // nvps.add(new BasicNameValuePair("content-type", "application/json")); // nvps.add(new BasicNameValuePair("x-kii-appid", "xxxxx")); // nvps.add(new BasicNameValuePair("x-kii-appkey", "xxxxxxxxxxxxxx")); // StringEntity input = new StringEntity("{\"username\": \"dummyuser\",\"password\": \"dummypassword\"}"); // input.setContentType("application/json"); // // httpPost.setEntity(input); // // for (NameValuePair h : nvps) // { // httpPost.addHeader(h.getName(), h.getValue()); // } response = httpClient.execute(httpGet); if (response.getStatusLine().getStatusCode() != 200) { throw new RuntimeException( "Failed : HTTP error code : " + response.getStatusLine().getStatusCode()); } BufferedReader br = new BufferedReader(new InputStreamReader((response.getEntity().getContent()))); StringBuffer sb = new StringBuffer(); String output; System.out.println("Output from Server .... \n"); while ((output = br.readLine()) != null) { System.out.println(output); sb.append(output); } if (comp != null) { comp.setResponse(sb.toString()); } JSONObject obj1 = new JSONObject(sb.toString()); JSONObject obj2 = obj1.getJSONObject("query"); JSONObject obj3 = obj2.getJSONObject("results"); JSONObject obj4 = obj3.getJSONObject(layerName); JSONObject obj5 = obj4.getJSONObject("printouts"); String nlq = obj5.optString("TMN layer nlq"); String elq = obj5.optString("TMN layer elq"); System.out.println(nlq); System.out.println(elq); q[0] = URLDecoder.decode(nlq.substring(2, nlq.length() - 2)); q[1] = URLDecoder.decode(elq.substring(2, elq.length() - 2)); } catch (MalformedURLException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } catch (URISyntaxException ex) { Exceptions.printStackTrace(ex); } catch (JSONException ex) { Exceptions.printStackTrace(ex); } finally { try { if (response != null) { response.close(); } httpClient.close(); } catch (Exception ex) { ex.printStackTrace(); } } return q; }
From source file:com.pianobakery.complsa.LicenseKeyGUI.java
private void buyButtonActionPerformed(ActionEvent evt) { System.out.println("Buying"); try {/* ww w . ja v a2 s. co m*/ openWebpage(new URI("http://www.oyonoko.com/semanticsearch/buy")); } catch (URISyntaxException e) { e.printStackTrace(); } }
From source file:com.ximai.savingsmore.save.activity.BusinessMyCenterActivity.java
@Override protected void onActivityResult(int requestCode, int resultCode, Intent intent) { super.onActivityResult(requestCode, resultCode, intent); if (resultCode != RESULT_OK) { return;/* w w w.ja va 2 s .co m*/ } else if (requestCode == PICK_FROM_CAMERA || requestCode == PICK_FROM_IMAGE) { Uri uri = null; if (null != intent && intent.getData() != null) { uri = intent.getData(); } else { String fileName = PreferencesUtils.getString(this, "tempName"); uri = Uri.fromFile(new File(FileSystem.getCachesDir(this, true).getAbsolutePath(), fileName)); } if (uri != null) { cropImage(uri, CROP_PHOTO_CODE); } } else if (requestCode == CROP_PHOTO_CODE) { Uri photoUri = intent.getParcelableExtra(MediaStore.EXTRA_OUTPUT); if (isslinece) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), slience_image); zhizhao_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "BusinessLicense"); } catch (URISyntaxException e) { e.printStackTrace(); } } else if (isZhengshu) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), zhengshu_iamge); xukezheng_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "LicenseKey"); } catch (URISyntaxException e) { e.printStackTrace(); } } else if (isheadImage) { MyImageLoader.displayDefaultImage("file://" + photoUri.getPath(), head_image); tuoxiang_path = photoUri.toString(); try { upLoadImage(new File((new URI(photoUri.toString()))), "Photo"); } catch (URISyntaxException e) { e.printStackTrace(); } //upLoadImage(new File((new URI(photoUri.toString()))), "Photo"); } else if (isItem) { if (imagePath.size() + images.size() < 10) { shangpu_path.add(photoUri.toString()); try { upLoadImage(new File((new URI(photoUri.toString()))), "Seller"); } catch (URISyntaxException e) { e.printStackTrace(); } //imagePath.add(photoUri.getPath()); } else { Toast.makeText(BusinessMyCenterActivity.this, "?9", Toast.LENGTH_SHORT).show(); } } //addImage(imagePath); } }
From source file:org.araqne.pkg.PackageManagerService.java
private byte[] download(PackageRepository repo, URL url) throws IOException, KeyStoreException, UnrecoverableKeyException, KeyManagementException { if (repo.isLocalFilesystem()) { FileInputStream stream = null; try {//from ww w . ja va 2 s . co m File file = new File(url.toURI()); long length = file.length(); stream = new FileInputStream(file); byte[] b = new byte[(int) length]; stream.read(b); return b; } catch (URISyntaxException e) { e.printStackTrace(); return new byte[0]; } finally { if (stream != null) stream.close(); } } else if (repo.isHttps()) { ServiceReference<?> ref = bc.getServiceReference(KeyStoreManager.class.getName()); KeyStoreManager keyman = (KeyStoreManager) bc.getService(ref); try { TrustManagerFactory tmf = keyman.getTrustManagerFactory(repo.getTrustStoreAlias(), TrustManagerFactory.getDefaultAlgorithm()); KeyManagerFactory kmf = keyman.getKeyManagerFactory(repo.getKeyStoreAlias(), KeyManagerFactory.getDefaultAlgorithm()); HttpWagon.download(url, tmf, kmf); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return HttpWagon.download(url); } else if (repo.isAuthRequired()) return HttpWagon.download(url, true, repo.getAccount(), repo.getPassword()); return HttpWagon.download(url); }
From source file:org.araqne.pkg.PackageManagerService.java
private String downloadString(PackageRepository repo, URL url) throws IOException, KeyStoreException, UnrecoverableKeyException, KeyManagementException { if (repo.isLocalFilesystem()) { FileInputStream stream = null; try {/*from w w w . j a va 2s . c om*/ File file = new File(url.toURI()); long length = file.length(); stream = new FileInputStream(file); byte[] b = new byte[(int) length]; stream.read(b); return new String(b, Charset.forName("UTF-8")); } catch (URISyntaxException e) { e.printStackTrace(); return new String(); } finally { if (stream != null) stream.close(); } } else if (repo.isHttps()) { ServiceReference<?> ref = bc.getServiceReference(KeyStoreManager.class.getName()); KeyStoreManager keyman = (KeyStoreManager) bc.getService(ref); try { TrustManagerFactory tmf = keyman.getTrustManagerFactory(repo.getTrustStoreAlias(), TrustManagerFactory.getDefaultAlgorithm()); KeyManagerFactory kmf = keyman.getKeyManagerFactory(repo.getKeyStoreAlias(), KeyManagerFactory.getDefaultAlgorithm()); HttpWagon.download(url, tmf, kmf); } catch (NoSuchAlgorithmException e) { e.printStackTrace(); } return HttpWagon.downloadString(url); } else if (repo.isAuthRequired()) return HttpWagon.downloadString(url, repo.getAccount(), repo.getPassword()); return HttpWagon.downloadString(url); }
From source file:org.opendatakit.aggregate.server.ServerDataServiceImpl.java
/** * This method more or less gets the user-friendly data to be displayed. It * adds the correct filename and returns only the non-deleted rows. *//*from w w w . j a v a 2 s . c o m*/ @Override public TableContentsForFilesClient getAppLevelFileInfoContents(String sortColumn, boolean ascending) throws AccessDeniedException, RequestFailureException, DatastoreFailureException, PermissionDeniedExceptionClient, EntityNotFoundExceptionClient { TableContentsForFilesClient tcc = new TableContentsForFilesClient(); HttpServletRequest req = this.getThreadLocalRequest(); CallingContext cc = ContextFactory.getCallingContext(this, req); try { TablesUserPermissions userPermissions = new TablesUserPermissionsImpl(cc); String appId = ServerPreferencesProperties.getOdkTablesAppId(cc); TableManager tm = new TableManager(appId, userPermissions, cc); List<DbTableFileInfo.DbTableFileInfoEntity> entities = DbTableFileInfo .queryForAllOdkClientVersionsOfAppLevelFiles(cc); DbTableFiles dbTableFiles = new DbTableFiles(cc); UriBuilder ub; try { ub = UriBuilder.fromUri(new URI( cc.getServerURL() + BasicConsts.FORWARDSLASH + ServletConsts.ODK_TABLES_SERVLET_BASE_PATH)); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestFailureException(e); } ub.path(OdkTables.class, "getFilesService"); ArrayList<FileSummaryClient> completedSummaries = new ArrayList<FileSummaryClient>(); for (DbTableFileInfo.DbTableFileInfoEntity entry : entities) { BlobEntitySet blobEntitySet = dbTableFiles.getBlobEntitySet(entry.getId(), cc); if (blobEntitySet.getAttachmentCount(cc) != 1) { continue; } String odkClientVersion = entry.getOdkClientVersion(); UriBuilder tmp = ub.clone().path(FileService.class, "getFile"); URI getFile = tmp.build(appId, odkClientVersion, entry.getPathToFile()); String downloadUrl; try { downloadUrl = getFile.toURL().toExternalForm() + "?" + FileService.PARAM_AS_ATTACHMENT + "=true"; } catch (MalformedURLException e) { e.printStackTrace(); throw new RequestFailureException("Unable to convert to URL"); } FileSummaryClient sum = new FileSummaryClient(entry.getPathToFile(), blobEntitySet.getContentType(1, cc), blobEntitySet.getContentLength(1, cc), entry.getId(), odkClientVersion, "", downloadUrl); completedSummaries.add(sum); } Comparator<FileSummaryClient> columnSorter = FILENAME.getAscendingSort(); if (StringUtils.isNotEmpty(sortColumn)) { FileInfoSortType columnType = FileInfoSortType.fromDbColumn(sortColumn); if (columnType != null) { if (ascending) { columnSorter = columnType.getAscendingSort(); } else { columnSorter = columnType.getDescendingSort(); } } } Collections.sort(completedSummaries, columnSorter); tcc.files = completedSummaries; return tcc; } catch (ODKEntityNotFoundException e) { e.printStackTrace(); throw new EntityNotFoundExceptionClient(e); } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException(e); } catch (ODKTaskLockException e) { e.printStackTrace(); throw new RequestFailureException(e); } catch (PermissionDeniedException e) { e.printStackTrace(); throw new PermissionDeniedExceptionClient(e); } }
From source file:org.opendatakit.aggregate.server.ServerDataServiceImpl.java
/** * This method more or less gets the user-friendly data to be displayed. It * adds the correct filename and returns only the non-deleted rows. *///from ww w. j ava 2 s.co m @Override public TableContentsForFilesClient getInstanceFileInfoContents(String tableId, String sortColumn, boolean ascending) throws AccessDeniedException, RequestFailureException, DatastoreFailureException, PermissionDeniedExceptionClient, EntityNotFoundExceptionClient { TableContentsForFilesClient tcc = new TableContentsForFilesClient(); HttpServletRequest req = this.getThreadLocalRequest(); CallingContext cc = ContextFactory.getCallingContext(this, req); try { TablesUserPermissions userPermissions = new TablesUserPermissionsImpl(cc); String appId = ServerPreferencesProperties.getOdkTablesAppId(cc); TableManager tm = new TableManager(appId, userPermissions, cc); TableEntry table = tm.getTable(tableId); if (table == null || table.getSchemaETag() == null) { // you couldn't find // the table throw new ODKEntityNotFoundException(); } String schemaETag = table.getSchemaETag(); DbTableInstanceFiles blobStore = new DbTableInstanceFiles(tableId, cc); List<BinaryContent> contents = blobStore.getAllBinaryContents(cc); UriBuilder ub; try { ub = UriBuilder.fromUri(new URI( cc.getServerURL() + BasicConsts.FORWARDSLASH + ServletConsts.ODK_TABLES_SERVLET_BASE_PATH)); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestFailureException(e); } ub.path(OdkTables.class, "getTablesService"); ArrayList<FileSummaryClient> completedSummaries = new ArrayList<FileSummaryClient>(); for (BinaryContent entry : contents) { if (entry.getUnrootedFilePath() == null) { continue; } // the rowId is the top-level auri for this record String rowId = entry.getTopLevelAuri(); UriBuilder tmp = ub.clone().path(TableService.class, "getRealizedTable") .path(RealizedTableService.class, "getInstanceFiles") .path(InstanceFileService.class, "getFile"); URI getFile = tmp.build(appId, tableId, schemaETag, rowId, entry.getUnrootedFilePath()); String downloadUrl = getFile.toASCIIString() + "?" + FileService.PARAM_AS_ATTACHMENT + "=true"; FileSummaryClient sum = new FileSummaryClient(entry.getUnrootedFilePath(), entry.getContentType(), entry.getContentLength(), entry.getUri(), null, tableId, downloadUrl); sum.setInstanceId(entry.getTopLevelAuri()); completedSummaries.add(sum); } Comparator<FileSummaryClient> columnSorter = FILENAME.getAscendingSort(); if (StringUtils.isNotEmpty(sortColumn)) { FileInfoSortType columnType = FileInfoSortType.fromDbColumn(sortColumn); if (columnType != null) { if (ascending) { columnSorter = columnType.getAscendingSort(); } else { columnSorter = columnType.getDescendingSort(); } } } Collections.sort(completedSummaries, columnSorter); tcc.files = completedSummaries; return tcc; } catch (ODKEntityNotFoundException e) { e.printStackTrace(); throw new EntityNotFoundExceptionClient(e); } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException(e); } catch (ODKTaskLockException e) { e.printStackTrace(); throw new RequestFailureException(e); } catch (PermissionDeniedException e) { e.printStackTrace(); throw new PermissionDeniedExceptionClient(e); } }
From source file:edu.ku.brc.util.FileStoreAttachmentManager.java
/** * @param iconName// ww w . j a va2 s . c om * @return */ private File getFileForIconName(final String iconName) { IconEntry entry = IconManager.getIconEntryByName(iconName); if (entry != null) { try { //System.err.println("****** entry.getUrl(): "+entry.getUrl().toExternalForm()); String fullPath = entry.getUrl().toExternalForm(); if (fullPath.startsWith("jar:")) { String[] segs = StringUtils.split(fullPath, "!"); if (segs.length != 2) return null; String jarPath = segs[1]; InputStream stream = IconManager.class.getResourceAsStream(jarPath); if (stream == null) { //send your exception or warning return null; } String fileName = FilenameUtils.getName(jarPath); String path = baseDirectory + File.separator + THUMBNAILS + File.separator + fileName; File outfile = new File(path); //System.err.println("Path: "+ path+"|"+jarPath+"|"+fileName); OutputStream resStreamOut; int readBytes; byte[] buffer = new byte[10240]; try { resStreamOut = new FileOutputStream(outfile); while ((readBytes = stream.read(buffer)) > 0) { resStreamOut.write(buffer, 0, readBytes); } resStreamOut.close(); stream.close(); return outfile; } catch (IOException e1) { e1.printStackTrace(); return null; } } else { return new File(entry.getUrl().toURI()); } } catch (URISyntaxException e) { e.printStackTrace(); } } return null; }
From source file:org.opendatakit.aggregate.server.ServerDataServiceImpl.java
/** * This method more or less gets the user-friendly data to be displayed. It * adds the correct filename and returns only the non-deleted rows. *///from www. ja v a 2 s. co m @Override public TableContentsForFilesClient getTableFileInfoContents(String tableId, String sortColumn, boolean ascending) throws AccessDeniedException, RequestFailureException, DatastoreFailureException, PermissionDeniedExceptionClient, EntityNotFoundExceptionClient { TableContentsForFilesClient tcc = new TableContentsForFilesClient(); HttpServletRequest req = this.getThreadLocalRequest(); CallingContext cc = ContextFactory.getCallingContext(this, req); try { TablesUserPermissions userPermissions = new TablesUserPermissionsImpl(cc); String appId = ServerPreferencesProperties.getOdkTablesAppId(cc); TableManager tm = new TableManager(appId, userPermissions, cc); TableEntry table = tm.getTable(tableId); if (table == null || table.getSchemaETag() == null) { // you couldn't find // the table throw new ODKEntityNotFoundException(); } List<DbTableFileInfo.DbTableFileInfoEntity> entities = DbTableFileInfo .queryForAllOdkClientVersionsOfTableIdFiles(table.getTableId(), cc); DbTableFiles dbTableFiles = new DbTableFiles(cc); UriBuilder ub; try { ub = UriBuilder.fromUri(new URI( cc.getServerURL() + BasicConsts.FORWARDSLASH + ServletConsts.ODK_TABLES_SERVLET_BASE_PATH)); } catch (URISyntaxException e) { e.printStackTrace(); throw new RequestFailureException(e); } ub.path(OdkTables.class, "getFilesService"); ArrayList<FileSummaryClient> completedSummaries = new ArrayList<FileSummaryClient>(); for (DbTableFileInfo.DbTableFileInfoEntity entry : entities) { BlobEntitySet blobEntitySet = dbTableFiles.getBlobEntitySet(entry.getId(), cc); if (blobEntitySet.getAttachmentCount(cc) != 1) { continue; } String odkClientVersion = entry.getOdkClientVersion(); UriBuilder tmp = ub.clone().path(FileService.class, "getFile"); URI getFile = tmp.build(appId, odkClientVersion, entry.getPathToFile()); String downloadUrl; try { downloadUrl = getFile.toURL().toExternalForm() + "?" + FileService.PARAM_AS_ATTACHMENT + "=true"; } catch (MalformedURLException e) { e.printStackTrace(); throw new RequestFailureException("Unable to convert to URL"); } FileSummaryClient sum = new FileSummaryClient(entry.getPathToFile(), blobEntitySet.getContentType(1, cc), blobEntitySet.getContentLength(1, cc), entry.getId(), odkClientVersion, tableId, downloadUrl); completedSummaries.add(sum); } Comparator<FileSummaryClient> columnSorter = FILENAME.getAscendingSort(); if (StringUtils.isNotEmpty(sortColumn)) { FileInfoSortType columnType = FileInfoSortType.fromDbColumn(sortColumn); if (columnType != null) { if (ascending) { columnSorter = columnType.getAscendingSort(); } else { columnSorter = columnType.getDescendingSort(); } } } Collections.sort(completedSummaries, columnSorter); tcc.files = completedSummaries; return tcc; } catch (ODKEntityNotFoundException e) { e.printStackTrace(); throw new EntityNotFoundExceptionClient(e); } catch (ODKDatastoreException e) { e.printStackTrace(); throw new DatastoreFailureException(e); } catch (ODKTaskLockException e) { e.printStackTrace(); throw new RequestFailureException(e); } catch (PermissionDeniedException e) { e.printStackTrace(); throw new PermissionDeniedExceptionClient(e); } }