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


Java ByteArrayEntity.setContentType方法代码示例

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


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

示例1: buildEntity

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
/**
 * Build the HttpEntity to be sent to the Service as part of (POST) request. Creates a off-memory
 * {@link FileExposingFileEntity} or a regular in-memory {@link ByteArrayEntity} depending on if the request
 * OutputStream fit into memory when built by calling.
 *
 * @param request -
 * @return - the built HttpEntity
 * @throws IOException -
 */
protected HttpEntity buildEntity(final ClientInvocation request) throws IOException {
  HttpEntity entityToBuild = null;
  DeferredFileOutputStream memoryManagedOutStream = writeRequestBodyToOutputStream(request);

  if (memoryManagedOutStream.isInMemory()) {
    ByteArrayEntity entityToBuildByteArray =
        new ByteArrayEntity(memoryManagedOutStream.getData());
    entityToBuildByteArray.setContentType(
        new BasicHeader(HTTP.CONTENT_TYPE, request.getHeaders().getMediaType().toString()));
    entityToBuild = entityToBuildByteArray;
  } else {
    File requestBodyFile = memoryManagedOutStream.getFile();
    requestBodyFile.deleteOnExit();
    entityToBuild = new FileExposingFileEntity(
        memoryManagedOutStream.getFile(), request.getHeaders().getMediaType().toString());
  }

  return entityToBuild;
}
 
开发者ID:cerner,项目名称:beadledom,代码行数:29,代码来源:ApacheHttpClient4Dot3Engine.java

示例2: handleException

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
/**
 * Handles the given exception and generates an HTTP response to be sent
 * back to the client to inform about the exceptional condition encountered
 * in the course of the request processing.
 *
 * @param ex the exception.
 * @param response the HTTP response.
 */
protected void handleException(final HttpException ex, final HttpResponse response) {
    if (ex instanceof MethodNotSupportedException) {
        response.setStatusCode(HttpStatus.SC_NOT_IMPLEMENTED);
    } else if (ex instanceof UnsupportedHttpVersionException) {
        response.setStatusCode(HttpStatus.SC_HTTP_VERSION_NOT_SUPPORTED);
    } else if (ex instanceof ProtocolException) {
        response.setStatusCode(HttpStatus.SC_BAD_REQUEST);
    } else {
        response.setStatusCode(HttpStatus.SC_INTERNAL_SERVER_ERROR);
    }
    String message = ex.getMessage();
    if (message == null) {
        message = ex.toString();
    }
    byte[] msg = EncodingUtils.getAsciiBytes(message);
    ByteArrayEntity entity = new ByteArrayEntity(msg);
    entity.setContentType("text/plain; charset=US-ASCII");
    response.setEntity(entity);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:28,代码来源:HttpService.java

示例3: HttpRequestWrapper

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
public HttpRequestWrapper(HttpRequestBase originalRequest)
        throws IllegalStateException, IOException {
    this.originalRequest = originalRequest;
    HttpEntity entity = null;
    if (originalRequest instanceof HttpEntityEnclosingRequest
            && (entity = ((HttpEntityEnclosingRequest) originalRequest)
            .getEntity()) != null) {
        body = IOUtils.toByteArray(entity.getContent());
        this.contentType = entity.getContentType() == null ? "" : entity
                .getContentType().getValue();
        this.contentLength = String.valueOf(body.length);

        ByteArrayEntity newEntity = new ByteArrayEntity(body);
        newEntity.setContentType(entity.getContentType());
        ((HttpEntityEnclosingRequest) originalRequest).setEntity(newEntity);
    } else {
        body = new byte[0];
        contentType = "";
        contentLength = "";
    }
}
 
开发者ID:paymax,项目名称:paymax-server-sdk-java,代码行数:22,代码来源:HttpRequestWrapper.java

示例4: returnResponse

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
public HttpResponse returnResponse() throws IOException {
    assertNotConsumed();
    try {
        final HttpEntity entity = this.response.getEntity();
        if (entity != null) {
            final ByteArrayEntity byteArrayEntity = new ByteArrayEntity(
                    EntityUtils.toByteArray(entity));
            final ContentType contentType = ContentType.getOrDefault(entity);
            byteArrayEntity.setContentType(contentType.toString());
            this.response.setEntity(byteArrayEntity);
        }
        return this.response;
    } finally {
        this.consumed = true;
    }
}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:17,代码来源:Response.java

示例5: addEntity

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
private void addEntity ( HttpEntityEnclosingRequestBase req, String contentType, byte[] o )
{
	final ByteArrayEntity input = new ByteArrayEntity ( o );
	input.setContentType ( contentType );
	req.addHeader ( "Content-Type", contentType );
	req.setEntity ( input );
}
 
开发者ID:att,项目名称:dmaap-framework,代码行数:8,代码来源:HttpClient.java

示例6: handle

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
/**
 * Handles a request by echoing the incoming request entity.
 * If there is no request entity, an empty document is returned.
 *
 * @param request   the request
 * @param response  the response
 * @param context   the context
 *
 * @throws HttpException    in case of a problem
 * @throws IOException      in case of an IO problem
 */
@Override
public void handle(final HttpRequest request,
                   final HttpResponse response,
                   final HttpContext context)
    throws HttpException, IOException {

    final String method = request.getRequestLine().getMethod().toUpperCase(Locale.ROOT);
    if (!"GET".equals(method) &&
        !"POST".equals(method) &&
        !"PUT".equals(method)
        ) {
        throw new MethodNotSupportedException
            (method + " not supported by " + getClass().getName());
    }

    HttpEntity entity = null;
    if (request instanceof HttpEntityEnclosingRequest) {
        entity = ((HttpEntityEnclosingRequest)request).getEntity();
    }

    // For some reason, just putting the incoming entity into
    // the response will not work. We have to buffer the message.
    byte[] data;
    if (entity == null) {
        data = new byte [0];
    } else {
        data = EntityUtils.toByteArray(entity);
    }

    final ByteArrayEntity bae = new ByteArrayEntity(data);
    if (entity != null) {
        bae.setContentType(entity.getContentType());
    }
    entity = bae;

    response.setStatusCode(HttpStatus.SC_OK);
    response.setEntity(entity);

}
 
开发者ID:MyPureCloud,项目名称:purecloud-iot,代码行数:51,代码来源:EchoHandler.java

示例7: setRequestBody

import org.apache.http.entity.ByteArrayEntity; //导入方法依赖的package包/类
/**
 * Set the given serialized remote invocation as request body.
 * <p>The default implementation simply sets the serialized invocation as the
 * HttpPost's request body. This can be overridden, for example, to write a
 * specific encoding and to potentially set appropriate HTTP request headers.
 * @param config the HTTP invoker configuration that specifies the target service
 * @param httpPost the HttpPost to set the request body on
 * @param baos the ByteArrayOutputStream that contains the serialized
 * RemoteInvocation object
 * @throws java.io.IOException if thrown by I/O methods
 */
protected void setRequestBody(
		HttpInvokerClientConfiguration config, HttpPost httpPost, ByteArrayOutputStream baos)
		throws IOException {

	ByteArrayEntity entity = new ByteArrayEntity(baos.toByteArray());
	entity.setContentType(getContentType());
	httpPost.setEntity(entity);
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:20,代码来源:HttpComponentsHttpInvokerRequestExecutor.java


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