Search in sources :

Example 46 with Request

use of okhttp3.Request in project azure-sdk-for-java by Azure.

the class AuthenticationTests method canCRUDWebAppWithAuthentication.

@Test
@Ignore("Need facebook developer account")
public void canCRUDWebAppWithAuthentication() throws Exception {
    // Create with new app service plan
    WebApp webApp1 = appServiceManager.webApps().define(WEBAPP_NAME_1).withRegion(Region.US_WEST).withNewResourceGroup(RG_NAME_1).withNewWindowsPlan(PricingTier.BASIC_B1).defineAuthentication().withDefaultAuthenticationProvider(BuiltInAuthenticationProvider.FACEBOOK).withFacebook("appId", "appSecret").attach().create();
    Assert.assertNotNull(webApp1);
    Assert.assertEquals(Region.US_WEST, webApp1.region());
    AppServicePlan plan1 = appServiceManager.appServicePlans().getById(webApp1.appServicePlanId());
    Assert.assertNotNull(plan1);
    Assert.assertEquals(Region.US_WEST, plan1.region());
    Assert.assertEquals(PricingTier.BASIC_B1, plan1.pricingTier());
    Request request = new Request.Builder().url("http://" + webApp1.defaultHostName()).get().build();
    String response = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build().newCall(request).execute().body().string();
    Assert.assertTrue(response.contains("do not have permission"));
    // Update
    webApp1.update().updateAuthentication().withAnonymousAuthentication().parent().apply();
    request = new Request.Builder().url("http://" + webApp1.defaultHostName()).get().build();
    response = new OkHttpClient.Builder().readTimeout(1, TimeUnit.MINUTES).build().newCall(request).execute().body().string();
    Assert.assertFalse(response.contains("do not have permission"));
}
Also used : OkHttpClient(okhttp3.OkHttpClient) Request(okhttp3.Request) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 47 with Request

use of okhttp3.Request in project azure-sdk-for-java by Azure.

the class JobSchedulesImpl method patchAsync.

/**
     * Updates the properties of the specified job schedule.
     *
     * @param jobScheduleId The id of the job schedule to update.
     * @param jobSchedulePatchParameter The parameters for the request.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall patchAsync(String jobScheduleId, JobSchedulePatchParameter jobSchedulePatchParameter, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobScheduleId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleId is required and cannot be null."));
        return null;
    }
    if (jobSchedulePatchParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobSchedulePatchParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobSchedulePatchParameter, serviceCallback);
    final JobSchedulePatchOptions jobSchedulePatchOptions = null;
    Integer timeout = null;
    String clientRequestId = null;
    Boolean returnClientRequestId = null;
    DateTime ocpDate = null;
    String ifMatch = null;
    String ifNoneMatch = null;
    DateTime ifModifiedSince = null;
    DateTime ifUnmodifiedSince = null;
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.patch(jobScheduleId, jobSchedulePatchParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(patchDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) JobSchedulePatchOptions(com.microsoft.azure.batch.protocol.models.JobSchedulePatchOptions) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 48 with Request

use of okhttp3.Request in project azure-sdk-for-java by Azure.

the class JobSchedulesImpl method updateAsync.

/**
     * Updates the properties of the specified job schedule.
     *
     * @param jobScheduleId The id of the job schedule to update.
     * @param jobScheduleUpdateParameter The parameters for the request.
     * @param jobScheduleUpdateOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall updateAsync(String jobScheduleId, JobScheduleUpdateParameter jobScheduleUpdateParameter, JobScheduleUpdateOptions jobScheduleUpdateOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobScheduleId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleId is required and cannot be null."));
        return null;
    }
    if (jobScheduleUpdateParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobScheduleUpdateParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobScheduleUpdateParameter, serviceCallback);
    Validator.validate(jobScheduleUpdateOptions, serviceCallback);
    Integer timeout = null;
    if (jobScheduleUpdateOptions != null) {
        timeout = jobScheduleUpdateOptions.timeout();
    }
    String clientRequestId = null;
    if (jobScheduleUpdateOptions != null) {
        clientRequestId = jobScheduleUpdateOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobScheduleUpdateOptions != null) {
        returnClientRequestId = jobScheduleUpdateOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobScheduleUpdateOptions != null) {
        ocpDate = jobScheduleUpdateOptions.ocpDate();
    }
    String ifMatch = null;
    if (jobScheduleUpdateOptions != null) {
        ifMatch = jobScheduleUpdateOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (jobScheduleUpdateOptions != null) {
        ifNoneMatch = jobScheduleUpdateOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (jobScheduleUpdateOptions != null) {
        ifModifiedSince = jobScheduleUpdateOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (jobScheduleUpdateOptions != null) {
        ifUnmodifiedSince = jobScheduleUpdateOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.update(jobScheduleId, jobScheduleUpdateParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(updateDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 49 with Request

use of okhttp3.Request in project azure-sdk-for-java by Azure.

the class JobsImpl method patchAsync.

/**
     * Updates the properties of a job.
     *
     * @param jobId The id of the job whose properties you want to update.
     * @param jobPatchParameter The parameters for the request.
     * @param jobPatchOptions Additional parameters for the operation
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall patchAsync(String jobId, JobPatchParameter jobPatchParameter, JobPatchOptions jobPatchOptions, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (jobId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobId is required and cannot be null."));
        return null;
    }
    if (jobPatchParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter jobPatchParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(jobPatchParameter, serviceCallback);
    Validator.validate(jobPatchOptions, serviceCallback);
    Integer timeout = null;
    if (jobPatchOptions != null) {
        timeout = jobPatchOptions.timeout();
    }
    String clientRequestId = null;
    if (jobPatchOptions != null) {
        clientRequestId = jobPatchOptions.clientRequestId();
    }
    Boolean returnClientRequestId = null;
    if (jobPatchOptions != null) {
        returnClientRequestId = jobPatchOptions.returnClientRequestId();
    }
    DateTime ocpDate = null;
    if (jobPatchOptions != null) {
        ocpDate = jobPatchOptions.ocpDate();
    }
    String ifMatch = null;
    if (jobPatchOptions != null) {
        ifMatch = jobPatchOptions.ifMatch();
    }
    String ifNoneMatch = null;
    if (jobPatchOptions != null) {
        ifNoneMatch = jobPatchOptions.ifNoneMatch();
    }
    DateTime ifModifiedSince = null;
    if (jobPatchOptions != null) {
        ifModifiedSince = jobPatchOptions.ifModifiedSince();
    }
    DateTime ifUnmodifiedSince = null;
    if (jobPatchOptions != null) {
        ifUnmodifiedSince = jobPatchOptions.ifUnmodifiedSince();
    }
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.patch(jobId, jobPatchParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(patchDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Example 50 with Request

use of okhttp3.Request in project azure-sdk-for-java by Azure.

the class PoolsImpl method resizeAsync.

/**
     * Changes the number of compute nodes that are assigned to a pool.
     *
     * @param poolId The id of the pool to resize.
     * @param poolResizeParameter The parameters for the request.
     * @param serviceCallback the async ServiceCallback to handle successful and failed responses.
     * @throws IllegalArgumentException thrown if callback is null
     * @return the {@link Call} object
     */
public ServiceCall resizeAsync(String poolId, PoolResizeParameter poolResizeParameter, final ServiceCallback<Void> serviceCallback) throws IllegalArgumentException {
    if (serviceCallback == null) {
        throw new IllegalArgumentException("ServiceCallback is required for async calls.");
    }
    if (poolId == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolId is required and cannot be null."));
        return null;
    }
    if (poolResizeParameter == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter poolResizeParameter is required and cannot be null."));
        return null;
    }
    if (this.client.apiVersion() == null) {
        serviceCallback.failure(new IllegalArgumentException("Parameter this.client.apiVersion() is required and cannot be null."));
        return null;
    }
    Validator.validate(poolResizeParameter, serviceCallback);
    final PoolResizeOptions poolResizeOptions = null;
    Integer timeout = null;
    String clientRequestId = null;
    Boolean returnClientRequestId = null;
    DateTime ocpDate = null;
    String ifMatch = null;
    String ifNoneMatch = null;
    DateTime ifModifiedSince = null;
    DateTime ifUnmodifiedSince = null;
    DateTimeRfc1123 ocpDateConverted = null;
    if (ocpDate != null) {
        ocpDateConverted = new DateTimeRfc1123(ocpDate);
    }
    DateTimeRfc1123 ifModifiedSinceConverted = null;
    if (ifModifiedSince != null) {
        ifModifiedSinceConverted = new DateTimeRfc1123(ifModifiedSince);
    }
    DateTimeRfc1123 ifUnmodifiedSinceConverted = null;
    if (ifUnmodifiedSince != null) {
        ifUnmodifiedSinceConverted = new DateTimeRfc1123(ifUnmodifiedSince);
    }
    Call<ResponseBody> call = service.resize(poolId, poolResizeParameter, this.client.apiVersion(), this.client.acceptLanguage(), timeout, clientRequestId, returnClientRequestId, ocpDateConverted, ifMatch, ifNoneMatch, ifModifiedSinceConverted, ifUnmodifiedSinceConverted, this.client.userAgent());
    final ServiceCall serviceCall = new ServiceCall(call);
    call.enqueue(new ServiceResponseCallback<Void>(serviceCallback) {

        @Override
        public void onResponse(Call<ResponseBody> call, Response<ResponseBody> response) {
            try {
                serviceCallback.success(resizeDelegate(response));
            } catch (BatchErrorException | IOException exception) {
                serviceCallback.failure(exception);
            }
        }
    });
    return serviceCall;
}
Also used : ServiceCall(com.microsoft.rest.ServiceCall) PoolResizeOptions(com.microsoft.azure.batch.protocol.models.PoolResizeOptions) DateTime(org.joda.time.DateTime) ResponseBody(okhttp3.ResponseBody) DateTimeRfc1123(com.microsoft.rest.DateTimeRfc1123)

Aggregations

Request (okhttp3.Request)1552 Response (okhttp3.Response)1090 Test (org.junit.Test)948 IOException (java.io.IOException)624 MockResponse (okhttp3.mockwebserver.MockResponse)560 RecordedRequest (okhttp3.mockwebserver.RecordedRequest)556 OkHttpClient (okhttp3.OkHttpClient)343 RequestBody (okhttp3.RequestBody)281 Call (okhttp3.Call)255 ResponseBody (okhttp3.ResponseBody)252 HttpUrl (okhttp3.HttpUrl)186 Test (org.junit.jupiter.api.Test)158 WatsonServiceUnitTest (com.ibm.watson.developer_cloud.WatsonServiceUnitTest)142 Buffer (okio.Buffer)138 List (java.util.List)114 Callback (okhttp3.Callback)114 File (java.io.File)105 URI (java.net.URI)101 InputStream (java.io.InputStream)99 JSONObject (org.json.JSONObject)96