本文整理匯總了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");
}
示例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;
}
示例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();
}
}
示例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;
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}