本文整理汇总了Java中org.apache.http.client.fluent.Content类的典型用法代码示例。如果您正苦于以下问题:Java Content类的具体用法?Java Content怎么用?Java Content使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Content类属于org.apache.http.client.fluent包,在下文中一共展示了Content类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: authenticate
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public Token authenticate() throws IOException {
final Gson gson = new GsonBuilder().create();
final Content response = Request.Post(this.metabaseHost.toString() + "/session")
.setHeader("Content-Type", "application/json")
.body(new StringEntity(gson.toJson(this.credential)))
.execute().returnContent();
this.token = gson.fromJson(response.asString(), Token.class);
this.authenticated = true;
return this.token;
}
示例2: post
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public static String post(String location, String jsonArgs)
{
Content result = null;
try {
StringEntity jsonEntity = new StringEntity(jsonArgs);
result = Request.Post(location)
.body(jsonEntity)
.execute()
.returnContent();
} catch (IOException e) {
e.printStackTrace();
}
return (result == null) ? null : result.toString();
}
示例3: get
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public static String get(String location)
{
Content result = null;
try {
result = Request.Get(location)
.execute()
.returnContent();
} catch (IOException e) {
e.printStackTrace();
}
System.out.println("Test Utility result = " + result.toString());
return (result == null) ? null : result.toString();
}
示例4: loadUnresolvedIncidents
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Override
public Collection<PagerdutyIncident> loadUnresolvedIncidents() {
Collection<PagerdutyIncident> pagerdutyIncidents = Lists.newArrayList();
try {
URI uri = new URIBuilder().setScheme("https").setHost(pagerDutyHost).setPath("/api/v1/incidents")
.setParameter("status", "triggered,acknowledged").build();
Content returnContent = Request.Get(uri).addHeader("Content-type", "application/json")
.addHeader("Authorization", pagerDutyToken).execute().returnContent();
String response = returnContent.asString();
pagerdutyIncidents = extractIncidents(response);
} catch (Exception e) {
logger.error(e.getMessage(), e);
}
return pagerdutyIncidents;
}
示例5: test
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Test
public void test() throws IOException {
final String sparkHelloWorldServiceUrl = this.getSparkHelloWorldServiceUrl();
final Content content = Request.Get(sparkHelloWorldServiceUrl + "/hello")
.execute()
.returnContent();
Assert.assertEquals("Hello World", content.asString());
}
示例6: getContent
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public Content getContent() throws IOException {
// byte[] byteArray = IOUtils.toByteArray(response.getEntity().getContent());
// ContentType contentType = ContentType.get(response.getEntity());
// response.close();
// return new Content(byteArray, contentType);
return content;
}
示例7: handleGetRequest
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Test
public void handleGetRequest() throws Exception {
final Content content = Request.Get("http://localhost:8080/")
.execute()
.returnContent();
assertEquals("Hello World!", content.asString());
}
示例8: handlePostRequest
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Test
public void handlePostRequest() throws Exception {
final Content content = Request.Post("http://localhost:8080/Vader")
.execute()
.returnContent();
assertEquals("Hello Vader!", content.asString());
}
示例9: handleStatic
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Test
public void handleStatic() throws Exception {
final Content content = Request.Get("http://localhost:8080/static/test.txt")
.execute()
.returnContent();
assertEquals("Content", content.asString());
}
示例10: handleException
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
@Test
public void handleException() throws Exception {
final Content content = Request.Get("http://localhost:8080/exception")
.execute()
.returnContent();
assertEquals("Programmatic Error", content.asString());
}
示例11: fetchBody
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
/**
* Fetch the body for a given HistoryRecord and add it to the record
*
* @param record HistoryRecord containing a URL to fetch
* @return
*/
protected static HistoryRecord fetchBody(HistoryRecord record) {
try {
Content content =
Request.Get(encodeSpecialChars(record.getUrl()))
.execute()
.returnContent();
if (content != null) {
record.setBody(content.asString(Charsets.UTF_8));
}
} catch (IOException e) {
System.err.println("Failed to fetch " + record.getUrl() + ": " + e.getLocalizedMessage());
}
return record;
}
示例12: send
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public static void send() throws URISyntaxException {
URIBuilder builder = new URIBuilder(_nodePollerURL);
JSONObject receiveJSON = JSONFactoryUtil.createJSONObject();
int i = 0;
for(RequestParams params: _requestParams){
JSONObject object = JSONFactoryUtil.createJSONObject();
object.put("portletId", params.getPortletId()).put("data", params.getData().toString())
.put("userIds", String.valueOf(params.getUserId()));
// builder.addParameter("portletId", params.getPortletId()).addParameter("data", params.getData().toString()).
// addParameter("userIds", String.valueOf(params.getUserId()));
receiveJSON.put(i+"", object);
i++;
}
_requestParams.clear();
builder.addParameter("receive", receiveJSON.toString());
final Request request = Request.Get(builder.build());
Future<Content> future = async.execute(request, new FutureCallback<Content>() {
public void failed (final Exception e) {
_log.error(e.getMessage() +": "+ request);
PollerProcessorUtil.destroy();
}
public void completed (final Content content) {
_log.info("Request completed: "+ request);
// _log.info("Response: "+ content.asString());
}
public void cancelled () {}
});
}
示例13: doHttpCall
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
private String doHttpCall(int port) throws IOException {
Content content = Request.Get(baseUrl + ":" + port + httpPath)
.execute().returnContent();
return content.asString();
}
示例14: getPublicCards
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
public List<Card> getPublicCards() throws IOException {
final Content content = executeGetAuthenticatedMethod("/card/public");
final Gson gson = new GsonBuilder().create();
return gson.fromJson(content.asString(), new TypeToken<List<Card>>() {
}.getType());
}
示例15: executeGetAuthenticatedMethod
import org.apache.http.client.fluent.Content; //导入依赖的package包/类
private Content executeGetAuthenticatedMethod(final String apiEndpoint) throws IOException {
return Request.Get(this.metabaseHost.toString() + apiEndpoint)
.setHeader("Content-Type", "application/json")
.setHeader(HEADER_X_KEY, this.token.getId())
.execute().returnContent();
}