本文整理汇总了Java中org.apache.http.entity.ByteArrayEntity类的典型用法代码示例。如果您正苦于以下问题:Java ByteArrayEntity类的具体用法?Java ByteArrayEntity怎么用?Java ByteArrayEntity使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
ByteArrayEntity类属于org.apache.http.entity包,在下文中一共展示了ByteArrayEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: send
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
public void send(List<Map<Object, Object>> events, AsyncSuccessCallback<ProducedEventsResult> onSuccess, AsyncFailCallback onFail, AsyncCancelledCallback onCancel) throws IOException, InterruptedException {
CloseableHttpAsyncClient httpClient = HttpAsyncClients.createDefault();
httpClient.start();
String url = String.format("%s/%s/bulk-produce", this.endpoint, this.topicId);
System.out.println(url);
HttpPost httpPost = new HttpPost(url);
httpPost.addHeader("Authorization", this.writeApiKey);
httpPost.addHeader("Content-type", this.format);
String jsonString = MAPPER.writeValueAsString(events);
HttpEntity entity = new ByteArrayEntity(jsonString.getBytes());
httpPost.setEntity(entity);
ResponseParser<ProducedEventsResult> parser = new BulkProduceEventsParser();
AsyncCallback cb = new AsyncCallback(httpClient, parser, MAPPER, onSuccess, onFail, onCancel);
httpClient.execute(httpPost, cb);
}
示例2: doPost
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例3: doPut
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* Put stream
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例4: executeOn
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
public String executeOn(String ip) throws IOException, SonosControllerException {
String uri = "http://" + ip + ":" + SOAP_PORT + this.endpoint;
HttpPost request = new HttpPost(uri);
request.setHeader("Content-Type", "text/xml");
request.setHeader("SOAPACTION", this.service + "#" + this.action);
String content = "<s:Envelope xmlns:s=\"http://schemas.xmlsoap.org/soap/envelope/\""
+ " s:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\"><s:Body>"
+ "<u:" + this.action + " xmlns:u=\"" + this.service + "\">"
+ this.getBody()
+ "</u:" + this.action + ">"
+ "</s:Body></s:Envelope>";
HttpEntity entity = new ByteArrayEntity(content.getBytes("UTF-8"));
request.setEntity(entity);
HttpResponse response = getHttpClient().execute(request);
String responseString = EntityUtils.toString(response.getEntity());
this.handleError(ip, responseString);
return responseString;
}
示例5: 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;
}
示例6: put
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
private Map put(String url, String data) throws IOException, HttpException {
Map<String,Object> map = null;
CredentialsProvider credentials = credentialsProvider();
CloseableHttpClient httpclient = HttpClients.custom()
.setDefaultCredentialsProvider(credentials)
.build();
try {
HttpPut httpPut = new HttpPut(url);
httpPut.setHeader("Accept", "application/json");
httpPut.setHeader("Content-Type", "application/json");
HttpEntity entity = new ByteArrayEntity(data.getBytes("utf-8"));
httpPut.setEntity(entity);
System.out.println("Executing request " + httpPut.getRequestLine());
CloseableHttpResponse response = httpclient.execute(httpPut);
try {
LOG.debug("----------------------------------------");
LOG.debug((String)response.getStatusLine().getReasonPhrase());
String responseBody = EntityUtils.toString(response.getEntity());
LOG.debug(responseBody);
Gson gson = new Gson();
map = new HashMap<String,Object>();
map = (Map<String,Object>) gson.fromJson(responseBody, map.getClass());
LOG.debug(responseBody);
} finally {
response.close();
}
} finally {
httpclient.close();
}
return map;
}
开发者ID:dellemc-symphony,项目名称:ticketing-service-paqx-parent-sample,代码行数:35,代码来源:TicketingIntegrationService.java
示例7: doPut
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* Put stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例8: 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);
}
示例9: makeRequest
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
HttpRequestBase makeRequest(final String method, final String path, final ByteArrayEntity data, final Header[] headers) {
HttpRequestBase request;
String uri = this.getAddress() + path;
switch (method) {
case "GET":
request = new HttpGet(uri);
break;
case "DELETE":
request = new HttpDelete(uri);
break;
case "PATCH":
request = new HttpPatch(uri);
((HttpPatch) request).setEntity(data);
break;
case "POST":
request = new HttpPost(uri);
((HttpPost) request).setEntity(data);
break;
default:
throw new IllegalArgumentException(String.format("%s is not a valid HTTP method", method));
}
request.setHeaders(headers);
return request;
}
示例10: queryPath
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
private QueryResponse queryPath(QueryRequest request) {
String path = String.format("/index/%s/query", request.getIndex().getName());
Internal.QueryRequest qr = request.toProtobuf();
ByteArrayEntity body = new ByteArrayEntity(qr.toByteArray());
try {
CloseableHttpResponse response = clientExecute("POST", path, body, protobufHeaders, "Error while posting query",
ReturnClientResponse.RAW_RESPONSE);
HttpEntity entity = response.getEntity();
if (entity != null) {
try (InputStream src = entity.getContent()) {
QueryResponse queryResponse = QueryResponse.fromProtobuf(src);
if (!queryResponse.isSuccess()) {
throw new PilosaException(queryResponse.getErrorMessage());
}
return queryResponse;
}
}
throw new PilosaException("Server returned empty response");
} catch (IOException ex) {
throw new PilosaException("Error while reading response", ex);
}
}
示例11: doPost
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* Post stream
*
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPost(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPost request = new HttpPost(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例12: doPut
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* Put stream
* @param host
* @param path
* @param method
* @param headers
* @param querys
* @param body
* @return
* @throws Exception
*/
public static HttpResponse doPut(String host, String path, String method,
Map<String, String> headers,
Map<String, String> querys,
byte[] body)
throws Exception {
HttpClient httpClient = wrapClient(host);
HttpPut request = new HttpPut(buildUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
request.addHeader(e.getKey(), e.getValue());
}
if (body != null) {
request.setEntity(new ByteArrayEntity(body));
}
return httpClient.execute(request);
}
示例13: httpPost
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* HTTP POST 字节数组
* @param host
* @param path
* @param connectTimeout
* @param headers
* @param querys
* @param bodys
* @param signHeaderPrefixList
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static Response httpPost(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, byte[] bodys, List<String> signHeaderPrefixList, String appKey, String appSecret)
throws Exception {
headers = initialBasicHeader(HttpMethod.POST, path, headers, querys, null, signHeaderPrefixList, appKey, appSecret);
HttpClient httpClient = wrapClient(host);
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout));
HttpPost post = new HttpPost(initUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
post.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue()));
}
if (bodys != null) {
post.setEntity(new ByteArrayEntity(bodys));
}
return convert(httpClient.execute(post));
}
示例14: httpPut
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
/**
* HTTP PUT字节数组
* @param host
* @param path
* @param connectTimeout
* @param headers
* @param querys
* @param bodys
* @param signHeaderPrefixList
* @param appKey
* @param appSecret
* @return
* @throws Exception
*/
public static Response httpPut(String host, String path, int connectTimeout, Map<String, String> headers, Map<String, String> querys, byte[] bodys, List<String> signHeaderPrefixList, String appKey, String appSecret)
throws Exception {
headers = initialBasicHeader(HttpMethod.PUT, path, headers, querys, null, signHeaderPrefixList, appKey, appSecret);
HttpClient httpClient = wrapClient(host);
httpClient.getParams().setParameter(CoreConnectionPNames.CONNECTION_TIMEOUT, getTimeout(connectTimeout));
HttpPut put = new HttpPut(initUrl(host, path, querys));
for (Map.Entry<String, String> e : headers.entrySet()) {
put.addHeader(e.getKey(), MessageDigestUtil.utf8ToIso88591(e.getValue()));
}
if (bodys != null) {
put.setEntity(new ByteArrayEntity(bodys));
}
return convert(httpClient.execute(put));
}
示例15: c
import org.apache.http.entity.ByteArrayEntity; //导入依赖的package包/类
private HttpUriRequest c() {
if (this.f != null) {
return this.f;
}
if (this.j == null) {
byte[] b = this.c.b();
CharSequence b2 = this.c.b(AsyncHttpClient.ENCODING_GZIP);
if (b != null) {
if (TextUtils.equals(b2, "true")) {
this.j = b.a(b);
} else {
this.j = new ByteArrayEntity(b);
}
this.j.setContentType(this.c.c());
}
}
HttpEntity httpEntity = this.j;
if (httpEntity != null) {
HttpUriRequest httpPost = new HttpPost(b());
httpPost.setEntity(httpEntity);
this.f = httpPost;
} else {
this.f = new HttpGet(b());
}
return this.f;
}