List of usage examples for org.apache.http.entity BasicHttpEntity setContentEncoding
public void setContentEncoding(Header header)
From source file:com.hackerati.android.user_sdk.volley.HHurlStack.java
/** * Initializes an {@link HttpEntity} from the given * {@link HttpURLConnection}.// www . ja v a 2 s . c o m * * @param connection * @return an HttpEntity populated with data from <code>connection</code>. */ private static HttpEntity entityFromConnection(final HttpURLConnection connection) { final BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream; try { inputStream = connection.getInputStream(); } catch (final IOException ioe) { inputStream = connection.getErrorStream(); } entity.setContent(inputStream); entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }
From source file:common.net.volley.toolbox.HurlStack.java
/** * Initializes an {@link org.apache.http.HttpEntity} from the given {@link java.net.HttpURLConnection}. * @param connection//from w w w . j a v a 2s. c om * @return an HttpEntity populated with data from <code>connection</code>. */ private static HttpEntity entityFromConnection(HttpURLConnection connection) throws IOException { BasicHttpEntity entity = new BasicHttpEntity(); ByteArrayOutputStream out = new ByteArrayOutputStream(); InputStream rawStream = null; try { rawStream = connection.getInputStream(); rawStream = stethoManager.interpretResponseStream(rawStream); InputStream decompressedStream = applyDecompressionIfApplicable(connection, rawStream); if (decompressedStream != null) { copy(decompressedStream, out, new byte[1024]); } entity.setContent(new ByteArrayInputStream(out.toByteArray())); } catch (IOException ioe) { rawStream = connection.getErrorStream(); entity.setContent(rawStream); } finally { // if(rawStream != null) { // rawStream.close(); // } } entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }
From source file:org.mobicents.slee.enabler.rest.client.RESTClientEnablerChildSbb.java
@Override public void execute(RESTClientEnablerRequest request) throws Exception { // validate request if (request == null) { throw new NullPointerException("request is null"); }//from w w w .ja va 2 s .c o m if (request.getType() == null) { throw new NullPointerException("request type is null"); } if (request.getUri() == null) { throw new NullPointerException("request uri is null"); } // create http request HttpUriRequest httpRequest = null; switch (request.getType()) { case DELETE: httpRequest = new HttpDelete(request.getUri()); break; case GET: httpRequest = new HttpGet(request.getUri()); break; case POST: httpRequest = new HttpPost(request.getUri()); break; case PUT: httpRequest = new HttpPut(request.getUri()); break; default: throw new IllegalArgumentException("unknown request type"); } // add headers, if any if (request.getHeaders() != null) { for (Header h : request.getHeaders()) { httpRequest.addHeader(h); } } // sign request using oauth, if needed if (request.getOAuthConsumer() != null) { request.getOAuthConsumer().sign(httpRequest); } // add content, if any if (request.getContent() != null) { if (!(httpRequest instanceof HttpEntityEnclosingRequest)) { throw new IllegalArgumentException("request includes content but type does not allows content"); } if (request.getContentType() == null) { throw new IllegalArgumentException("request includes content but no content type"); } BasicHttpEntity entity = new BasicHttpEntity(); entity.setContent(request.getContent()); if (request.getContentEncoding() != null) entity.setContentEncoding(request.getContentEncoding()); entity.setContentType(request.getContentType()); ((HttpEntityEnclosingRequest) httpRequest).setEntity(entity); } // get http client activity and attach to related aci HttpClientActivity activity = httpProvider.createHttpClientActivity(true, null); ActivityContextInterface aci = httpClientActivityContextInterfaceFactory .getActivityContextInterface(activity); aci.attach(this.sbbContext.getSbbLocalObject()); // execute request on the activity activity.execute(httpRequest, request); }
From source file:com.gistlabs.mechanize.PageRequest.java
public HttpResponse consume(final HttpClient client, final HttpRequestBase request) throws Exception { if (!wasExecuted) { this.client = client; this.request = request; if (!request.getMethod().equalsIgnoreCase(httpMethod)) throw new IllegalArgumentException( String.format("Expected %s, but was %s", httpMethod, request.getMethod())); if (request.getURI().toString().equals(uri)) { HttpResponse response = new BasicHttpResponse(new ProtocolVersion("HTTP", 1, 1), 200, "OK"); BasicHttpEntity entity = new BasicHttpEntity(); if (contentLocation != null) response.addHeader(new BasicHeader("Content-Location", contentLocation)); entity.setContentEncoding(charset); entity.setContentType(this.contentType); entity.setContent(this.body); response.setEntity(new BufferedHttpEntity(entity)); assertParameters(request);/*from w w w . j a v a 2s . c om*/ assertHeaders(request); this.wasExecuted = true; return response; } else { assertEquals("URI of the next PageRequest does not match", uri, request.getURI().toString()); return null; } } else throw new UnsupportedOperationException("Request already executed"); }
From source file:com.overture.questdroid.utility.ExtHttpClientStack.java
private HttpEntity convertEntityNewToOld(HttpEntity ent) throws IllegalStateException, IOException { BasicHttpEntity ret = new BasicHttpEntity(); if (ent != null) { ret.setContent(ent.getContent()); ret.setContentLength(ent.getContentLength()); Header h;/*from w w w .j av a 2 s . co m*/ h = ent.getContentEncoding(); if (h != null) { ret.setContentEncoding(convertheaderNewToOld(h)); } h = ent.getContentType(); if (h != null) { ret.setContentType(convertheaderNewToOld(h)); } } return ret; }
From source file:carleton150.edu.carleton.carleton150.CertificateManagement.ExtHttpClientStack.java
private org.apache.http.HttpEntity convertEntityNewToOld(HttpEntity ent) throws IllegalStateException, IOException { BasicHttpEntity ret = new BasicHttpEntity(); if (ent != null) { ret.setContent(ent.getContent()); ret.setContentLength(ent.getContentLength()); Header h;//from w ww . jav a 2 s . c o m h = ent.getContentEncoding(); if (h != null) { ret.setContentEncoding(convertheaderNewToOld(h)); } h = ent.getContentType(); if (h != null) { ret.setContentType(convertheaderNewToOld(h)); } } return ret; }
From source file:dk.slott.super_volley.stacks.ExtHttpClientStack.java
private org.apache.http.HttpEntity convertEntityNewToOld(HttpEntity ent) throws IllegalStateException, IOException { final BasicHttpEntity ret = new BasicHttpEntity(); if (ent != null) { ret.setContent(ent.getContent()); ret.setContentLength(ent.getContentLength()); Header h;//from w w w . ja v a 2 s.c o m h = ent.getContentEncoding(); if (h != null) { ret.setContentEncoding(convertheaderNewToOld(h)); } h = ent.getContentType(); if (h != null) { ret.setContentType(convertheaderNewToOld(h)); } } return ret; }
From source file:com.android.volley.toolbox.https.ExtHttpClientStack.java
private HttpEntity convertEntityNewToOld(HttpEntity ent) throws IllegalStateException, IOException { BasicHttpEntity ret = new BasicHttpEntity(); if (ent != null) { ret.setContent(ent.getContent()); ret.setContentLength(ent.getContentLength()); Header h;/*from w ww.j ava 2s . co m*/ h = (Header) ent.getContentEncoding(); if (h != null) { ret.setContentEncoding(convertheaderNewToOld(h)); } h = ent.getContentType(); if (h != null) { ret.setContentType(convertheaderNewToOld(h)); } } return ret; }
From source file:com.baasbox.android.HttpUrlConnectionClient.java
private HttpEntity asEntity(HttpURLConnection connection) { BasicHttpEntity entity = new BasicHttpEntity(); InputStream in;// w ww. j av a 2 s .c om try { in = connection.getInputStream(); } catch (IOException e) { in = connection.getErrorStream(); } entity.setContent(in); entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }
From source file:com.example.chengcheng.network.httpstacks.HttpUrlConnStack.java
/** * HTTP????,??//w w w .j ava 2s.c o m * @param connection * @return HttpEntity */ private HttpEntity entityFromURLConnwction(HttpURLConnection connection) { BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream = null; try { inputStream = connection.getInputStream(); } catch (IOException e) { e.printStackTrace(); inputStream = connection.getErrorStream(); } // TODO : GZIP entity.setContent(inputStream); entity.setContentLength(connection.getContentLength()); entity.setContentEncoding(connection.getContentEncoding()); entity.setContentType(connection.getContentType()); return entity; }