Skip to content

Commit

Permalink
Spelling + spacing changes
Browse files Browse the repository at this point in the history
  • Loading branch information
elliotfehr committed Nov 9, 2015
1 parent 4daf7b6 commit 98b783d
Show file tree
Hide file tree
Showing 41 changed files with 405 additions and 447 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
1.0.5
Add: Make connection and read timeouts configurable in `wurflcloud.properties` file

1.0.4
Add: `getDeviceFromUserAgent` method

1.0.3
Open source release

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ public AuthenticationManager(CloudClientConfig config) {
public Credentials splitApiKey() {
String api_key = config.apiKey;
if (api_key == null || api_key.length() == 0) {
throw new IllegalArgumentException("Api key must be not empty");
throw new IllegalArgumentException("API key must be not empty");
}

int indexOfColon = api_key.indexOf(':');
if (indexOfColon < 0) {
throw new IllegalArgumentException("Api key must contain a \':\' separator.");
throw new IllegalArgumentException("API key must contain a \':\' separator.");
}

String username = api_key.substring(0, indexOfColon);
if (username.length() == 0) {
throw new IllegalArgumentException("Api key username is empty.");
throw new IllegalArgumentException("API key username is empty.");
}

String pwd = api_key.substring(indexOfColon + 1);
if (pwd.length() == 0) {
throw new IllegalArgumentException("Api key password is empty.");
throw new IllegalArgumentException("API key password is empty.");
}

return new Credentials(username, pwd);
Expand Down
184 changes: 92 additions & 92 deletions code/src/main/java/com/scientiamobile/wurflcloud/CloudClient.java

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
* Mantains Cloud client configuration.
*/
public class CloudClientConfig extends Loggable implements Serializable {
private static final long serialVersionUID = 2L;
private static final long serialVersionUID = 2L;

/**
* The API Key is used to authenticate with the WURFL Cloud Service. It can be found at in your account
* at http://www.scientiamobile.com/myaccount
* The API Key is 39 characters in with the format: nnnnnn:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
* The API Key is 39 characters with the format: nnnnnn:xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
* where 'n' is a number and 'x' is a letter or number
*/
protected String apiKey = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
* Entry point for Cloud Client Application.
*/
public class CloudClientLoader extends Loggable implements Constants, Serializable {
private static final long serialVersionUID = 2L;
private final Properties properties = new Properties();
private static final long serialVersionUID = 2L;
private final Properties properties = new Properties();
private final CloudClientConfig config = new CloudClientConfig();
private final ICloudClientManager managerI;

Expand All @@ -47,7 +47,7 @@ public class CloudClientLoader extends Loggable implements Constants, Serializab
* @throws Exception
*/
public CloudClientLoader() throws Exception {
this (null, null, null);
this (null, null, null);
}

/**
Expand All @@ -56,7 +56,7 @@ public CloudClientLoader() throws Exception {
* @throws Exception
*/
public CloudClientLoader(String apiKey) throws Exception {
this(apiKey, null, null);
this(apiKey, null, null);
}

/**
Expand All @@ -68,7 +68,7 @@ public CloudClientLoader(String apiKey) throws Exception {
* @throws Exception
*/
public CloudClientLoader(String apiKey, String proxyIp, int proxyPort, Proxy.Type proxyType) throws Exception {
this(apiKey, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
this(apiKey, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
}

/**
Expand All @@ -79,7 +79,7 @@ public CloudClientLoader(String apiKey, String proxyIp, int proxyPort, Proxy.Typ
* @throws Exception
*/
public CloudClientLoader(String proxyIp, int proxyPort, Proxy.Type proxyType) throws Exception {
this(null, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
this(null, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
}

/**
Expand All @@ -88,7 +88,7 @@ public CloudClientLoader(String proxyIp, int proxyPort, Proxy.Type proxyType) th
* @throws Exception
*/
public CloudClientLoader(Proxy proxy) throws Exception {
this(null, null, proxy);
this(null, null, proxy);
}

/**
Expand All @@ -98,7 +98,7 @@ public CloudClientLoader(Proxy proxy) throws Exception {
* @throws Exception
*/
public CloudClientLoader(String apiKey, Proxy proxy) throws Exception {
this(apiKey, null, proxy);
this(apiKey, null, proxy);
}

/**
Expand All @@ -108,7 +108,7 @@ public CloudClientLoader(String apiKey, Proxy proxy) throws Exception {
* @throws Exception
*/
public CloudClientLoader(String apiKey, String propertiesFile) throws Exception {
this(apiKey, propertiesFile, null);
this(apiKey, propertiesFile, null);
}

/**
Expand All @@ -121,7 +121,7 @@ public CloudClientLoader(String apiKey, String propertiesFile) throws Exception
* @throws Exception
*/
public CloudClientLoader(String apiKey, String propertiesFile, String proxyIp, int proxyPort, Proxy.Type proxyType) throws Exception {
this(apiKey, propertiesFile, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
this(apiKey, propertiesFile, new Proxy(proxyType, new InetSocketAddress(proxyIp, proxyPort)));
}

/**
Expand All @@ -133,22 +133,22 @@ public CloudClientLoader(String apiKey, String propertiesFile, String proxyIp, i
*/
public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) throws Exception {

IWurflCloudCache cache = null;
IWurflCloudCache cache = null;
String[] capabilities = new String[0];

if (apiKey != null && apiKey.length() > 0) {
config.apiKey = apiKey;
}

if (propertiesFile == null) {
propertiesFile = WURFL_CLOUD_CONFIG_FILE;
propertiesFile = WURFL_CLOUD_CONFIG_FILE;
}

try {
InputStream stream = getClass().getResourceAsStream(propertiesFile);

if (stream == null) {
stream = new FileInputStream(new File(propertiesFile));
stream = new FileInputStream(new File(propertiesFile));
}

properties.load(stream);
Expand All @@ -157,7 +157,7 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro
if (apiKey == null || apiKey.length() == 0) {
String key = properties.getProperty(APIKEY);
if (key == null || key.length() == 0) {
throw new IllegalArgumentException("You must supply a not empty Cloud Client API key");
throw new IllegalArgumentException("Your API key cannot be empty");
}
config.apiKey = key;
}
Expand All @@ -167,23 +167,23 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro
logger.warn("Unable to load '" + CACHE + "' property, setting default cache");
property = defaultCacheType();
}
logger.info("setting cache type to " + property);
logger.info("Setting cache type to " + property);
cache = getStrategyCache(property);

property = properties.getProperty(COMPRESSION);
if (property == null) {
logger.warn("Unable to load '" + COMPRESSION + "' property, setting default");
property = defaultCompression();
}
logger.info("setting 'compression' to " + property);
logger.info("Setting 'compression' to " + property);
config.compression = Boolean.valueOf(property);

property = properties.getProperty(CONNECTION_TIMEOUT_PROP);
if (property != null) {
try {
int timeout = Integer.parseInt(property);
if ( timeout >= 0 ) {
logger.info("setting 'connection_timeout' to " + timeout + " mSec");
logger.info("Setting 'connection_timeout' to " + timeout + " mSec");
config.connectionTimeout = timeout;
}
else {
Expand All @@ -201,7 +201,7 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro
try {
int timeout = Integer.parseInt(property);
if ( timeout >= 0 ) {
logger.info("setting 'read_timeout' to " + timeout + " mSec");
logger.info("Setting 'read_timeout' to " + timeout + " mSec");
config.readTimeout = timeout;
}
else {
Expand All @@ -219,66 +219,66 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro
logger.warn("Unable to load 'autoPurge' property, setting default");
property = String.valueOf(DEFAULT_AUTO_PURGE);
}
logger.info("setting 'autoPurge' to " + property);
logger.info("Setting 'autoPurge' to " + property);
config.autoPurge = Boolean.valueOf(property);

List<String> capList = new ArrayList<String>();
for (Object propertyObject : properties.keySet()) {
String propertyString = (String) propertyObject;
if (propertyString.startsWith(CAPABILITY_PREFIX)) {
String propertyString = (String) propertyObject;
if (propertyString.startsWith(CAPABILITY_PREFIX)) {
capList.add(properties.getProperty(propertyString));
}
}

if (capList.size() == 0) {
logger.debug("no capabilities in config, server will give back all authorized ones");
logger.debug("No capabilities listed in config, server will give back all authorized ones");
} else {
capabilities = capList.toArray(new String[]{});
capabilities = capList.toArray(new String[]{});
}

// Proxy
if (proxy == null) { // ignore if passed programmatically
String address = properties.getProperty(PROXY_URL);
if (address != null) {
String portStr = properties.getProperty(PROXY_PORT);
String typeStr = properties.getProperty(PROXY_TYPE);
try {
int port = Integer.valueOf(portStr);
Proxy.Type type = Proxy.Type.valueOf(typeStr);
try {
proxy = new Proxy(type, new InetSocketAddress(address, port));
logger.info("wurfl-cloud initialized with proxy from properties file on " + address + ":" + portStr + " of type " + proxy.type().toString());
} catch (IllegalArgumentException e) {
logger.warn("unable to setup proxy from properties file; invalid values: " + e.getLocalizedMessage());
}
} catch (NumberFormatException e) {
logger.warn("unable to setup proxy from properties file; invalid port: " + portStr);
} catch (IllegalArgumentException e) {
logger.warn("unable to setup proxy from properties file; invalid proxy type: " + typeStr + " - see java.net.Proxy.Type javadoc for valid values");
} catch (NullPointerException e) {
logger.warn("unable to setup proxy from properties file; invalid proxy type: " + typeStr + " - see java.net.Proxy.Type javadoc for valid values");
}
}
String address = properties.getProperty(PROXY_URL);
if (address != null) {
String portStr = properties.getProperty(PROXY_PORT);
String typeStr = properties.getProperty(PROXY_TYPE);
try {
int port = Integer.valueOf(portStr);
Proxy.Type type = Proxy.Type.valueOf(typeStr);
try {
proxy = new Proxy(type, new InetSocketAddress(address, port));
logger.info("WURFL-cloud initialized with proxy from properties file on " + address + ":" + portStr + " of type " + proxy.type().toString());
} catch (IllegalArgumentException e) {
logger.warn("Unable to setup proxy from properties file; invalid values: " + e.getLocalizedMessage());
}
} catch (NumberFormatException e) {
logger.warn("Unable to setup proxy from properties file; invalid port: " + portStr);
} catch (IllegalArgumentException e) {
logger.warn("Unable to setup proxy from properties file; invalid proxy type: " + typeStr + " - see java.net.Proxy.Type javadoc for valid values");
} catch (NullPointerException e) {
logger.warn("Unable to setup proxy from properties file; invalid proxy type: " + typeStr + " - see java.net.Proxy.Type javadoc for valid values");
}
}
}

property = properties.getProperty(CACHE + ".reportInterval");
if (property == null) {
logger.warn("Unable to load 'reportInterval' property, setting default");
property = String.valueOf(DEFAULT_REPORT_INTERVAL);
}
logger.info("setting 'reportInterval' to " + property);
logger.info("Setting 'reportInterval' to " + property);
config.reportInterval = Integer.valueOf(property);

} catch (FileNotFoundException exception) {
logger.warn("Configuration file not found at path: " + propertiesFile + ", proceeding with defaults");
logger.warn("Configuration file not found at path: " + propertiesFile + ", proceeding with defaults");
} catch (NumberFormatException exception) {
logger.warn("Could not parse cache's reportInterval parameter, not a valid integer value.");
config.reportInterval = DEFAULT_REPORT_INTERVAL;
logger.warn("Could not parse cache's reportInterval parameter, not a valid integer value.");
config.reportInterval = DEFAULT_REPORT_INTERVAL;
}

if (cache == null) {
Expand Down
Loading

0 comments on commit 98b783d

Please sign in to comment.