當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。