List of usage examples for org.apache.http.entity BasicHttpEntity setContentLength
public void setContentLength(long j)
From source file:ste.web.http.velocity.VelocityHandler.java
@Override public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException { String view = (String) context.getAttribute(ATTR_VIEW); if (view == null) { return;//from ww w .ja v a 2 s .c o m } view = getViewPath(request.getRequestLine().getUri(), view); ByteArrayOutputStream baos = new ByteArrayOutputStream(); Writer out = new OutputStreamWriter(baos); try { Template t = engine.getTemplate(view); t.merge(buildContext(request, (HttpSessionContext) context), out); out.flush(); } catch (ResourceNotFoundException e) { response.setStatusLine(HttpVersion.HTTP_1_1, HttpStatus.SC_NOT_FOUND, "View " + view + " not found."); return; } catch (ParseErrorException e) { throw new HttpException("Parse error evaluating " + view + ": " + e, e); } catch (MethodInvocationException e) { throw new HttpException("Method invocation error evaluating " + view + ": " + e, e); } BasicHttpEntity body = (BasicHttpEntity) response.getEntity(); body.setContentLength(baos.size()); body.setContent(new ByteArrayInputStream(baos.toByteArray())); if ((body.getContentType() == null) || StringUtils.isBlank(body.getContentType().getValue())) { body.setContentType(ContentType.TEXT_HTML.getMimeType()); } }
From source file:org.jenkinsci.plugins.relution_publisher.net.requests.ZeroCopyFileRequestProducer.java
@Override public HttpRequest generateRequest() throws IOException, HttpException { final BasicHttpEntity entity = new BasicHttpEntity(); entity.setContentLength(this.getContentLength()); entity.setContentType(this.getContentType()); entity.setChunked(false);//from w w w . j av a 2 s .c o m return this.createRequest(this.mRequest.getUri(), entity); }
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 www . ja v a2s .com 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 w w. java2 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.baasbox.android.net.OkClient.java
private HttpEntity asEntity(Response resp) { BasicHttpEntity entity = new BasicHttpEntity(); InputStream inputStream = resp.body().byteStream(); entity.setContent(inputStream);/*w ww .ja v a2s. c o m*/ entity.setContentLength(resp.body().contentLength()); String ctnt = resp.body().contentType().toString(); entity.setContentType(ctnt); return entity; }
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 . j ava 2 s .c om 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;/* www . j ava2 s. c o 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:org.zenoss.zep.rest.RestClient.java
private HttpEntity createProtobufEntity(Message msg) { BasicHttpEntity entity = new BasicHttpEntity(); entity.setContentType(ProtobufConstants.CONTENT_TYPE_PROTOBUF); entity.setContentLength(msg.getSerializedSize()); entity.setContent(new ByteArrayInputStream(msg.toByteArray())); return entity; }
From source file:cn.geowind.takeout.verify.JsonRestApi.java
public String sendCall(String accountSid, String authToken, String appId, String to, String verifyCode) throws KeyManagementException, NoSuchAlgorithmException { String result = ""; CcopHttpClient chc = new CcopHttpClient(); DefaultHttpClient httpclient = chc.registerSSL("sandboxapp.cloopen.com", "TLS", 8883, "https"); try {//from ww w .ja va2 s. c om // URL String timestamp = DateUtil.dateToStr(new Date(), DateUtil.DATE_TIME_NO_SLASH); // md5(Id + ? + ) String sig = accountSid + authToken + timestamp; // MD5 EncryptUtil eu = new EncryptUtil(); String signature = eu.md5Digest(sig); StringBuffer sb = new StringBuffer(); String url = sb.append(TEST_SMS_BASE_URL).append(SMS_VERSION).append("/Accounts/").append(accountSid) .append("/Calls").append("/VoiceVerify").append("?sig=").append(signature).toString(); // HttpPost HttpPost httppost = new HttpPost(url); setHttpHeader(httppost); String src = accountSid + ":" + timestamp; String auth = eu.base64Encoder(src); httppost.setHeader("Authorization", auth);// base64(Id + ? + // ) JSONObject obj = new JSONObject(); obj.put("to", to); obj.put("appId", appId); obj.put("verifyCode", verifyCode); obj.put("playTimes", "3"); String data = obj.toString(); System.out.println("---------------------------- SendSMS for JSON begin----------------------------"); System.out.println("data: " + data); BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(data.getBytes("UTF-8"))); requestBody.setContentLength(data.getBytes("UTF-8").length); httppost.setEntity(requestBody); // HttpResponse response = httpclient.execute(httppost); // ??? HttpEntity entity = response.getEntity(); if (entity != null) { result = EntityUtils.toString(entity, "UTF-8"); } // ?HTTP?? EntityUtils.consume(entity); } catch (Exception e) { e.printStackTrace(); } finally { // httpclient.getConnectionManager().shutdown(); } // ??? return result; }
From source file:cn.geowind.takeout.verify.JsonRestApi.java
/** * @brief ??/*from www. ja va 2 s. c om*/ * @param accountSid * ? * @param authToken * ? * @param appId * id * @param to * ? * @return HttpPost ??? * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public String sendTemplateSMS(String accountSid, String authToken, String appId, String to, String code) throws NoSuchAlgorithmException, KeyManagementException { String result = ""; // HttpClient CcopHttpClient chc = new CcopHttpClient(); DefaultHttpClient httpclient = chc.registerSSL("app.cloopen.com", "TLS", 8883, "https"); try { // URL String timestamp = DateUtil.dateToStr(new Date(), DateUtil.DATE_TIME_NO_SLASH); // md5(Id + ? + ) String sig = accountSid + authToken + timestamp; // MD5 EncryptUtil eu = new EncryptUtil(); String signature = eu.md5Digest(sig); StringBuffer sb = new StringBuffer(); String url = sb.append(SMS_BASE_URL).append(SMS_VERSION).append("/Accounts/").append(accountSid) .append(SMS).append(TEMPLATE_SMS).append("?sig=").append(signature).toString(); // HttpPost HttpPost httppost = new HttpPost(url); setHttpHeader(httppost); String src = accountSid + ":" + timestamp; String auth = eu.base64Encoder(src); httppost.setHeader("Authorization", auth);// base64(Id + ? + // ) JSONObject obj = new JSONObject(); obj.put("to", to); obj.put("appId", appId); obj.put("templateId", SMS_TEMPLATE_ID); JSONArray replace = new JSONArray(); replace.put(code); obj.put("datas", replace); String data = obj.toString(); System.out.println("---------------------------- SendSMS for JSON begin----------------------------"); System.out.println("data: " + data); BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(data.getBytes("UTF-8"))); requestBody.setContentLength(data.getBytes("UTF-8").length); httppost.setEntity(requestBody); // HttpResponse response = httpclient.execute(httppost); // ??? HttpEntity entity = response.getEntity(); if (entity != null) { result = EntityUtils.toString(entity, "UTF-8"); } // ?HTTP?? EntityUtils.consume(entity); } catch (Exception e) { e.printStackTrace(); } finally { // httpclient.getConnectionManager().shutdown(); } // ??? return result; }