当前位置: 首页>>代码示例>>Java>>正文


Java CloseableHttpResponse.getStatusLine方法代码示例

本文整理汇总了Java中org.apache.http.client.methods.CloseableHttpResponse.getStatusLine方法的典型用法代码示例。如果您正苦于以下问题:Java CloseableHttpResponse.getStatusLine方法的具体用法?Java CloseableHttpResponse.getStatusLine怎么用?Java CloseableHttpResponse.getStatusLine使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.http.client.methods.CloseableHttpResponse的用法示例。


在下文中一共展示了CloseableHttpResponse.getStatusLine方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postAttempt

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
public static String postAttempt(int id) throws IOException {
  final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
  if (client == null || StudySettings.getInstance().getUser() == null) return "";
  final HttpPost attemptRequest = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.ATTEMPTS);
  String attemptRequestBody = new Gson().toJson(new StepicWrappers.AttemptWrapper(id));
  attemptRequest.setEntity(new StringEntity(attemptRequestBody, ContentType.APPLICATION_JSON));

  final CloseableHttpResponse attemptResponse = client.execute(attemptRequest);
  final HttpEntity responseEntity = attemptResponse.getEntity();
  final String attemptResponseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
  final StatusLine statusLine = attemptResponse.getStatusLine();
  EntityUtils.consume(responseEntity);
  if (statusLine.getStatusCode() != HttpStatus.SC_CREATED) {
    LOG.warn("Failed to make attempt " + attemptResponseString);
    return "";
  }
  return attemptResponseString;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:19,代码来源:EduStepicConnector.java

示例2: postSubmission

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private static void postSubmission(boolean passed, StepicWrappers.AttemptWrapper.Attempt attempt,
                                   ArrayList<StepicWrappers.SolutionFile> files) throws IOException {
  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.SUBMISSIONS);

  String requestBody = new Gson().toJson(new StepicWrappers.SubmissionWrapper(attempt.id, passed ? "1" : "0", files));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));
  final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
  if (client == null) return;
  final CloseableHttpResponse response = client.execute(request);
  final HttpEntity responseEntity = response.getEntity();
  final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
  final StatusLine line = response.getStatusLine();
  EntityUtils.consume(responseEntity);
  if (line.getStatusCode() != HttpStatus.SC_CREATED) {
    LOG.error("Failed to make submission " + responseString);
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:18,代码来源:EduStepicConnector.java

示例3: extractFromResponse

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private RestHeartClientResponse extractFromResponse(final CloseableHttpResponse httpResponse) {
    RestHeartClientResponse response = null;
    JsonObject responseObj = null;
    if (httpResponse != null) {
        StatusLine statusLine = httpResponse.getStatusLine();
        Header[] allHeaders = httpResponse.getAllHeaders();
        HttpEntity resEntity = httpResponse.getEntity();
        if (resEntity != null) {
            try {
                String responseStr = IOUtils.toString(resEntity.getContent(), "UTF-8");
                if (responseStr != null && !responseStr.isEmpty()) {
                    JsonParser parser = new JsonParser();
                    responseObj = parser.parse(responseStr).getAsJsonObject();
                }
            } catch (IOException e) {
                LOGGER.log(Level.SEVERE, "Was unable to extract response body", e);
            }
        }

        response = new RestHeartClientResponse(statusLine, allHeaders, responseObj);
    }
    return response;
}
 
开发者ID:SoftGorilla,项目名称:restheart-java-client,代码行数:24,代码来源:RestHeartClientApi.java

示例4: enrollToCourse

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
public static boolean enrollToCourse(final int courseId, @Nullable final StepicUser stepicUser) {
  if (stepicUser == null) return false;
  HttpPost post = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.ENROLLMENTS);
  try {
    final StepicWrappers.EnrollmentWrapper enrollment = new StepicWrappers.EnrollmentWrapper(String.valueOf(courseId));
    post.setEntity(new StringEntity(new GsonBuilder().create().toJson(enrollment)));
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient(stepicUser);
    CloseableHttpResponse response = client.execute(post);
    StatusLine line = response.getStatusLine();
    return line.getStatusCode() == HttpStatus.SC_CREATED;
  }
  catch (IOException e) {
    LOG.warn(e.getMessage());
  }
  return false;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:17,代码来源:EduStepicConnector.java

示例5: getFromStepic

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
static <T> T getFromStepic(String link, final Class<T> container, @NotNull final CloseableHttpClient client) throws IOException {
  if (!link.startsWith("/")) link = "/" + link;
  final HttpGet request = new HttpGet(EduStepicNames.STEPIC_API_URL + link);

  final CloseableHttpResponse response = client.execute(request);
  final StatusLine statusLine = response.getStatusLine();
  final HttpEntity responseEntity = response.getEntity();
  final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
  EntityUtils.consume(responseEntity);
  if (statusLine.getStatusCode() != HttpStatus.SC_OK) {
    throw new IOException("Stepic returned non 200 status code " + responseString);
  }
  return deserializeStepicResponse(container, responseString);
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:15,代码来源:EduStepicClient.java

示例6: getTokens

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
@Nullable
private static StepicWrappers.TokenInfo getTokens(@NotNull final List<NameValuePair> parameters) {
  final Gson gson = new GsonBuilder().setFieldNamingPolicy(FieldNamingPolicy.LOWER_CASE_WITH_UNDERSCORES).create();

  final HttpPost request = new HttpPost(EduStepicNames.TOKEN_URL);
  request.setEntity(new UrlEncodedFormEntity(parameters, Consts.UTF_8));

  try {
    final CloseableHttpClient client = EduStepicClient.getHttpClient();
    final CloseableHttpResponse response = client.execute(request);
    final StatusLine statusLine = response.getStatusLine();
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    EntityUtils.consume(responseEntity);
    if (statusLine.getStatusCode() == HttpStatus.SC_OK) {
      return gson.fromJson(responseString, StepicWrappers.TokenInfo.class);
    }
    else {
      LOG.warn("Failed to get tokens: " + statusLine.getStatusCode() + statusLine.getReasonPhrase());
    }
  }
  catch (IOException e) {
    LOG.warn(e.getMessage());
  }
  return null;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:27,代码来源:EduStepicAuthorizedClient.java

示例7: checkResponse

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private CloseableHttpResponse checkResponse(CloseableHttpResponse response) 
		throws HttpLayerException {
	LOG.debug(">> checkResponse(..): checking HTTP response for non-OK status codes & "
			+ "unexpected header values");
	StatusLine statusLine = response.getStatusLine();
	if ((statusLine.getStatusCode() >= 400) && (statusLine.getStatusCode() <= 499)) {
		throw new HttpLayerException(Errors.RESPONSE_HTTP_CLIENT_FAULT, statusLine.toString());
	}
	if ((statusLine.getStatusCode() == 500)) {
		return response;
	}
	if ((statusLine.getStatusCode() >= 501) && (statusLine.getStatusCode() <= 599)) {
		throw new HttpLayerException(Errors.RESPONSE_HTTP_SERVER_FAULT, statusLine.toString());
	}	
	return response;
}
 
开发者ID:Roxas240,项目名称:CryptoPayAPI,代码行数:17,代码来源:SimpleHttpClientImpl.java

示例8: load

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
@Override
public boolean load(BuildCacheKey key, BuildCacheEntryReader reader) throws BuildCacheException {
    final URI uri = root.resolve("./" + key.getHashCode());
    HttpGet httpGet = new HttpGet(uri);
    CloseableHttpResponse response = null;
    try {
        response = httpClient.execute(httpGet);
        StatusLine statusLine = response.getStatusLine();
        if (LOGGER.isDebugEnabled()) {
            LOGGER.debug("Response for GET {}: {}", safeUri(uri), statusLine);
        }
        int statusCode = statusLine.getStatusCode();
        if (statusCode >= 200 && statusCode < 300) {
            reader.readFrom(response.getEntity().getContent());
            return true;
        } else if (statusCode == 404) {
            return false;
        } else {
            // TODO: We should consider different status codes as fatal/recoverable
            throw new BuildCacheException(String.format("For key '%s', using %s response status %d: %s", key, getDescription(), statusCode, statusLine.getReasonPhrase()));
        }
    } catch (IOException e) {
        // TODO: We should consider different types of exceptions as fatal/recoverable.
        // Right now, everything is considered recoverable.
        throw new BuildCacheException(String.format("loading key '%s' from %s", key, getDescription()), e);
    } finally {
        HttpClientUtils.closeQuietly(response);
    }
}
 
开发者ID:lxxlxx888,项目名称:Reer,代码行数:30,代码来源:HttpBuildCache.java

示例9: checkServerRunning

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private void checkServerRunning() {

		try (CloseableHttpClient client = HttpClientBuilder.create().build()) {
			CloseableHttpResponse response = client.execute(new HttpGet(baseUrl + PING_PATH));
			if (response != null && response.getStatusLine() != null) {
				Assume.assumeThat(response.getStatusLine().getStatusCode(), Is.is(200));
			}
		} catch (IOException e) {
			throw new AssumptionViolatedException("SolrServer does not seem to be running", e);
		}
	}
 
开发者ID:Just-Fun,项目名称:spring-data-examples,代码行数:12,代码来源:RequiresSolrServer.java

示例10: postUnit

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
public static void postUnit(int lessonId, int position, int sectionId, Project project) {
  if (!checkIfAuthorized(project, "postTask")) return;

  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + EduStepicNames.UNITS);
  final StepicWrappers.UnitWrapper unitWrapper = new StepicWrappers.UnitWrapper();
  final StepicWrappers.Unit unit = new StepicWrappers.Unit();
  unit.setLesson(lessonId);
  unit.setPosition(position);
  unit.setSection(sectionId);
  unitWrapper.setUnit(unit);

  String requestBody = new Gson().toJson(unitWrapper);
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) return;
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_CREATED) {
      LOG.error(FAILED_TITLE + responseString);
      showErrorNotification(project, FAILED_TITLE, responseString);
    }
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:32,代码来源:CCStepicConnector.java

示例11: postLesson

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
public static int postLesson(@NotNull final Project project, @NotNull final Lesson lesson) {
  if (!checkIfAuthorized(project, "postLesson")) return -1;

  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + "/lessons");

  String requestBody = new Gson().toJson(new StepicWrappers.LessonWrapper(lesson));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) return -1;
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_CREATED) {
      final String message = FAILED_TITLE + "lesson ";
      LOG.error(message + responseString);
      showErrorNotification(project, message, responseString);
      return 0;
    }
    final Lesson postedLesson = new Gson().fromJson(responseString, RemoteCourse.class).getLessons(true).get(0);
    lesson.setId(postedLesson.getId());
    for (Task task : lesson.getTaskList()) {
      final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
      if (indicator != null) {
        indicator.checkCanceled();
      }
      postTask(project, task, postedLesson.getId());
    }
    return postedLesson.getId();
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
  return -1;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:39,代码来源:CCStepicConnector.java

示例12: sendSmsGetMethod

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
/**
 * This method is used to send SMS using Get method  
 * @param mobileNumber String
 * @param smsText  String
 * @param countryCode String
 * @return boolean
 */
public boolean sendSmsGetMethod(String mobileNumber, String smsText,
    String countryCode) {
  CloseableHttpClient httpClient = null;
  try {
    httpClient = HttpClients.createDefault();
    String path = null;
    if (validateSettings(mobileNumber, smsText)) {

      mobileNumber = removePlusFromMobileNumber(mobileNumber);

      logger.debug("Msg91SmsProvider - after removePlusFromMobileNumber "
          + mobileNumber);

      logger.debug("Inside GET");
      path =
          getCompletePath(baseUrl + getUrl, sender, smsRoute, mobileNumber,
              authKey, country, URLEncoder.encode(smsText, "UTF-8"));

      logger.debug("Msg91SmsProvider -Executing request - " + path);

      HttpGet httpGet = new HttpGet(path);

      CloseableHttpResponse response = httpClient.execute(httpGet);
      StatusLine sl = response.getStatusLine();
      response.close();
      if (sl.getStatusCode() != 200) {
        logger.error("SMS code for " + mobileNumber + " could not be sent: "
            + sl.getStatusCode() + " - " + sl.getReasonPhrase());
      }
      return sl.getStatusCode() == 200;

    } else {
      logger.debug("Msg91SmsProvider - Some mandatory parameters are empty!");
      return false;
    }
  } catch (IOException e) {
    logger.error(e);
    return false;
  } finally {
    closeHttpResource(httpClient);
  }
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:50,代码来源:Msg91SmsProvider.java

示例13: send

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
@Override
public boolean send(List<String> phoneNumber, String smsText) {

	logger.debug("[email protected] " + smsText + "  to mobileNumber ");
	logger.debug("[email protected] Provider parameters \n" + "Gateway - " + baseUrl + "\n" + "authKey - "
			+ authKey + "\n" + "sender - " + sender + "\n" + "country - " + country + "\n" + "smsMethodType - "
			+ smsMethodType + "\n" + "smsRoute - " + smsRoute + "\n");
	if (JsonUtil.isStringNullOREmpty(smsText)) {
		logger.debug("can't sent empty msg.");
		return false;
	}
	phoneNumber = validatePhoneList(phoneNumber);
	if (phoneNumber == null || phoneNumber.size() == 0) {
		logger.debug("can't sent msg with empty phone list.");
		return false;
	}
	CloseableHttpClient httpClient = null;
	try {
		httpClient = HttpClients.createDefault();

		String path = null;
		logger.debug("Inside POST");

		path = baseUrl + postUrl;
		logger.debug("Msg91SmsProvider -Executing request - " + path);

		HttpPost httpPost = new HttpPost(path);

		// add content-type headers
		httpPost.setHeader("content-type", "application/json");

		// add authkey header
		httpPost.setHeader("authkey", authKey);
		// create sms
		Sms sms = new Sms(URLEncoder.encode(smsText, "UTF-8"), phoneNumber);

		List<Sms> smsList = new ArrayList<>();
		smsList.add(sms);

		// create body
		ProviderDetails providerDetails = new ProviderDetails(sender, smsRoute, country, smsList);

		String providerDetailsString = JsonUtil.toJson(providerDetails);

		if (!JsonUtil.isStringNullOREmpty(providerDetailsString)) {
			logger.debug("Msg91SmsProvider - Body - " + providerDetailsString);

			HttpEntity entity = new ByteArrayEntity(providerDetailsString.getBytes("UTF-8"));
			httpPost.setEntity(entity);

			CloseableHttpResponse response = httpClient.execute(httpPost);
			StatusLine sl = response.getStatusLine();
			response.close();
			if (sl.getStatusCode() != 200) {
				logger.error("SMS code for " + phoneNumber + " could not be sent: " + sl.getStatusCode() + " - "
						+ sl.getReasonPhrase());
			}
			return sl.getStatusCode() == 200;
		} else {
			return false;
		}

	} catch (IOException e) {
		logger.error(e);
		return false;
	} finally {
		closeHttpResource(httpClient);
	}
}
 
开发者ID:project-sunbird,项目名称:sunbird-utils,代码行数:70,代码来源:Msg91SmsProvider.java

示例14: postCourse

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private static void postCourse(final Project project, @NotNull Course course) {
  if (!checkIfAuthorized(project, "post course")) return;

  final ProgressIndicator indicator = ProgressManager.getInstance().getProgressIndicator();
  if (indicator != null) {
    indicator.setText("Uploading course to " + EduStepicNames.STEPIC_URL);
    indicator.setIndeterminate(false);
  }
  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + "/courses");

  final StepicUser currentUser = EduStepicAuthorizedClient.getCurrentUser();
  if (currentUser != null) {
    final List<StepicUser> courseAuthors = course.getAuthors();
    for (int i = 0; i < courseAuthors.size(); i++) {
      if (courseAuthors.size() > i) {
        final StepicUser courseAuthor = courseAuthors.get(i);
        currentUser.setFirstName(courseAuthor.getFirstName());
        currentUser.setLastName(courseAuthor.getLastName());
      }
    }
    course.setAuthors(Collections.singletonList(currentUser));
  }

  String requestBody = new Gson().toJson(new StepicWrappers.CourseWrapper(course));
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) {
      LOG.warn("Http client is null");
      return;
    }
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_CREATED) {
      final String message = FAILED_TITLE + "course ";
      LOG.error(message + responseString);
      showErrorNotification(project, FAILED_TITLE, responseString);
      return;
    }
    final RemoteCourse postedCourse = new Gson().fromJson(responseString, StepicWrappers.CoursesContainer.class).courses.get(0);
    postedCourse.setLessons(course.getLessons(true));
    postedCourse.setAuthors(course.getAuthors());
    postedCourse.setCourseMode(CCUtils.COURSE_MODE);
    postedCourse.setLanguage(course.getLanguageID());
    final int sectionId = postModule(postedCourse.getId(), 1, String.valueOf(postedCourse.getName()), project);
    int position = 1;
    for (Lesson lesson : course.getLessons()) {
      if (indicator != null) {
        indicator.checkCanceled();
        indicator.setText2("Publishing lesson " + lesson.getIndex());
      }
      final int lessonId = postLesson(project, lesson);
      postUnit(lessonId, position, sectionId, project);
      if (indicator != null) {
        indicator.setFraction((double)lesson.getIndex()/course.getLessons().size());
        indicator.checkCanceled();
      }
      position += 1;
    }
    ApplicationManager.getApplication().runReadAction(() -> postAdditionalFiles(course, project, postedCourse.getId()));
    StudyTaskManager.getInstance(project).setCourse(postedCourse);
    showNotification(project, "Course published");
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:72,代码来源:CCStepicConnector.java

示例15: postModule

import org.apache.http.client.methods.CloseableHttpResponse; //导入方法依赖的package包/类
private static int postModule(int courseId, int position, @NotNull final String title, Project project) {
  final HttpPost request = new HttpPost(EduStepicNames.STEPIC_API_URL + "/sections");
  final StepicWrappers.Section section = new StepicWrappers.Section();
  section.setCourse(courseId);
  section.setTitle(title);
  section.setPosition(position);
  final StepicWrappers.SectionWrapper sectionContainer = new StepicWrappers.SectionWrapper();
  sectionContainer.setSection(section);
  String requestBody = new Gson().toJson(sectionContainer);
  request.setEntity(new StringEntity(requestBody, ContentType.APPLICATION_JSON));

  try {
    final CloseableHttpClient client = EduStepicAuthorizedClient.getHttpClient();
    if (client == null) return -1;
    final CloseableHttpResponse response = client.execute(request);
    final HttpEntity responseEntity = response.getEntity();
    final String responseString = responseEntity != null ? EntityUtils.toString(responseEntity) : "";
    final StatusLine line = response.getStatusLine();
    EntityUtils.consume(responseEntity);
    if (line.getStatusCode() != HttpStatus.SC_CREATED) {
      LOG.error(FAILED_TITLE + responseString);
      showErrorNotification(project, FAILED_TITLE, responseString);
      return -1;
    }
    final StepicWrappers.Section
      postedSection = new Gson().fromJson(responseString, StepicWrappers.SectionContainer.class).getSections().get(0);
    return postedSection.getId();
  }
  catch (IOException e) {
    LOG.error(e.getMessage());
  }
  return -1;
}
 
开发者ID:medvector,项目名称:educational-plugin,代码行数:34,代码来源:CCStepicConnector.java


注:本文中的org.apache.http.client.methods.CloseableHttpResponse.getStatusLine方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。