protected HttpEntity createEntity(String ct, byte[] byteArray) { final ByteArrayEntity byteArrayEntity = new ByteArrayEntity(byteArray); byteArrayEntity.setContentType(ct); return byteArrayEntity; }
public HttpEntity getEntity() { return new ByteArrayEntity(body); } }
import java.nio.charset.Charset; import org.apache.http.entity.ContentType; ContentType contentType = ContentType.getOrDefault(entity); Charset charSet = contentType.getCharset();
/** * Add payload to request. By default, payload is sent as application/json */ protected int addPayload(RequestBuilder builder, String payload) { if (payload == null || payload.length() == 0) { return 0; } builder.setHeader(HttpHeaders.CONTENT_TYPE, contentType.getMimeType()); builder.setEntity(new StringEntity(payload, contentType)); return payload.length(); }
private void setEntityIfGiven(HttpEntityEnclosingRequestBase request, Object entity) { if (entity != null) { if (entity instanceof File) { request.setEntity(new FileEntity((File) entity)); } else { request.setEntity(new StringEntity((String) entity, Charset.defaultCharset())); } } }
private CloseableHttpResponse execute(HttpEntityEnclosingRequestBase requestBase, Object entity) throws IOException { requestBase.setEntity(new StringEntity(gson.toJson(entity), ContentType.APPLICATION_JSON)); return execute(requestBase); }
private HttpEntity createEntity(final ByteBuf content, final long contentLength) { return new InputStreamEntity(new ByteBufInputStream(content), contentLength); }
@Override protected InputStream getStreamFromNetwork(String imageUri, Object extra) throws IOException { HttpGet httpRequest = new HttpGet(imageUri); HttpResponse response = httpClient.execute(httpRequest); HttpEntity entity = response.getEntity(); BufferedHttpEntity bufHttpEntity = new BufferedHttpEntity(entity); return bufHttpEntity.getContent(); } }
public IgnitedHttpResponseImpl(HttpResponse response) throws IOException { this.response = response; HttpEntity temp = response.getEntity(); if (temp != null) { entity = new BufferedHttpEntity(temp); } }
/** * Returns true if the underlying InputStream supports marking/reseting or * if the underlying InputStreamRequestEntity is repeatable (i.e. its * content length has been set to * {@link InputStreamRequestEntity#CONTENT_LENGTH_AUTO} and therefore its * entire contents will be buffered in memory and can be repeated). * * @see org.apache.commons.httpclient.methods.RequestEntity#isRepeatable() */ @Override public boolean isRepeatable() { return content.markSupported() || inputStreamRequestEntity.isRepeatable(); }
@Override public void writeTo(final OutputStream outstream) throws IOException { super.writeTo(outstream); consumeContent(); }
public FileEntity(final File file, final String contentType) { super(); if (file == null) { throw new IllegalArgumentException("File may not be null"); } this.file = file; setContentType(contentType); }
public InputStream getContent() throws IOException, IllegalStateException { if (this.objSer == null) { createBytes(this.objRef); } return new ByteArrayInputStream(this.objSer); }
public void writeTo(final OutputStream outstream) throws IOException { if (outstream == null) { throw new IllegalArgumentException("Output stream may not be null"); } this.contentproducer.writeTo(outstream); }
/** * 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); }
@Override public void sendRequest() throws IOException { request.setEntity(new ByteArrayEntity(output.toByteArray())); this.response = httpClient.execute(request); }
public SerializableEntity(Serializable ser, boolean bufferize) throws IOException { super(); if (ser == null) { throw new IllegalArgumentException("Source object may not be null"); } if (bufferize) { createBytes(ser); } else { this.objRef = ser; } }
private RequestBuilder addFormParams(RequestBuilder requestBuilder, Request request) { if (request.getRequestBody() != null) { ByteArrayEntity entity = new ByteArrayEntity(request.getRequestBody().getBody()); entity.setContentType(request.getRequestBody().getContentType()); requestBuilder.setEntity(entity); } return requestBuilder; }
@Override public void sendRequest() throws IOException { request.setEntity(new ByteArrayEntity(output.toByteArray())); this.response = httpClient.execute(request); }
@Override protected ClientHttpResponse executeInternal(HttpHeaders headers, byte[] bufferedOutput) throws IOException { addHeaders(this.httpRequest, headers); if (this.httpRequest instanceof HttpEntityEnclosingRequest) { HttpEntityEnclosingRequest entityEnclosingRequest = (HttpEntityEnclosingRequest) this.httpRequest; HttpEntity requestEntity = new ByteArrayEntity(bufferedOutput); entityEnclosingRequest.setEntity(requestEntity); } HttpResponse httpResponse = this.httpClient.execute(this.httpRequest, this.httpContext); return new HttpComponentsClientHttpResponse(httpResponse); }