Skip to content
This repository has been archived by the owner on Jun 18, 2024. It is now read-only.

Commit

Permalink
Browse files Browse the repository at this point in the history
…-Android into dev
  • Loading branch information
anihojnadel committed Nov 19, 2014
2 parents e7f700f + 6288ecc commit a2a72e7
Show file tree
Hide file tree
Showing 8 changed files with 34 additions and 146 deletions.
3 changes: 3 additions & 0 deletions sdk/odata-engine-android-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ dependencies {
compile fileTree(dir: 'libs', include: ['*.jar'])
compile 'com.google.code.gson:gson:2.3'
compile project(':odata-engine-core')
compile('com.microsoft.aad:adal:(,2.0)') {
exclude group: 'com.android.support'
}
}

apply from : '../android-libraries.gradle'
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,26 @@
import com.microsoft.services.odata.Constants;
import com.microsoft.services.odata.impl.http.AndroidHttpTransport;
import com.microsoft.services.odata.impl.http.RequestImpl;
import com.microsoft.services.odata.interfaces.*;
import com.microsoft.services.odata.interfaces.Credentials;
import com.microsoft.services.odata.interfaces.DependencyResolver;
import com.microsoft.services.odata.interfaces.HttpTransport;
import com.microsoft.services.odata.interfaces.JsonSerializer;
import com.microsoft.services.odata.interfaces.ODataURL;
import com.microsoft.services.odata.interfaces.Request;

/**
* The type Default dependency resolver.
*/
public class DefaultDependencyResolver implements DependencyResolver {

private CredentialsFactory credentialsFactory;
private LoggerImpl logger;
private String token;

/**
* Instantiates a new Default dependency resolver.
*/
public DefaultDependencyResolver() {
public DefaultDependencyResolver(String token) {
this.token = token;
this.logger = new LoggerImpl();
}

Expand All @@ -37,11 +43,6 @@ public JsonSerializer getJsonSerializer() {
return new GsonSerializer();
}

@Override
public CredentialsFactory getCredentialsFactory() {
return credentialsFactory;
}

@Override
public ODataURL createODataURL() {
return new ODataURLImpl();
Expand All @@ -59,15 +60,15 @@ public String getPlatformUserAgent(String productName) {
"%s/1.0 (lang=%s; os=%s; os_version=%s; arch=%s; version=%s)",
productName, "Java", "Android", Build.VERSION.RELEASE,
Build.CPU_ABI, Constants.SDK_VERSION);

}

/**
* Sets credentials factory.
*
* @param credentialsFactory the credentials factory
*/
public void setCredentialsFactory(CredentialsFactory credentialsFactory) {
this.credentialsFactory = credentialsFactory;
@Override
public Credentials getCredentials() {
return new Credentials() {
@Override
public void prepareRequest(Request request) {
request.addHeader("Authorization", "Bearer " + token);
}
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.SettableFuture;
import com.microsoft.services.odata.interfaces.Credentials;
import com.microsoft.services.odata.interfaces.CredentialsFactory;
import com.microsoft.services.odata.interfaces.DependencyResolver;
import com.microsoft.services.odata.interfaces.HttpTransport;
import com.microsoft.services.odata.interfaces.LogLevel;
Expand Down Expand Up @@ -69,13 +68,10 @@ protected ListenableFuture<ODataResponse> oDataExecute(Request request) {
}

boolean credentialsSet = false;
CredentialsFactory credFactory = resolver.getCredentialsFactory();
if (credFactory != null) {
Credentials cred = credFactory.getCredentials();
if (cred != null) {
cred.prepareRequest(request);
credentialsSet = true;
}
Credentials cred = resolver.getCredentials();
if (cred != null) {
cred.prepareRequest(request);
credentialsSet = true;
}

if (!credentialsSet) {
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,6 @@ public interface DependencyResolver {
*/
JsonSerializer getJsonSerializer();

/**
* Gets credentials factory.
*
* @return the credentials factory
*/
CredentialsFactory getCredentialsFactory();

/**
* Create o data uRL.
*
Expand All @@ -52,4 +45,11 @@ public interface DependencyResolver {
* @return the user agent
*/
String getPlatformUserAgent(String productName);

/**
* Gets credentials.
*
* @return the credentials
*/
Credentials getCredentials();
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,11 @@
import com.microsoft.discoveryservices.odata.DiscoveryClient;
import com.microsoft.listservices.SharepointListsClient;
import com.microsoft.office365.test.integration.TestPlatformContext;
import com.microsoft.office365.test.integration.framework.OAuthCredentials;
import com.microsoft.office365.test.integration.framework.TestCase;
import com.microsoft.office365.test.integration.framework.TestExecutionCallback;
import com.microsoft.office365.test.integration.framework.TestResult;
import com.microsoft.outlookservices.odata.OutlookClient;
import com.microsoft.services.odata.impl.DefaultDependencyResolver;
import com.microsoft.services.odata.impl.http.CredentialsFactoryImpl;
import com.microsoft.services.odata.interfaces.DependencyResolver;
import com.microsoft.services.odata.interfaces.LogLevel;
import com.microsoft.sharepointservices.odata.SharePointClient;
Expand Down Expand Up @@ -250,7 +248,8 @@ public void onError(Exception exc) {
public void onSuccess(AuthenticationResult result) {
TClient client = null;
try {
client = clientClass.getDeclaredConstructor(String.class, DependencyResolver.class).newInstance(endpointUrl, getDependencyResolver(result.getAccessToken()));
client = clientClass.getDeclaredConstructor(String.class, DependencyResolver.class)
.newInstance(endpointUrl, getDependencyResolver(result.getAccessToken()));
future.set(client);
} catch (Throwable t) {
onError(new Exception(t));
Expand Down Expand Up @@ -303,12 +302,8 @@ public void onSuccess(AuthenticationResult result) {
}

private DependencyResolver getDependencyResolver(final String token) {
OAuthCredentials credentials = new OAuthCredentials(token);
CredentialsFactoryImpl credFactory = new CredentialsFactoryImpl();
credFactory.setCredentials(credentials);

DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver();
dependencyResolver.setCredentialsFactory(credFactory);
DefaultDependencyResolver dependencyResolver = new DefaultDependencyResolver(token);

dependencyResolver.getLogger().setEnabled(true);
dependencyResolver.getLogger().setLogLevel(LogLevel.VERBOSE);
Expand Down

0 comments on commit a2a72e7

Please sign in to comment.