Skip to content

Commit

Permalink
Merge pull request #1 from WURFL/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
elliotfehr committed Oct 21, 2015
2 parents 67acf01 + 651a4b2 commit 3c4e061
Show file tree
Hide file tree
Showing 51 changed files with 301 additions and 146 deletions.
8 changes: 8 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Contributing Guidelines
=======================

The WURFL Cloud Client for Java is released under the GNU GENERAL PUBLIC LICENSE, Version 2.0, as well as the MIT License.

Contributors agree that any contributions are owned by the copyright holder and that contributors have absolutely no rights to their contributions.

To get started, sign the [Contributor License Agreement](https://www.clahub.com/agreements/WURFL/wurfl-cloud-client-java).
2 changes: 1 addition & 1 deletion code/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>com.scientiamobile.wurflcloud</groupId>
<artifactId>client-java</artifactId>
<version>1.0.3</version>
<version>1.0.4</version>
<packaging>jar</packaging>

<name>wurfl-cloud-client</name>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.Set;
import java.util.zip.GZIPInputStream;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.codehaus.jackson.map.ObjectMapper;
Expand All @@ -44,8 +43,6 @@


/**
* Date: 22/07/11
* <p/>
* Cloud thin client, associated to every request.
*/
public class CloudClient extends Loggable implements ICloudClientRequest, Constants, Serializable {
Expand Down Expand Up @@ -82,7 +79,7 @@ public class CloudClient extends Loggable implements ICloudClientRequest, Consta
/**
* The incoming request, not propagated to the Cloud Server!
*/
private final HttpServletRequest request;
private final CloudRequest request;

/**
* The response that will be served to the client application.
Expand Down Expand Up @@ -111,7 +108,7 @@ public class CloudClient extends Loggable implements ICloudClientRequest, Consta
* @param recoveryManager
* @param clientManager
*/
protected CloudClient(HttpServletRequest request, HttpServletResponse response, CloudClientConfig cfg, String[] searchCapabilities, Credentials credentials, IWurflCloudCache cache, CloudClientManager clientManager, Proxy proxy) {
protected CloudClient(CloudRequest request, HttpServletResponse response, CloudClientConfig cfg, String[] searchCapabilities, Credentials credentials, IWurflCloudCache cache, CloudClientManager clientManager, Proxy proxy) {
this.response = response;
this.request = request;
this.searchCapabilities = searchCapabilities;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,14 +32,6 @@

/**
* Entry point for Cloud Client Application.
* It looks for a 'wurfcloud.properties' file, in the root of classpath.
* This file is optional, and it is significant only in premium version.
* There you configure searched capabilities, cache type and so on.
* Searched capabilities are optional, from version 2.0.
* If you query for unauthorized capabilities, an exception will be raised.
* This is an application singleton, which give access to client functionality.
* <p/>
* @version $Id$
*/
public class CloudClientLoader extends Loggable implements Constants, Serializable {
private static final long serialVersionUID = 2L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@

/**
* WURFL Cloud Client Manager.
* It's the general responsible for client managing, in singleton fashion.
* It creates a fresh new CloudClient instance, for every request.
*/
public class CloudClientManager extends Loggable implements CloudListener, ICloudClientManager, Serializable {
private static final long serialVersionUID = 2L;
Expand Down Expand Up @@ -138,23 +136,35 @@ public String getClientVersion() {
return clientVersion;
}

/**
* {@inheritDoc}
*/
public AbstractDevice getDeviceFromRequest(HttpServletRequest request, HttpServletResponse response, String... search_capabilities) {
CloudClient cc = new CloudClient(request, response, config, (search_capabilities != null && search_capabilities.length > 0) ? search_capabilities : parsedCapabilities, credentials, cache, this, proxy);
private AbstractDevice detectDevice(CloudClient client) {
read.lock();
AbstractDevice dev = null;
try {
try {
return cc.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 {
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 {
read.unlock();
}
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) {
CloudClient cc = new CloudClient(new DefaultCloudRequest(request), response, config, (search_capabilities != null && search_capabilities.length > 0) ? search_capabilities : parsedCapabilities, credentials, cache, this, proxy);
return detectDevice(cc);
}

/**
Expand Down Expand Up @@ -229,7 +239,7 @@ public Object nextElement() {
HttpServletResponse response = mock(HttpServletResponse.class);

// Determine the HTTP method to use and grab the response from the server
CloudClient client = new CloudClient(request, response, config, new String[0], credentials, cache, this, proxy);
CloudClient client = new CloudClient(new DefaultCloudRequest(request), response, config, new String[0], credentials, cache, this, proxy);
return client.testCall(Constants.Encoding.PLAIN);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

/**
* Thin response event.
* $Id$
*
*/
public class CloudEvent extends EventObject {
private static final long serialVersionUID = 1L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,7 @@
package com.scientiamobile.wurflcloud;

/**
* listener for update, receiving a cloud response.
* At this moment the CloudClientManager only is listener
*
* $Id$
* Listener for update, receiving a cloud response.
*/
public interface CloudListener {

Expand Down
28 changes: 21 additions & 7 deletions code/src/main/java/com/scientiamobile/wurflcloud/CloudRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,22 +11,36 @@
*/
package com.scientiamobile.wurflcloud;

import java.util.Enumeration;

import javax.servlet.http.Cookie;

/**
* @version $Id$
* CloudRequest interface
*/
public interface CloudRequest {

/**
* Retrieves the user agent
* @return The user agent
* Returns all the header names
* @return The header names
*/
String getUserAgent();
Enumeration<String> 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
*/
String getRemoteAddr();

/**
* Retrieves the Cloud cookie
* @return The @{link Cookie} instance
* @return The stored {@link Cookie} array, if available
*/
Cookie getCloudCookie();
Cookie[] getCookies();
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
/**
* Bean which is automatically filled by json engine.
*
* $Id$
*/
public class CloudResponse extends Loggable implements Serializable {
private static final long serialVersionUID = 2L;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@
*/
package com.scientiamobile.wurflcloud;



/**
* Abstraction of a server, in a server pool structure.
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/**
* 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 java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import java.util.Vector;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;

import com.scientiamobile.wurflcloud.utils.Constants;

/**
* CloudRequest default implementation.
*
*/
public final class DefaultCloudRequest implements CloudRequest {

private final Map<String, String> headers = new HashMap<String, String>();

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<String> getHeaderNames() {
return new Vector<String>(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.");
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import com.scientiamobile.wurflcloud.utils.Credentials;

/**
* @version $Id$
* AuthenticationManager interface
*/
public interface IAuthenticationManager {
/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
import javax.servlet.http.HttpServletResponse;

/**
* @version $Id$
* CloudClientManager interface
*/
public interface ICloudClientManager {
String getClientVersion();
Expand All @@ -31,6 +31,14 @@ public interface ICloudClientManager {
*/
AbstractDevice getDeviceFromRequest(HttpServletRequest request, HttpServletResponse response, String... search_capabilities);

/**
* Retrieves a {@link AbstractDevice} instance given the user agent and an optional array of capabilities
* @param userAgent The user agent string
* @param search_capabilities Array of capabilities that you would like to retrieve, optional
* @return A {@link AbstractDevice} instance
*/
AbstractDevice getDeviceFromUserAgent(String userAgent, String... search_capabilities);

/**
* Checks if local cache is still valid based on the date that the WURFL Cloud Server
* was last updated. If auto_purge is enabled, this method will clear the cache provider
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@

/**
* The client request interface
* @version $Id$
*/
public interface ICloudClientRequest {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,7 @@
import org.slf4j.LoggerFactory;

/**
* <p/>
* Facility logging superclass.
*
* @version $Id$
* Facility logging base class
*/
public abstract class Loggable {
protected final Logger logger = LoggerFactory.getLogger(getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@
package com.scientiamobile.wurflcloud;

/**
* Response types.
* $Id$
* Response types.
*/
public enum ResponseType {
cloud, cache, cookie, recovery
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,10 @@
*/
package com.scientiamobile.wurflcloud.cache;

import com.scientiamobile.wurflcloud.CloudRequest;
import com.scientiamobile.wurflcloud.ICloudClientRequest;
import com.scientiamobile.wurflcloud.device.AbstractDevice;

import javax.servlet.http.HttpServletRequest;

/**
* @version $Id$
*/
public abstract class AbstractUseragentWurflCloudCache extends AbstractWurflCloudCache {

/**
Expand All @@ -27,7 +23,7 @@ public abstract class AbstractUseragentWurflCloudCache extends AbstractWurflClou
* @return A {@link AbstractDevice} instance, or null if there's no such device cached
*/
@Override
public final AbstractDevice getDevice(HttpServletRequest request, ICloudClientRequest client) {
public final AbstractDevice getDevice(CloudRequest request, ICloudClientRequest client) {
if (request == null) return null;
String userAgent = request.getHeader(USER_AGENT_LC);
return getDeviceFromUserAgent(userAgent);
Expand Down
Loading

0 comments on commit 3c4e061

Please sign in to comment.