diff --git a/CHANGELOG.txt b/CHANGELOG.txt index cfa9d37..975f481 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -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 diff --git a/code/pom.xml b/code/pom.xml index 5a9179d..86c6f8d 100755 --- a/code/pom.xml +++ b/code/pom.xml @@ -4,7 +4,7 @@ 4.0.0 com.scientiamobile.wurflcloud client-java - 1.0.4 + 1.0.5 jar wurfl-cloud-client diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/AuthenticationManager.java b/code/src/main/java/com/scientiamobile/wurflcloud/AuthenticationManager.java index 81d9560..112f8f8 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/AuthenticationManager.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/AuthenticationManager.java @@ -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); diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClient.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClient.java index 282525a..e07c6be 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClient.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClient.java @@ -46,15 +46,15 @@ * Cloud thin client, associated to every request. */ public class CloudClient extends Loggable implements ICloudClientRequest, Constants, Serializable { - private static final long serialVersionUID = 2L; - - private static final Set FILTERED_HEADERS = new HashSet(); - static { - FILTERED_HEADERS.add("content-length"); - FILTERED_HEADERS.add("content-type"); - } - - private final CloudClientConfig config; + private static final long serialVersionUID = 2L; + + private static final Set FILTERED_HEADERS = new HashSet(); + static { + FILTERED_HEADERS.add("content-length"); + FILTERED_HEADERS.add("content-type"); + } + + private final CloudClientConfig config; private final String[] searchCapabilities; private final Credentials credentials; private final IWurflCloudCache cache; @@ -148,16 +148,16 @@ private String initialize() { String headerNameLC = headerName.toLowerCase(); logger.info("putting " + headerNameLC); if (USER_AGENT_LC.equals(headerNameLC)) { - userAgent = request.getHeader(headerName); + userAgent = request.getHeader(headerName); } reqHeaders.put(headerNameLC, request.getHeader(headerName)); } } if (userAgent.length() == 0) { - logger.warn("The user agent is empty."); + logger.warn("The User-Agent is empty."); } else if (userAgent.length() > Constants.USER_AGENT_MAX_LENGTH) { - userAgent = userAgent.substring(0, Constants.USER_AGENT_MAX_LENGTH); + userAgent = userAgent.substring(0, Constants.USER_AGENT_MAX_LENGTH); } logger.info(USER_AGENT_LC + ": " + userAgent); @@ -167,9 +167,9 @@ private String initialize() { if (ip != null) { String fwd = reqHeaders.get(X_FORWARDED_FOR_LC); if (fwd != null) { - addRequestHeader(X_FORWARDED_FOR, ip + ", " + fwd); + addRequestHeader(X_FORWARDED_FOR, ip + ", " + fwd); } else { - addRequestHeader(X_FORWARDED_FOR, ip); + addRequestHeader(X_FORWARDED_FOR, ip); } } else { String remoteAddr = request.getRemoteAddr(); @@ -179,19 +179,19 @@ private String initialize() { // add X-Accept String accept = reqHeaders.get(ACCEPT_LC); if (accept != null) { - addRequestHeader(X_ACCEPT, accept); + addRequestHeader(X_ACCEPT, accept); } // add X-Wap-Profile String xWapProfile = reqHeaders.get(X_WAP_PROFILE_LC); if (xWapProfile != null) { - addRequestHeader(X_WAP_PROFILE, xWapProfile); + addRequestHeader(X_WAP_PROFILE, xWapProfile); } String reqPath = AuthorizationUtils.buildRequestPath(searchCapabilities); addOtherHeaders(reqPath); - logger.info("headers map at initialize end: " + reqHeaders); + logger.info("Headers map at initialize end: " + reqHeaders); return reqPath; } @@ -216,10 +216,10 @@ private void addReportDataToRequest() { Map counters = cache.getCounters(); StringBuilder sb = new StringBuilder(); for (Map.Entry cacheItem : counters.entrySet()) { - sb.append(cacheItem.getKey()).append(":").append(cacheItem.getValue()).append(","); + sb.append(cacheItem.getKey()).append(":").append(cacheItem.getValue()).append(","); } if (sb.length() > 0) { - sb.setLength(sb.length() - 1); + sb.setLength(sb.length() - 1); } addRequestHeader("X-Cloud-Counters", sb.toString()); @@ -263,15 +263,15 @@ public boolean testCall(Encoding enc) { String host = config.getCloudHost().host; String reqPath = AuthorizationUtils.buildRequestPath(new String[]{"is_wireless_device"}); String reqString = api_type + "://" + host + reqPath; - logger.info("request: " + reqString); + logger.info("Request: " + reqString); try { - URLConnection connection; - if (proxy != null) { - connection = new URL(reqString).openConnection(proxy); - } else { - connection = new URL(reqString).openConnection(); - } + URLConnection connection; + if (proxy != null) { + connection = new URL(reqString).openConnection(proxy); + } else { + connection = new URL(reqString).openConnection(); + } logger.info(connection.toString()); switch (enc) { case GZIP: @@ -304,11 +304,11 @@ public boolean testCall(Encoding enc) { * @throws WURFLCloudClientException If the parser could not read the passed raw data */ private CloudResponse processResponse(String rawData) { - try { - return mapper.readValue(rawData, CloudResponse.class); - } catch (IOException e) { - throw new WURFLCloudClientException("", HTTP_ERROR_JSON_KEY); - } + try { + return mapper.readValue(rawData, CloudResponse.class); + } catch (IOException e) { + throw new WURFLCloudClientException("", HTTP_ERROR_JSON_KEY); + } } /** @@ -320,7 +320,7 @@ private String buildRequestURL() { String api_type = Constants.API_TYPE; String host = config.getCloudHost().host; String reqString = api_type + "://" + host + reqPath; - logger.info("request: " + reqString); + logger.info("Request: " + reqString); return reqString; } @@ -331,49 +331,51 @@ private String buildRequestURL() { * @return */ private URLConnection setupUrlConnection(String request) throws IOException { - URLConnection connection = null; - - if (proxy != null) { - connection = new URL(request).openConnection(proxy); - } else { - connection = new URL(request).openConnection(); - } - - int timeout = 10000; - logger.debug("Setting connection timeout: " + timeout); - connection.setConnectTimeout(timeout); - - if (Constants.API_TYPE.equals(Constants.API_HTTP) && connection instanceof HttpURLConnection) { - logger.info("Explicitly setting connection method to GET"); - ((HttpURLConnection)connection).setRequestMethod("GET"); - } - + URLConnection connection = null; + + if (proxy != null) { + connection = new URL(request).openConnection(proxy); + } else { + connection = new URL(request).openConnection(); + } + + logger.debug("Setting connection timeout: " + config.connectionTimeout + " mSec"); + connection.setConnectTimeout(config.connectionTimeout); + + logger.debug("Setting read timeout: " + config.readTimeout + " mSec"); + connection.setReadTimeout(config.readTimeout); + + if (Constants.API_TYPE.equals(Constants.API_HTTP) && connection instanceof HttpURLConnection) { + logger.info("Explicitly setting connection method to GET"); + ((HttpURLConnection)connection).setRequestMethod("GET"); + } + logger.info(connection.toString()); logger.info("Incoming connection headers count: " + reqHeaders.size()); for (Map.Entry entry : reqHeaders.entrySet()) { - if (FILTERED_HEADERS.contains(entry.getKey().toLowerCase())) { - logger.info("filtering entry: " + entry); - } else { - logger.info(" adding entry: " + entry); - connection.setRequestProperty(entry.getKey(), entry.getValue()); - } + if (FILTERED_HEADERS.contains(entry.getKey().toLowerCase())) { + logger.info("filtering entry: " + entry); + } else { + logger.info(" adding entry: " + entry); + connection.setRequestProperty(entry.getKey(), entry.getValue()); + } } Map> headers = connection.getRequestProperties(); - logger.info("Outgouing connection headers count: " + headers.size()); + logger.info("Outgoing connection headers count: " + headers.size()); for (Map.Entry> entry : headers.entrySet()) { - logger.info("Outgoing Header: " + entry.getKey() + " -> " + entry.getValue()); + logger.info("Outgoing Header: " + entry.getKey() + " -> " + entry.getValue()); } - return connection; + return connection; } /** * {@inheritDoc} */ public Object queryCloudForCapability(String capabilityName, AbstractDevice device) { - String reqString = buildRequestURL(); - Object cap = null; + String reqString = buildRequestURL(); + Object cap = null; try { URLConnection connection = setupUrlConnection(reqString); @@ -384,7 +386,7 @@ public Object queryCloudForCapability(String capabilityName, AbstractDevice devi updateCache(device, response.getMtime()); cap = response.getCapabilities().get(capabilityName); if (cap == null) { - throw new IllegalArgumentException("You're not authorized to retrieve the capability \'" + capabilityName + "\'"); + throw new IllegalArgumentException("You're not authorized to retrieve the capability \'" + capabilityName + "\'"); } } catch (IOException e) { logger.error(e.toString()); @@ -400,17 +402,17 @@ public Object queryCloudForCapability(String capabilityName, AbstractDevice devi * @throws IOException */ public AbstractDevice detectDevice() throws IOException { - AbstractDevice device = cache.getDevice(request, this); + AbstractDevice device = cache.getDevice(request, this); if (device != null) { //check if capabilities search is changed if (searchCapabilities != null && searchCapabilities.length > 0) { Map capabilities = device.getCapabilities(); for (String searchCapability : searchCapabilities) { - if (!capabilities.containsKey(searchCapability)) { - device = null; + if (!capabilities.containsKey(searchCapability)) { + device = null; logger.info("capability not found, must query Cloud: " + searchCapability); break; - } + } } } } @@ -428,7 +430,7 @@ public AbstractDevice detectDevice() throws IOException { if (searchCapabilities != null && searchCapabilities.length > 0) { Map capabilities = cloudResponse.getCapabilities(); for (String searchCapability : searchCapabilities) { - if (capabilities.get(searchCapability) == null) { + if (capabilities.get(searchCapability) == null) { throw new IllegalArgumentException("The requested capability '" + searchCapability + "' is invalid or you are not subscribed to it."); } } @@ -442,24 +444,24 @@ public AbstractDevice detectDevice() throws IOException { } private void checkHttpConnectionOrThrow(URLConnection connection) throws IOException { - int httpResponseCode = HTTP_ERROR_UNREACHABLE; + int httpResponseCode = HTTP_ERROR_UNREACHABLE; if (connection instanceof HttpURLConnection) { - httpResponseCode = ((HttpURLConnection)connection).getResponseCode(); + httpResponseCode = ((HttpURLConnection)connection).getResponseCode(); } if (httpResponseCode >= 400) { switch (httpResponseCode) { - case HTTP_ERROR_INVALID_KEY: - throw new WURFLCloudClientException("Invalid API key", httpResponseCode); - case HTTP_ERROR_MISSING_KEY: - throw new WURFLCloudClientException("No API key was provided", httpResponseCode); - case HTTP_ERROR_EXPIRED_KEY: - throw new WURFLCloudClientException("API key is expired or revoked", httpResponseCode); - default: - throw new UnreachableServerException("The WURFL Cloud service returned an unexpected response: " + httpResponseCode); - } + case HTTP_ERROR_INVALID_KEY: + throw new WURFLCloudClientException("Invalid API key", httpResponseCode); + case HTTP_ERROR_MISSING_KEY: + throw new WURFLCloudClientException("No API key was provided", httpResponseCode); + case HTTP_ERROR_EXPIRED_KEY: + throw new WURFLCloudClientException("API key is expired or revoked", httpResponseCode); + default: + throw new UnreachableServerException("The WURFL Cloud service returned an unexpected response: " + httpResponseCode); + } } - logger.info("URLConnection to cloud returned correctly"); + logger.info("URLConnection to cloud returned correctly"); } /** @@ -474,7 +476,7 @@ private long updateListeners(CloudResponse cloudResponse) { CloudEvent evt = new CloudEvent(this, mtime, apiVersion); for (CloudListener listener : listeners) { - listener.processEvent(evt); + listener.processEvent(evt); } return mtime; } @@ -492,19 +494,19 @@ private String processContent(URLConnection connection) throws IOException { logger.info("Trying to get InputStream from Connection..."); InputStream is = connection.getInputStream(); if (is == null) { - logger.error("Failed, InputStream is NULL"); + logger.error("Failed, InputStream is NULL"); } else { - logger.info("InputStream received"); + logger.info("InputStream received"); } InputStreamReader in = new InputStreamReader(getStream(getEncodingType(connection), is)); int read; do { - logger.debug("Trying to read " + buffer.length + " bytes..."); + logger.debug("Trying to read " + buffer.length + " bytes..."); read = in.read(buffer, 0, buffer.length); if (read >= 0) { - logger.debug(read + " bytes received"); + logger.debug(read + " bytes received"); } else { - logger.info("EOF received"); + logger.info("EOF received"); } if (read > 0) { out.append(buffer, 0, read); @@ -526,9 +528,9 @@ private String processContent(URLConnection connection) throws IOException { private Encoding getEncodingType(URLConnection connection) { String encoding = connection.getHeaderField("Content-Encoding"); if (encoding != null && encoding.equals("gzip")) { - return Encoding.GZIP; + return Encoding.GZIP; } - return Encoding.PLAIN; + return Encoding.PLAIN; } /** @@ -549,10 +551,10 @@ private InputStream getStream(Encoding type, InputStream in) throws IOException } private void updateCache(AbstractDevice device, long mtime) { - String userAgent = request.getHeader(USER_AGENT_LC); - if (userAgent == null || userAgent.length() == 0) { - userAgent = request.getHeader("User-Agent"); - } + String userAgent = request.getHeader(USER_AGENT_LC); + if (userAgent == null || userAgent.length() == 0) { + userAgent = request.getHeader("User-Agent"); + } cache.setDevice(response, userAgent, new CacheDevice(device)); cache.setMtime(mtime); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientConfig.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientConfig.java index 65d9744..3e18d3c 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientConfig.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientConfig.java @@ -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; @@ -53,6 +53,12 @@ public class CloudClientConfig extends Loggable implements Serializable { protected boolean autoPurge = false; + /** + * The timeouts on connections + */ + protected int connectionTimeout = Constants.DEFAULT_CONNECTION_TIMEOUT; + protected int readTimeout = Constants.DEFAULT_READ_TIMEOUT; + /** * Protected, created by application. */ @@ -81,6 +87,7 @@ public void addCloudServer(String nickname, String url, int weight) { */ public void clearServers() { wcloud_servers.clear(); + current_server = null; } /** diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientLoader.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientLoader.java index 57df16e..3744307 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientLoader.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientLoader.java @@ -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; @@ -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); } /** @@ -56,7 +56,7 @@ public CloudClientLoader() throws Exception { * @throws Exception */ public CloudClientLoader(String apiKey) throws Exception { - this(apiKey, null, null); + this(apiKey, null, null); } /** @@ -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))); } /** @@ -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))); } /** @@ -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); } /** @@ -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); } /** @@ -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); } /** @@ -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))); } /** @@ -133,7 +133,7 @@ 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) { @@ -141,14 +141,14 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro } 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); @@ -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; } @@ -167,7 +167,7 @@ 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); @@ -175,59 +175,95 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro 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"); + config.connectionTimeout = timeout; + } + else { + logger.warn("Unable to load '" + CONNECTION_TIMEOUT_PROP + "' property (not an integer value >= 0) , using default (" + DEFAULT_CONNECTION_TIMEOUT + " mSec)"); + config.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + } + } catch(NumberFormatException e){ + logger.warn("Unable to load '" + CONNECTION_TIMEOUT_PROP + "' property (not a valid integer value) , using default (" + DEFAULT_CONNECTION_TIMEOUT + " mSec)"); + config.connectionTimeout = DEFAULT_CONNECTION_TIMEOUT; + } + } + + property = properties.getProperty(READ_TIMEOUT_PROP); + if (property != null) { + try { + int timeout = Integer.parseInt(property); + if ( timeout >= 0 ) { + logger.info("Setting 'read_timeout' to " + timeout + " mSec"); + config.readTimeout = timeout; + } + else { + logger.warn("Unable to load '" + READ_TIMEOUT_PROP + "' property (not an integer value >= 0) , using default (" + DEFAULT_CONNECTION_TIMEOUT + " mSec)"); + config.readTimeout = DEFAULT_READ_TIMEOUT; + } + } catch(NumberFormatException e){ + logger.warn("Unable to load '" + READ_TIMEOUT_PROP + "' property (not a valid integer value) , using default (" + DEFAULT_CONNECTION_TIMEOUT + " mSec)"); + config.readTimeout = DEFAULT_READ_TIMEOUT; + } + } + property = properties.getProperty(CACHE + ".autoPurge"); if (property == null) { 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 capList = new ArrayList(); 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"); @@ -235,14 +271,14 @@ public CloudClientLoader(String apiKey, String propertiesFile, Proxy proxy) thro 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) { diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientManager.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientManager.java index 28a8cb9..3af0593 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientManager.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudClientManager.java @@ -38,9 +38,9 @@ * WURFL Cloud Client Manager. */ public class CloudClientManager extends Loggable implements CloudListener, ICloudClientManager, Serializable { - private static final long serialVersionUID = 2L; + private static final long serialVersionUID = 2L; - /** + /** * The WURFL Cloud Server that will be used to request device information (e.g.. 'api.scientiamobile.com') * */ @@ -50,7 +50,7 @@ public class CloudClientManager extends Loggable implements CloudListener, IClou * The capabilities parsed from the .properties file */ private final String[] parsedCapabilities; - + /** * The version of the WURFL Cloud Server * @@ -68,7 +68,7 @@ public class CloudClientManager extends Loggable implements CloudListener, IClou * */ protected final CloudClientConfig config; - + /** * Client cache object * @@ -106,9 +106,9 @@ public class CloudClientManager extends Loggable implements CloudListener, IClou * @param proxy */ public CloudClientManager(IAuthenticationManager authenticationManager, CloudClientConfig config, IWurflCloudCache cache, Proxy proxy) { - this(authenticationManager, config, cache, proxy, null); + this(authenticationManager, config, cache, proxy, null); } - + /** * Full constructor. * @param authenticationManager @@ -140,26 +140,26 @@ private AbstractDevice detectDevice(CloudClient client) { read.lock(); AbstractDevice dev = null; try { - dev = client.detectDevice(); + dev = client.detectDevice(); } catch (SocketTimeoutException e) { - throw new WURFLCloudClientException("Unable to contact server: socket timeout", -1); - } catch (IOException e) { - throw new WURFLCloudClientException("Unable to contact server: connection error", -1); - } finally { + throw new WURFLCloudClientException("Unable to contact server: socket timeout", -1); + } catch (IOException e) { + throw new WURFLCloudClientException("Unable to contact server: connection error", -1); + } finally { read.unlock(); } - return dev; + return dev; } - - /** + + /** * {@inheritDoc} */ public AbstractDevice getDeviceFromUserAgent(String userAgent, String... search_capabilities) { CloudClient cc = new CloudClient(new DefaultCloudRequest(userAgent), null, config, (search_capabilities != null && search_capabilities.length > 0) ? search_capabilities : parsedCapabilities, credentials, cache, this, proxy); return detectDevice(cc); } - - /** + + /** * {@inheritDoc} */ public AbstractDevice getDeviceFromRequest(HttpServletRequest request, HttpServletResponse response, String... search_capabilities) { @@ -177,7 +177,7 @@ protected long getLoadedDate() { return loadedDate; } - /** + /** * {@inheritDoc} */ public boolean validateCache() { @@ -196,7 +196,7 @@ public boolean validateCache() { return false; } - /** + /** * {@inheritDoc} */ public String getAPIVersion() { diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudEvent.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudEvent.java index 1eb0f2c..1451c39 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudEvent.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudEvent.java @@ -18,9 +18,9 @@ * */ public class CloudEvent extends EventObject { - private static final long serialVersionUID = 1L; - - private final long mtime; + private static final long serialVersionUID = 1L; + + private final long mtime; private final String apiVersion; public CloudEvent(Object o, long mtime, String apiVersion) { diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudListener.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudListener.java index ecf5743..7c47cbf 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudListener.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudListener.java @@ -15,11 +15,11 @@ * Listener for update, receiving a cloud response. */ public interface CloudListener { - - /** - * Tells the listener when a specific {@link CloudEvent} has been raised. - * @param {@link CloudEvent} The raised CloudEvent - * - */ + + /** + * Tells the listener when a specific {@link CloudEvent} has been raised. + * @param {@link CloudEvent} The raised CloudEvent + * + */ void processEvent(CloudEvent evt); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudRequest.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudRequest.java index 286bbfe..49fc1ad 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudRequest.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudRequest.java @@ -19,20 +19,20 @@ * CloudRequest interface */ public interface CloudRequest { - - /** - * Returns all the header names - * @return The header names - */ + + /** + * Returns all the header names + * @return The header names + */ Enumeration getHeaderNames(); - + /** * Gets the header value associated to the requested header name * @param name The requested header name * @return The header value */ String getHeader(String name); - + /** * Returns the Internet Protocol (IP) address of the client or last proxy that sent the request * @return The IP address of the client or last proxy that sent the request @@ -42,5 +42,5 @@ public interface CloudRequest { /** * @return The stored {@link Cookie} array, if available */ - Cookie[] getCookies(); + Cookie[] getCookies(); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudResponse.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudResponse.java index 023f0cf..5a58ea0 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudResponse.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudResponse.java @@ -20,9 +20,9 @@ * */ public class CloudResponse extends Loggable implements Serializable { - private static final long serialVersionUID = 2L; - - private String apiVersion; + private static final long serialVersionUID = 2L; + + private String apiVersion; private long mtime; private String id; private Map capabilities; diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/CloudServerConfig.java b/code/src/main/java/com/scientiamobile/wurflcloud/CloudServerConfig.java index c970bb7..91c8ae2 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/CloudServerConfig.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/CloudServerConfig.java @@ -27,19 +27,19 @@ public CloudServerConfig(String nickname, String host, int weight) { @Override public String toString() { - StringBuilder sb = new StringBuilder(); - sb.append(this.getClass().getName()) - .append('@') - .append(this.hashCode()) - .append('-') - .append("nickname:") - .append(nickname) - .append('-') - .append("host:") - .append(host) - .append('-') - .append("weight:") - .append(weight); + StringBuilder sb = new StringBuilder(); + sb.append(this.getClass().getName()) + .append('@') + .append(this.hashCode()) + .append('-') + .append("nickname:") + .append(nickname) + .append('-') + .append("host:") + .append(host) + .append('-') + .append("weight:") + .append(weight); return sb.toString(); } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/DefaultCloudRequest.java b/code/src/main/java/com/scientiamobile/wurflcloud/DefaultCloudRequest.java index 00791e1..21e843a 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/DefaultCloudRequest.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/DefaultCloudRequest.java @@ -26,48 +26,48 @@ * */ public final class DefaultCloudRequest implements CloudRequest { - - private final Map headers = new HashMap(); - - public DefaultCloudRequest(HttpServletRequest servletRequest) throws IllegalArgumentException { - if (servletRequest == null) { - throw new IllegalArgumentException("Error: Servlet request cannot be null."); - } - String userAgentLC = servletRequest.getHeader(Constants.USER_AGENT_LC); - String userAgentUC = servletRequest.getHeader("User-Agent"); - this.headers.put("user-agent", userAgentUC != null ? userAgentUC : userAgentLC); - } - - public DefaultCloudRequest(String userAgent) throws IllegalArgumentException { - this.headers.put(Constants.USER_AGENT_LC, userAgent); - } - /** - * {@inheritDoc} - */ - public Enumeration getHeaderNames() { - return new Vector(headers.keySet()).elements(); - } + private final Map headers = new HashMap(); - /** - * {@inheritDoc} - */ - public String getHeader(String name) { - return headers.get(name); - } + public DefaultCloudRequest(HttpServletRequest servletRequest) throws IllegalArgumentException { + if (servletRequest == null) { + throw new IllegalArgumentException("ERROR: Servlet request cannot be null."); + } + String userAgentLC = servletRequest.getHeader(Constants.USER_AGENT_LC); + String userAgentUC = servletRequest.getHeader("User-Agent"); + this.headers.put("user-agent", userAgentUC != null ? userAgentUC : userAgentLC); + } - /** - * {@inheritDoc} - */ - public String getRemoteAddr() { - return null; - } - - /** - * {@inheritDoc} - */ - public Cookie[] getCookies() { - throw new IllegalStateException("ERROR: Trying to get cookies from a CloudRequest which does not support cookie storage."); - } + public DefaultCloudRequest(String userAgent) throws IllegalArgumentException { + this.headers.put(Constants.USER_AGENT_LC, userAgent); + } + + /** + * {@inheritDoc} + */ + public Enumeration getHeaderNames() { + return new Vector(headers.keySet()).elements(); + } + + /** + * {@inheritDoc} + */ + public String getHeader(String name) { + return headers.get(name); + } + + /** + * {@inheritDoc} + */ + public String getRemoteAddr() { + return null; + } + + /** + * {@inheritDoc} + */ + public Cookie[] getCookies() { + throw new IllegalStateException("ERROR: Trying to get cookies from a CloudRequest which does not support cookie storage."); + } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/ICloudClientRequest.java b/code/src/main/java/com/scientiamobile/wurflcloud/ICloudClientRequest.java index 7ebb595..d5ca337 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/ICloudClientRequest.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/ICloudClientRequest.java @@ -17,12 +17,12 @@ * The client request interface */ public interface ICloudClientRequest { - - /** + + /** * Perform a request to the Cloud for a specific device and check if the caller is authorized to get a certain capability * @param capabilityName The requested capability name * @param device The device to be used with the query * @return The capability value, or null if the caller isn't authorized to get the requested capability - */ - Object queryCloudForCapability(String capabilityName, AbstractDevice device); + */ + Object queryCloudForCapability(String capabilityName, AbstractDevice device); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/cache/AbstractUseragentWurflCloudCache.java b/code/src/main/java/com/scientiamobile/wurflcloud/cache/AbstractUseragentWurflCloudCache.java index 14b05c5..5c50048 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/cache/AbstractUseragentWurflCloudCache.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/cache/AbstractUseragentWurflCloudCache.java @@ -17,12 +17,12 @@ public abstract class AbstractUseragentWurflCloudCache extends AbstractWurflCloudCache { - /** - * Queries the cache for a {@link AbstractDevice} instance, using the provided servlet request. - * @param request The servlet request - * @return A {@link AbstractDevice} instance, or null if there's no such device cached - */ - @Override + /** + * Queries the cache for a {@link AbstractDevice} instance, using the provided servlet request. + * @param request The servlet request + * @return A {@link AbstractDevice} instance, or null if there's no such device cached + */ + @Override public final AbstractDevice getDevice(CloudRequest request, ICloudClientRequest client) { if (request == null) return null; String userAgent = request.getHeader(USER_AGENT_LC); diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/cache/EhcachePremiumCloudCache.java b/code/src/main/java/com/scientiamobile/wurflcloud/cache/EhcachePremiumCloudCache.java index 451b275..01e424b 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/cache/EhcachePremiumCloudCache.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/cache/EhcachePremiumCloudCache.java @@ -28,7 +28,7 @@ public class EhcachePremiumCloudCache extends AbstractUseragentWurflCloudCache { private final Cache cache; public EhcachePremiumCloudCache() { - CacheManager manager = new CacheManager(); + CacheManager manager = new CacheManager(); cache = manager.getCache("com.scientiamobile.wurflcloud.Device"); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/cache/HashMapPremiumCloudCache.java b/code/src/main/java/com/scientiamobile/wurflcloud/cache/HashMapPremiumCloudCache.java index 135acc4..c3ba84b 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/cache/HashMapPremiumCloudCache.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/cache/HashMapPremiumCloudCache.java @@ -91,7 +91,7 @@ protected AbstractDevice getDeviceFromUserAgent(String ua) { if (device == null) { incrementMiss(); } else { - incrementHit(); + incrementHit(); } return device; } @@ -101,7 +101,7 @@ public AbstractDevice getDeviceFromID(String id) { if (device == null) { incrementMiss(); } else { - incrementHit(); + incrementHit(); } return device; } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/cache/IWurflCloudCache.java b/code/src/main/java/com/scientiamobile/wurflcloud/cache/IWurflCloudCache.java index 293740d..ba0caf8 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/cache/IWurflCloudCache.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/cache/IWurflCloudCache.java @@ -23,12 +23,12 @@ * Cache interface. */ public interface IWurflCloudCache extends Constants { - + /** * Get the device capabilities for the given user agent from the cache provider */ public AbstractDevice getDevice(CloudRequest request, ICloudClientRequest client); - + /** * Get the device for the given key from the cache provider * diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/cache/SimpleCookieCache.java b/code/src/main/java/com/scientiamobile/wurflcloud/cache/SimpleCookieCache.java index 5b4ef84..c814a46 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/cache/SimpleCookieCache.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/cache/SimpleCookieCache.java @@ -32,7 +32,7 @@ * */ public class SimpleCookieCache extends AbstractWurflCloudCache { - + /** * Default cookie cache expiration, in seconds. */ @@ -55,8 +55,8 @@ public AbstractDevice getDevice(CloudRequest request, ICloudClientRequest client AbstractDevice ret = null; Cookie[] cookies = null; try { - cookies = request.getCookies(); - } catch (IllegalStateException e) {} + cookies = request.getCookies(); + } catch (IllegalStateException e) {} if (cookies == null) return null; for (int i = 0; i < cookies.length; i++) { Cookie cookie = cookies[i]; @@ -83,7 +83,7 @@ public AbstractDevice getDevice(CloudRequest request, ICloudClientRequest client logger.debug("device: " + ret); return ret; } - + public AbstractDevice getDeviceFromID(String key) { return null; } @@ -120,8 +120,8 @@ public boolean setDevice(HttpServletResponse response, String key, AbstractDevic response.addCookie(cookie); logger.debug(WURFL_COOKIE_NAME + " cookie added to response: " + cookie.getValue()); } else { - // TODO: Check message - logger.warn("Trying to save cookie on a null response. Maybe you're trying to use a CookieCache while querying the cloud with a simple user agent string."); + // TODO: Check message + logger.warn("Trying to save cookie on a null response. Maybe you're trying to use a CookieCache while querying the cloud with a simple user agent string."); } return true; } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/device/AbstractDevice.java b/code/src/main/java/com/scientiamobile/wurflcloud/device/AbstractDevice.java index 34d6eee..51dafbf 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/device/AbstractDevice.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/device/AbstractDevice.java @@ -45,7 +45,7 @@ public AbstractDevice(Map capabilities, ResponseType source, Str capabilityMap = capabilities; this.clientRequest = clientRequest; } - + /** * Convenience constructor which takes the queried capabilities, response type, device identifier and a map of errors * @param capabilities The capabilities queried for this AbstractDevice @@ -56,21 +56,21 @@ public AbstractDevice(Map capabilities, ResponseType source, Str public AbstractDevice(Map capabilities, ResponseType source, String id, Map errors) { this(capabilities, source, id, errors, null); } - + /** * Gets the capability value corresponding to the requested capability name. If this capability isn't already available locally the WURFL Cloud server will be queried for it. * @param capabilityName The requested capability name * @return The capability value. */ public Object get(String capabilityName) { - // check the stored capabilities for this device - Object value = capabilityMap.get(capabilityName); - if (value == null) { - // Must query the Cloud to check if the user is authorized to get the requested capability - logger.debug("Requested unauthorized capability \'" + capabilityName + "\'. Querying the Cloud.."); - value = clientRequest.queryCloudForCapability(capabilityName, this); - } - return value; + // check the stored capabilities for this device + Object value = capabilityMap.get(capabilityName); + if (value == null) { + // Must query the Cloud to check if the user is authorized to get the requested capability + logger.debug("Requested unauthorized capability \'" + capabilityName + "\'. Querying the Cloud.."); + value = clientRequest.queryCloudForCapability(capabilityName, this); + } + return value; } /** diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/device/CacheDevice.java b/code/src/main/java/com/scientiamobile/wurflcloud/device/CacheDevice.java index a75bd15..60cfa0a 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/device/CacheDevice.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/device/CacheDevice.java @@ -18,10 +18,10 @@ */ public class CacheDevice extends AbstractDevice { - /** - * Builds an AbstractDevice object using "cache" as response type. - * @param d The device to use - */ + /** + * Builds an AbstractDevice object using "cache" as response type. + * @param d The device to use + */ public CacheDevice(AbstractDevice device) { super(device.getCapabilities(), ResponseType.cache, device.getId(), device.getErrors()); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/device/CloudDevice.java b/code/src/main/java/com/scientiamobile/wurflcloud/device/CloudDevice.java index 0621674..0f76133 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/device/CloudDevice.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/device/CloudDevice.java @@ -16,15 +16,15 @@ import com.scientiamobile.wurflcloud.ResponseType; /** - * Object filled by wurfl cloud response, by mean of {@link com.scientiamobile.wurflcloud.CloudResponse} + * Object filled by WURFL cloud response, by mean of {@link com.scientiamobile.wurflcloud.CloudResponse} */ public class CloudDevice extends AbstractDevice { - /** - * Builds an AbstractDevice object using "cloud" as response type. - * @param response The CloudResponse object to use - * @param clientRequest The client request - */ + /** + * Builds an AbstractDevice object using "cloud" as response type. + * @param response The CloudResponse object to use + * @param clientRequest The client request + */ public CloudDevice(CloudResponse response, ICloudClientRequest clientRequest) { super(response.getCapabilities(), ResponseType.cloud, response.getId(), response.getErrors(), clientRequest); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/device/CookieDevice.java b/code/src/main/java/com/scientiamobile/wurflcloud/device/CookieDevice.java index 756a1ea..0b66716 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/device/CookieDevice.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/device/CookieDevice.java @@ -20,13 +20,13 @@ * Represents a {@link AbstractDevice} retrieved from a Cookie. */ public class CookieDevice extends AbstractDevice{ - - /** - * Builds an AbstractDevice object using "cookie" as response type. - * @param capabilities The map of queried capabilities - * @param id The device identifier - * @param clientRequest The client request - */ + + /** + * Builds an AbstractDevice object using "cookie" as response type. + * @param capabilities The map of queried capabilities + * @param id The device identifier + * @param clientRequest The client request + */ public CookieDevice(Map capabilities, String id, ICloudClientRequest clientRequest) { super(capabilities, ResponseType.cookie, id, null, clientRequest); } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/device/RecoveryDevice.java b/code/src/main/java/com/scientiamobile/wurflcloud/device/RecoveryDevice.java index 7633d47..2d7d175 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/device/RecoveryDevice.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/device/RecoveryDevice.java @@ -16,8 +16,6 @@ import java.util.Map; /** - * Date: 28/07/11 - * * @since 1.0 * @version $Id$ */ diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/exc/FatalException.java b/code/src/main/java/com/scientiamobile/wurflcloud/exc/FatalException.java index ae8a22f..9535891 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/exc/FatalException.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/exc/FatalException.java @@ -12,9 +12,9 @@ package com.scientiamobile.wurflcloud.exc; public class FatalException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public FatalException(String s, Throwable throwable) { + public FatalException(String s, Throwable throwable) { super(s, throwable); } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/exc/UnreachableServerException.java b/code/src/main/java/com/scientiamobile/wurflcloud/exc/UnreachableServerException.java index 8127014..fa22ebd 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/exc/UnreachableServerException.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/exc/UnreachableServerException.java @@ -12,9 +12,9 @@ package com.scientiamobile.wurflcloud.exc; public class UnreachableServerException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - public UnreachableServerException(String s) { + public UnreachableServerException(String s) { super(s); } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/exc/WURFLCloudClientException.java b/code/src/main/java/com/scientiamobile/wurflcloud/exc/WURFLCloudClientException.java index aa97a4b..622f926 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/exc/WURFLCloudClientException.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/exc/WURFLCloudClientException.java @@ -12,21 +12,21 @@ package com.scientiamobile.wurflcloud.exc; public class WURFLCloudClientException extends RuntimeException { - private static final long serialVersionUID = 1L; + private static final long serialVersionUID = 1L; - private final int httpResponseCode; - - public WURFLCloudClientException(String s, int httpResponseCode) { + private final int httpResponseCode; + + public WURFLCloudClientException(String s, int httpResponseCode) { super(s); this.httpResponseCode = httpResponseCode; } - - /** - * Returns the HTTP response code received from the server, from the connection - * which has thrown the exception - * @return the HTTP response code - */ - public int getHttpResponseCode() { - return httpResponseCode; - } + + /** + * Returns the HTTP response code received from the server, from the connection + * which has thrown the exception + * @return the HTTP response code + */ + public int getHttpResponseCode() { + return httpResponseCode; + } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/utils/AuthorizationUtils.java b/code/src/main/java/com/scientiamobile/wurflcloud/utils/AuthorizationUtils.java index 39a5304..f7873bd 100644 --- a/code/src/main/java/com/scientiamobile/wurflcloud/utils/AuthorizationUtils.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/utils/AuthorizationUtils.java @@ -39,10 +39,10 @@ private AuthorizationUtils() { * @return The constructed build domain inner path */ public static String buildRequestPath(String[] search_capabilities) { - // build capabilities - StringBuilder sb = new StringBuilder(); + // build capabilities + StringBuilder sb = new StringBuilder(); if (search_capabilities != null) { - char delimiter = ','; + char delimiter = ','; for (int i = 0; i < search_capabilities.length; i++) { final String s = search_capabilities[i]; if (s != null && s.length() > 0) diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/utils/Base64.java b/code/src/main/java/com/scientiamobile/wurflcloud/utils/Base64.java index 54a03de..b31826c 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/utils/Base64.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/utils/Base64.java @@ -51,7 +51,6 @@ public static String encode(String string) { } return splitLines(encoded.substring(0, encoded.length() - paddingCount) + "==".substring(0, paddingCount)); - } public static String splitLines(String string) { @@ -64,7 +63,6 @@ public static String splitLines(String string) { } return lines; - } public static void main(String[] args) { @@ -75,7 +73,6 @@ public static void main(String[] args) { System.out.println(encode(args[i])); } - } } diff --git a/code/src/main/java/com/scientiamobile/wurflcloud/utils/Constants.java b/code/src/main/java/com/scientiamobile/wurflcloud/utils/Constants.java index 2461594..30045a7 100755 --- a/code/src/main/java/com/scientiamobile/wurflcloud/utils/Constants.java +++ b/code/src/main/java/com/scientiamobile/wurflcloud/utils/Constants.java @@ -24,7 +24,7 @@ public interface Constants { /** * The version of this client */ - String CLIENT_VERSION = "1.0.4"; + String CLIENT_VERSION = "1.0.5"; /** * Accepted encoding enum. @@ -49,7 +49,7 @@ private Encoding(String val) { * Default host name. */ String DEFAULT_SERVER_HOST = "api.wurflcloud.com"; - + /** * Default Server Info */ @@ -124,6 +124,10 @@ enum CacheType { String COMPRESSION = PREFIX + "compression"; + String CONNECTION_TIMEOUT_PROP = PREFIX + "connTimeout"; + + String READ_TIMEOUT_PROP = PREFIX + "readTimeout"; + /** * Proxy */ @@ -139,6 +143,12 @@ enum CacheType { public static final float DEFAULT_LOAD_FACTOR = .75f; public static final int DEFAULT_CONCURRENT_WRITES = 16; + /** + * Default timeout values on connections + */ + int DEFAULT_CONNECTION_TIMEOUT = 5000; + int DEFAULT_READ_TIMEOUT = 10000; + /** * lowercase userAgent header */ @@ -167,12 +177,12 @@ enum CacheType { * X-Wap-Profile */ String X_WAP_PROFILE = "X-Wap-Profile"; - + /** * X-Forwarded-For */ String X_FORWARDED_FOR = "X-Forwarded-For"; - + /** * The max allowed length of the user-agent */ @@ -182,13 +192,13 @@ enum CacheType { * The HTTP Headers that will be examined to find the best User Agent, if one is not specified */ String[] HEADERS = new String[] { - "Device-Stock-UA", // "HTTP_DEVICE_STOCK_UA", - "X-Device-User-Agent", // "HTTP_X_DEVICE_USER_AGENT", + "Device-Stock-UA", // "HTTP_DEVICE_STOCK_UA", + "X-Device-User-Agent", // "HTTP_X_DEVICE_USER_AGENT", "X-Original-User-Agent",// "HTTP_X_ORIGINAL_USER_AGENT", - "X-Operamini-Phone-Ua", // "HTTP_X_OPERAMINI_PHONE_UA", - "X-Skyfire-Phone", // "HTTP_X_SKYFIRE_PHONE", - "X-Bolt-Phone-Ua", // "HTTP_X_BOLT_PHONE_UA", - USER_AGENT_LC, // "HTTP_USER_AGENT" + "X-Operamini-Phone-Ua", // "HTTP_X_OPERAMINI_PHONE_UA", + "X-Skyfire-Phone", // "HTTP_X_SKYFIRE_PHONE", + "X-Bolt-Phone-Ua", // "HTTP_X_BOLT_PHONE_UA", + USER_AGENT_LC, // "HTTP_USER_AGENT" }; } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/ClientWithResponseHandler.java b/code/src/test/java/com/scientiamobile/wurflcloud/ClientWithResponseHandler.java index 4480425..5ac7f82 100755 --- a/code/src/test/java/com/scientiamobile/wurflcloud/ClientWithResponseHandler.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/ClientWithResponseHandler.java @@ -11,37 +11,6 @@ */ package com.scientiamobile.wurflcloud; -/** - * Date: 14/07/11 - * - */ -/* - * ==================================================================== - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - * ==================================================================== - * - * This software consists of voluntary contributions made by many - * individuals on behalf of the Apache Software Foundation. For more - * information on the Apache Software Foundation, please see - * . - * - */ - import com.scientiamobile.wurflcloud.utils.AeSimpleMD5; import com.scientiamobile.wurflcloud.utils.Base64; import com.scientiamobile.wurflcloud.utils.Constants; @@ -84,12 +53,12 @@ public final static void main(String[] args) throws Exception { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources - // httpclient.getConnectionManager().shutdown(); + // httpclient.getConnectionManager().shutdown(); } } private static String getSignature(String password) throws NoSuchAlgorithmException, UnsupportedEncodingException { - String a = reqPath+userAgent+password; + String a = reqPath+userAgent+password; return AeSimpleMD5.MD5(a); } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientConnectionTimeoutTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientConnectionTimeoutTest.java new file mode 100644 index 0000000..38c0bb9 --- /dev/null +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientConnectionTimeoutTest.java @@ -0,0 +1,67 @@ +/** + * Copyright (c) 2015 ScientiaMobile Inc. + * + * The WURFL Cloud Client is intended to be used in both open-source and + * commercial environments. To allow its use in as many situations as possible, + * the WURFL Cloud Client is dual-licensed. You may choose to use the WURFL + * Cloud Client under either the GNU GENERAL PUBLIC LICENSE, Version 2.0, or + * the MIT License. + * + * Refer to the COPYING.txt file distributed with this package. + */ +package com.scientiamobile.wurflcloud; + +import static org.testng.Assert.assertTrue; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.scientiamobile.wurflcloud.device.AbstractDevice; +import com.scientiamobile.wurflcloud.exc.WURFLCloudClientException; +import com.scientiamobile.wurflcloud.cache.WurflCloudCache_Null; +/** + * @version $Id$ + */ +@Test(groups = "unit") +public class CloudClientConnectionTimeoutTest extends Loggable{ + + private static final String ua = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/30.0.1599.12 Mobile/11A465 Safari/8536.25 (3B92C18B-D9DE-4CB7-A02A-22FD2AF17C8F)"; + + private ICloudClientManager ICloudClient; + private AbstractDevice device; + private String[] capabilities; + + private CloudClientConfig cfg; + private IAuthenticationManager am; + private ICloudClientManager ccm; + + + + @BeforeClass + public void setup() throws Exception { + + cfg = new CloudClientConfig(); + cfg.clearServers(); + cfg.addCloudServer("timeout_server", "8.8.8.8", 10); + cfg.apiKey = "XXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY"; + cfg.connectionTimeout = 2000; + am = new AuthenticationManager(cfg); + ccm = new CloudClientManager(am, cfg, new WurflCloudCache_Null(), null); + + } + + @Test + public void testClient() { + /** + * Mantaining compatibility with Junit version < 4 + */ + boolean excThrown = false; + try { + device = ccm.getDeviceFromUserAgent(ua, capabilities); + } + catch (WURFLCloudClientException exc) { + excThrown = true; + } + assertTrue(excThrown); + } +} diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientCookieTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientCookieTest.java index d15dd73..1809811 100644 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientCookieTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientCookieTest.java @@ -28,8 +28,6 @@ /** - * Date: 20/07/11 - * * @version $Id$ */ @Test(groups = "unit") diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidApiKeyTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidApiKeyTest.java index ad51ab7..d4a2627 100644 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidApiKeyTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidApiKeyTest.java @@ -17,14 +17,13 @@ import org.testng.annotations.Test; /** - * Date: 06/05/15 * */ @Test(groups = "connected") public class CloudClientInvalidApiKeyTest extends Loggable { - - private ICloudClientManager manager; - + + private ICloudClientManager manager; + @BeforeClass public void setup() throws Exception { CloudClientLoader loader = new CloudClientLoader(null, "/InvalidApiKey.properties"); @@ -33,8 +32,8 @@ public void setup() throws Exception { @Test public void testApiKeyFailure() { - boolean res = manager.testCallWurflCloud(); - assertFalse(res); + boolean res = manager.testCallWurflCloud(); + assertFalse(res); } } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidCapabilityTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidCapabilityTest.java index 426cc77..a21e58d 100644 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidCapabilityTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientInvalidCapabilityTest.java @@ -25,7 +25,6 @@ /** - * Date: 20/07/11 * */ @Test(groups = "unit") @@ -52,9 +51,9 @@ public void invalidCapabilityQuery() { boolean passed = false; try { ICloudClient.getDeviceFromRequest(request, response, capabilities); - } catch (IllegalArgumentException e) { - passed = true; - } + } catch (IllegalArgumentException e) { + passed = true; + } Assert.assertTrue(passed); } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientLoaderTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientLoaderTest.java index 0ef0af2..5315481 100755 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientLoaderTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientLoaderTest.java @@ -17,7 +17,6 @@ import org.testng.annotations.Test; /** - * Date: 27/07/11 * */ @Test(groups = "connected") @@ -28,7 +27,7 @@ public void setup() throws Exception { new CloudClientLoader(null, "/DefaultTest.properties"); } @Test - public void testConstructor(){ - assertTrue(true); - } + public void testConstructor(){ + assertTrue(true); + } } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientManagerTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientManagerTest.java index 5991653..1548af0 100755 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientManagerTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientManagerTest.java @@ -22,8 +22,8 @@ */ @Test(groups = "connected") public class CloudClientManagerTest extends Loggable { - - private ICloudClientManager ICloudClient; + + private ICloudClientManager ICloudClient; @BeforeClass public void setup() throws Exception { @@ -39,7 +39,7 @@ public void testCallTest() { @Test public void testValidateCache() { - // this test passes if the cache autopurge property is set to true + // this test passes if the cache autopurge property is set to true boolean b = ICloudClient.validateCache(); assertTrue(b); } diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientQueryTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientQueryTest.java index f52a968..784297a 100644 --- a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientQueryTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientQueryTest.java @@ -26,8 +26,6 @@ /** - * Date: 20/07/11 - * * @version $Id$ */ @Test(groups = "unit") diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientReadTimeoutTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientReadTimeoutTest.java new file mode 100644 index 0000000..114349f --- /dev/null +++ b/code/src/test/java/com/scientiamobile/wurflcloud/CloudClientReadTimeoutTest.java @@ -0,0 +1,56 @@ +/** + * Copyright (c) 2015 ScientiaMobile Inc. + * + * The WURFL Cloud Client is intended to be used in both open-source and + * commercial environments. To allow its use in as many situations as possible, + * the WURFL Cloud Client is dual-licensed. You may choose to use the WURFL + * Cloud Client under either the GNU GENERAL PUBLIC LICENSE, Version 2.0, or + * the MIT License. + * + * Refer to the COPYING.txt file distributed with this package. + */ +package com.scientiamobile.wurflcloud; + +import static org.testng.Assert.assertTrue; + +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import com.scientiamobile.wurflcloud.device.AbstractDevice; +import com.scientiamobile.wurflcloud.exc.WURFLCloudClientException; +import com.scientiamobile.wurflcloud.cache.WurflCloudCache_Null; +/** + * @version $Id$ + */ +@Test(groups = "unit") +public class CloudClientReadTimeoutTest extends Loggable{ + + private static final String ua = "Mozilla/5.0 (iPad; CPU OS 7_0 like Mac OS X) AppleWebKit/537.51.1 (KHTML, like Gecko) CriOS/30.0.1599.12 Mobile/11A465 Safari/8536.25 (3B92C18B-D9DE-4CB7-A02A-22FD2AF17C8F)"; + + private ICloudClientManager ICloudClient; + private AbstractDevice device; + private String[] capabilities; + + @BeforeClass + public void setup() throws Exception { + + CloudClientLoader loader = new CloudClientLoader(null, "/CloudClientReadTimeoutTest.properties"); + ICloudClient = loader.getClientManager(); + + } + + @Test + public void testClient() { + /** + * Mantaining compatibility with Junit version < 4 + */ + boolean excThrown = false; + try { + device = ICloudClient.getDeviceFromUserAgent(ua, capabilities); + } + catch (WURFLCloudClientException exc) { + excThrown = true; + } + assertTrue(excThrown); + } +} diff --git a/code/src/test/java/com/scientiamobile/wurflcloud/VersionTest.java b/code/src/test/java/com/scientiamobile/wurflcloud/VersionTest.java index a0d90f1..f1e4cfb 100644 --- a/code/src/test/java/com/scientiamobile/wurflcloud/VersionTest.java +++ b/code/src/test/java/com/scientiamobile/wurflcloud/VersionTest.java @@ -19,17 +19,17 @@ @Test(groups = "unit") public class VersionTest extends Loggable { - - /** - * Ensures that the version reported in pom.xml matches the - * String value returned from Constants.CLIENT_VERSION - */ - @Test - public void versionReadTest() { - String versionStr = System.getProperty("wurflcloudversion"); - logger.debug("Version read from pom.xml: " + versionStr); - logger.debug("Version read from Constants.java: " + Constants.CLIENT_VERSION); - Assert.assertEquals(versionStr, Constants.CLIENT_VERSION); - } + + /** + * Ensures that the version reported in pom.xml matches the + * String value returned from Constants.CLIENT_VERSION + */ + @Test + public void versionReadTest() { + String versionStr = System.getProperty("wurflcloudversion"); + logger.debug("Version read from pom.xml: " + versionStr); + logger.debug("Version read from Constants.java: " + Constants.CLIENT_VERSION); + Assert.assertEquals(versionStr, Constants.CLIENT_VERSION); + } } diff --git a/code/src/test/resources/CloudClientReadTimeoutTest.properties b/code/src/test/resources/CloudClientReadTimeoutTest.properties new file mode 100644 index 0000000..62e565a --- /dev/null +++ b/code/src/test/resources/CloudClientReadTimeoutTest.properties @@ -0,0 +1,42 @@ +# +# Copyright (c) 2015 ScientiaMobile Inc. +# +# The WURFL Cloud Client is intended to be used in both open-source and +# commercial environments. To allow its use in as many situations as possible, +# the WURFL Cloud Client is dual-licensed. You may choose to use the WURFL +# Cloud Client under either the GNU GENERAL PUBLIC LICENSE, Version 2.0, or +# the MIT License. +# +# Refer to the COPYING.txt file distributed with this package. +# + +wurflcloud.key=XXXXXX:YYYYYYYYYYYYYYYYYYYYYYYYYYYYYYYY + +wurflcloud.cache=None + +# Timeout on read over connection ( default value 10000 mSec ) +# default is 10000 mSec +wurflcloud.readTimeout=1 + +#Java Cloud Client Configuration File example +#For Simple Client is almost useless + +#to manage gzip compressed response, for network performance +#default is true +#wurflcloud.compression=true + +#You can write whatever you want after wurflcloud.capability. +#From version 2.0, capabilities are optional +#Necessary is the prefix: wurflcloud.capability. (with the trailing dot) +#For example: +#wurflcloud.capability.a=is_wireless_device +#wurflcloud.capability.b=model_name + + +#wurflcloud.capability.0=is_wireless_device +#wurflcloud.capability.1=brand_name +#wurflcloud.capability.2=model_name +#wurflcloud.capability.3=resolution_height +#wurflcloud.capability.4=resolution_width +#wurflcloud.capability.5=pippo + diff --git a/examples/pom.xml b/examples/pom.xml index edb350e..ed2bf5e 100755 --- a/examples/pom.xml +++ b/examples/pom.xml @@ -5,7 +5,7 @@ com.scientiamobile.wurflcloud client-example - 1.0.4 + 1.0.5 war WURFL Cloud Client example webapp diff --git a/examples/src/main/java/my/wurflcloud/example/MyCloudClientServlet.java b/examples/src/main/java/my/wurflcloud/example/MyCloudClientServlet.java index a4cccc7..ad0ef15 100755 --- a/examples/src/main/java/my/wurflcloud/example/MyCloudClientServlet.java +++ b/examples/src/main/java/my/wurflcloud/example/MyCloudClientServlet.java @@ -15,24 +15,23 @@ import com.scientiamobile.wurflcloud.device.AbstractDevice; public class MyCloudClientServlet extends HttpServlet { - private static final long serialVersionUID = -6370538869254374459L; - private final Logger logger = Logger.getLogger(getClass().getName()); + private static final long serialVersionUID = -6370538869254374459L; + private final Logger logger = Logger.getLogger(getClass().getName()); private ICloudClientManager manager; private String[] capabilities; public void init() throws ServletException { super.init(); CloudClientLoader loader; - try { - loader = new CloudClientLoader("nnnnnn:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); // Place your API Key here - //loader = new CloudClientLoader(); // use this constructor to read all the configuration properties from wurflcloud.properties file (including the API Key) - manager = loader.getClientManager(); - capabilities = loader.getSearchedCapabilities(); - } catch (Exception e) { - e.printStackTrace(); - } + try { + loader = new CloudClientLoader("nnnnnn:XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX"); // Place your API Key here + manager = loader.getClientManager(); + capabilities = loader.getSearchedCapabilities(); + } catch (Exception e) { + e.printStackTrace(); + } } - + @Override protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException { doPost(req, resp); diff --git a/examples/src/main/resources/wurflcloud.properties b/examples/src/main/resources/wurflcloud.properties index 40ee797..7cb3523 100755 --- a/examples/src/main/resources/wurflcloud.properties +++ b/examples/src/main/resources/wurflcloud.properties @@ -37,6 +37,16 @@ wurflcloud.cache.reportInterval=15 # Auto-purging cache when WURFL is updated (default is true) wurflcloud.cache.autoPurge=true +####### Connection configuration ####### + +# Timeout on opening connection to server +# default is 5000 mSec +#wurflcloud.connTimeout=5000 + +# Timeout on read over connection +# default is 10000 mSec +#wurflcloud.readTimeout=10000 + ####### Proxy configuration ####### # Proxy URL or IP address diff --git a/examples/src/main/webapp/WEB-INF/web.xml b/examples/src/main/webapp/WEB-INF/web.xml index 5b30a03..b2f8b00 100755 --- a/examples/src/main/webapp/WEB-INF/web.xml +++ b/examples/src/main/webapp/WEB-INF/web.xml @@ -1,15 +1,15 @@ + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> - HelloWorld Cloud Example + HelloWorld Cloud Example - HelloWorld WURFL Cloud Example webapp + HelloWorld WURFL Cloud Example webapp - + HelloWorldCloudServlet my.wurflcloud.example.MyCloudClientServlet 1 @@ -21,7 +21,7 @@ *.htm - - index.jsp - + + index.jsp +