List of usage examples for org.apache.http.entity BasicHttpEntity BasicHttpEntity
public BasicHttpEntity()
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_PC_OB() throws IOException { String data = "0123456789"; BasicHttpEntity basic;//from w w w . j a v a 2s. c o m PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 4); assertThat(text, is("0123456789")); stream.close(); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testS_C1_PC_IB__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/* w ww . j a v a2 s . co m*/ CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, 4); assertThat(text, is("0123")); stream.close(); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); }
From source file:org.mycard.net.network.AndroidHttpClientConnection.java
/*** * Return the next response entity./*from w ww .ja v a 2 s .c o 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.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testS_C1_PC_IB__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic;/*w ww.ja v a 2 s . c o m*/ PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = byteRead(stream, 4); assertThat(text, is("0123")); stream.close(); stream = replay.getContent(); text = byteRead(stream, -1); assertThat(text, is("0123456789")); }
From source file:com.tmount.business.cloopen.restAPI.RestAPI.java
/** * ??//from ww w. j ava 2s. c o m * @param to ? * @param body * @param msgType 0: 1:65 * @param sms_type ? 0: 1: 2??? 3tomcat * @return * @throws NoSuchAlgorithmException * @throws KeyManagementException */ public String SendSMS(String to, String body, String msgType, String sms_type) throws NoSuchAlgorithmException, KeyManagementException { String filePath = this.getClass().getClassLoader().getResource("config.properties").toString().substring(6); filePath = "/" + filePath; AgentSysInfo agentSysInfo = new AgentSysInfo(); agentSysInfo = PropertiesUtil.getAgentSysInfo(filePath); String accountSid = agentSysInfo.getAccountSid(); String authToken = agentSysInfo.getAuthToken(); String appId = agentSysInfo.getAppId(); String subAccountSid = agentSysInfo.getSub_account(); String app_name = agentSysInfo.getApp_name(); String reserve_date = agentSysInfo.getReserve_date(); String reserve_address = agentSysInfo.getReserve_address(); String sms_time = agentSysInfo.getSms_time(); String reslut = ""; // 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); String url = (new StringBuilder(hostname)).append(":").append(port).append("/").append(softVer) .append("/Accounts/").append(accountSid).append("/SMS/TemplateSMS?sig=")//Messages TemplateSMS .append(signature).toString(); // HttpPost System.out.println("url:" + url); HttpPost httppost = new HttpPost(url); setHttpHeader(httppost); String src = accountSid + ":" + timestamp; String auth = eu.base64Encoder(src); httppost.setHeader("Authorization", auth);// base64(Id + ? + ) String bodyData = null; logger.info("~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~SMS is bigining sms_type:" + sms_type); if (!JsonUtils.JSON_ENABLE) { // Body if (sms_type.equalsIgnoreCase("0"))//? { bodyData = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?>")).append("<TemplateSMS>") .append("<to>").append(to).append("</to>").append("<appId>").append(appId) .append("</appId>").append("<templateId>4106</templateId>").append("<datas>") .append("<data>" + app_name + "</data>").append("<data>" + body + "</data>") /*.append("<data>"+sms_time+"</data>")*/ .append("</datas>").append("</TemplateSMS>").toString(); } else if (sms_type.equalsIgnoreCase("1"))// { bodyData = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?>")).append("<TemplateSMS>") .append("<to>").append(to).append("</to>").append("<appId>").append(appId) .append("</appId>").append("<templateId>1519</templateId>").append("<datas>") .append("<data>" + body + "</data>").append("<data>" + sms_time + "</data>") .append("</datas>").append("</TemplateSMS>").toString(); } else if (sms_type.equalsIgnoreCase("2"))//???? { bodyData = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?>")).append("<TemplateSMS>") .append("<to>").append(to).append("</to>").append("<appId>").append(appId) .append("</appId>").append("<templateId>1520</templateId>").append("<datas>") .append("<data>" + DatatimeUtil.getCurrentDate().toString() + "</data>")//? .append("<data>" + body + "</data>")//?? .append("<data>" + reserve_date + "</data>")//? .append("<data>" + reserve_address + "</data>")//?? .append("</datas>").append("</TemplateSMS>").toString(); } else if (sms_type.equalsIgnoreCase("3"))//tomcat { bodyData = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?>")).append("<TemplateSMS>") .append("<to>").append(to).append("</to>").append("<appId>").append(appId) .append("</appId>").append("<templateId>1758</templateId>").append("<datas>") .append("<data>" + body + "</data>")//? .append("</datas>").append("</TemplateSMS>").toString(); } } else { SendSMSRequest sendSMS = new SendSMSRequest(to, bodyData, msgType, appId, subAccountSid); Gson gson = new Gson(); bodyData = gson.toJson(sendSMS); } System.out.println("?? : request _" + bodyData); BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(bodyData.getBytes("UTF-8"))); requestBody.setContentLength(bodyData.getBytes("UTF-8").length); httppost.setEntity(requestBody); // HttpResponse response = httpclient.execute(httppost); // ??? HttpEntity entity = response.getEntity(); if (entity != null) { reslut = EntityUtils.toString(entity, "UTF-8"); } // ?HTTP?? EntityUtils.consume(entity); } catch (Exception e) { e.printStackTrace(); } finally { // httpclient.getConnectionManager().shutdown(); } //??? return reslut; }
From source file:org.wso2.carbon.apimgt.handlers.AuthenticationHandlerTest.java
private CloseableHttpResponse getDCRResponse() throws IOException { CloseableHttpResponse mockDCRResponse = new MockHttpResponse(); String dcrResponseFile = TestUtils.getAbsolutePathOfConfig("dcr-response.json"); BasicHttpEntity responseEntity = new BasicHttpEntity(); responseEntity.setContent(//from www . j a va2s . c o m new ByteArrayInputStream(getContent(dcrResponseFile).getBytes(StandardCharsets.UTF_8.name()))); responseEntity.setContentType(TestUtils.CONTENT_TYPE); mockDCRResponse.setEntity(responseEntity); mockDCRResponse.setStatusLine(new BasicStatusLine(new ProtocolVersion("http", 1, 0), 200, "OK")); return mockDCRResponse; }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testB_C1_PC_IB__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic;//from w w w . ja va2 s .c om CappedBufferHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, 4, 1); assertThat(text, is("0123")); stream.close(); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 7); assertThat(text, is("0123456789")); }
From source file:cvut.fel.mobilevoting.murinrad.communications.Connection.java
public void postAndRecieve(String method, String URL, ArrayList<BasicHeader> headers, String body, boolean authenticate) throws IOException { BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest(method, URL); BasicHeader head = null;//from www . j a va2 s .c o m BasicHeader h2 = null; if (authenticate) { head = new BasicHeader("ID", server.getLogin()); h2 = new BasicHeader("Password", server.getPassword()); } BasicHttpEntity entity = new BasicHttpEntity(); if (body != null) { InputStream in = null; Log.i("Android Mobile Voting", "loading entity"); try { in = new ByteArrayInputStream(body.getBytes("UTF-8")); } catch (UnsupportedEncodingException e1) { e1.printStackTrace(); } entity.setContent(in); request.setEntity(entity); } request.addHeader(head); request.addHeader(h2); if (headers != null) { } HttpHost g = new HttpHost(server.getAddress(), port, usingScheme); connection.execute(g, request); Log.e("Android Mobile Voting", "sending"); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testB_C1_PC_IB__C2_FC() throws IOException { String data = "0123456789"; BasicHttpEntity basic;//w ww . jav a 2s .c o m PartiallyRepeatableHttpEntity replay; InputStream stream; String text; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(data.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 20); stream = replay.getContent(); text = blockRead(stream, UTF8, 4, 1); assertThat(text, is("0123")); stream.close(); stream = replay.getContent(); text = blockRead(stream, UTF8, -1, 7); assertThat(text, is("0123456789")); }