Android Open Source - socialcde4android Get O Auth Data_ Operation From Project Back to project page socialcde4android .
License The source code is released under:
MIT License
If you think the Android project socialcde4android listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.
Java Source Code package it.uniba.socialcde4android.data.operation;
/ * w w w . j a v a 2 s . c o m * /
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.net.HttpURLConnection;
import java.net.URL;
import it.uniba.socialcde4android.config.Config;
import it.uniba.socialcde4android.costants.Consts;
import it.uniba.socialcde4android.costants.Error_consts;
import it.uniba.socialcde4android.preferences.Preferences;
import it.uniba.socialcde4android.shared.library.WOAuthData;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import com.foxykeep.datadroid.exception.ConnectionException;
import com.foxykeep.datadroid.exception.CustomRequestException;
import com.foxykeep.datadroid.exception.DataException;
import com.foxykeep.datadroid.requestmanager.Request;
import com.foxykeep.datadroid.service.RequestService.Operation;
import com.google.gson.Gson;
public class GetOAuthData_Operation implements Operation{
@Override
public Bundle execute(Context context, Request request)
throws ConnectionException, DataException, CustomRequestException {
String username = request.getString(Preferences.USERNAME);
String password = request.getString(Preferences.PASSWORD);
String service = request.getString(Consts.SERVICE_ID);
String host = request.getString(Preferences.PROXYSERVER) + "/SocialTFSProxy.svc" ;
WOAuthData woutAuthData = null;
try {
URL url = new URL(host + "/GetOAuth1Data" );
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setConnectTimeout(Config.CONN_TIMEOUT_MS);
conn.setReadTimeout(Config.READ_TIMEOUT_MS);
conn.setRequestMethod("POST" );
conn.setDoOutput(true);
conn.setDoInput(true);
conn.setUseCaches(false);
conn.setAllowUserInteraction(false);
conn.setRequestProperty("Content-Type" , "application/json" );
// Create the form content
OutputStream out = conn.getOutputStream();
Writer writer = new OutputStreamWriter(out, "UTF-8" );
writer.write("{ \"username\":\"" + username + "\", \"password\":\""
+ password + "\" , \"service\":\"" + service + "\" }" );
writer.close();
out.close();
int status = conn.getResponseCode();
if (status >= 200 && status <= 299) {
InputStreamReader in = new InputStreamReader(
conn.getInputStream());
BufferedReader br = new BufferedReader(in);
String output;
String result = "" ;
while ((output = br.readLine()) != null) {
result += output;
}
br.close();
Gson gson = new Gson();
woutAuthData = gson.fromJson(result, WOAuthData.class);
}else {
throw new ConnectionException ("Error retrieving services" , Error_consts.ERROR_RETRIEVING_SERVICES);
}
conn.disconnect();
} catch (java.net.SocketTimeoutException e) {
throw new ConnectionException ("Error retrieving services" , Error_consts.ERROR_GET_OAUTHDATA * Error_consts.TIMEOUT_FACTOR);
} catch (Exception e) {
throw new ConnectionException ("Error retrieving services" , Error_consts.ERROR_GET_OAUTHDATA);
}
Bundle bundle = new Bundle();
Log.i("woutdata" ,woutAuthData.toString());
bundle.putParcelable(Consts.OAUTH_DATA, woutAuthData);
bundle.putInt(Consts.REQUEST_TYPE, Consts.REQUESTTYPE_GETOAUTDATA);
bundle.putString(Consts.SERVICE_ID, service);
bundle.putInt(Consts.OAUTH_VERSION, Integer.valueOf(request.getString(Consts.OAUTH_VERSION)));
return bundle;
}
}
Java Source Code List it.uniba.socialcde4android.activity.HomeActivity.java it.uniba.socialcde4android.activity.LoginActivity.java it.uniba.socialcde4android.activity.RegistrationActivity.java it.uniba.socialcde4android.activity.WebViewActivity.java it.uniba.socialcde4android.adapters.ConfiguratedImageLoader.java it.uniba.socialcde4android.adapters.FeaturesAdapter.java it.uniba.socialcde4android.adapters.ServicesAdapter.java it.uniba.socialcde4android.adapters.SquareImageView.java it.uniba.socialcde4android.adapters.TimeLineAdapter.java it.uniba.socialcde4android.adapters.UserAvatarsAdapter.java it.uniba.socialcde4android.adapters.UsersAdapter.java it.uniba.socialcde4android.config.Config.java it.uniba.socialcde4android.costants.Consts.java it.uniba.socialcde4android.costants.Error_consts.java it.uniba.socialcde4android.costants.Services_id.java it.uniba.socialcde4android.data.operation.Authorize_Operation.java it.uniba.socialcde4android.data.operation.ChangePasswordWithPassword_Operation.java it.uniba.socialcde4android.data.operation.GetAvailableAvatars_Operation.java it.uniba.socialcde4android.data.operation.GetColleagueProfile_Operation.java it.uniba.socialcde4android.data.operation.GetFeatures_Operation.java it.uniba.socialcde4android.data.operation.GetFriends_Operation.java it.uniba.socialcde4android.data.operation.GetHideSettings_Operation.java it.uniba.socialcde4android.data.operation.GetOAuthData_Operation.java it.uniba.socialcde4android.data.operation.GetUser_Operation.java it.uniba.socialcde4android.data.operation.IsUsernameAvailable_Operation.java it.uniba.socialcde4android.data.operation.IsWebServiceRunning_Operation.java it.uniba.socialcde4android.data.operation.RecordService_Operation.java it.uniba.socialcde4android.data.operation.RetrieveServices_Operation.java it.uniba.socialcde4android.data.operation.SendTFSpost_Operation.java it.uniba.socialcde4android.data.operation.SetActiveFeatures_Operation.java it.uniba.socialcde4android.data.operation.SetAvatar_Operation.java it.uniba.socialcde4android.data.operation.SetFollowed_Operation.java it.uniba.socialcde4android.data.operation.SetHideSettings_Operation.java it.uniba.socialcde4android.data.operation.SubscribeUser_Operation.java it.uniba.socialcde4android.data.operation.UnregisterService_Operation.java it.uniba.socialcde4android.data.requestmanager.SocialCDERequestFactory.java it.uniba.socialcde4android.data.requestmanager.SocialCDERequestManager.java it.uniba.socialcde4android.data.service.SocialCDERequestService.java it.uniba.socialcde4android.dialogs.ChangePasswordDialog.java it.uniba.socialcde4android.dialogs.ChooseAvatarDialog.java it.uniba.socialcde4android.dialogs.HideUnhideDialog.java it.uniba.socialcde4android.dialogs.NoNetworkDialog.java it.uniba.socialcde4android.dialogs.SetServiceFeaturesDialog.java it.uniba.socialcde4android.dialogs.TFSAuthDialog.java it.uniba.socialcde4android.fragments.TimeLine_AbstractFragment.java it.uniba.socialcde4android.fragments.TimeLine_Fragment.java it.uniba.socialcde4android.fragments.WUserColleagueProfile_Fragment.java it.uniba.socialcde4android.fragments.WUserProfile_Fragment.java it.uniba.socialcde4android.preferences.Preferences.java it.uniba.socialcde4android.shared.library.JsonDateDeserializer.java it.uniba.socialcde4android.shared.library.WFeature.java it.uniba.socialcde4android.shared.library.WHidden.java it.uniba.socialcde4android.shared.library.WOAuthData.java it.uniba.socialcde4android.shared.library.WPost.java it.uniba.socialcde4android.shared.library.WService.java it.uniba.socialcde4android.shared.library.WUser.java it.uniba.socialcde4android.utility.ScreenUtility.java