use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.
the class ScraperModule method providesRMP.
@Provides
@Singleton
public RMPScraper providesRMP(OkHttpClient client) {
OkHttpClient okClient = client.clone();
okClient.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
okClient.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
//okClient.networkInterceptors().add(getCacheControlInterceptor(TimeUnit.DAYS.toMillis(7)));
return new RMPScraper(okClient);
}
use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.
the class RutgersCTModule method providesOkHttpClient.
@Provides
@Singleton
public OkHttpClient providesOkHttpClient(Context context) {
OkHttpClient client = new OkHttpClient();
client.setConnectTimeout(CONNECT_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.setReadTimeout(READ_TIMEOUT_MILLIS, TimeUnit.MILLISECONDS);
client.networkInterceptors().add(new StethoInterceptor());
File httpCacheDir = new File(context.getCacheDir(), context.getString(R.string.application_name));
// 50 MiB
long httpCacheSize = 50 * 1024 * 1024;
Cache cache = new Cache(httpCacheDir, httpCacheSize);
client.setCache(cache);
if (BuildConfig.DEBUG) {
try {
cache.evictAll();
} catch (IOException e) {
e.printStackTrace();
}
}
return client;
}
use of javax.inject.Singleton in project Rutgers-Course-Tracker by tevjef.
the class RetroRutgersModule method providesRutgersRestAdapter.
@Provides
@Singleton
public RetroRutgersService providesRutgersRestAdapter(OkHttpClient client, Gson gson) {
OkHttpClient okClient = client.clone();
okClient.networkInterceptors().add(getCacheControlInterceptor(TimeUnit.SECONDS.toMillis(5)));
return new RestAdapter.Builder().setEndpoint("http://sis.rutgers.edu/soc/").setLogLevel(RestAdapter.LogLevel.HEADERS_AND_ARGS).setErrorHandler(new MyErrorHandler()).setClient(new OkClient(okClient)).setConverter(new GsonConverter(gson)).build().create(RetroRutgersService.class);
}
use of javax.inject.Singleton in project OpenAM by OpenRock.
the class CoreRestGuiceModule method getServerAttributeTitles.
@Provides
@Singleton
@Named("ServerAttributeTitles")
public Properties getServerAttributeTitles() throws IOException {
Properties titleProperties = new Properties();
titleProperties.load(getClass().getClassLoader().getResourceAsStream("amConsole.properties"));
return titleProperties;
}
use of javax.inject.Singleton in project OpenAM by OpenRock.
the class SoapSTSInstanceModule method getSTSProperties.
/**
* This method will provide the instance of the STSPropertiesMBean necessary both for the STS proper, and for the
* CXF interceptor-set which enforces the SecurityPolicy bindings.
*
* It should be a singleton because this same instance is shared by all of the token operation instances, as well as
* by the CXF interceptor-set
*/
@Provides
@Singleton
@Inject
STSPropertiesMBean getSTSProperties(Logger logger) {
StaticSTSProperties stsProperties = new StaticSTSProperties();
// KeystoreConfig may be null for a TLS-based SecurityPolicy binding, or for the AM-bare binding.
if (stsInstanceConfig.getKeystoreConfig() != null) {
stsProperties.setCallbackHandler(new SoapSTSCallbackHandler(stsInstanceConfig.getKeystoreConfig(), logger));
Crypto crypto;
try {
crypto = CryptoFactory.getInstance(getEncryptionProperties());
} catch (WSSecurityException e) {
String message = "Exception caught initializing the CryptoFactory: " + e;
logger.error(message, e);
throw new IllegalStateException(message);
}
stsProperties.setSignatureCrypto(crypto);
stsProperties.setEncryptionCrypto(crypto);
stsProperties.setSignatureUsername(stsInstanceConfig.getKeystoreConfig().getSignatureKeyAlias());
}
return stsProperties;
}
Aggregations