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


Java ResponseEntity.getStatusCode方法代码示例

本文整理汇总了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;
    }
}
 
开发者ID:HewlettPackard,项目名称:loom,代码行数:29,代码来源:BaseApi.java

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


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

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

示例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());
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:40,代码来源:RestAuthenticationHandler.java

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

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

示例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);
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:25,代码来源:UgcService.java

示例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;
}
 
开发者ID:avdyk,项目名称:be.liege.cti.ged,代码行数:24,代码来源:AlfredServiceImpl.java

示例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;
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:19,代码来源:UgcService.java

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

示例11: 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

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

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

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

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


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