use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class GitlabRepository method fetchProjects.
/**
* Always forcibly attempts do fetch new projects from server.
*/
@NotNull
public List<GitlabProject> fetchProjects() throws Exception {
final ResponseHandler<List<GitlabProject>> handler = new GsonMultipleObjectsDeserializer<>(GSON, LIST_OF_PROJECTS_TYPE);
final String projectUrl = getRestApiUrl("projects");
final List<GitlabProject> result = new ArrayList<>();
int pageNum = 1;
while (true) {
final URI paginatedProjectsUrl = new URIBuilder(projectUrl).addParameter("page", String.valueOf(pageNum)).addParameter("per_page", "30").build();
final List<GitlabProject> page = getHttpClient().execute(new HttpGet(paginatedProjectsUrl), handler);
// Gitlab's REST API doesn't allow to know beforehand how many projects are available
if (page.isEmpty()) {
break;
}
result.addAll(page);
pageNum++;
}
myProjects = result;
return Collections.unmodifiableList(myProjects);
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class GitlabRepository method fetchIssues.
@NotNull
public List<GitlabIssue> fetchIssues(int pageNumber, int pageSize, boolean openedOnly) throws Exception {
ensureProjectsDiscovered();
final URIBuilder uriBuilder = new URIBuilder(getIssuesUrl()).addParameter("page", String.valueOf(pageNumber)).addParameter("per_page", String.valueOf(pageSize)).addParameter("order_by", "updated_at");
if (openedOnly) {
// Filtering by state was added in v7.3
uriBuilder.addParameter("state", "opened");
}
final ResponseHandler<List<GitlabIssue>> handler = new GsonMultipleObjectsDeserializer<>(GSON, LIST_OF_ISSUES_TYPE);
return getHttpClient().execute(new HttpGet(uriBuilder.build()), handler);
}
use of org.apache.http.client.utils.URIBuilder in project opennms by OpenNMS.
the class WebClient method connect.
@Override
public void connect(InetAddress address, int port, int timeout) throws IOException, Exception {
final URIBuilder ub = new URIBuilder();
ub.setScheme(m_schema);
ub.setHost(InetAddressUtils.str(address));
ub.setPort(port);
ub.setPath(m_path);
if (m_queryString != null && m_queryString.trim().length() > 0) {
final List<NameValuePair> params = URLEncodedUtils.parse(m_queryString, StandardCharsets.UTF_8);
if (!params.isEmpty()) {
ub.setParameters(params);
}
}
m_httpMethod = new HttpGet(ub.build());
m_httpMethod.setProtocolVersion(m_version);
m_httpClientWrapper = HttpClientWrapper.create();
if (m_overrideSSL) {
try {
m_httpClientWrapper.trustSelfSigned("https");
} catch (final Exception e) {
LOG.warn("Failed to create relaxed SSL client.", e);
}
}
if (m_userAgent != null && !m_userAgent.trim().isEmpty()) {
m_httpClientWrapper.setUserAgent(m_userAgent);
}
if (timeout > 0) {
m_httpClientWrapper.setConnectionTimeout(timeout);
m_httpClientWrapper.setSocketTimeout(timeout);
}
if (m_virtualHost != null && !m_virtualHost.trim().isEmpty()) {
m_httpClientWrapper.setVirtualHost(m_virtualHost);
}
if (m_userName != null && !m_userName.trim().isEmpty()) {
m_httpClientWrapper.addBasicCredentials(m_userName, m_password);
}
if (m_authPreemptive) {
m_httpClientWrapper.usePreemptiveAuth();
}
}
use of org.apache.http.client.utils.URIBuilder in project ats-framework by Axway.
the class HttpClient method constructURI.
private URI constructURI() throws HttpException {
// navigate to internal resource
StringBuilder uriBuilder = new StringBuilder(url);
if (resourcePath.size() > 0) {
if (!url.endsWith(IoUtils.FORWARD_SLASH)) {
uriBuilder.append(IoUtils.FORWARD_SLASH);
}
for (String token : resourcePath) {
uriBuilder.append(token);
uriBuilder.append(IoUtils.FORWARD_SLASH);
}
// remove the last slash if added resource path tokens
actualUrl = uriBuilder.substring(0, uriBuilder.length() - 1);
} else {
actualUrl = uriBuilder.toString();
}
try {
URIBuilder builder = new URIBuilder(actualUrl);
// add request parameters
for (Entry<String, List<String>> reqParam : requestParameters.entrySet()) {
for (String value : reqParam.getValue()) {
builder.setParameter(reqParam.getKey(), value);
}
}
return builder.build();
} catch (URISyntaxException e) {
throw new HttpException("Exception occurred when creating URL.", e);
}
}
use of org.apache.http.client.utils.URIBuilder in project intellij-community by JetBrains.
the class EduAdaptiveStepicConnector method getNextRecommendation.
@Nullable
public static Task getNextRecommendation(@NotNull Project project, @NotNull Course course) {
try {
final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
if (client == null) {
LOG.warn("Http client is null");
return null;
}
final URI uri = new URIBuilder(EduStepicNames.STEPIC_API_URL + EduStepicNames.RECOMMENDATIONS_URL).addParameter(EduNames.COURSE, String.valueOf(course.getId())).build();
final HttpGet request = new HttpGet(uri);
setTimeout(request);
final CloseableHttpResponse response = client.execute(request);
final HttpEntity responseEntity = response.getEntity();
final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
final int statusCode = response.getStatusLine().getStatusCode();
EntityUtils.consume(responseEntity);
if (statusCode == HttpStatus.SC_OK) {
final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();
final StepicWrappers.RecommendationWrapper recomWrapper = gson.fromJson(responseString, StepicWrappers.RecommendationWrapper.class);
if (recomWrapper.recommendations.length != 0) {
final StepicWrappers.Recommendation recommendation = recomWrapper.recommendations[0];
final String lessonId = recommendation.lesson;
final StepicWrappers.LessonContainer lessonContainer = EduStepicAuthorizedClient.getFromStepic(EduStepicNames.LESSONS + lessonId, StepicWrappers.LessonContainer.class);
if (lessonContainer != null && lessonContainer.lessons.size() == 1) {
final Lesson realLesson = lessonContainer.lessons.get(0);
course.getLessons().get(0).setId(Integer.parseInt(lessonId));
for (int stepId : realLesson.steps) {
final Task taskFromStep = getTask(project, realLesson.getName(), stepId);
if (taskFromStep != null)
return taskFromStep;
}
} else {
LOG.warn("Got unexpected number of lessons: " + (lessonContainer == null ? null : lessonContainer.lessons.size()));
}
} else {
LOG.warn("Got empty recommendation for the task: " + responseString);
}
} else {
throw new IOException("Stepic returned non 200 status code: " + responseString);
}
} catch (IOException e) {
LOG.warn(e.getMessage());
final String connectionMessages = "Connection problems, Please, try again";
final Balloon balloon = JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(connectionMessages, MessageType.ERROR, null).createBalloon();
ApplicationManager.getApplication().invokeLater(() -> {
if (StudyUtils.getSelectedEditor(project) != null) {
StudyUtils.showCheckPopUp(project, balloon);
}
});
} catch (URISyntaxException e) {
LOG.warn(e.getMessage());
}
return null;
}
Aggregations