use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
use of okhttp3.Credentials in project mbed-cloud-sdk-java by ARMmbed.
the class HttpBasicAuth method intercept.
@Override
public Response intercept(Chain chain) throws IOException {
Request request = chain.request();
// If the request already have an authorization (eg. Basic auth), do nothing
if (request.header("Authorization") == null) {
String credentials = Credentials.basic(username, password);
request = request.newBuilder().addHeader("Authorization", credentials).build();
}
return chain.proceed(request);
}
use of okhttp3.Credentials in project java-sdk by watson-developer-cloud.
the class SpeechToText method addCorpus.
/**
* Adds a corpus text file to a custom language model.
*
* Adds a single corpus text file of new training data to a custom language model. Use multiple requests to submit
* multiple corpus text files. You must use credentials for the instance of the service that owns a model to add a
* corpus to it. Note that adding a corpus does not affect the custom language model until you train the model for the
* new data by using the `POST /v1/customizations/{customization_id}/train` method. Submit a plain text file that
* contains sample sentences from the domain of interest to enable the service to extract words in context. The more
* sentences you add that represent the context in which speakers use words from the domain, the better the service's
* recognition accuracy. For guidelines about adding a corpus text file and for information about how the service
* parses a corpus file, see [Preparing a corpus text
* file](https://console.bluemix.net/docs/services/speech-to-text/language-resource.html#prepareCorpus). The call
* returns an HTTP 201 response code if the corpus is valid. The service then asynchronously processes the contents of
* the corpus and automatically extracts new words that it finds. This can take on the order of a minute or two to
* complete depending on the total number of words and the number of new words in the corpus, as well as the current
* load on the service. You cannot submit requests to add additional corpora or words to the custom model, or to train
* the model, until the service's analysis of the corpus for the current request completes. Use the `GET
* /v1/customizations/{customization_id}/corpora/{corpus_name}` method to check the status of the analysis. The
* service auto-populates the model's words resource with any word that is not found in its base vocabulary; these are
* referred to as out-of-vocabulary (OOV) words. You can use the `GET /v1/customizations/{customization_id}/words`
* method to examine the words resource, using other words method to eliminate typos and modify how words are
* pronounced as needed. To add a corpus file that has the same name as an existing corpus, set the allow_overwrite
* query parameter to true; otherwise, the request fails. Overwriting an existing corpus causes the service to process
* the corpus text file and extract OOV words anew. Before doing so, it removes any OOV words associated with the
* existing corpus from the model's words resource unless they were also added by another corpus or they have been
* modified in some way with the `POST /v1/customizations/{customization_id}/words` or `PUT
* /v1/customizations/{customization_id}/words/{word_name}` method. The service limits the overall amount of data that
* you can add to a custom model to a maximum of 10 million total words from all corpora combined. Also, you can add
* no more than 30 thousand new custom words to a model; this includes words that the service extracts from corpora
* and words that you add directly.
*
* @param addCorpusOptions the {@link AddCorpusOptions} containing the options for the call
* @return a {@link ServiceCall} with a response type of Void
*/
public ServiceCall<Void> addCorpus(AddCorpusOptions addCorpusOptions) {
Validator.notNull(addCorpusOptions, "addCorpusOptions cannot be null");
String[] pathSegments = { "v1/customizations", "corpora" };
String[] pathParameters = { addCorpusOptions.customizationId(), addCorpusOptions.corpusName() };
RequestBuilder builder = RequestBuilder.post(RequestBuilder.constructHttpUrl(getEndPoint(), pathSegments, pathParameters));
if (addCorpusOptions.allowOverwrite() != null) {
builder.query("allow_overwrite", String.valueOf(addCorpusOptions.allowOverwrite()));
}
MultipartBody.Builder multipartBuilder = new MultipartBody.Builder();
multipartBuilder.setType(MultipartBody.FORM);
RequestBody corpusFileBody = RequestUtils.inputStreamBody(addCorpusOptions.corpusFile(), addCorpusOptions.corpusFileContentType());
multipartBuilder.addFormDataPart("corpus_file", addCorpusOptions.corpusFilename(), corpusFileBody);
builder.body(multipartBuilder.build());
return createServiceCall(builder.build(), ResponseConverterUtils.getVoid());
}
use of okhttp3.Credentials in project okhttp-digest by rburgst.
the class AuthenticationCacheInterceptorTest method givenCachedAuthenticationFor.
private void givenCachedAuthenticationFor(String url, Map<String, CachingAuthenticator> authCache) throws IOException {
Authenticator decorator = new CachingAuthenticatorDecorator(new BasicAuthenticator(new Credentials("user1", "user1")), authCache);
Request dummyRequest = new Request.Builder().url(url).get().build();
Response response = new Response.Builder().request(dummyRequest).protocol(Protocol.HTTP_1_1).code(HTTP_UNAUTHORIZED).message("Unauthorized").header("WWW-Authenticate", "Basic realm=\"myrealm\"").build();
decorator.authenticate(null, response);
}
Aggregations