本文整理汇总了Java中org.springframework.http.ResponseEntity.getHeaders方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseEntity.getHeaders方法的具体用法?Java ResponseEntity.getHeaders怎么用?Java ResponseEntity.getHeaders使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.ResponseEntity
的用法示例。
在下文中一共展示了ResponseEntity.getHeaders方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: RestTemplateResponse
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public RestTemplateResponse(ResponseEntity<String> response) {
this.body = response.getBody();
this.status = response.getStatusCodeValue();
this.message = response.getStatusCode().getReasonPhrase();
this.headers = response.getHeaders();
}
示例2: executeGetRequestWithDelayPolicy
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
/**
* Enforces delay policy on HTTP calls as described here:
* https://github.com/reddit/reddit/wiki/API
*
* @param request : Reddit specific request
* @return Children JSONArray
*/
@Retryable(maxAttempts = 3, backoff = @Backoff(delay = 1000))
public JSONArray executeGetRequestWithDelayPolicy(RedditRequest request) {
if (delayInMs > 0) {
try {
Thread.sleep((long) delayInMs);
} catch (InterruptedException e) {
logger.warn("Interrupted Exception thrown while enforcing delay policy", e);
}
}
ResponseEntity<String> response = restTemplate.exchange(request.generateURI(), HttpMethod.GET, request.generateHttpHeaders(), String.class);
HttpHeaders headers = response.getHeaders();
double requestsRemaining = Double.valueOf(headers.get("X-Ratelimit-Remaining").get(0));
double timeRemaining = Double.valueOf(headers.get("X-Ratelimit-Reset").get(0));
calculateDelay(requestsRemaining, timeRemaining);
lastCall = System.currentTimeMillis();
return RedditAPIUtils.shortChildrenArray(new JSONObject(response.getBody()).getJSONObject("data"));
}
示例3: doRestExchange
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
RestResponse<Object> doRestExchange(RestExchangeProperties properties)
throws IOException, HttpStatusCodeException {
ResponseEntity<String> responseEntity = restTemplate.exchange(properties.getUrl(),
properties.getHttpMethod(), properties.getHttpEntity(),
new ParameterizedTypeReference<String>() {
}, properties.getUrlVariables());
ObjectMapper objectMapper = new ObjectMapper();
Object returnBody = null;
if (!StringHelper.isNullOrEmpty(responseEntity.getBody())) {
if (responseEntity.getBody().startsWith("[")) {
returnBody = objectMapper.readValue(responseEntity.getBody(),
objectMapper.getTypeFactory().constructCollectionType(List.class,
properties.getReturnType()));
} else {
returnBody = objectMapper.readValue(responseEntity.getBody(), properties.getReturnType());
}
}
RestResponse<Object> restResponse = new RestResponse<>(returnBody,
responseEntity.getHeaders(),
responseEntity.getStatusCode());
return restResponse;
}
示例4: invokeAPI
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
/**
* Invoke API by sending HTTP request with the given options.
*
* @param <T> the return type to use
* @param path The sub-path of the HTTP URL
* @param method The request method
* @param queryParams The query parameters
* @param body The request body object
* @param headerParams The header parameters
* @param formParams The form parameters
* @param accept The request's Accept header
* @param contentType The request's Content-Type header
* @param authNames The authentications to apply
* @param returnType The return type into which to deserialize the response
* @return The response body in chosen type
*/
public <T> T invokeAPI(String path, HttpMethod method, MultiValueMap<String, String> queryParams, Object body, HttpHeaders headerParams, MultiValueMap<String, Object> formParams, List<MediaType> accept, MediaType contentType, String[] authNames, ParameterizedTypeReference<T> returnType) throws RestClientException {
updateParamsForAuth(authNames, queryParams, headerParams);
final UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(basePath).path(path);
if (queryParams != null) {
builder.queryParams(queryParams);
}
final BodyBuilder requestBuilder = RequestEntity.method(method, builder.build().toUri());
if(accept != null) {
requestBuilder.accept(accept.toArray(new MediaType[accept.size()]));
}
if(contentType != null) {
requestBuilder.contentType(contentType);
}
addHeadersToRequest(headerParams, requestBuilder);
addHeadersToRequest(defaultHeaders, requestBuilder);
RequestEntity<Object> requestEntity = requestBuilder.body(selectBody(body, formParams, contentType));
ResponseEntity<T> responseEntity = restTemplate.exchange(requestEntity, returnType);
statusCode = responseEntity.getStatusCode();
responseHeaders = responseEntity.getHeaders();
if (responseEntity.getStatusCode() == HttpStatus.NO_CONTENT) {
return null;
} else if (responseEntity.getStatusCode().is2xxSuccessful()) {
if (returnType == null) {
return null;
}
return responseEntity.getBody();
} else {
// The error handler built into the RestTemplate should handle 400 and 500 series errors.
throw new RestClientException("API returned " + statusCode + " and it wasn't handled by the RestTemplate error handler");
}
}
示例5: WebhookRequestResponse
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public WebhookRequestResponse(HttpHeaders requestHeaders, Object requestBody, ResponseEntity<String> responseEntity) {
this.requestHeaders = requestHeaders;
this.requestBody = requestBody;
this.statusCode = responseEntity.getStatusCode().value();
this.responseHeaders = responseEntity.getHeaders();
this.responseBody = responseEntity.getBody();
}
示例6: startApplication
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public StartingInfo startApplication(String appName) {
CloudApplication app = getApplication(appName);
if (app.getState() != CloudApplication.AppState.STARTED) {
HashMap<String, Object> appRequest = new HashMap<String, Object>();
appRequest.put("state", CloudApplication.AppState.STARTED);
HttpEntity<Object> requestEntity = new HttpEntity<Object>(appRequest);
ResponseEntity<String> entity = getRestTemplate().exchange(getUrl("/v2/apps/{guid}?stage_async=true"), HttpMethod.PUT,
requestEntity, String.class, app.getMeta().getGuid());
HttpHeaders headers = entity.getHeaders();
// Return a starting info, even with a null staging log value, as a non-null starting info
// indicates that the response entity did have headers. The API contract is to return starting info
// if there are headers in the response, null otherwise.
if (headers != null && !headers.isEmpty()) {
String stagingFile = headers.getFirst("x-app-staging-log");
if (stagingFile != null) {
try {
stagingFile = URLDecoder.decode(stagingFile, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("unexpected inability to UTF-8 decode", e);
}
}
// Return the starting info even if decoding failed or staging file is null
return new StartingInfo(stagingFile);
}
}
return null;
}
示例7: process
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
/**
* Post-process Problem payload to add the message key for front-end if needed
*/
@Override
public ResponseEntity<Problem> process(@Nullable ResponseEntity<Problem> entity, NativeWebRequest request) {
if (entity == null || entity.getBody() == null) {
return entity;
}
Problem problem = entity.getBody();
if (!(problem instanceof ConstraintViolationProblem || problem instanceof DefaultProblem)) {
return entity;
}
ProblemBuilder builder = Problem.builder()
.withType(Problem.DEFAULT_TYPE.equals(problem.getType()) ? ErrorConstants.DEFAULT_TYPE : problem.getType())
.withStatus(problem.getStatus())
.withTitle(problem.getTitle())
.with("path", request.getNativeRequest(HttpServletRequest.class).getRequestURI());
if (problem instanceof ConstraintViolationProblem) {
builder
.with("violations", ((ConstraintViolationProblem) problem).getViolations())
.with("message", ErrorConstants.ERR_VALIDATION);
return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
} else {
builder
.withCause(((DefaultProblem) problem).getCause())
.withDetail(problem.getDetail())
.withInstance(problem.getInstance());
problem.getParameters().forEach(builder::with);
if (!problem.getParameters().containsKey("message") && problem.getStatus() != null) {
builder.with("message", "error.http." + problem.getStatus().getStatusCode());
}
return new ResponseEntity<>(builder.build(), entity.getHeaders(), entity.getStatusCode());
}
}
示例8: assertNoCaching
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public static void assertNoCaching(ResponseEntity<?> response) {
HttpHeaders hs = response.getHeaders();
String cache = joinAllHeadersFor(HttpHeaders.CACHE_CONTROL, response);
assertThat(cache, containsString("no-cache"));
assertThat(cache, containsString("no-store"));
assertThat(hs.getPragma(), containsString("no-cache"));
assertThat(hs.getFirst("Expires"), is("0"));
}
示例9: getContentType
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
private MediaType getContentType(ResponseEntity response) {
if (response.getBody() == null) {
return null;
}
if (response.getHeaders() == null || response.getHeaders().getContentType() == null) {
return contentType;
}
return response.getHeaders().getContentType();
}
示例10: returnValueHandle
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Around( "execution(org.springframework.http.ResponseEntity com.aidijing.*.controller.*Controller.*(..)) )" )
public Object returnValueHandle ( ProceedingJoinPoint joinPoint ) throws Throwable {
Object returnValue = joinPoint.proceed();
ResponseEntity responseEntity = ( ResponseEntity ) returnValue;
// 用户权限或者用户自定义处理
final RolePermissionResource currentRequestRolePermissionResource = ContextUtils.getCurrentRequestRolePermissionResource();
if ( Objects.isNull( currentRequestRolePermissionResource ) ) {
return returnValue;
}
if ( ResponseEntityPro.WILDCARD_ALL.equals( currentRequestRolePermissionResource.getResourceApiUriShowFields() ) ) {
ContextUtils.removeCurrentRequestRolePermissionResource();
return returnValue;
}
final String resourceApiUriShowFields = currentRequestRolePermissionResource.getResourceApiUriShowFields();
final String filterAfterJsonBody = toFilterJson( responseEntity.getBody() , resourceApiUriShowFields );
final Object filterAfterBody = jsonToType( filterAfterJsonBody , responseEntity.getBody().getClass() );
ContextUtils.removeCurrentRequestRolePermissionResource();
return new ResponseEntity<>( filterAfterBody ,
responseEntity.getHeaders() ,
responseEntity.getStatusCode() );
}
示例11: testPolicyEvaluationWithAdapters
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Test(dataProvider = "adapterStatusesAndResultingEffects")
public void testPolicyEvaluationWithAdapters(final boolean adapterActive, final Effect expectedEffect,
final boolean enableSleuthTracing) throws Exception {
String testPolicyName = this.policyHelper
.setTestPolicy(this.acsAdminRestTemplate, zoneHeader(), this.zoneFactory.getAcsBaseURL(),
"src/test/resources/policy-set-with-one-policy-using-resource-attributes-from-asset-adapter"
+ ".json");
try {
this.configureAttributeConnector(adapterActive);
PolicyEvaluationRequestV1 policyEvaluationRequest = this.policyHelper
.createEvalRequest("GET", "testSubject", TEST_PART_ID, null);
if (enableSleuthTracing) {
this.tracer.continueSpan(Span.builder().traceId(1L).spanId(2L).parent(3L).build());
}
ResponseEntity<PolicyEvaluationResult> policyEvaluationResponse = this.acsAdminRestTemplate
.postForEntity(this.zoneFactory.getAcsBaseURL() + PolicyHelper.ACS_POLICY_EVAL_API_PATH,
new HttpEntity<>(policyEvaluationRequest, zoneHeader()), PolicyEvaluationResult.class);
Assert.assertEquals(policyEvaluationResponse.getStatusCode(), HttpStatus.OK);
HttpHeaders responseHeaders = policyEvaluationResponse.getHeaders();
Assert.assertTrue(
responseHeaders.containsKey(Span.TRACE_ID_NAME) && StringUtils.isNotEmpty(Span.TRACE_ID_NAME));
if (enableSleuthTracing) {
Assert.assertEquals(Span.hexToId(responseHeaders.get(Span.TRACE_ID_NAME).get(0)), 1L);
}
PolicyEvaluationResult policyEvaluationResult = policyEvaluationResponse.getBody();
Assert.assertEquals(policyEvaluationResult.getEffect(), expectedEffect);
} finally {
this.policyHelper
.deletePolicySet(this.acsAdminRestTemplate, this.zoneFactory.getAcsBaseURL(), testPolicyName,
zoneHeader());
this.deconfigureAttributeConnector();
}
}
示例12: post
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
private <T> T post(final String url, final Object bodyObj, final java.lang.Class<T> tClass,
final Object... uriVariables) {
setErrorHandler();
StopWatch watch = new StopWatch();
watch.start();
// T object = restTemplate.postForObject(url, bodyObj, tClass, uriVariables);
ResponseEntity<T> response = restTemplate.postForEntity(url, bodyObj, tClass, uriVariables);
HttpHeaders headers = response.getHeaders();
List<String> cookies = headers.get("Set-Cookie");
if (cookies != null && cookies.size() > 0) {
for (String cookie : cookies) {
if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
if (sessionId.equals("")) {
sessionId = null;
}
break;
}
}
}
watch.stop();
if (log.isTraceEnabled()) {
// if (watch.getTime() > timeWarning) {
// bodyStr += " WARNING:";
// }
String args = "";
for (Object arg : uriVariables) {
args += " " + arg;
}
log.trace("POST " + url + " " + args + " " + bodyObj + " Operation took " + watch);
}
return response.getBody();
// return object;
}
示例13: get
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
private <T> T get(final String url, final java.lang.Class<T> tClass, final Object... uriVariables) {
setErrorHandler();
StopWatch watch = new StopWatch();
watch.start();
// T object = restTemplate.getForObject(url, tClass, uriVariables);
ResponseEntity<T> response = restTemplate.getForEntity(url, tClass, uriVariables);
HttpHeaders headers = response.getHeaders();
List<String> cookies = headers.get("Set-Cookie");
if (cookies != null && cookies.size() > 0) {
for (String cookie : cookies) {
if (cookie.substring(0, cookie.indexOf("=")).equals(LoomClient.SESSION_COOKIE)) {
sessionId = cookie.substring(cookie.indexOf("=") + 1, cookie.indexOf(";"));
if (sessionId.equals("")) {
sessionId = null;
}
break;
}
}
}
watch.stop();
if (log.isTraceEnabled()) {
String args = "";
for (Object arg : uriVariables) {
args += " " + arg;
}
if (watch.getTime() > timewarning) {
log.trace("GET " + url + " " + args + " WARNING: Operation took " + watch);
} else {
log.trace("GET " + url + " " + args + " Operation took " + watch);
}
}
return response.getBody();
// return object;
}
示例14: RestResponse
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public RestResponse(ResponseEntity<T> responseEntity) {
super(responseEntity.getBody(), responseEntity.getHeaders(), responseEntity.getStatusCode());
}
示例15: assertPlainText
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public static void assertPlainText(ResponseEntity<?> response) {
HttpHeaders hs = response.getHeaders();
MediaType expected = new MediaType("text", "plain",
StandardCharsets.UTF_8);
assertThat(hs.getContentType(), is(expected));
}