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


Java ContentType.TEXT_PLAIN属性代码示例

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


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

示例1: constructContentBody

ContentBody constructContentBody() throws UnsupportedEncodingException {

        ContentType contentTypeObject = constructContentTypeObject();

        if (filePath != null) { // FILE part
            if (contentTypeObject != null) {
                return new FileBody(new File(filePath), contentTypeObject);
            } else {
                return new FileBody(new File(filePath));
            }
        } else if (content != null) { // TEXT part
            if (contentTypeObject != null) {
                return new StringBody(content, contentTypeObject);
            } else {
                return new StringBody(content, ContentType.TEXT_PLAIN);
            }
        } else { // BYTE ARRAY part
            if (contentTypeObject != null) {
                return new ByteArrayBody(this.fileBytes, contentTypeObject, fileName);
            } else {
                return new ByteArrayBody(this.fileBytes, fileName);
            }
        }
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:24,代码来源:HttpBodyPart.java

示例2: attachFileToTransaction

/**
 * Retorna a lista de anexos de uma transação com ou sem filtro de tipo
 * @param idTransacao: Código da transação à ser consultada
 * @param arquivo: Arquivo à ser anexado (imagem [JPEG/PNG] ou documento [PDF])
 * @param tipoAnexo: Tipo de anexo à ser enviado
 * @return boolean
 */
public boolean attachFileToTransaction(String idTransacao, File arquivo, TipoAnexo tipoAnexo) throws IOException,
        PJBankException {
    Set<String> extensoesPermitidas = new HashSet<>();
    extensoesPermitidas.add("pdf");
    extensoesPermitidas.add("jpg");
    extensoesPermitidas.add("jpeg");
    extensoesPermitidas.add("png");

    if (!extensoesPermitidas.contains(FilenameUtils.getExtension(arquivo.getName()))) {
        throw new IllegalArgumentException("O arquivo a ser anexado em uma transação deve estar no formato PDF, JPG," +
                " JPEG ou PNG, sendo assim um documento ou uma imagem.");
    }

    PJBankClient client = new PJBankClient(this.endPoint.concat("/transacoes/").concat(idTransacao).concat("/documentos"));
    HttpPost httpPost = client.getHttpPostClient();
    httpPost.addHeader("x-chave-conta", this.chave);

    MultipartEntityBuilder builder = MultipartEntityBuilder.create();

    //FileBody fileBody = new FileBody(arquivo);
    StringBody stringBody = new StringBody(tipoAnexo.getName(), ContentType.TEXT_PLAIN);
    //builder.addPart("arquivos", fileBody);
    builder.addBinaryBody("arquivos", arquivo,
            ContentType.APPLICATION_OCTET_STREAM, arquivo.getName());
    builder.addPart("tipo", stringBody);

    httpPost.setEntity(builder.build());

    return client.doRequest(httpPost).getStatusLine().getStatusCode() == 201;
}
 
开发者ID:pjbank,项目名称:pjbank-java-sdk,代码行数:37,代码来源:ContaDigitalManager.java

示例3: testWrapExceptionToPreserveStatus

public void testWrapExceptionToPreserveStatus() throws IOException {
    Exception cause = new Exception();

    // Successfully get the status without a body
    RestStatus status = randomFrom(RestStatus.values());
    ElasticsearchStatusException wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), null, cause);
    assertEquals(status, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("No error body.", wrapped.getMessage());

    // Successfully get the status without a body
    HttpEntity okEntity = new StringEntity("test body", ContentType.TEXT_PLAIN);
    wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), okEntity, cause);
    assertEquals(status, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("body=test body", wrapped.getMessage());

    // Successfully get the status with a broken body
    IOException badEntityException = new IOException();
    HttpEntity badEntity = mock(HttpEntity.class);
    when(badEntity.getContent()).thenThrow(badEntityException);
    wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(status.getStatus(), badEntity, cause);
    assertEquals(status, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("Failed to extract body.", wrapped.getMessage());
    assertEquals(badEntityException, wrapped.getSuppressed()[0]);

    // Fail to get the status without a body
    int notAnHttpStatus = -1;
    assertNull(RestStatus.fromCode(notAnHttpStatus));
    wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(notAnHttpStatus, null, cause);
    assertEquals(RestStatus.INTERNAL_SERVER_ERROR, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("Couldn't extract status [" + notAnHttpStatus + "]. No error body.", wrapped.getMessage());

    // Fail to get the status without a body
    wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(notAnHttpStatus, okEntity, cause);
    assertEquals(RestStatus.INTERNAL_SERVER_ERROR, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("Couldn't extract status [" + notAnHttpStatus + "]. body=test body", wrapped.getMessage());

    // Fail to get the status with a broken body
    wrapped = RemoteScrollableHitSource.wrapExceptionToPreserveStatus(notAnHttpStatus, badEntity, cause);
    assertEquals(RestStatus.INTERNAL_SERVER_ERROR, wrapped.status());
    assertEquals(cause, wrapped.getCause());
    assertEquals("Couldn't extract status [" + notAnHttpStatus + "]. Failed to extract body.", wrapped.getMessage());
    assertEquals(badEntityException, wrapped.getSuppressed()[0]);
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:48,代码来源:RemoteScrollableHitSourceTests.java


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