List of usage examples for org.apache.http.entity BasicHttpEntity setContentEncoding
public void setContentEncoding(Header header)
From source file:org.restcomm.camelgateway.slee.CamelGatewaySbb.java
private void pushContent(HttpUriRequest request, String contentType, String contentEncoding, byte[] content) { // TODO: check other preconditions? if (contentType != null && content != null && request instanceof HttpEntityEnclosingRequest) { BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(new ByteArrayInputStream(content)); entity.setContentLength(content.length); entity.setChunked(false);/*w w w . j a va 2 s . com*/ if (contentEncoding != null) entity.setContentEncoding(contentEncoding); entity.setContentType(contentType); HttpEntityEnclosingRequest rr = (HttpEntityEnclosingRequest) request; rr.setEntity(entity); } }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testGetContentEncoding() throws Exception { String input = "0123456789"; BasicHttpEntity basic; CappedBufferHttpEntity replay;/*from www . j ava 2s . c om*/ basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.getContentEncoding(), nullValue()); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentEncoding("UTF-8"); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.getContentEncoding().getValue(), is("UTF-8")); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testGetContentEncoding() throws Exception { String input = "0123456789"; BasicHttpEntity basic; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentEncoding(), nullValue()); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentEncoding("UTF-8"); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentEncoding().getValue(), is("UTF-8")); }
From source file:org.mycard.net.network.AndroidHttpClientConnection.java
/*** * Return the next response entity.//from w ww. j ava 2s.co m * @param headers contains values for parsing entity * @see HttpClientConnection#receiveResponseEntity(HttpResponse response) */ public HttpEntity receiveResponseEntity(final Headers headers) { assertOpen(); BasicHttpEntity entity = new BasicHttpEntity(); long len = determineLength(headers); if (len == ContentLengthStrategy.CHUNKED) { entity.setChunked(true); entity.setContentLength(-1); entity.setContent(new ChunkedInputStream(inbuffer)); } else if (len == ContentLengthStrategy.IDENTITY) { entity.setChunked(false); entity.setContentLength(-1); entity.setContent(new IdentityInputStream(inbuffer)); } else { entity.setChunked(false); entity.setContentLength(len); entity.setContent(new ContentLengthInputStream(inbuffer, len)); } String contentTypeHeader = headers.getContentType(); if (contentTypeHeader != null) { entity.setContentType(contentTypeHeader); } String contentEncodingHeader = headers.getContentEncoding(); if (contentEncodingHeader != null) { entity.setContentEncoding(contentEncodingHeader); } return entity; }
From source file:org.jenkinsci.plugins.skytap.ConnectToVPNTunnelStep.java
private String connectVPNToConfiguration(String confId, String networkId, String vpnId) { // build url/*from www . j a va 2 s . c o m*/ String reqUrl = this.buildConnectRequestURL(confId, networkId, vpnId); // create request HttpPut hp = SkytapUtils.buildHttpPutRequest(reqUrl, this.authCredentials); // add content to request - vpn identifier BasicHttpEntity he = new BasicHttpEntity(); he.setContentEncoding("gzip"); he.setContentType("application/json"); // json string for connected attribute String jsonString = "{\"connected\" :true}"; InputStream stream; try { stream = new ByteArrayInputStream(jsonString.getBytes("UTF-8")); Integer len = jsonString.getBytes("UTF-8").length; long llen = len.longValue(); he.setContent(stream); he.setContentLength(llen); } catch (UnsupportedEncodingException e) { JenkinsLogger.error("Error encoding json string for connected attribute: " + e.getMessage()); } hp.setEntity(he); String response = ""; try { response = SkytapUtils.executeHttpRequest(hp); } catch (SkytapException e) { JenkinsLogger.error("Skytap Exception: " + e.getMessage()); } return response; }
From source file:org.jenkinsci.plugins.skytap.ConnectToVPNTunnelStep.java
private String attachVPNToConfiguration(String confId, String networkId, String vpnId) { // build url//from w ww . j av a 2 s. com String requestUrl = this.buildRequestURL(confId, networkId); // create request HttpPost hp = SkytapUtils.buildHttpPostRequest(requestUrl, this.authCredentials); // add content to request - vpn identifier BasicHttpEntity he = new BasicHttpEntity(); he.setContentEncoding("gzip"); he.setContentType("application/json"); // json string for vpn id String jsonString = "{\"id\":\"" + vpnId + "\"}"; InputStream stream; try { stream = new ByteArrayInputStream(jsonString.getBytes("UTF-8")); Integer len = jsonString.getBytes("UTF-8").length; long llen = len.longValue(); he.setContent(stream); he.setContentLength(llen); } catch (UnsupportedEncodingException e) { JenkinsLogger.error("Error encoding json string for vpn id: " + e.getMessage()); } hp.setEntity(he); JenkinsLogger.log("HTTP POST request: " + hp.toString()); // execute request String httpRespBody = ""; try { httpRespBody = SkytapUtils.executeHttpRequest(hp); } catch (SkytapException e) { JenkinsLogger.error("Skytap Exception: " + e.getMessage()); } // return response return httpRespBody; }