当前位置: 首页>>代码示例>>Java>>正文


Java InputStreamEntity类代码示例

本文整理汇总了Java中org.apache.http.entity.InputStreamEntity的典型用法代码示例。如果您正苦于以下问题:Java InputStreamEntity类的具体用法?Java InputStreamEntity怎么用?Java InputStreamEntity使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


InputStreamEntity类属于org.apache.http.entity包,在下文中一共展示了InputStreamEntity类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: postInputStreamEntity

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test public void postInputStreamEntity() throws Exception {
  server.enqueue(new MockResponse());

  final HttpPost post = new HttpPost(server.url("/").url().toURI());
  byte[] body = "Hello, world!".getBytes(UTF_8);
  post.setEntity(new InputStreamEntity(new ByteArrayInputStream(body), body.length));
  client.execute(post);

  RecordedRequest request = server.takeRequest();
  assertEquals("Hello, world!", request.getBody().readUtf8());
  assertEquals(request.getHeader("Content-Length"), "13");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:13,代码来源:OkApacheClientTest.java

示例2: getContent

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
public byte[] getContent() throws IOException{
	if(content != null){
		return content;
	}

	// don't close stream
	content = EntityUtils.toByteArray(new InputStreamEntity(super.getInputStream()));
	return content;
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:10,代码来源:CachingHttpServletRequest.java

示例3: _testAuthenticationHttpClient

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
protected void _testAuthenticationHttpClient(Authenticator authenticator, boolean doPost) throws Exception {
  start();
  try {
    SystemDefaultHttpClient httpClient = getHttpClient();
    doHttpClientRequest(httpClient, new HttpGet(getBaseURL()));

    // Always do a GET before POST to trigger the SPNego negotiation
    if (doPost) {
      HttpPost post = new HttpPost(getBaseURL());
      byte [] postBytes = POST.getBytes();
      ByteArrayInputStream bis = new ByteArrayInputStream(postBytes);
      InputStreamEntity entity = new InputStreamEntity(bis, postBytes.length);

      // Important that the entity is not repeatable -- this means if
      // we have to renegotiate (e.g. b/c the cookie wasn't handled properly)
      // the test will fail.
      Assert.assertFalse(entity.isRepeatable());
      post.setEntity(entity);
      doHttpClientRequest(httpClient, post);
    }
  } finally {
    stop();
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:25,代码来源:AuthenticatorTestCase.java

示例4: transformResponse

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
private static HttpResponse transformResponse(Response response) {
  int code = response.code();
  String message = response.message();
  BasicHttpResponse httpResponse = new BasicHttpResponse(HTTP_1_1, code, message);

  ResponseBody body = response.body();
  InputStreamEntity entity = new InputStreamEntity(body.byteStream(), body.contentLength());
  httpResponse.setEntity(entity);

  Headers headers = response.headers();
  for (int i = 0, size = headers.size(); i < size; i++) {
    String name = headers.name(i);
    String value = headers.value(i);
    httpResponse.addHeader(name, value);
    if ("Content-Type".equalsIgnoreCase(name)) {
      entity.setContentType(value);
    } else if ("Content-Encoding".equalsIgnoreCase(name)) {
      entity.setContentEncoding(value);
    }
  }

  return httpResponse;
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:24,代码来源:OkApacheClient.java

示例5: createIndex

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
private void createIndex() {
  Response response;

  try (InputStream payload = FactSearchManager.class.getClassLoader().getResourceAsStream(MAPPINGS_JSON)) {
    // Need to use low-level client here because the Index API is not yet supported by the high-level client.
    HttpEntity body = new InputStreamEntity(payload, ContentType.APPLICATION_JSON);
    response = clientFactory.getLowLevelClient().performRequest("PUT", INDEX_NAME, Collections.emptyMap(), body);
  } catch (IOException ex) {
    throw logAndExit(ex, "Could not perform request to create index.");
  }

  if (response.getStatusLine().getStatusCode() != HttpStatus.SC_OK) {
    String msg = String.format("Could not create index '%s'.", INDEX_NAME);
    LOGGER.error(msg);
    throw new IllegalStateException(msg);
  }

  LOGGER.info("Successfully created index '%s'.", INDEX_NAME);
}
 
开发者ID:mnemonic-no,项目名称:act-platform,代码行数:20,代码来源:FactSearchManager.java

示例6: test

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void test() throws IOException{
	String sentBody = "{ 'key': 'value' }";
	Charset charset = StandardCharsets.UTF_8;
	StringEntity sentEntity = new StringEntity(sentBody, charset);
	HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
	Mockito.doAnswer(any -> new CachingServletInputStream(sentEntity.getContent()))
			.when(request).getInputStream();

	CachingHttpServletRequest cachingRequest = CachingHttpServletRequest.getOrCreate(request);
	// test repeat reads
	for(int i = 0; i < 5; i++){
		InputStreamEntity entity = new InputStreamEntity(request.getInputStream());
		String receivedBody = EntityUtils.toString(entity, charset);
		Assert.assertEquals(sentBody, receivedBody);

		receivedBody = EntityUtils.toString(new InputStreamEntity(cachingRequest.getInputStream()), charset);
		Assert.assertEquals(sentBody, receivedBody);
	}

	Assert.assertSame(CachingHttpServletRequest.getOrCreate(cachingRequest), cachingRequest);
}
 
开发者ID:hotpads,项目名称:datarouter,代码行数:23,代码来源:CachingHttpServletRequestTests.java

示例7: testRetrievingContentInSpecificLanguage

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testRetrievingContentInSpecificLanguage() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "items/on_roasts"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("DocsExamplesRetrievingContentInSpecificLanguage.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    List<NameValuePair> params = DeliveryParameterBuilder.params().language("es-ES").build();

    ArticleItem item = client.getItem("on_roasts", ArticleItem.class, params);
    Assert.assertNotNull(item);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:26,代码来源:DocsExamplesTest.java

示例8: testViewContentItem

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testViewContentItem() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "items/on_roasts"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentItem.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    List<NameValuePair> params = DeliveryParameterBuilder.params().projection("title", "summary", "post_date", "teaser_image", "related_articles").build();

    ArticleItem item = client.getItem("on_roasts", ArticleItem.class, params);
    Assert.assertNotNull(item);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:26,代码来源:DocsExamplesTest.java

示例9: testListContentTypes

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testListContentTypes() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "types"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentTypeList.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    List<NameValuePair> params = DeliveryParameterBuilder.params().page(null, 3).build();
    ContentTypesListingResponse types = client.getTypes(params);

    Assert.assertNotNull(types);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:26,代码来源:DocsExamplesTest.java

示例10: testViewContentType

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testViewContentType() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "types/coffee"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentType.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    ContentType type = client.getType("coffee");
    Assert.assertNotNull(type);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:24,代码来源:DocsExamplesTest.java

示例11: testViewContentTypeElement

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testViewContentTypeElement() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "types/coffee/elements/processing"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentTypeElementResponse.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    Element element = client.getContentTypeElement("coffee", "processing");
    Assert.assertNotNull(element);
    Assert.assertEquals("processing", element.getCodeName());
    Assert.assertTrue(element instanceof MultipleChoiceElement);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:26,代码来源:DocsExamplesTest.java

示例12: testViewTaxonomyGroup

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testViewTaxonomyGroup() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "taxonomies/personas"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleTaxonomyGroup.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    TaxonomyGroup taxonomyGroup = client.getTaxonomyGroup("personas");
    Assert.assertNotNull(taxonomyGroup);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:24,代码来源:DocsExamplesTest.java

示例13: testGetAllItems

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testGetAllItems() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "items"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentItemList.json")
                    )
            ));
    HttpHost httpHost = this.start();

    DeliveryOptions deliveryOptions = new DeliveryOptions();
    deliveryOptions.setProductionEndpoint(httpHost.toURI() + "/%s");
    deliveryOptions.setProjectId(projectId);
    DeliveryClient client = new DeliveryClient(deliveryOptions, null);

    ContentItemsListingResponse items = client.getItems();
    Assert.assertNotNull(items);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:22,代码来源:DeliveryClientTest.java

示例14: testGetItem

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testGetItem() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "items/on_roasts"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleContentItem.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    ContentItemResponse item = client.getItem("on_roasts");
    Assert.assertNotNull(item);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:24,代码来源:DeliveryClientTest.java

示例15: testGetTaxonomyGroup

import org.apache.http.entity.InputStreamEntity; //导入依赖的package包/类
@Test
public void testGetTaxonomyGroup() throws Exception {
    String projectId = "02a70003-e864-464e-b62c-e0ede97deb8c";

    this.serverBootstrap.registerHandler(
            String.format("/%s/%s", projectId, "taxonomies/personas"),
            (request, response, context) -> response.setEntity(
                    new InputStreamEntity(
                            this.getClass().getResourceAsStream("SampleTaxonomyGroup.json")
                    )
            ));
    HttpHost httpHost = this.start();
    DeliveryClient client = new DeliveryClient(projectId);

    //modify default baseurl to point to test server, this is private so using reflection
    String testServerUri = httpHost.toURI() + "/%s";
    Field deliveryOptionsField = client.getClass().getDeclaredField("deliveryOptions");
    deliveryOptionsField.setAccessible(true);
    ((DeliveryOptions) deliveryOptionsField.get(client)).setProductionEndpoint(testServerUri);

    TaxonomyGroup taxonomyGroup = client.getTaxonomyGroup("personas");
    Assert.assertNotNull(taxonomyGroup);
}
 
开发者ID:Kentico,项目名称:delivery-sdk-java,代码行数:24,代码来源:DeliveryClientTest.java


注:本文中的org.apache.http.entity.InputStreamEntity类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。