Search in sources :

Example 61 with URIBuilder

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());
            }
        }
    }));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) RequestBuilder(com.intellij.util.io.RequestBuilder) URISyntaxException(java.net.URISyntaxException) NotNull(org.jetbrains.annotations.NotNull) HttpURLConnection(java.net.HttpURLConnection) URLConnection(java.net.URLConnection) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 62 with URIBuilder

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"));
    }
}
Also used : URI(java.net.URI) HttpPut(org.apache.http.client.methods.HttpPut) JsonParseException(com.google.gson.JsonParseException) URISyntaxException(java.net.URISyntaxException) IOException(java.io.IOException) URIBuilder(org.apache.http.client.utils.URIBuilder)

Example 63 with URIBuilder

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;
}
Also used : JsonParseException(com.google.gson.JsonParseException) TypeToken(com.google.gson.reflect.TypeToken) Tag(com.intellij.util.xmlb.annotations.Tag) URISyntaxException(java.net.URISyntaxException) BaseRepository(com.intellij.tasks.impl.BaseRepository) HttpUriRequest(org.apache.http.client.methods.HttpUriRequest) TrelloList(com.intellij.tasks.trello.model.TrelloList) ContainerUtil(com.intellij.util.containers.ContainerUtil) HttpRequestWrapper(org.apache.http.client.methods.HttpRequestWrapper) EntityUtils(org.apache.http.util.EntityUtils) TrelloBoard(com.intellij.tasks.trello.model.TrelloBoard) HashSet(java.util.HashSet) Comparing(com.intellij.openapi.util.Comparing) HttpClient(org.apache.http.client.HttpClient) URI(java.net.URI) Logger(com.intellij.openapi.diagnostic.Logger) TaskResponseUtil(com.intellij.tasks.impl.httpclient.TaskResponseUtil) URIBuilder(org.apache.http.client.utils.URIBuilder) StringUtil(com.intellij.openapi.util.text.StringUtil) GsonMultipleObjectsDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonMultipleObjectsDeserializer) TaskRepositoryType(com.intellij.tasks.TaskRepositoryType) Set(java.util.Set) IOException(java.io.IOException) GsonSingleObjectDeserializer(com.intellij.tasks.impl.httpclient.TaskResponseUtil.GsonSingleObjectDeserializer) org.apache.http(org.apache.http) CustomTaskState(com.intellij.tasks.CustomTaskState) Task(com.intellij.tasks.Task) TaskBundle(com.intellij.tasks.TaskBundle) NewBaseRepositoryImpl(com.intellij.tasks.impl.httpclient.NewBaseRepositoryImpl) Nullable(org.jetbrains.annotations.Nullable) List(java.util.List) HttpPut(org.apache.http.client.methods.HttpPut) HttpGet(org.apache.http.client.methods.HttpGet) HttpContext(org.apache.http.protocol.HttpContext) Function(com.intellij.util.Function) ObjectUtils(com.intellij.util.ObjectUtils) TrelloUser(com.intellij.tasks.trello.model.TrelloUser) ResponseHandler(org.apache.http.client.ResponseHandler) NotNull(org.jetbrains.annotations.NotNull) Collections(java.util.Collections) Condition(com.intellij.openapi.util.Condition) TrelloCard(com.intellij.tasks.trello.model.TrelloCard) TrelloCard(com.intellij.tasks.trello.model.TrelloCard) URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 64 with URIBuilder

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();
}
Also used : URIBuilder(org.apache.http.client.utils.URIBuilder) NotNull(org.jetbrains.annotations.NotNull)

Example 65 with URIBuilder

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());
            }
        }
    };
}
Also used : StatusLine(org.apache.http.StatusLine) HttpGet(org.apache.http.client.methods.HttpGet) HttpClient(org.apache.http.client.HttpClient) HttpResponse(org.apache.http.HttpResponse) URIBuilder(org.apache.http.client.utils.URIBuilder) Nullable(org.jetbrains.annotations.Nullable)

Aggregations

URIBuilder (org.apache.http.client.utils.URIBuilder)107 URISyntaxException (java.net.URISyntaxException)42 URI (java.net.URI)37 HttpGet (org.apache.http.client.methods.HttpGet)22 IOException (java.io.IOException)21 NameValuePair (org.apache.http.NameValuePair)13 HttpEntity (org.apache.http.HttpEntity)10 NotNull (org.jetbrains.annotations.NotNull)9 Map (java.util.Map)8 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)8 ArrayList (java.util.ArrayList)7 HashMap (java.util.HashMap)7 HttpResponse (org.apache.http.HttpResponse)7 List (java.util.List)6 HttpClient (org.apache.http.client.HttpClient)5 CloseableHttpClient (org.apache.http.impl.client.CloseableHttpClient)5 Gson (com.google.gson.Gson)4 URL (java.net.URL)4 RequestConfig (org.apache.http.client.config.RequestConfig)4 HttpPost (org.apache.http.client.methods.HttpPost)4