本文整理了Java中com.ibm.watson.developer_cloud.http.RequestBuilder.header
方法的一些代码示例,展示了RequestBuilder.header
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。RequestBuilder.header
方法的具体详情如下:
包路径:com.ibm.watson.developer_cloud.http.RequestBuilder
类名称:RequestBuilder
方法名:header
[英]Adds header parameters.
[中]添加标题参数。
代码示例来源:origin: com.ibm.watson.developer_cloud/retrieve-and-rank
@Override
public ServiceCall<InputStream> getSolrClusterConfiguration(String solrClusterId, String configName) {
Validator.isTrue((solrClusterId != null) && !solrClusterId.isEmpty(), "solrClusterId cannot be null or empty");
Validator.isTrue((configName != null) && !configName.isEmpty(), "configName cannot be null or empty");
final String configPath = createConfigPath(solrClusterId, configName);
final RequestBuilder requestBuider =
RequestBuilder.get(configPath).header(HttpHeaders.ACCEPT, HttpMediaType.APPLICATION_ZIP);
return createServiceCall(requestBuider.build(), ResponseConverterUtils.getInputStream());
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Gets an authorization token that can be use to authorize API calls.
*
*
* @return the token
*/
public ServiceCall<String> getToken() {
HttpUrl url = HttpUrl.parse(getEndPoint()).newBuilder()
.setPathSegment(0, AUTHORIZATION)
.addPathSegment(PATH_AUTHORIZATION_V1_TOKEN)
.build();
Request request = RequestBuilder.get(url)
.header(HttpHeaders.ACCEPT, HttpMediaType.TEXT_PLAIN).query(URL, getEndPoint()).build();
return createServiceCall(request, ResponseConverterUtils.getString());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Gets an authorization token that can be use to authorize API calls.
*
*
* @return the token
*/
public ServiceCall<String> getToken() {
HttpUrl url = HttpUrl.parse(getEndPoint()).newBuilder()
.setPathSegment(0, AUTHORIZATION)
.addPathSegment(PATH_AUTHORIZATION_V1_TOKEN)
.build();
Request request = RequestBuilder.get(url)
.header(HttpHeaders.ACCEPT, HttpMediaType.TEXT_PLAIN).query(URL, getEndPoint()).build();
return createServiceCall(request, ResponseConverterUtils.getString());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Refresh an IAM token using a refresh token. Also updates internal managed IAM token information.
*
* @return the new access token
*/
private String refreshToken() {
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(url, new String[0]));
builder.header(HttpHeaders.CONTENT_TYPE, HttpMediaType.APPLICATION_FORM_URLENCODED);
builder.header(HttpHeaders.AUTHORIZATION, DEFAULT_AUTHORIZATION);
FormBody formBody = new FormBody.Builder()
.add(GRANT_TYPE, REFRESH_GRANT_TYPE)
.add(REFRESH_TOKEN, tokenData.getRefreshToken())
.build();
builder.body(formBody);
tokenData = callIamApi(builder.build());
return tokenData.getAccessToken();
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Refresh an IAM token using a refresh token. Also updates internal managed IAM token information.
*
* @return the new access token
*/
private String refreshToken() {
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(url, new String[0]));
builder.header(HttpHeaders.CONTENT_TYPE, HttpMediaType.APPLICATION_FORM_URLENCODED);
builder.header(HttpHeaders.AUTHORIZATION, DEFAULT_AUTHORIZATION);
FormBody formBody = new FormBody.Builder()
.add(GRANT_TYPE, REFRESH_GRANT_TYPE)
.add(REFRESH_TOKEN, tokenData.getRefreshToken())
.build();
builder.body(formBody);
tokenData = callIamApi(builder.build());
return tokenData.getAccessToken();
}
代码示例来源:origin: watson-developer-cloud/java-sdk
/**
* Request an IAM token using an API key. Also updates internal managed IAM token information.
*
* @return the new access token
*/
private String requestToken() {
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(url, new String[0]));
builder.header(HttpHeaders.CONTENT_TYPE, HttpMediaType.APPLICATION_FORM_URLENCODED);
builder.header(HttpHeaders.AUTHORIZATION, DEFAULT_AUTHORIZATION);
FormBody formBody = new FormBody.Builder()
.add(GRANT_TYPE, REQUEST_GRANT_TYPE)
.add(API_KEY, apiKey)
.add(RESPONSE_TYPE, CLOUD_IAM)
.build();
builder.body(formBody);
tokenData = callIamApi(builder.build());
return tokenData.getAccessToken();
}
代码示例来源:origin: com.ibm.watson.developer_cloud/core
/**
* Request an IAM token using an API key. Also updates internal managed IAM token information.
*
* @return the new access token
*/
private String requestToken() {
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(url, new String[0]));
builder.header(HttpHeaders.CONTENT_TYPE, HttpMediaType.APPLICATION_FORM_URLENCODED);
builder.header(HttpHeaders.AUTHORIZATION, DEFAULT_AUTHORIZATION);
FormBody formBody = new FormBody.Builder()
.add(GRANT_TYPE, REQUEST_GRANT_TYPE)
.add(API_KEY, apiKey)
.add(RESPONSE_TYPE, CLOUD_IAM)
.build();
builder.body(formBody);
tokenData = callIamApi(builder.build());
return tokenData.getAccessToken();
}
代码示例来源:origin: com.ibm.watson.developer_cloud/natural-language-classifier
/**
* List classifiers.
*
* Returns an empty array if no classifiers are available.
*
* @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link ClassifierList}
*/
public ServiceCall<ClassifierList> listClassifiers(ListClassifiersOptions listClassifiersOptions) {
String[] pathSegments = { "v1/classifiers" };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=natural_language_classifier;service_version=v1;operation_id=listClassifiers");
if (listClassifiersOptions != null) {
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(ClassifierList.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/text-to-speech
/**
* List voices.
*
* Lists all voices available for use with the service. The information includes the name, language, gender, and other
* details about the voice. To see information about a specific voice, use the **Get a voice** method.
*
* **See also:** [Specifying a voice](https://cloud.ibm.com/docs/services/text-to-speech/http.html#voices).
*
* @param listVoicesOptions the {@link ListVoicesOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Voices}
*/
public ServiceCall<Voices> listVoices(ListVoicesOptions listVoicesOptions) {
String[] pathSegments = { "v1/voices" };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=text_to_speech;service_version=v1;operation_id=listVoices");
if (listVoicesOptions != null) {
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Voices.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/visual-recognition
/**
* Retrieve a list of classifiers.
*
* @param listClassifiersOptions the {@link ListClassifiersOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifiers}
*/
public ServiceCall<Classifiers> listClassifiers(ListClassifiersOptions listClassifiersOptions) {
String[] pathSegments = { "v3/classifiers" };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=watson_vision_combined;service_version=v3;operation_id=listClassifiers");
if (listClassifiersOptions != null) {
if (listClassifiersOptions.verbose() != null) {
builder.query("verbose", String.valueOf(listClassifiersOptions.verbose()));
}
}
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifiers.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/natural-language-classifier
/**
* Delete classifier.
*
* @param deleteClassifierOptions the {@link DeleteClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) {
Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null");
String[] pathSegments = { "v1/classifiers" };
String[] pathParameters = { deleteClassifierOptions.classifierId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=natural_language_classifier;service_version=v1;operation_id=deleteClassifier");
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/speech-to-text
/**
* Get a model.
*
* Gets information for a single specified language model that is available for use with the service. The information
* includes the name of the model and its minimum sampling rate in Hertz, among other things.
*
* **See also:** [Languages and models](https://cloud.ibm.com/docs/services/speech-to-text/models.html).
*
* @param getModelOptions the {@link GetModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link SpeechModel}
*/
public ServiceCall<SpeechModel> getModel(GetModelOptions getModelOptions) {
Validator.notNull(getModelOptions, "getModelOptions cannot be null");
String[] pathSegments = { "v1/models" };
String[] pathParameters = { getModelOptions.modelId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.header("X-IBMCloud-SDK-Analytics", "service_name=speech_to_text;service_version=v1;operation_id=getModel");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(SpeechModel.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/speech-to-text
/**
* Get a custom language model.
*
* Gets information about a specified custom language model. You must use credentials for the instance of the service
* that owns a model to list information about it.
*
* **See also:** [Listing custom language
* models](https://cloud.ibm.com/docs/services/speech-to-text/language-models.html#listModels).
*
* @param getLanguageModelOptions the {@link GetLanguageModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link LanguageModel}
*/
public ServiceCall<LanguageModel> getLanguageModel(GetLanguageModelOptions getLanguageModelOptions) {
Validator.notNull(getLanguageModelOptions, "getLanguageModelOptions cannot be null");
String[] pathSegments = { "v1/customizations" };
String[] pathParameters = { getLanguageModelOptions.customizationId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=speech_to_text;service_version=v1;operation_id=getLanguageModel");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(LanguageModel.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/natural-language-classifier
/**
* Get information about a classifier.
*
* Returns status and other information about a classifier.
*
* @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifier}
*/
public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) {
Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null");
String[] pathSegments = { "v1/classifiers" };
String[] pathParameters = { getClassifierOptions.classifierId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=natural_language_classifier;service_version=v1;operation_id=getClassifier");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.class));
}
代码示例来源:origin: com.ibm.watson.developer_cloud/visual-recognition
/**
* Delete a classifier.
*
* @param deleteClassifierOptions the {@link DeleteClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteClassifier(DeleteClassifierOptions deleteClassifierOptions) {
Validator.notNull(deleteClassifierOptions, "deleteClassifierOptions cannot be null");
String[] pathSegments = { "v3/classifiers" };
String[] pathParameters = { deleteClassifierOptions.classifierId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=watson_vision_combined;service_version=v3;operation_id=deleteClassifier");
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/visual-recognition
/**
* Retrieve a Core ML model of a classifier.
*
* Download a Core ML model file (.mlmodel) of a custom classifier that returns <tt>\"core_ml_enabled\": true</tt> in
* the classifier details.
*
* @param getCoreMlModelOptions the {@link GetCoreMlModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link InputStream}
*/
public ServiceCall<InputStream> getCoreMlModel(GetCoreMlModelOptions getCoreMlModelOptions) {
Validator.notNull(getCoreMlModelOptions, "getCoreMlModelOptions cannot be null");
String[] pathSegments = { "v3/classifiers", "core_ml_model" };
String[] pathParameters = { getCoreMlModelOptions.classifierId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=watson_vision_combined;service_version=v3;operation_id=getCoreMlModel");
return createServiceCall(builder.build(), ResponseConverterUtils.getInputStream());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/language-translator
/**
* Delete model.
*
* Deletes a custom translation model.
*
* @param deleteModelOptions the {@link DeleteModelOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> deleteModel(DeleteModelOptions deleteModelOptions) {
Validator.notNull(deleteModelOptions, "deleteModelOptions cannot be null");
String[] pathSegments = { "v3/models" };
String[] pathParameters = { deleteModelOptions.modelId() };
RequestBuilder builder = RequestBuilder.delete(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=language_translator;service_version=v3;operation_id=deleteModel");
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
代码示例来源:origin: com.ibm.watson.developer_cloud/visual-recognition
/**
* Retrieve classifier details.
*
* Retrieve information about a custom classifier.
*
* @param getClassifierOptions the {@link GetClassifierOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of {@link Classifier}
*/
public ServiceCall<Classifier> getClassifier(GetClassifierOptions getClassifierOptions) {
Validator.notNull(getClassifierOptions, "getClassifierOptions cannot be null");
String[] pathSegments = { "v3/classifiers" };
String[] pathParameters = { getClassifierOptions.classifierId() };
RequestBuilder builder = RequestBuilder.get(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments,
pathParameters));
builder.query(VERSION, versionDate);
builder.header("X-IBMCloud-SDK-Analytics",
"service_name=watson_vision_combined;service_version=v3;operation_id=getClassifier");
return createServiceCall(builder.build(), ResponseConverterUtils.getObject(Classifier.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));
}
内容来源于网络,如有侵权,请联系作者删除!