public void updateIcon() { myUserIcon = null; String email = myState.email; if (email == null) { myState.iconBytes = null; return; } // get node size int size = AllIcons.Actions.Find.getIconHeight(); ApplicationManager.getApplication().executeOnPooledThread(() -> { String emailHash = DigestUtils.md5Hex(email.toLowerCase().trim()); try { byte[] bytes = HttpRequests.request("https://www.gravatar.com/avatar/" + emailHash + ".png?s=" + size + "&d=identicon").readBytes(null); myState.iconBytes = Base64.getEncoder().encodeToString(bytes); } catch (IOException e) { LOGGER.error(e); } }); }
private File downloadPlugin(final ProgressIndicator indicator) throws IOException { File pluginsTemp = new File(PathManager.getPluginTempPath()); if (!pluginsTemp.exists() && !pluginsTemp.mkdirs()) { throw new IOException(IdeBundle.message("error.cannot.create.temp.dir", pluginsTemp)); } final File file = FileUtil.createTempFile(pluginsTemp, "plugin_", "_download", true, false); indicator.checkCanceled(); if (myIsPlatform) { indicator.setText2(IdeBundle.message("progress.downloading.platform")); } else { indicator.setText2(IdeBundle.message("progress.downloading.plugin", getPluginName())); } return HttpRequests.request(myPluginUrl).gzip(false).connect(request -> { request.saveToFile(file, indicator); String fileName = getFileName(); File newFile = new File(file.getParentFile(), fileName); FileUtil.rename(file, newFile); return newFile; }); }
@Override public String call() throws Exception { logger.debug("About to fetch experiments."); return HttpRequests.request( System.getProperty(EXPERIMENTS_URL_PROPERTY, DEFAULT_EXPERIMENT_URL) + pluginName) .readString(/* progress indicator */ null); }
@Override public ActionCallback perform(List<LibraryOrderEntry> orderEntriesContainingFile) { final ActionCallback callback = new ActionCallback(); Task task = new Task.Backgroundable(myProject, "Downloading Sources", true) { @Override public void run(@NotNull final ProgressIndicator indicator) { final byte[] bytes; try { LOG.info("Downloading sources JAR: " + myUrl); indicator.checkCanceled(); bytes = HttpRequests.request(myUrl).readBytes(indicator); } catch (IOException e) { LOG.warn(e); ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { new Notification(myMessageGroupId, "Downloading failed", "Failed to download sources: " + myUrl, NotificationType.ERROR) .notify(getProject()); callback.setDone(); } }); return; } ApplicationManager.getApplication().invokeLater(new Runnable() { @Override public void run() { AccessToken accessToken = WriteAction.start(); try { storeFile(bytes); } finally { accessToken.finish(); callback.setDone(); } } }); } @Override public void onCancel() { callback.setRejected(); } }; task.queue(); return callback; }
@Nullable private List<Task> getIssuesFromRepositories(@Nullable String request, int offset, int limit, boolean withClosed, boolean forceRequest, @NotNull final ProgressIndicator cancelled) { List<Task> issues = null; for(final TaskRepository repository : getAllRepositories()) { if(!repository.isConfigured() || (!forceRequest && myBadRepositories.contains(repository))) { continue; } try { long start = System.currentTimeMillis(); Task[] tasks = repository.getIssues(request, offset, limit, withClosed, cancelled); long timeSpent = System.currentTimeMillis() - start; LOG.info(String.format("Total %s ms to download %d issues from '%s' (pattern '%s')", timeSpent, tasks.length, repository.getUrl(), request)); myBadRepositories.remove(repository); if(issues == null) { issues = new ArrayList<>(tasks.length); } if(!repository.isSupported(TaskRepository.NATIVE_SEARCH) && request != null) { List<Task> filteredTasks = TaskSearchSupport.filterTasks(request, ContainerUtil.list(tasks)); ContainerUtil.addAll(issues, filteredTasks); } else { ContainerUtil.addAll(issues, tasks); } } catch(ProcessCanceledException ignored) { // OK } catch(Exception e) { String reason = ""; // Fix to IDEA-111810 //noinspection InstanceofCatchParameter if(e.getClass() == Exception.class || e instanceof RequestFailedException) { // probably contains some message meaningful to end-user reason = e.getMessage(); } //noinspection InstanceofCatchParameter if(e instanceof SocketTimeoutException || e instanceof HttpRequests.HttpStatusException) { LOG.warn("Can't connect to " + repository + ": " + e.getMessage()); } else { LOG.warn("Cannot connect to " + repository, e); } myBadRepositories.add(repository); if(forceRequest) { notifyAboutConnectionFailure(repository, reason); } } } return issues; }
private void configureCheckButton() { if (HttpConfigurable.getInstance() == null) { myCheckButton.setVisible(false); return; } myCheckButton.addActionListener(new ActionListener() { @Override public void actionPerformed(@Nonnull ActionEvent e) { final String title = "Check Proxy Settings"; final String answer = Messages.showInputDialog(myMainPanel, "Warning: your settings will be saved.\n\nEnter any URL to check connection to:", title, Messages.getQuestionIcon(), "http://", null); if (StringUtil.isEmptyOrSpaces(answer)) { return; } final HttpConfigurable settings = HttpConfigurable.getInstance(); apply(settings); final AtomicReference<IOException> exceptionReference = new AtomicReference<>(); myCheckButton.setEnabled(false); myCheckButton.setText("Check connection (in progress...)"); myConnectionCheckInProgress = true; ApplicationManager.getApplication().executeOnPooledThread(() -> { try { //already checked for null above //noinspection ConstantConditions HttpRequests.request(answer) .readTimeout(3 * 1000) .tryConnect(); } catch (IOException e1) { exceptionReference.set(e1); } //noinspection SSBasedInspection SwingUtilities.invokeLater(() -> { myConnectionCheckInProgress = false; reset(settings); // since password might have been set Component parent; if (myMainPanel.isShowing()) { parent = myMainPanel; myCheckButton.setText("Check connection"); myCheckButton.setEnabled(canEnableConnectionCheck()); } else { IdeFrame frame = IdeFocusManager.findInstance().getLastFocusedFrame(); if (frame == null) { return; } parent = frame.getComponent(); } //noinspection ThrowableResultOfMethodCallIgnored final IOException exception = exceptionReference.get(); if (exception == null) { Messages.showMessageDialog(parent, "Connection successful", title, Messages.getInformationIcon()); } else { final String message = exception.getMessage(); if (settings.USE_HTTP_PROXY) { settings.LAST_ERROR = message; } Messages.showErrorDialog(parent, errorText(message)); } }); }); } }); }