List of usage examples for org.apache.http.entity ByteArrayEntity setContentType
public void setContentType(Header header)
From source file:com.subgraph.vega.internal.model.requests.LazyEntityLoader.java
private HttpEntity createEntityCopy(RequestLogEntity entity) { final ByteArrayEntity copy = new ByteArrayEntity(entity.getContentArray()); copy.setContentType(entity.getContentType()); copy.setContentEncoding(copy.getContentEncoding()); return copy;/* www . j av a 2 s . c om*/ }
From source file:com.github.restdriver.serverdriver.http.ByteArrayRequestBody.java
@Override public void applyTo(ServerDriverHttpUriRequest request) { HttpUriRequest internalRequest = request.getHttpUriRequest(); if (!(internalRequest instanceof HttpEntityEnclosingRequest)) { return;/* w ww. jav a 2s .c om*/ } HttpEntityEnclosingRequest entityRequest = (HttpEntityEnclosingRequest) internalRequest; entityRequest.setHeader("Content-type", contentType); ByteArrayEntity entity = new ByteArrayEntity(content); entity.setContentType(contentType); entityRequest.setEntity(entity); }
From source file:com.nominanuda.web.http.FormEncodingUtf8Test.java
private String g1(byte[] v, String ct) throws IOException { byte[] x = new byte[2 + v.length]; x[0] = 'f';//from ww w. j a v a2 s .c o m x[1] = '='; System.arraycopy(v, 0, x, 2, v.length); ByteArrayEntity se = new ByteArrayEntity(x); if (ct != null) { se.setContentType(ct); } List<NameValuePair> pairs = h.parseEntityWithDefaultUtf8(se); String vv = pairs.get(0).getValue(); return vv; }
From source file:ee.ioc.phon.netspeechapi.Recognizer.java
private String postByteArray(byte[] bytes, String mime, int rate) throws ClientProtocolException, IOException { HttpPost post = new HttpPost(mWsUrl); setUserAgent(post);//from w w w . j a va 2 s. c o m ByteArrayEntity entity = new ByteArrayEntity(bytes); entity.setContentType(mime + "; rate=" + rate); post.setEntity(entity); return Utils.getResponseEntityAsString(post); }
From source file:com.subgraph.vega.ui.httpviewer.entity.HttpEntityBinaryViewer.java
private HttpEntity createEntity(byte[] content, String contentType, String contentEncoding) { final ByteArrayEntity entity = new ByteArrayEntity(content); if (contentType != null && !contentType.isEmpty()) { entity.setContentType(contentType); }/* ww w. jav a 2 s. com*/ if (contentEncoding != null && !contentEncoding.isEmpty()) { entity.setContentEncoding(contentEncoding); } return entity; }
From source file:org.apache.http.localserver.EchoHandler.java
/** * Handles a request by echoing the incoming request entity. * If there is no request entity, an empty document is returned. * * @param request the request// w w w . j ava 2 s. c o m * @param response the response * @param context the context * * @throws HttpException in case of a problem * @throws IOException in case of an IO problem */ public void handle(final HttpRequest request, final HttpResponse response, final HttpContext context) throws HttpException, IOException { String method = request.getRequestLine().getMethod().toUpperCase(Locale.ENGLISH); 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); } ByteArrayEntity bae = new ByteArrayEntity(data); if (entity != null) { bae.setContentType(entity.getContentType()); } entity = bae; response.setStatusCode(HttpStatus.SC_OK); response.setEntity(entity); }
From source file:com.subgraph.vega.internal.http.proxy.VegaHttpService.java
private void sendCertificateDownloadResponse(VegaHttpServerConnection connection, HttpContext context) throws HttpException, IOException { final String pem = sslContextRepository.getCaCertificatePem(); final byte[] body = EncodingUtils.getAsciiBytes(pem); ByteArrayEntity entity = new ByteArrayEntity(body); entity.setContentType("application/x-x509-ca-cert; charset=US-ASCII"); sendResponseOk(connection, context, entity); }
From source file:org.hydracache.server.httpd.handler.BaseHttpMethodHandler.java
protected ByteArrayEntity generateBinaryEntityForData(Data data) throws IOException { Buffer buffer = ProtocolUtils.encodeDataMessage(messageEncoder, data); ByteArrayEntity body = new ByteArrayEntity(buffer.toByteArray()); body.setContentType(BINARY_RESPONSE_CONTENT_TYPE); return body;//ww w. j a v a 2 s . c o m }
From source file:com.longle1.facedetection.TimedAsyncHttpResponseHandler.java
public void executePut(String putURL, RequestParams params, byte[] bb) { try {/* w w w . j a va2s . c om*/ AsyncHttpClient client = new AsyncHttpClient(); ByteArrayEntity bae = null; bae = new ByteArrayEntity(bb); bae.setContentType(new BasicHeader(HTTP.CONTENT_TYPE, "application/octet-stream")); // Add SSL KeyStore trustStore = KeyStore.getInstance(KeyStore.getDefaultType()); trustStore.load(mContext.getResources().openRawResource(R.raw.truststore), "changeit".toCharArray()); SSLSocketFactory sf = new SSLSocketFactory(trustStore); client.setSSLSocketFactory(sf); client.setTimeout(30000); client.put(null, putURL + "?" + params.toString(), bae, null, this); } catch (Exception e) { e.printStackTrace(); } Log.i("executePut", "done"); }