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


Java ResponseEntity.hasBody方法代码示例

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


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

示例1: findEmail

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public String findEmail(final String username) {
    final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlEmail())) {
        return null;
    }

    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(username));
    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<String> result = restTemplate.exchange(rest.getEndpointUrlEmail(), HttpMethod.GET, entity, String.class);

    if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
        return result.getBody();
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:RestPasswordManagementService.java

示例2: getSecurityQuestions

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public Map<String, String> getSecurityQuestions(final String username) {
    final PasswordManagementProperties.Rest rest = passwordManagementProperties.getRest();
    if (StringUtils.isBlank(rest.getEndpointUrlSecurityQuestions())) {
        return null;
    }
    final HttpHeaders headers = new HttpHeaders();
    headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON));
    headers.put("username", Arrays.asList(username));
    final HttpEntity<String> entity = new HttpEntity<>(headers);
    final ResponseEntity<Map> result = restTemplate.exchange(rest.getEndpointUrlSecurityQuestions(),
            HttpMethod.GET, entity, Map.class);

    if (result.getStatusCodeValue() == HttpStatus.OK.value() && result.hasBody()) {
        return result.getBody();
    }
    return null;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:19,代码来源:RestPasswordManagementService.java

示例3: doPost

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
// A. It must be a POST request.
protected void doPost(final HttpServletRequest httpRequest, final HttpServletResponse httpResponse) throws ServletException, IOException {
    byte[] serializedSpeechletRequest = IOUtils.toByteArray(httpRequest.getInputStream());

    try {
        if (this.checkAmazonSignature) {
            // B. It must come from the Amazon Alexa cloud.
            SpeechletRequestSignatureVerifier.checkRequestSignature(serializedSpeechletRequest,
                    httpRequest.getHeader(Sdk.SIGNATURE_REQUEST_HEADER),
                    httpRequest.getHeader(Sdk.SIGNATURE_CERTIFICATE_CHAIN_URL_REQUEST_HEADER));
        }

        final SpeechletRequestEnvelope<?> requestEnvelope = SpeechletRequestEnvelope.fromJson(serializedSpeechletRequest);

        for (SpeechletRequestEnvelopeVerifier verifier : this.requestEnvelopeVerifiers) {
            if (!verifier.verify(requestEnvelope)) {
                throw new SpeechletRequestHandlerException(this.createExceptionMessage(verifier, requestEnvelope));
            }
        }

        HttpEntity<byte[]> requestEntity = new HttpEntity<>(serializedSpeechletRequest);
        ResponseEntity<SpeechletResponseEnvelope> speechletResponse = this.restTemplate.postForEntity(
                this.endpoint, requestEntity, SpeechletResponseEnvelope.class);
        if (speechletResponse.getStatusCode().is2xxSuccessful() && speechletResponse.hasBody()) {
            byte[] outputBytes = speechletResponse.getBody().toJsonBytes();
            httpResponse.setContentType("application/json");
            httpResponse.setStatus(speechletResponse.getStatusCodeValue());
            httpResponse.setContentLength(outputBytes.length);
            httpResponse.getOutputStream().write(outputBytes);
        } else {
            // Should never happen, cause all edge cases are already covered by actual exceptions thrown.
            httpResponse.sendError(speechletResponse.getStatusCodeValue(), "Unexpected error in proxy");
        }
    } catch (Exception e) {
        int statusCode = HttpServletResponse.SC_INTERNAL_SERVER_ERROR;
        if (BAD_REQUEST_EXCEPTION_TYPES.contains(e.getClass())) {
            statusCode = HttpServletResponse.SC_BAD_REQUEST;
        }
        this.log.error("Exception occurred in doPost, returning status code {}", statusCode, e);
        httpResponse.sendError(statusCode, e.getClass().getSimpleName() + ": " + e.getMessage());
    }
}
 
开发者ID:ewjmulder,项目名称:alexa-proxy,代码行数:44,代码来源:AlexaProxyServlet.java

示例4: extract

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public String extract(Post post) {
    logger.info("Extracting " + post.getUrl());
    StringBuilder builder = new StringBuilder();

    String nextUrl = apiPrefix + post.getUrl();
    try {
        MercuryResponse response;
        do {
            ResponseEntity<MercuryResponse> exchange = restTemplate.exchange(nextUrl,
                HttpMethod.GET,
                entity,
                MercuryResponse.class);

            if (!exchange.hasBody()) {
                break;
            }

            response = exchange.getBody();

            if (response.getContent() != null) {
                builder.append(Jsoup.clean(response.getContent(), whitelist));
            }

            nextUrl = apiPrefix + response.getNextPageUrl();
        } while (response.getNextPageUrl() != null);

    } catch (RestClientException e) {
        logger.warn("Could not read from " + nextUrl, e);
    }

    String result = builder.toString();

    if (result.isEmpty()) {
        return post.getContentText() != null ? post.getContentText() : "";
    } else {
        return result;
    }
}
 
开发者ID:BakkerTom,项目名称:happy-news,代码行数:40,代码来源:ArticleExtractor.java

示例5: send

import org.springframework.http.ResponseEntity; //导入方法依赖的package包/类
@Override
public boolean send(final String from, final String to, final String message) {
    try {
        final MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        headers.add("Authorization", this.token);
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        headers.add("Accept", MediaType.APPLICATION_JSON_VALUE);

        final Map<String, Object> map = new HashMap<>();
        map.put("content", message);
        map.put("to", Arrays.asList(to));
        map.put("from", from);

        final StringWriter stringify = new StringWriter();
        mapper.writeValue(stringify, map);

        final HttpEntity<String> request = new HttpEntity<>(stringify.toString(), headers);
        final ResponseEntity<Map> response = restTemplate.postForEntity(new URI(this.serverUrl), request, Map.class);
        if (response.hasBody()) {
            final List<Map> messages = (List<Map>) response.getBody().get("messages");

            final String error = (String) response.getBody().get("error");
            if (StringUtils.isNotBlank(error)) {
                LOGGER.error(error);
                return false;
            }

            final List<String> errors = messages.stream()
                    .filter(m -> m.containsKey("accepted") && !Boolean.valueOf(m.get("accepted").toString()) && m.containsKey("error"))
                    .map(m -> (String) m.get("error"))
                    .collect(Collectors.toList());
            if (errors.isEmpty()) {
                return true;
            }
            errors.forEach(LOGGER::error);
        }
    } catch (final Exception e) {
        LOGGER.error(e.getMessage(), e);
    }
    return false;
}
 
开发者ID:mrluo735,项目名称:cas-5.1.0,代码行数:42,代码来源:ClickatellSmsSender.java


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