use of okhttp3.OkHttpClient in project sonarqube by SonarSource.
the class OkHttpClientProviderTest method get_returns_a_singleton.
@Test
public void get_returns_a_singleton() {
OkHttpClient client1 = underTest.provide(settings, runtime);
OkHttpClient client2 = underTest.provide(settings, runtime);
assertThat(client2).isNotNull().isSameAs(client1);
}
use of okhttp3.OkHttpClient in project Pokemap by omkarmoghe.
the class NianticManager method loginPTC.
private void loginPTC(final String username, final String password, NianticService.LoginValues values, final LoginListener loginListener) {
HttpUrl url = HttpUrl.parse(LOGIN_URL).newBuilder().addQueryParameter("lt", values.getLt()).addQueryParameter("execution", values.getExecution()).addQueryParameter("_eventId", "submit").addQueryParameter("username", username).addQueryParameter("password", password).build();
OkHttpClient client = mClient.newBuilder().followRedirects(false).followSslRedirects(false).build();
NianticService service = new Retrofit.Builder().baseUrl(BASE_URL).addConverterFactory(GsonConverterFactory.create()).client(client).build().create(NianticService.class);
Callback<NianticService.LoginResponse> loginCallback = new Callback<NianticService.LoginResponse>() {
@Override
public void onResponse(Call<NianticService.LoginResponse> call, Response<NianticService.LoginResponse> response) {
String location = response.headers().get("location");
if (location != null && location.split("ticket=").length > 0) {
String ticket = location.split("ticket=")[1];
requestToken(ticket, loginListener);
} else {
Log.e(TAG, "PTC login failed via loginPTC(). There was no location header in response.");
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
}
@Override
public void onFailure(Call<NianticService.LoginResponse> call, Throwable t) {
t.printStackTrace();
Log.e(TAG, "PTC login failed via loginPTC(). loginCallback.onFailure() threw: " + t.getMessage());
loginListener.authFailed("Pokemon Trainer Club Login Failed");
}
};
Call<NianticService.LoginResponse> call = service.login(url.toString());
call.enqueue(loginCallback);
}
use of okhttp3.OkHttpClient in project CloudReader by youlookwhat.
the class HttpUtils method getOkClient.
public OkHttpClient getOkClient() {
OkHttpClient client1;
client1 = getUnsafeOkHttpClient();
return client1;
}
use of okhttp3.OkHttpClient in project CloudReader by youlookwhat.
the class HttpUtils method getUnsafeOkHttpClient.
public OkHttpClient getUnsafeOkHttpClient() {
try {
final TrustManager[] trustAllCerts = new TrustManager[] { new X509TrustManager() {
@Override
public void checkClientTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public void checkServerTrusted(X509Certificate[] chain, String authType) throws CertificateException {
}
@Override
public X509Certificate[] getAcceptedIssuers() {
return new X509Certificate[] {};
}
} };
// Install the all-trusting trust manager
SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, trustAllCerts, new SecureRandom());
// Create an ssl socket factory with our all-trusting manager
SSLSocketFactory sslSocketFactory = sslContext.getSocketFactory();
OkHttpClient.Builder okBuilder = new OkHttpClient.Builder();
okBuilder.readTimeout(20, TimeUnit.SECONDS);
okBuilder.connectTimeout(10, TimeUnit.SECONDS);
okBuilder.writeTimeout(20, TimeUnit.SECONDS);
okBuilder.addInterceptor(new HttpHeadInterceptor());
okBuilder.addInterceptor(getInterceptor());
okBuilder.sslSocketFactory(sslSocketFactory);
okBuilder.hostnameVerifier(new HostnameVerifier() {
@Override
public boolean verify(String hostname, SSLSession session) {
// Log.d("HttpUtils", "==come");
return true;
}
});
return okBuilder.build();
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of okhttp3.OkHttpClient in project Android by Tracman-org.
the class LoginActivity method authenticateWithTracmanServer.
private void authenticateWithTracmanServer(final Request request) throws Exception {
// Needed to support TLS 1.1 and 1.2
// TrustManagerFactory trustManagerFactory = TrustManagerFactory.getInstance(
// TrustManagerFactory.getDefaultAlgorithm());
// trustManagerFactory.init((KeyStore) null);
// TrustManager[] trustManagers = trustManagerFactory.getTrustManagers();
// if (trustManagers.length != 1 || !(trustManagers[0] instanceof X509TrustManager)) {
// throw new IllegalStateException("Unexpected default trust managers:"
// + Arrays.toString(trustManagers));
// }
// X509TrustManager trustManager = (X509TrustManager) trustManagers[0];
OkHttpClient client = new OkHttpClient.Builder().build();
client.newCall(request).enqueue(new Callback() {
@Override
public void onFailure(Call call, IOException e) {
//Log.e(TAG, "Failed to connect to Tracman server!");
showError(R.string.server_connection_error);
e.printStackTrace();
}
@Override
public void onResponse(Call call, Response res) throws IOException {
if (!res.isSuccessful()) {
showError(R.string.login_no_user_error);
res.body().close();
throw new IOException("Unexpected code: " + res);
} else {
//Log.d(TAG, "Response code: " + res.code());
String userString = res.body().string();
System.out.println("Full response: " + userString);
String userID, userName, userSK;
try {
JSONObject user = new JSONObject(userString);
userID = user.getString("_id");
userName = user.getString("name");
userSK = user.getString("sk32");
//Log.v(TAG, "User retrieved with ID: " + userID);
} catch (JSONException e) {
//Log.e(TAG, "Unable to parse user JSON: ", e);
//Log.e(TAG, "JSON String used: " + userString);
userID = null;
userName = null;
userSK = null;
}
// Save user as loggedInUser
SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(getApplicationContext());
SharedPreferences.Editor editor = sharedPref.edit();
editor.putString("loggedInUser", userString);
editor.putString("loggedInUserId", userID);
editor.putString("loggedInUserName", userName);
editor.putString("loggedInUserSk", userSK);
editor.commit();
startActivityForResult(new Intent(LoginActivity.this, SettingsActivity.class), SIGN_OUT);
}
}
});
}
Aggregations