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 testGetContentLength() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/* w w w .ja va 2s. c o m*/ PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentLength(), is(-1L)); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentLength(input.length()); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentLength(), is(10L)); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testGetContentEncoding() throws Exception { String input = "0123456789"; BasicHttpEntity basic;//www .j ava2 s .c o m CappedBufferHttpEntity replay; 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 testGetContentType() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/* w w w.j a v a 2s .co m*/ PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentType(), nullValue()); basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); basic.setContentType(ContentType.APPLICATION_JSON.getMimeType()); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.getContentType().getValue(), is("application/json")); }
From source file:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testIsStreaming() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/*www.j ava2 s . c o m*/ InputStreamEntity streaming; CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(true)); basic = new BasicHttpEntity(); basic.setContent(null); replay = new CappedBufferHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(false)); streaming = new InputStreamEntity(new ByteArrayInputStream(input.getBytes(UTF8)), 10, ContentType.TEXT_PLAIN); replay = new CappedBufferHttpEntity(streaming, 5); assertThat(replay.isStreaming(), is(true)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testGetContentEncoding() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/* www . j a va2s . c om*/ 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:com.tmount.business.cloopen.restAPI.RestAPI.java
/** * @brief ??//www.j a v a 2s.c o m * @param accountSid ? * @param authToken ? * @param appId id * @param verifyCode ?????4-20? * @param playTimes 1?3 * @param to ?? */ public String VoiceVerifyCode(String accountSid, String authToken, String appId, String verifyCode, String playTimes, String to) throws NoSuchAlgorithmException, KeyManagementException { // ? String result = ""; // HttpClient CcopHttpClient chc = new CcopHttpClient(); DefaultHttpClient httpclient = chc.registerSSL("sandboxapp.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("/Calls/VoiceVerify?sig=").append(signature) .toString(); // HttpPost HttpPost httppost = new HttpPost(url); setHttpHeader(httppost); String src = accountSid + ":" + timestamp; // base64(Id + ? +) String auth = eu.base64Encoder(src); httppost.setHeader("Authorization", auth); String body = null; if (!JsonUtils.JSON_ENABLE) { // Body body = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?><VoiceVerify>").append("<appId>")) .append(appId).append("</appId>").append("<verifyCode>").append(verifyCode) .append("</verifyCode>").append("<playTimes>").append(playTimes).append("</playTimes>") .append("<to>").append(to).append("</to></VoiceVerify>").toString(); } else { VoiceVerifyCodeRequest verifyCodeRequest = new VoiceVerifyCodeRequest(appId, verifyCode, playTimes, to); Gson gson = new Gson(); body = gson.toJson(verifyCodeRequest); } System.out.println("CreateSubAccount : request _" + body); BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(body.getBytes("UTF-8"))); requestBody.setContentLength(body.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:org.apache.hadoop.gateway.dispatch.CappedBufferHttpEntityTest.java
@Test public void testConsumeContent() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/*from w w w .j a v a 2s. c o m*/ CappedBufferHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new CappedBufferHttpEntity(basic, 5); try { replay.consumeContent(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // Expected. } }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testIsStreaming() throws Exception { String input = "0123456789"; BasicHttpEntity basic;//from w w w . j ava2 s . com InputStreamEntity streaming; PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(true)); basic = new BasicHttpEntity(); basic.setContent(null); replay = new PartiallyRepeatableHttpEntity(basic, 5); assertThat(replay.isStreaming(), is(false)); streaming = new InputStreamEntity(new ByteArrayInputStream(input.getBytes(UTF8)), 10, ContentType.TEXT_PLAIN); replay = new PartiallyRepeatableHttpEntity(streaming, 5); assertThat(replay.isStreaming(), is(true)); }
From source file:org.apache.hadoop.gateway.dispatch.PartiallyRepeatableHttpEntityTest.java
@Test public void testConsumeContent() throws Exception { String input = "0123456789"; BasicHttpEntity basic;/*from ww w .j av a2 s .c om*/ PartiallyRepeatableHttpEntity replay; basic = new BasicHttpEntity(); basic.setContent(new ByteArrayInputStream(input.getBytes(UTF8))); replay = new PartiallyRepeatableHttpEntity(basic, 5); try { replay.consumeContent(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { // Expected. } }
From source file:com.tmount.business.cloopen.restAPI.RestAPI.java
public String getSubAccountSid(String accountSid, String authToken, String appId) throws NoSuchAlgorithmException, KeyManagementException { // ?//ww w . j a v a 2 s . c om 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); String url = (new StringBuilder(hostname)).append("/").append(softVer).append("/Accounts/") .append(accountSid).append("/GetSubAccounts?sig=").append(signature).toString(); // HttpPost System.out.println("url:" + url); HttpPost httppost = new HttpPost(url); setHttpHeader(httppost); String src = accountSid + ":" + timestamp; // base64(Id + ? +) String auth = eu.base64Encoder(src); httppost.setHeader("Authorization", auth); String body = null; if (!JsonUtils.JSON_ENABLE) { // Body body = (new StringBuilder("<?xml version='1.0' encoding='utf-8'?><SubAccount>").append("<appId>")) .append(appId).append("</appId>").append("<startNo>1</startNo>") .append("<offset>100</offset></SubAccount>").toString(); } System.out.println("CreateSubAccount : request _" + body); BasicHttpEntity requestBody = new BasicHttpEntity(); requestBody.setContent(new ByteArrayInputStream(body.getBytes("UTF-8"))); requestBody.setContentLength(body.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; }