Search in sources :

Example 21 with Credentials

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);
}
Also used : Request(okhttp3.Request)

Example 22 with Credentials

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);
}
Also used : Request(okhttp3.Request)

Example 23 with Credentials

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);
}
Also used : Request(okhttp3.Request)

Example 24 with Credentials

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());
}
Also used : RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) MultipartBody(okhttp3.MultipartBody) RequestBuilder(com.ibm.watson.developer_cloud.http.RequestBuilder) RequestBody(okhttp3.RequestBody) InputStreamRequestBody(com.ibm.watson.developer_cloud.http.InputStreamRequestBody)

Example 25 with Credentials

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);
}
Also used : Response(okhttp3.Response) BasicAuthenticator(com.burgstaller.okhttp.basic.BasicAuthenticator) Request(okhttp3.Request) Authenticator(okhttp3.Authenticator) CachingAuthenticator(com.burgstaller.okhttp.digest.CachingAuthenticator) BasicAuthenticator(com.burgstaller.okhttp.basic.BasicAuthenticator) Credentials(com.burgstaller.okhttp.digest.Credentials)

Aggregations

Request (okhttp3.Request)39 Response (okhttp3.Response)29 OkHttpClient (okhttp3.OkHttpClient)22 IOException (java.io.IOException)20 Test (org.junit.Test)16 HttpUrl (okhttp3.HttpUrl)10 RequestBody (okhttp3.RequestBody)9 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)9 ResponseBody (okhttp3.ResponseBody)8 NonNull (androidx.annotation.NonNull)7 MockResponse (okhttp3.mockwebserver.MockResponse)7 BasicAuthenticator (com.burgstaller.okhttp.basic.BasicAuthenticator)6 CachingAuthenticator (com.burgstaller.okhttp.digest.CachingAuthenticator)6 Credentials (com.burgstaller.okhttp.digest.Credentials)6 DigestAuthenticator (com.burgstaller.okhttp.digest.DigestAuthenticator)6 Observable (rx.Observable)6 AuthenticationCacheInterceptor (com.burgstaller.okhttp.AuthenticationCacheInterceptor)5 CachingAuthenticatorDecorator (com.burgstaller.okhttp.CachingAuthenticatorDecorator)5 PokemonGo (com.pokegoapi.api.PokemonGo)5 PtcCredentialProvider (com.pokegoapi.auth.PtcCredentialProvider)5