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


Java HttpClientErrorException.getResponseBodyAsString方法代码示例

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


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

示例1: testErrorsSerializedAsJsonApi

import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
@Test
public void testErrorsSerializedAsJsonApi() throws IOException {
	RestTemplate testRestTemplate = new RestTemplate();
	try {
		testRestTemplate
				.getForEntity("http://localhost:" + this.port + "/doesNotExist", String.class);
		Assert.fail();
	}
	catch (HttpClientErrorException e) {
		assertEquals(HttpStatus.NOT_FOUND, e.getStatusCode());

		String body = e.getResponseBodyAsString();
		ObjectMapper mapper = new ObjectMapper();
		mapper.registerModule(JacksonModule.createJacksonModule());
		Document document = mapper.readerFor(Document.class).readValue(body);

		Assert.assertEquals(1, document.getErrors().size());
		ErrorData errorData = document.getErrors().get(0);
		Assert.assertEquals("404", errorData.getStatus());
		Assert.assertEquals("Not Found", errorData.getTitle());
		Assert.assertEquals("No message available", errorData.getDetail());
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:24,代码来源:BasicSpringBootTest.java

示例2: postRightHolder

import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
private void postRightHolder(String eppn) {
	String url = webUrl + "/rightholders";
	HttpHeaders headers = this.getAuthHeaders();			
	RightHolder rightHolder = this.computeEsupSgcRightHolder(eppn);
	HttpEntity entity = new HttpEntity(rightHolder, headers);
	log.debug("Try to post to CROUS RightHolder : " + rightHolder); 
	try {
		ResponseEntity<String> response = restTemplate.exchange(url, HttpMethod.POST, entity, String.class);
	} catch(HttpClientErrorException clientEx) {
		if(HttpStatus.LOCKED.equals(clientEx.getStatusCode())) {
			if("Account is closed".equals(getErrorMessage(clientEx.getResponseBodyAsString()))) {
				log.info("Account " + eppn + " is closed");
				return;
			} else {
				throw new CrousAccountLockException(clientEx.getResponseBodyAsString(), clientEx);
			}
		} else {
			throw clientEx;
		}
	}
	log.info(eppn + " sent in CROUS as RightHolder");	
}
 
开发者ID:EsupPortail,项目名称:esup-sgc,代码行数:23,代码来源:ApiCrousService.java

示例3: execute

import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
@Override
public RestTemplateResponse execute() throws IOException {
	HttpEntity<String> entityReq = new HttpEntity<>(requestBody, headers);
	try {
		ResponseEntity<String> response = template.exchange(url, HttpMethod.resolve(method.name()), entityReq, String.class);
		return new RestTemplateResponse(response);
	}
	catch (HttpClientErrorException e) {
		return new RestTemplateResponse(e.getRawStatusCode(), e.getStatusCode().getReasonPhrase(), e.getResponseBodyAsString
				(), e.getResponseHeaders());
	}
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:13,代码来源:RestTemplateRequest.java

示例4: assertExceptionResponseBody

import org.springframework.web.client.HttpClientErrorException; //导入方法依赖的package包/类
public void assertExceptionResponseBody(final HttpClientErrorException e, final String message) {
    String responseBody = e.getResponseBodyAsString();
    Assert.assertNotNull(responseBody);
    Assert.assertTrue(responseBody.contains(message),
            String.format("Expected=[%s], Actual=[%s]", message, responseBody));
}
 
开发者ID:eclipse,项目名称:keti,代码行数:7,代码来源:ACSTestUtil.java


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