本文整理了Java中com.ibm.watson.developer_cloud.http.RequestBuilder.bodyContent
方法的一些代码示例,展示了RequestBuilder.bodyContent
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RequestBuilder.bodyContent
方法的具体详情如下:
包路径:com.ibm.watson.developer_cloud.http.RequestBuilder
类名称:RequestBuilder
方法名:bodyContent
[英]Sets the file content (InputStream) to the request (used with POST/PUT).
[中]将文件内容(InputStream)设置为请求(与POST/PUT一起使用)。
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Adds a JSON content to the request (used with POST/PUT). This will encapsulate the json into a
* {@link RequestBody} encoded with UTF-8 and use {@code "application/json"} as Content-Type
*
* @param json the JsonObject json
*
* @return this
*/
public RequestBuilder bodyJson(JsonObject json) {
return bodyContent(json.toString(), HttpMediaType.APPLICATION_JSON);
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Adds a JSON content to the request (used with POST/PUT/PATCH). This will encapsulate the json into a
* {@link RequestBody} encoded with UTF-8 and use {@code "application/json"} as Content-Type
*
* @param json the JsonObject json
* @param mediaType the contentType value
*
* @return this
*/
public RequestBuilder bodyJson(JsonObject json, String mediaType) {
return bodyContent(json.toString(), mediaType);
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Adds a JSON content to the request (used with POST/PUT). This will encapsulate the json into a
* {@link RequestBody} encoded with UTF-8 and use {@code "application/json"} as Content-Type
*
* @param json the JsonObject json
*
* @return this
*/
public RequestBuilder bodyJson(JsonObject json) {
return bodyContent(json.toString(), HttpMediaType.APPLICATION_JSON);
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Adds a JSON content to the request (used with POST/PUT/PATCH). This will encapsulate the json into a
* {@link RequestBody} encoded with UTF-8 and use {@code "application/json"} as Content-Type
*
* @param json the JsonObject json
* @param mediaType the contentType value
*
* @return this
*/
public RequestBuilder bodyJson(JsonObject json, String mediaType) {
return bodyContent(json.toString(), mediaType);
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Sets the request body content from one of three different sources, based on the content type.
*
* @param contentType
* the value of the "Content-Type" header associated with the outgoing request
* @param jsonContent
* the body content to be used if the content type indicates JSON
* @param jsonPatchContent
* the body content to be used if the content type indicates JsonPatch
* @param nonJsonContent
* the body content to be used if the content type indicates non-JSON content
* @return this
*/
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
String nonJsonContent) {
InputStream nonJson = null;
if (nonJsonContent != null) {
nonJson = StringHelper.toInputStream(nonJsonContent);
}
return bodyContent(contentType, jsonContent, jsonPatchContent, nonJson);
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Sets the request body content from one of three different sources, based on the content type.
*
* @param contentType
* the value of the "Content-Type" header associated with the outgoing request
* @param jsonContent
* the body content to be used if the content type indicates JSON
* @param jsonPatchContent
* the body content to be used if the content type indicates JsonPatch
* @param nonJsonContent
* the body content to be used if the content type indicates non-JSON content
* @return this
*/
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
String nonJsonContent) {
InputStream nonJson = null;
if (nonJsonContent != null) {
nonJson = StringHelper.toInputStream(nonJsonContent);
}
return bodyContent(contentType, jsonContent, jsonPatchContent, nonJson);
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Sets the request body content from one of three different sources, based on the content type.
*
* @param contentType
* the value of the "Content-Type" header associated with the outgoing request
* @param jsonContent
* the body content to be used if the content type indicates JSON
* @param jsonPatchContent
* the body content to be used if the content type indicates JsonPatch
* @param nonJsonContent
* the body content to be used if the content type indicates non-JSON content
* @return this
*/
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
InputStream nonJsonContent) {
if (contentType != null) {
if (WatsonService.isJsonMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
} else if (WatsonService.isJsonPatchMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
} else {
this.bodyContent(nonJsonContent, contentType);
}
}
return this;
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Sets the request body content from one of three different sources, based on the content type.
*
* @param contentType
* the value of the "Content-Type" header associated with the outgoing request
* @param jsonContent
* the body content to be used if the content type indicates JSON
* @param jsonPatchContent
* the body content to be used if the content type indicates JsonPatch
* @param nonJsonContent
* the body content to be used if the content type indicates non-JSON content
* @return this
*/
public RequestBuilder bodyContent(String contentType, Object jsonContent, Object jsonPatchContent,
InputStream nonJsonContent) {
if (contentType != null) {
if (WatsonService.isJsonMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonContent).getAsJsonObject().toString(), contentType);
} else if (WatsonService.isJsonPatchMimeType(contentType)) {
this.bodyContent(
GsonSingleton.getGson().toJsonTree(jsonPatchContent).getAsJsonObject().toString(), contentType);
} else {
this.bodyContent(nonJsonContent, contentType);
}
}
return this;
}
代码示例来源:origin: com.ibm.watson.developer_cloud/retrieve-and-rank
private Request buildResizeRequest(String solrClusterId, int desiredSize) {
final String resizePath = createSizePath(solrClusterId);
final SolrClusterResizeRequest resizeRequest = new SolrClusterResizeRequest(desiredSize);
final RequestBuilder requestBuilder = RequestBuilder.put(resizePath);
requestBuilder.bodyContent(GsonSingleton.getGsonWithoutPrettyPrinting().toJson(resizeRequest),
HttpMediaType.APPLICATION_JSON);
return requestBuilder.build();
}
代码示例来源:origin: com.ibm.watson.developer_cloud/retrieve-and-rank
@Override
public ServiceCall<SolrCluster> createSolrCluster(SolrClusterOptions config) {
final RequestBuilder requestBuilder = RequestBuilder.post(PATH_SOLR_CLUSTERS);
if (config != null) {
requestBuilder.bodyContent(GsonSingleton.getGsonWithoutPrettyPrinting().toJson(config),
HttpMediaType.APPLICATION_JSON);
}
return createServiceCall(requestBuilder.build(), ResponseConverterUtils.getObject(SolrCluster.class));
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Identify language.
*
* Identifies the language of the input text.
*
* @param identifyOptions the {@link IdentifyOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link IdentifiedLanguages}
*/
public ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions) {
Validator.notNull(identifyOptions, "identifyOptions cannot be null");
String[] pathSegments = { "v3/identify" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.bodyContent(identifyOptions.text(), "text/plain");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IdentifiedLanguages.class));
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Test build.
*/
@Test
public void testBuild() {
final String xToken = X_TOKEN;
final RequestBuilder builder =
RequestBuilder.post(HttpUrl.parse(urlWithQuery))
.bodyContent("body1", HttpMediaType.TEXT_PLAIN)
.header(X_TOKEN, "token1");
final Request request = builder.build();
assertEquals("POST", request.method());
assertEquals("token1", request.header(xToken));
assertNotNull(builder.toString());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/language-translator
/**
* Identify language.
*
* Identifies the language of the input text.
*
* @param identifyOptions the {@link IdentifyOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link IdentifiedLanguages}
*/
public ServiceCall<IdentifiedLanguages> identify(IdentifyOptions identifyOptions) {
Validator.notNull(identifyOptions, "identifyOptions cannot be null");
String[] pathSegments = { "v3/identify" };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=language_translator;service_version=v3;operation_id=identify");
builder.bodyContent(identifyOptions.text(), "text/plain");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(IdentifiedLanguages.class));
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Test with content string.
*
* @throws IOException Signals that an I/O exception has occurred.
*/
@Test
public void testWithContentString() throws IOException {
final String body = "test2";
final Request request = RequestBuilder.post(HttpUrl.parse(urlWithQuery))
.bodyContent(body, HttpMediaType.TEXT_PLAIN).build();
final RequestBody requestedBody = request.body();
final Buffer buffer = new Buffer();
requestedBody.writeTo(buffer);
assertEquals(body, buffer.readUtf8());
assertEquals(HttpMediaType.TEXT, requestedBody.contentType());
}
代码示例来源:origin: watson-developer-cloud/java-sdk
builder.query("allow_overwrite", String.valueOf(addGrammarOptions.allowOverwrite()));
builder.bodyContent(addGrammarOptions.contentType(), null, null, addGrammarOptions.grammarFile());
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
代码示例来源:origin: com.ibm.watson.developer_cloud/speech-to-text
builder.query("allow_overwrite", String.valueOf(addGrammarOptions.allowOverwrite()));
builder.bodyContent(addGrammarOptions.contentType(), null, null, addGrammarOptions.grammarFile());
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
代码示例来源:origin: watson-developer-cloud/java-sdk
builder.query("consumption_preferences", String.valueOf(profileOptions.consumptionPreferences()));
builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Profile.class));
代码示例来源:origin: watson-developer-cloud/java-sdk
builder.query("csv_headers", includeHeaders);
builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body());
return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream());
代码示例来源:origin: com.ibm.watson.developer_cloud/personality-insights
builder.query("csv_headers", includeHeaders);
builder.bodyContent(profileOptions.contentType(), profileOptions.content(), null, profileOptions.body());
return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream());
代码示例来源:origin: watson-developer-cloud/java-sdk
builder.query("tones", RequestUtils.join(toneOptions.tones(), ","));
builder.bodyContent(toneOptions.contentType(), toneOptions.toneInput(), null, toneOptions.body());
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ToneAnalysis.class));
内容来源于网络,如有侵权,请联系作者删除!