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


Java ResponseEntity.getHeaders方法代码示例

本文整理汇总了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();
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:7,代码来源:RestTemplateResponse.java

示例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"));
}
 
开发者ID:nicolasmanic,项目名称:JRockets,代码行数:28,代码来源:RedditAPIClient.java

示例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;
}
 
开发者ID:mental-party,项目名称:meparty,代码行数:28,代码来源:RestApiProxyInvocationHandler.java

示例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");
    }
}
 
开发者ID:jopache,项目名称:Settings,代码行数:55,代码来源:ApiClient.java

示例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();
}
 
开发者ID:zouzhirong,项目名称:configx,代码行数:8,代码来源:WebhookRequestResponse.java

示例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;
}
 
开发者ID:SAP,项目名称:cf-java-client-sap,代码行数:33,代码来源:CloudControllerClientImpl.java

示例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());
    }
}
 
开发者ID:torgcrm,项目名称:TorgCRM-Server,代码行数:36,代码来源:ExceptionTranslator.java

示例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"));
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:9,代码来源:Asserts.java

示例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();
}
 
开发者ID:tyro,项目名称:pact-spring-mvc,代码行数:12,代码来源:ReturnExpect.java

示例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() );


}
 
开发者ID:yujunhao8831,项目名称:spring-boot-start-current,代码行数:28,代码来源:ResponseEntityAspect.java

示例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();
    }
}
 
开发者ID:eclipse,项目名称:keti,代码行数:39,代码来源:PolicyEvaluationWithAttributeConnectorIT.java

示例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;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:38,代码来源:RestClient.java

示例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;
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:39,代码来源:RestClient.java

示例14: RestResponse

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public RestResponse(ResponseEntity<T> responseEntity) {
  super(responseEntity.getBody(), responseEntity.getHeaders(), responseEntity.getStatusCode());
}
 
开发者ID:mental-party,项目名称:meparty,代码行数:4,代码来源:RestResponse.java

示例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));
}
 
开发者ID:openmicroscopy,项目名称:omero-ms-queue,代码行数:7,代码来源:Asserts.java


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