use of okhttp3.Request.Builder in project Fast-Android-Networking by amitshekhariitbhu.
the class Rx2InternalNetworking method generateSimpleObservable.
public static <T> Observable<T> generateSimpleObservable(Rx2ANRequest request) {
Request okHttpRequest;
Request.Builder builder = new Request.Builder().url(request.getUrl());
InternalNetworking.addHeadersToRequestBuilder(builder, request);
RequestBody requestBody;
switch(request.getMethod()) {
case GET:
{
builder = builder.get();
break;
}
case POST:
{
requestBody = request.getRequestBody();
builder = builder.post(requestBody);
break;
}
case PUT:
{
requestBody = request.getRequestBody();
builder = builder.put(requestBody);
break;
}
case DELETE:
{
requestBody = request.getRequestBody();
builder = builder.delete(requestBody);
break;
}
case HEAD:
{
builder = builder.head();
break;
}
case PATCH:
{
requestBody = request.getRequestBody();
builder = builder.patch(requestBody);
break;
}
}
if (request.getCacheControl() != null) {
builder.cacheControl(request.getCacheControl());
}
okHttpRequest = builder.build();
if (request.getOkHttpClient() != null) {
request.setCall(request.getOkHttpClient().newBuilder().cache(InternalNetworking.sHttpClient.cache()).build().newCall(okHttpRequest));
} else {
request.setCall(InternalNetworking.sHttpClient.newCall(okHttpRequest));
}
return new SimpleANObservable<>(request);
}
use of okhttp3.Request.Builder in project keywhiz by square.
the class ClientResourceTest method clientDelete_success.
@Test
public void clientDelete_success() throws Exception {
// Sample client
create(CreateClientRequestV2.builder().name("to-delete").build());
// Deleting is successful
Response httpResponse = delete("to-delete");
assertThat(httpResponse.code()).isEqualTo(204);
// Deleting again produces not-found
httpResponse = delete("to-delete");
assertThat(httpResponse.code()).isEqualTo(404);
}
use of okhttp3.Request.Builder in project keywhiz by square.
the class ClientResourceTest method modifyClientGroups_notFound.
@Test
public void modifyClientGroups_notFound() throws Exception {
ModifyGroupsRequestV2 request = ModifyGroupsRequestV2.builder().build();
RequestBody body = RequestBody.create(JSON, mapper.writeValueAsString(request));
Request put = clientRequest("/automation/v2/clients/non-existent/groups").put(body).build();
Response httpResponse = mutualSslClient.newCall(put).execute();
assertThat(httpResponse.code()).isEqualTo(404);
}
use of okhttp3.Request.Builder in project keywhiz by square.
the class SecretResourceTest method createSecret_successUnVersioned.
//---------------------------------------------------------------------------------------
// createSecret
//---------------------------------------------------------------------------------------
@Test
public void createSecret_successUnVersioned() throws Exception {
CreateSecretRequestV2 request = CreateSecretRequestV2.builder().name("secret1").content(encoder.encodeToString("supa secret".getBytes(UTF_8))).description("desc").metadata(ImmutableMap.of("owner", "root", "mode", "0440")).type("password").build();
Response httpResponse = create(request);
assertThat(httpResponse.code()).isEqualTo(201);
URI location = URI.create(httpResponse.header(LOCATION));
assertThat(location.getPath()).isEqualTo("/automation/v2/secrets/secret1");
}
use of okhttp3.Request.Builder in project keywhiz by square.
the class SecretResourceTest method backfillExpirationTest.
//---------------------------------------------------------------------------------------
// backfillExpiration
//---------------------------------------------------------------------------------------
@Test
public void backfillExpirationTest() throws Exception {
byte[] certs = Resources.toByteArray(Resources.getResource("fixtures/expiring-certificates.crt"));
byte[] pubring = Resources.toByteArray(Resources.getResource("fixtures/expiring-pubring.gpg"));
byte[] p12 = Resources.toByteArray(Resources.getResource("fixtures/expiring-keystore.p12"));
byte[] jceks = Resources.toByteArray(Resources.getResource("fixtures/expiring-keystore.jceks"));
create(CreateSecretRequestV2.builder().name("certificate-chain.crt").content(encoder.encodeToString(certs)).build());
create(CreateSecretRequestV2.builder().name("public-keyring.gpg").content(encoder.encodeToString(pubring)).build());
create(CreateSecretRequestV2.builder().name("keystore.p12").content(encoder.encodeToString(p12)).build());
create(CreateSecretRequestV2.builder().name("keystore.jceks").content(encoder.encodeToString(jceks)).build());
Response response = backfillExpiration("certificate-chain.crt", ImmutableList.of());
assertThat(response.isSuccessful()).isTrue();
response = backfillExpiration("public-keyring.gpg", ImmutableList.of());
assertThat(response.isSuccessful()).isTrue();
response = backfillExpiration("keystore.p12", ImmutableList.of("password"));
assertThat(response.isSuccessful()).isTrue();
response = backfillExpiration("keystore.jceks", ImmutableList.of("password"));
assertThat(response.isSuccessful()).isTrue();
SecretDetailResponseV2 details = lookup("certificate-chain.crt");
assertThat(details.expiry()).isEqualTo(1501533950);
details = lookup("public-keyring.gpg");
assertThat(details.expiry()).isEqualTo(1536442365);
details = lookup("keystore.p12");
assertThat(details.expiry()).isEqualTo(1681596851);
details = lookup("keystore.jceks");
assertThat(details.expiry()).isEqualTo(1681596851);
}
Aggregations