use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class RepositoryHelper method loadPlugins.
@NotNull
public static List<IdeaPluginDescriptor> loadPlugins(@Nullable String repositoryUrl, @Nullable BuildNumber buildnumber, @Nullable String channel, boolean forceHttps, @Nullable final ProgressIndicator indicator) throws IOException {
String url;
final File pluginListFile;
final String host;
try {
URIBuilder uriBuilder;
if (repositoryUrl == null) {
uriBuilder = new URIBuilder(ApplicationInfoImpl.getShadowInstance().getPluginsListUrl());
pluginListFile = new File(PathManager.getPluginsPath(), channel == null ? PLUGIN_LIST_FILE : channel + "_" + PLUGIN_LIST_FILE);
if (pluginListFile.length() > 0) {
uriBuilder.addParameter("crc32", crc32(pluginListFile));
}
} else {
uriBuilder = new URIBuilder(repositoryUrl);
pluginListFile = null;
}
if (!URLUtil.FILE_PROTOCOL.equals(uriBuilder.getScheme())) {
uriBuilder.addParameter("build", (buildnumber != null ? buildnumber.asString() : ApplicationInfoImpl.getShadowInstance().getApiVersion()));
if (channel != null)
uriBuilder.addParameter("channel", channel);
}
host = uriBuilder.getHost();
url = uriBuilder.build().toString();
} catch (URISyntaxException e) {
throw new IOException(e);
}
if (indicator != null) {
indicator.setText2(IdeBundle.message("progress.connecting.to.plugin.manager", host));
}
RequestBuilder request = HttpRequests.request(url).forceHttps(forceHttps);
return process(repositoryUrl, request.connect(new HttpRequests.RequestProcessor<List<IdeaPluginDescriptor>>() {
@Override
public List<IdeaPluginDescriptor> process(@NotNull HttpRequests.Request request) throws IOException {
if (indicator != null) {
indicator.checkCanceled();
}
URLConnection connection = request.getConnection();
if (pluginListFile != null && pluginListFile.length() > 0 && connection instanceof HttpURLConnection && ((HttpURLConnection) connection).getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) {
return loadPluginList(pluginListFile);
}
if (indicator != null) {
indicator.checkCanceled();
indicator.setText2(IdeBundle.message("progress.downloading.list.of.plugins", host));
}
if (pluginListFile != null) {
synchronized (PLUGIN_LIST_FILE) {
FileUtil.ensureExists(pluginListFile.getParentFile());
request.saveToFile(pluginListFile, indicator);
return loadPluginList(pluginListFile);
}
} else {
return parsePluginList(request.getReader());
}
}
}));
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class TrelloRepository method setTaskState.
@Override
public void setTaskState(@NotNull Task task, @NotNull CustomTaskState state) throws Exception {
final URI url = new URIBuilder(getRestApiUrl("cards", task.getId(), "idList")).addParameter("value", state.getId()).build();
final HttpResponse response = getHttpClient().execute(new HttpPut(url));
if (response.getStatusLine() != null && response.getStatusLine().getStatusCode() == HttpStatus.SC_UNAUTHORIZED && EntityUtils.toString(response.getEntity()).trim().equals("unauthorized card permission requested")) {
throw new Exception(TaskBundle.message("trello.failure.write.access.required"));
}
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class TrelloRepository method fetchCards.
@NotNull
public List<TrelloCard> fetchCards(int limit, boolean withClosed) throws Exception {
boolean fromList = false;
// choose most appropriate card provider
String baseUrl;
if (myCurrentList != null && myCurrentList != UNSPECIFIED_LIST) {
baseUrl = getRestApiUrl("lists", myCurrentList.getId(), "cards");
fromList = true;
} else if (myCurrentBoard != null && myCurrentBoard != UNSPECIFIED_BOARD) {
baseUrl = getRestApiUrl("boards", myCurrentBoard.getId(), "cards");
} else if (myCurrentUser != null) {
baseUrl = getRestApiUrl("members", "me", "cards");
} else {
throw new IllegalStateException("Not configured");
}
final URIBuilder fetchCardUrl = new URIBuilder(baseUrl).addParameter("fields", TrelloCard.REQUIRED_FIELDS).addParameter("limit", String.valueOf(limit));
// 'visible' filter for some reason is not supported for lists
if (withClosed || fromList) {
fetchCardUrl.addParameter("filter", "all");
} else {
fetchCardUrl.addParameter("filter", "visible");
}
List<TrelloCard> cards = makeRequestAndDeserializeJsonResponse(fetchCardUrl.build(), TrelloUtil.LIST_OF_CARDS_TYPE);
LOG.debug("Total " + cards.size() + " cards downloaded");
if (!myIncludeAllCards) {
cards = ContainerUtil.filter(cards, card -> card.getIdMembers().contains(myCurrentUser.getId()));
LOG.debug("Total " + cards.size() + " cards after filtering");
}
if (!cards.isEmpty()) {
if (fromList) {
baseUrl = getRestApiUrl("boards", cards.get(0).getIdBoard(), "cards");
}
// fix for IDEA-111470 and IDEA-111475
// Select IDs of visible cards, e.d. cards that either archived explicitly, belong to archived list or closed board.
// This information can't be extracted from single card description, because its 'closed' field
// reflects only the card state and doesn't show state of parental list and board.
// NOTE: According to Trello REST API "filter=visible" parameter may be used only when fetching cards for
// particular board or user.
final URIBuilder visibleCardsUrl = new URIBuilder(baseUrl).addParameter("filter", "visible").addParameter("fields", "none");
final List<TrelloCard> visibleCards = makeRequestAndDeserializeJsonResponse(visibleCardsUrl.build(), TrelloUtil.LIST_OF_CARDS_TYPE);
LOG.debug("Total " + visibleCards.size() + " visible cards");
final Set<String> visibleCardsIDs = ContainerUtil.map2Set(visibleCards, card -> card.getId());
for (TrelloCard card : cards) {
card.setVisible(visibleCardsIDs.contains(card.getId()));
}
}
return cards;
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class RedmineRepository method getProjectsUrl.
@NotNull
private URI getProjectsUrl(int offset, int limit) throws URISyntaxException {
URIBuilder builder = createUriBuilderWithApiKey("projects.json");
builder.addParameter("offset", String.valueOf(offset));
builder.addParameter("limit", String.valueOf(limit));
return builder.build();
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class RedmineRepository method createCancellableConnection.
@Nullable
@Override
public CancellableConnection createCancellableConnection() {
return new NewBaseRepositoryImpl.HttpTestConnection(new HttpGet()) {
@Override
protected void test() throws Exception {
// Strangely, Redmine doesn't return 401 or 403 error codes, if client sent wrong credentials, and instead
// merely returns empty array of issues with status code of 200. This means that we should attempt to fetch
// something more specific than issues to test proper configuration, e.g. current user information at
// /users/current.json. Unfortunately this endpoint may be unavailable on some old servers (see IDEA-122845)
// and in this case we have to come back to requesting issues in this case to test anything at all.
URIBuilder uriBuilder = createUriBuilderWithApiKey("users", "current.json");
myCurrentRequest.setURI(uriBuilder.build());
HttpClient client = getHttpClient();
HttpResponse httpResponse = client.execute(myCurrentRequest);
StatusLine statusLine = httpResponse.getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
// Check that projects can be downloaded via given URL and the latter is not project-specific
myCurrentRequest = new HttpGet(getProjectsUrl(0, 1));
statusLine = client.execute(myCurrentRequest).getStatusLine();
if (statusLine != null && statusLine.getStatusCode() == HttpStatus.SC_OK) {
myCurrentRequest = new HttpGet(getIssuesUrl(0, 1, true));
statusLine = client.execute(myCurrentRequest).getStatusLine();
}
}
if (statusLine != null && statusLine.getStatusCode() != HttpStatus.SC_OK) {
throw RequestFailedException.forStatusCode(statusLine.getStatusCode(), statusLine.getReasonPhrase());
}
}
};
}
Aggregations