use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project natural-voice-mobile-sdk-android by aimmatic.
the class AimMatic method fetchUserProfile.
/**
* Fetch user profile
*
* @param token a valid token
* @param callback a callback function to notice when request is success or failure
*/
public static void fetchUserProfile(String token, final Callback<Profile> callback) {
OkHttpClient okHttpClient = new OkHttpClient();
Request request = new Request.Builder().url(String.format("%s/v1/profile", service)).addHeader("Authorization", "Bearer " + token).build();
okHttpClient.newCall(request).enqueue(new okhttp3.Callback() {
@Override
public void onFailure(Call call, IOException e) {
callback.onError(e);
}
@Override
public void onResponse(Call call, Response response) throws IOException {
try {
ProfileResponse profileResponse = new Gson().fromJson(response.body().string(), ProfileResponse.class);
callback.onSuccess(profileResponse.getProfile());
} catch (Exception e) {
if (response.code() != 200) {
callback.onError(new Exception("Server reply with status " + response.code()));
} else {
callback.onError(e);
}
}
}
});
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project intellij-common by redhat-developer.
the class NetworkUtils method getClient.
public static OkHttpClient getClient() {
final HttpConfigurable httpConfigurable = HttpConfigurable.getInstance();
final IdeaWideProxySelector ideaWideProxySelector = new IdeaWideProxySelector(httpConfigurable);
final IdeaWideAuthenticator ideaWideAuthenticator = new IdeaWideAuthenticator(httpConfigurable);
final Authenticator proxyAuthenticator = getProxyAuthenticator(ideaWideAuthenticator);
final OkHttpClient.Builder builder = new OkHttpClient.Builder();
builder.proxySelector(ideaWideProxySelector).proxyAuthenticator(proxyAuthenticator);
return builder.build();
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project fineract by apache.
the class ThitsaWorksCreditBureauIntegrationWritePlatformServiceImpl method okHttpConnectionMethod.
@Transactional
@Override
@SuppressWarnings("deprecation")
public String okHttpConnectionMethod(String userName, String password, String subscriptionKey, String subscriptionId, String url, String token, File file, FormDataContentDisposition fileData, Long uniqueId, String nrcId, String process) {
String reponseMessage = null;
RequestBody requestBody = null;
OkHttpClient client = new OkHttpClient();
if (process.equals("UploadCreditReport")) {
String fileName = fileData.getFileName();
requestBody = RequestBody.create(file, MediaType.parse("multipart/form-data"));
requestBody = new MultipartBody.Builder().setType(MultipartBody.FORM).addFormDataPart("file", fileName, requestBody).addFormDataPart("BODY", "formdata").addFormDataPart("userName", userName).build();
} else if (process.equals("token")) {
final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
String jsonBody = "" + "BODY=x-www-form-urlencoded&\r" + "grant_type=password&\r" + "userName=" + userName + "&\r" + "password=" + password + "&\r";
requestBody = RequestBody.create(jsonBody, mediaType);
} else if (process.equals("NRC")) {
final MediaType mediaType = MediaType.parse("application/x-www-form-urlencoded");
String jsonBody = "BODY=x-www-form-urlencoded&nrc=" + nrcId + "&";
requestBody = RequestBody.create(jsonBody, mediaType);
}
HttpUrl.Builder urlBuilder = HttpUrl.parse(url).newBuilder();
String urlokhttp = urlBuilder.build().toString();
Request request = null;
if (token == null) {
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").url(urlokhttp).post(requestBody).build();
}
if (token != null) {
if (process.equals("CreditReport")) {
// GET method for fetching credit report
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").header("Authorization", "Bearer " + token).url(urlokhttp).get().build();
} else if (process.equals("UploadCreditReport")) {
// POST for uploading Credit-Report(multipart/form-data)
// To ThitsaWork
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "multipart/form-data").header("Authorization", "Bearer " + token).url(urlokhttp).post(requestBody).build();
} else {
// POST method for application/x-www-form-urlencoded
request = new Request.Builder().header("mcix-subscription-key", subscriptionKey).header("mcix-subscription-id", subscriptionId).header("Content-Type", "application/x-www-form-urlencoded").header("Authorization", "Bearer " + token).url(urlokhttp).post(requestBody).build();
}
}
Response response;
Integer responseCode = 0;
try {
response = client.newCall(request).execute();
responseCode = response.code();
reponseMessage = response.body().string();
} catch (IOException e) {
LOG.error("error occured in HTTP request-response method.", e);
}
if (responseCode != HttpURLConnection.HTTP_OK) {
this.httpResponse(responseCode, reponseMessage);
}
if (process.equals("UploadCreditReport")) {
// to show the Response on frontEnd
JsonObject reportObject = JsonParser.parseString(reponseMessage).getAsJsonObject();
String ResponseMessageJson = reportObject.get("ResponseMessage").getAsString();
this.handleAPIIntegrityIssues(ResponseMessageJson);
}
return reponseMessage;
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project fineract by apache.
the class ProcessorHelper method createWebHookService.
public WebHookService createWebHookService(final String url) {
final OkHttpClient client = createClient();
final Retrofit.Builder retrofitBuilder = new Retrofit.Builder();
retrofitBuilder.baseUrl(url);
retrofitBuilder.client(client);
retrofitBuilder.addConverterFactory(GsonConverterFactory.create());
final Retrofit retrofit = retrofitBuilder.build();
return retrofit.create(WebHookService.class);
}
use of com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient in project axonserver-connector-java by AxonIQ.
the class AbstractAxonServerIntegrationTest method initialize.
@BeforeAll
static void initialize() throws IOException {
client = new OkHttpClient();
axonServerAddress = new ServerAddress(toxiProxyContainer.getContainerIpAddress(), toxiProxyContainer.getMappedPort(8124));
axonServerHttpPort = new ServerAddress(axonServerContainer.getContainerIpAddress(), axonServerContainer.getMappedPort(8024));
ToxiproxyClient client = new ToxiproxyClient(toxiProxyContainer.getContainerIpAddress(), toxiProxyContainer.getMappedPort(8474));
axonServerProxy = getOrCreateProxy(client, "axonserver", "0.0.0.0:8124", "axonserver:8124");
}
Aggregations