本文整理汇总了Java中org.springframework.http.ResponseEntity.getStatusCode方法的典型用法代码示例。如果您正苦于以下问题:Java ResponseEntity.getStatusCode方法的具体用法?Java ResponseEntity.getStatusCode怎么用?Java ResponseEntity.getStatusCode使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.springframework.http.ResponseEntity
的用法示例。
在下文中一共展示了ResponseEntity.getStatusCode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getResourcesFromGet
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
/**
* Get the resources for a given URL. It can throw a number of RuntimeExceptions (connection not
* found etc - which are all wrapped in a RestClientException).
*
* @param rt the RestTemplate to use
* @param targetURI the url to access
* @return the returns object or null if not found
*/
public R getResourcesFromGet(final RestTemplate rt, final URI targetURI) {
ResponseEntity<R> resp = rt.getForEntity(targetURI, getTypeClass());
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
this.processHeaders(targetURI, resp.getHeaders());
return resp.getBody();
} else {
return null;
}
} else {
return null;
}
}
示例2: 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() );
}
示例3: getResourcesFromGet
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
protected List<JsonProject> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonProjects> resp = rt.getForEntity(targetURI, JsonProjects.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getProjects();
} else {
throw new UpdaterHttpException(
"unable to collect projects - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect projects - HTTP response was null");
}
}
示例4: authenticateUsernamePasswordInternal
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
protected HandlerResult authenticateUsernamePasswordInternal(final UsernamePasswordCredential c, final String originalPassword)
throws GeneralSecurityException, PreventedException {
try {
final UsernamePasswordCredential creds = new UsernamePasswordCredential(c.getUsername(), c.getPassword());
final ResponseEntity<SimplePrincipal> authenticationResponse = api.authenticate(creds);
if (authenticationResponse.getStatusCode() == HttpStatus.OK) {
final SimplePrincipal principalFromRest = authenticationResponse.getBody();
if (principalFromRest == null || StringUtils.isBlank(principalFromRest.getId())) {
throw new FailedLoginException("Could not determine authentication response from rest endpoint for " + c.getUsername());
}
return createHandlerResult(c,
this.principalFactory.createPrincipal(principalFromRest.getId(), principalFromRest.getAttributes()),
new ArrayList<>());
}
} catch (final HttpClientErrorException e) {
if (e.getStatusCode() == HttpStatus.FORBIDDEN) {
throw new AccountDisabledException("Could not authenticate forbidden account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.UNAUTHORIZED) {
throw new FailedLoginException("Could not authenticate account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.NOT_FOUND) {
throw new AccountNotFoundException("Could not locate account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.LOCKED) {
throw new AccountLockedException("Could not authenticate locked account for " + c.getUsername());
}
if (e.getStatusCode() == HttpStatus.PRECONDITION_REQUIRED) {
throw new AccountExpiredException("Could not authenticate expired account for " + c.getUsername());
}
throw new FailedLoginException("Rest endpoint returned an unknown status code "
+ e.getStatusCode() + " for " + c.getUsername());
}
throw new FailedLoginException("Rest endpoint returned an unknown response for " + c.getUsername());
}
示例5: getResourcesFromGet
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
protected List<JsonRoleAssignment> getResourcesFromGet(final RestTemplate rt, final URI targetURI)
throws HttpStatusCodeException, UpdaterHttpException {
ResponseEntity<JsonRoleAssignments> resp = rt.getForEntity(targetURI, JsonRoleAssignments.class);
if (resp != null) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is not null: " + resp.getStatusCode());
}
if (resp.getStatusCode() == HttpStatus.OK) {
if (LOG.isDebugEnabled()) {
LOG.debug("response is OK");
}
return resp.getBody().getRoleAssignments();
} else {
throw new UpdaterHttpException(
"unable to collect roleAssigments - status code: " + resp.getStatusCode().toString());
}
} else {
throw new UpdaterHttpException("unable to collect roleAssignments - HTTP response was null");
}
}
示例6: fetch
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public String fetch(String slotName)
{
try
{
ResponseEntity<FetchResponse> responseEntity = this.restTemplate.getForEntity(baseUrl + "/api/buckets/{0}", FetchResponse.class, slotName);
if (!responseEntity.getStatusCode().is2xxSuccessful())
{
throw new RuntimeException("Fetch failed: " + responseEntity.getStatusCode());
}
return responseEntity.getBody().data;
}
catch (HttpClientErrorException ex)
{
if (ex.getStatusCode() == HttpStatus.NOT_FOUND)
{
return null;
}
else
{
throw new RuntimeException("Fetch failed: " + ex.getStatusCode());
}
}
}
示例7: getTeam
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Retryable(maxAttempts = 10, backoff = @Backoff(2000L))
@Cacheable("team")
public UgcTeam getTeam(Long id, Boolean withRoster) throws IOException {
Objects.requireNonNull(id, "ID must not be null");
Map<String, Object> vars = getVariablesMap();
vars.put("id", id);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(endpoints.get("teamPage"), String.class, vars);
log.trace("[TeamPage] {}", responseEntity);
if (responseEntity.getStatusCode().is4xxClientError() || responseEntity.getStatusCode().is5xxServerError()) {
throw new CustomParameterizedException("UGC API returned status " + responseEntity.getStatusCode());
}
JsonUgcResponse response = objectMapper.readValue(clean(responseEntity.getBody()), JsonUgcResponse.class);
List<Map<String, Object>> raw = convertTabularData(response);
if (!raw.isEmpty()) {
UgcTeam team = objectMapper.convertValue(raw.get(0), UgcTeam.class);
log.debug("Team {} ({}) retrieved", team.getClanName(), team.getClanId());
if (withRoster) {
team.setRoster(getRoster(id));
}
return team;
} else {
throw new CustomParameterizedException("Could not find a team with id: " + id);
}
}
示例8: pathSearchByName
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public AlfredPath pathSearchByName(String path) throws PathNotFoundException {
logger.debug("Search path: {}", path);
final ObjectNode body = JsonNodeFactory.instance.objectNode();
final ObjectNode query = JsonNodeFactory.instance.objectNode();
query.put("path", path);
body.putPOJO("query", query);
final ResponseEntity<ObjectNode> objectNodeResponseEntity =
restTemplate.postForEntity(url + AlfredConstants.SEARCH, body, ObjectNode.class);
final AlfredPath alfredPath;
if (objectNodeResponseEntity.getStatusCode().equals(HttpStatus.OK)) {
final ObjectNode bodyResponse = objectNodeResponseEntity.getBody();
final String nodeRef = bodyResponse.get("noderefs").get(0).asText();
alfredPath = ()
-> name
-> type
-> new AlfredDocumentBuilderWithTNameAndNameAndTypeImpl(nodeReferenceBuilder, url, restTemplate, nodeRef, name, type);
logger.debug("Found: {}", nodeRef);
} else {
throw new PathNotFoundException(path, objectNodeResponseEntity.getStatusCode());
}
return alfredPath;
}
示例9: getLegacyPlayer
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Retryable(maxAttempts = 10, backoff = @Backoff(2000L))
@Cacheable("legacyPlayer")
public UgcLegacyPlayer getLegacyPlayer(Long id) throws IOException {
Objects.requireNonNull(id, "ID must not be null");
Map<String, Object> vars = getVariablesMap();
vars.put("id64", id);
ResponseEntity<String> responseEntity = restTemplate.getForEntity(endpoints.get("teamPlayer"), String.class, vars);
log.trace("[Player] {}", responseEntity);
if (responseEntity.getStatusCode().is4xxClientError() || responseEntity.getStatusCode().is5xxServerError()) {
throw new CustomParameterizedException("UGC API returned status " + responseEntity.getStatusCode());
}
JsonUgcResponse response = objectMapper.readValue(responseEntity.getBody(), JsonUgcResponse.class);
UgcLegacyPlayer player = new UgcLegacyPlayer();
player.setId(id);
player.setTeams(objectMapper.convertValue(convertTabularData(response), new TypeReference<List<UgcLegacyPlayer.Membership>>() {
}));
return player;
}
示例10: 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());
}
}
示例11: RestResponse
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public RestResponse(ResponseEntity<T> responseEntity) {
super(responseEntity.getBody(), responseEntity.getHeaders(), responseEntity.getStatusCode());
}
示例12: validateDestination
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@PostMapping(value = "/{serviceInstanceId}/destinations/validate")
public ResponseEntity<HashMap> validateDestination(@PathVariable String serviceInstanceId, @RequestBody HashMap plan) throws ServiceInstanceDoesNotExistException {
ResponseEntity<HashMap> response = backupService.validateDestination(serviceInstanceId, plan);
return new ResponseEntity<>(response.getBody(), response.getStatusCode());
}
示例13: authenticate
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public boolean authenticate(final Credentials creds) {
boolean allowed = false;
try {
LOG.info("authenticate call: starting...");
RestTemplate rt = restManager.getRestTemplate("keystone-auth");
LOG.info("posting to " + keystoneTokenURI.toString());
ResponseEntity<String> resp =
rt.postForEntity(keystoneTokenURI, KeystoneUtils.getUnscopedAuth(creds), String.class);
if (resp != null) {
LOG.info("response is not null: " + resp.getStatusCode());
if (resp.getStatusCode() == HttpStatus.CREATED) {
LOG.info("response is CREATED");
String token = resp.getHeaders().getFirst("X-Subject-Token");
if (token != null) {
LOG.info("response contains header X-Subject-Token with value: " + token);
TokenManager.getInstance().setTokenHolder(creds.getUsername(), new TokenHolder(token));
allowed = true;
}
}
}
} catch (HttpClientErrorException ex) {
// LOG.error(ex);
// LOG.error("authentication refused for user: "+ creds.getUsername(),ex);
LOG.error("authentication refused for user: " + creds.getUsername() + " - " + ex.getMessage());
}
LOG.info("authenticate call: and we're done...");
return allowed;
}
示例14: publish
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
public void publish(String bucketName, String data)
{
ResponseEntity<PublishResponse> responseEntity = this.restTemplate.postForEntity(baseUrl + "/api/buckets",
new PublishRequest(bucketName, data),
PublishResponse.class);
if (!responseEntity.getStatusCode().is2xxSuccessful())
{
throw new RuntimeException("Publish failed: " + responseEntity.getStatusCode());
}
}
示例15: putDestinaton
import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@PatchMapping(value = "/{serviceInstanceId}/destinations/{destinationId}")
public ResponseEntity<HashMap> putDestinaton(@PathVariable String serviceInstanceId,
@PathVariable String destinationId,
@RequestBody HashMap plan) throws ServiceInstanceDoesNotExistException {
ResponseEntity<HashMap> response = backupService.updateDestination(serviceInstanceId, destinationId, plan);
return new ResponseEntity<>(response.getBody(), response.getStatusCode());
}