Issue with Google Contacts API - gwt

I'm running an issue with gwt-oauth and Google contacts API.
I use gwt-oauth to login and everything works fine.
While running the RPC for retrieving the contacts I get
WARNING: Authentication error: Unable to respond to any of these challenges: {}
java.lang.NullPointerException: No authentication header information
Here is the code in Client
Button button = new Button("Authenticate with Google");
button.addClickHandler(new ClickHandler() {
#Override
public void onClick(ClickEvent event) {
final AuthRequest req = new AuthRequest(K.GOOGLE_AUTH_URL, K.GOOGLE_CLIENT_ID).withScopes(K.CONTACTS_SCOPE, K.AUTH_SCOPE);
AUTH.expiresIn(req);
AUTH.login(req, new Callback<String, Throwable>() {
#Override
public void onSuccess(final String token) {
greetingService.loginDetails(token, new AsyncCallback<LoginInfo>() {
#Override
public void onSuccess(LoginInfo result) {
greetingService.getContactList(token, new AsyncCallback<Boolean>() {
#Override
public void onSuccess(Boolean result) {
Window.alert("oh");
}
#Override
public void onFailure(Throwable caught) {
Window.alert("Error:\n" + caught.getMessage());
}
});
}
#Override
public void onFailure(Throwable caught) {
// TODO Auto-generated method stub
}
});
}
#Override
public void onFailure(Throwable caught) {
Window.alert("Error:\n" + caught.getMessage());
}
});
}
});
And here the serverside for contacts:
try {
ContactsService s = new ContactsService(K.APPLICATION_NAME);
s.setProtocolVersion(ContactsService.Versions.V3);
s.setAuthSubToken(token);
s.setHeader("Authorization", "Bearer " + token);
for (ContactEntry entry : s.query(new Query(new URL(K.CONTACTS_SCOPE)), ContactFeed.class).getEntries())
System.out.println(entry.toString());
} catch (Exception e) {
e.printStackTrace();
}
return true;
This was working couple of weeks ago...
I assume is not a scope issue since loginDetails works properly...
Any idea?

Solved.
Scope for contacts in Auth was set to: https://www.google.com/m8/feeds/contacts/default/full/
Apparently this doesn't work anymore and I just set https://www.google.com/m8/feeds/ for auth
and the full url for querying in ContactService

Related

How can I test #onFailure method?

How could I go to "#Override public void onFailure(Throwable ex) { ... }"?
It always go "#Override public void onSuccess(SendResult<String, KafkaPresponseDto> result) {...}.
I want to print
log.error("Unable to send message=["+kafkaPgResponseDto.toString()+"] due to : " + ex.getMessage());
Please help...
ListenableFuture<SendResult<String, KafkaPgResponseDto>> future = pgResponseKafkaTemplate.send(kurlyTopicNamePgResponse, kafkaPgResponseDto);
future.addCallback(new ListenableFutureCallback<SendResult<String, KafkaPgResponseDto>>(){
#Override
public void onSuccess(SendResult<String, KafkaPgResponseDto> result) {
KafkaPgResponseDto kafkaPgResponseDto = result.getProducerRecord().value();
log.debug("Send message=["+kafkaPgResponseDto.toString()+"] with offset=["+result.getRecordMetadata().offset()+"]");
}
#Override
public void onFailure(Throwable ex) {
log.error("Unable to send message=["+kafkaPgResponseDto.toString()+"] due to : "+ex.getMessage());
kafkaTransactionService.failedProcessingKafkaHistorySave(orderNo, kurlyTopicNamePgResponse, gson.toJson(payload), ex.toString());
}
});
I believe there is no need in the real Kafka to test your functionality. Consider to use a MockProducer for injection into that KafkaTemplate and emulate an error for that onFailure() case: https://www.baeldung.com/kafka-mockproducer

Getting skipped frames with RxAndroid on a simple call

I'm implementing in a LauncherActivity (with just a loading indicator) an Observable (Single) from RxJava library to login with the previously recorded users credentials.
The activity is very very simple, and yet I get a skipped frames warning (40ish), both on my phone and on emulator, and I can't figure out why (though sometimes it doesn't show up).
Here is the code :
public class LauncherActivity extends AppCompatActivity {
#Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_launcher);
mProgressBar = findViewById(R.id.progress_bar);
mProgressBar.setVisibility(View.VISIBLE);
if (UsersUtils.hasCredentialsRecorded(this)) {
getAccessToken();
} else {
login();
}
}
public void getAccessToken() {
Callable<Token> callable = new Callable<Token>() {
#Override
public Token call() throws Exception {
final Map<String, byte[]> credentials = UsersUtils.getCredentials(getApplicationContext());
Token token = OauthCalls.getToken(new String(credentials.get(UsersUtils.PREFERENCES_USER_KEY)),
new String(credentials.get(UsersUtils.PREFERENCES_PASS_KEY)));
return token;
}
};
Single.fromCallable(callable)
.subscribeOn(Schedulers.io())
.subscribe(new DisposableSingleObserver<Token>() {
#Override
public void onSuccess(Token token) {
if (token == null) {
login();
} else {
Intent intent = new Intent(getApplicationContext(), MainActivity.class);
startActivity(intent);
}
}
#Override
public void onError(Throwable e) {
login();
}
});
}
public void login() {
Intent intent = new Intent(this, LoginActivity.class);
startActivity(intent);
}
}
Thanks a lot for your help !

Android Webview signout issue

In my webview app when I run the app for the first time and log out from a user session, close the app and then when I open the app again instead of asking user credentials I find myself already logged in. I tried clearing cookies but then it always require sign in on every restart. I only want it to ask for sign in when the user logs out from the app.
Please Help!!
Here is a snippet of the code:
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
frameLayout = (FrameLayout) findViewById(R.id.framelayout);
bar = (ProgressBar) findViewById(R.id.progressBar2);
bar.setMax(100);
webview = (WebView) findViewById(R.id.mywebview);
webview.clearCache(true);
webview.clearHistory();
WebSettings mWebSettings = webview.getSettings();
mWebSettings.setSaveFormData(false);
swipe = (SwipeRefreshLayout) findViewById(R.id.swipe);
swipe.setOnRefreshListener(new SwipeRefreshLayout.OnRefreshListener() {
#Override
public void onRefresh() {
LoadWeb();
}
});
LoadWeb();
}
public void LoadWeb(){
webview = (WebView) findViewById(R.id.mywebview);
webview.setWebViewClient(new HelpClient());
webview.setWebChromeClient(new WebChromeClient(){
#Override
public void onProgressChanged(WebView view, int newProgress) {
frameLayout.setVisibility(View.VISIBLE);
bar.setProgress(newProgress);
setTitle("Loading....");
if (newProgress == 100){
frameLayout.setVisibility(View.GONE);
setTitle(view.getTitle());
}
super.onProgressChanged(view, newProgress);
}
});
webview.getSettings().setJavaScriptEnabled(true);
webview.setVerticalScrollBarEnabled(false);
webview.loadUrl(WebAddress);
webview.loadUrl("javascript:window.location.reload(true)");
swipe.setRefreshing(false);
bar.setProgress(0);
}
private class HelpClient extends WebViewClient{
#Override
public boolean shouldOverrideUrlLoading(WebView view, String url) {
view.loadUrl(url);
frameLayout.setVisibility(view.VISIBLE);
return true;
}
#Override
public void onPageFinished(WebView view, String url) {
swipe.setRefreshing(false);
}
#Override
public void onReceivedError(WebView view, WebResourceRequest request, WebResourceError error) {
try {
webview.stopLoading();
} catch (Exception e) {
}
if (webview.canGoBack()) {
webview.goBack();
}
webview.loadUrl("about:blank");
AlertDialog alertDialog = new AlertDialog.Builder(MainActivity.this).create();
alertDialog.setTitle("Error");
alertDialog.setMessage("Check your internet connection and try again.");
alertDialog.setButton(DialogInterface.BUTTON_POSITIVE, "Try Again", new DialogInterface.OnClickListener() {
#Override
public void onClick(DialogInterface dialogInterface, int i) {
finish();
startActivity(getIntent());
}
});
alertDialog.show();
super.onReceivedError(view, request, error);
}
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK){
if (webview.canGoBack()){
webview.goBack();
return true;
}
}
return super.onKeyDown(keyCode, event);
}
Run below code before loadUrl()
WebStorage webStorage = WebStorage.getInstance();
webStorage.deleteAllData();
CookieSyncManager.createInstance(this);
CookieManager cookieManager = CookieManager.getInstance();
cookieManager.removeAllCookie();
I test it using Gmail account
CookieSynManager is now deprecated. This works for me :
WebStorage.getInstance().deleteAllData()
CookieManager.getInstance().removeAllCookies(null)

Deezer android sdk UI freeze during login

I implemented the Deeezer android SDK in my application and I got a user who can't log into its Deezer account on its Motorola Razr I. The login UI freezes on this page and the application restarts. He doesn't encounter the issue on its other devices.
The SDK version I use is 0.9.3
Here is a screenshot of the page where the application freezes.
What kind of information would help identify the issue?
Edit
Here is the source code :
public class LoginActivity extends Activity
{
protected static final String[] PERMISSIONS = new String[] {"basic_access", "manage_library", "delete_library", "listening_history", "manage_community"};
// DeezerConnect object
private DeezerConnect m_deezerConnect;
// Handle connection callbacks.
private DialogHandler m_dialogHandler = new DialogHandler();
// if the authentication failed, retry once
private boolean m_firstTry = true;
/** Called when the activity is first created. */
#Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.login_activity);
m_deezerConnect = new DeezerConnectImpl(getString(R.string.deezer_app_id));
SessionStore sessionStore = new SessionStore();
AlertDialog.Builder deezerAuthDialog = new AlertDialog.Builder(this);
deezerAuthDialog.setTitle(R.string.deezer_authentication);
deezerAuthDialog.setMessage(R.string.enter_deezer_credentials);
deezerAuthDialog.setPositiveButton(R.string.ok, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
connectToDeezer(m_dialogHandler);
}
});
deezerAuthDialog.setNegativeButton(R.string.cancel, new DialogInterface.OnClickListener()
{
#Override
public void onClick(DialogInterface dialog, int which)
{
dialog.dismiss();
finish();
}
});
deezerAuthDialog.setOnCancelListener(new DialogInterface.OnCancelListener()
{
#Override
public void onCancel(DialogInterface dialog)
{
finish();
}
});
deezerAuthDialog.show();
}
#Override
public void onResume()
{
super.onResume();
}
#Override
public void onDestroy()
{
super.onDestroy();
}
/**
* Connects to Deezer web services using an injectable DialogListener listener.
* #param listener event listener that will be notified of the connection progress.
*/
private void connectToDeezer(final DialogListener listener)
{
m_deezerConnect.authorize(this, PERMISSIONS, listener);
}
/** Handle DeezerConnect callbacks. */
private class DialogHandler implements DialogListener
{
#Override
public void onComplete(final Bundle values)
{
SessionStore sessionStore = new SessionStore();
sessionStore.save(m_deezerConnect, LoginActivity.this);
LoginActivity.this.finish();
}
#Override
public void onDeezerError(final DeezerError deezerError)
{
Log.e(DeemoteGlobals.TAG, "DialogError error during login" , deezerError );
LoginActivity.this.finish();
}
#Override
public void onError(final DialogError dialogError)
{
// the api returns an error while the authentication succeed, so we force a retry once
int errorCode = dialogError.getErrorCode();
if (errorCode == -10 && m_firstTry)
{
m_firstTry = false;
connectToDeezer(m_dialogHandler);
return;
}
Log.e(DeemoteGlobals.TAG, "DialogError error during login", dialogError);
}
LoginActivity.this.finish();
}
#Override
public void onCancel()
{
LoginActivity.this.finish();
}
#Override
public void onOAuthException(OAuthException oAuthException)
{
LoginActivity.this.finish();
}
}
}

How to integrate oauth with gwt?

Here is my code, how do I use oauth to get the data such as user_id or first and last name of the user and sign them to fields? Should I implement them in the onSuccess method?
private void addFacebookAuth(){
loginButton.addClickHandler(new ClickHandler(){
#Override
public void onClick(ClickEvent event) {
final AuthRequest req = new AuthRequest(FACEBOOK_AUTH_URL, FACEBOOK_APP_ID).withScopes(
FACEBOOK_EMAIL_SCOPE,
FACEBOOK_BIRTHDAY_SCOPE,
FACEBOOK_USERID_SCOPE,
FACEBOOK_USER_LAST_NAME_SCOPE,
FACEBOOK_USER_FIRST_NAME_SCOPE).withScopeDelimiter(",");
AUTH.login(req, new Callback<String, Throwable>(){
#Override
public void onFailure(Throwable reason) {
Window.alert("Error:\n" + reason.getMessage());
}
#Override
public void onSuccess(String token) {
// Window.alert("Got an OAuth token:\n" + token + "\n"
// + "Token expires in " + AUTH.expiresIn(req) + " ms\n");
RootPanel.get().remove(loginButton);
}
});
}
});
RootPanel.get().add(loginButton);
}