implementing afterlogin

Hi,

The below code keeps throwing “com.backendless.BackendlessUser cannot be cast to java”.
It worked previously, until I remove afterlogin servercode.

public void afterLogin( RunnerContext context, String login, String password, ExecutionResult<HashMap> result ) throws Exception

{		

	HashMap user = result.getResult(); //this line throws exception

	user.put("loginTime", new Double(System.currentTimeMillis()));

}

Thanks

Hi, Scott,
Could you please provide full exception message with stacktrace?
And also what actions do you keep in mind when saying “remove afterlogin servercode”?

Hi Sergey,

Aug 10, 2015 2:30:47 PM com.backendless.coderunner.runtime.task.EventInvocationTask runImpl

SEVERE: com.backendless.BackendlessUser cannot be cast to java.util.HashMap

java.lang.reflect.InvocationTargetException

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)

at java.lang.reflect.Method.invoke(Method.java:606)

at com.backendless.coderunner.runtime.task.EventInvocationTask.runImpl(EventInvocationTask.java:97)

at com.backendless.coderunner.runtime.concurrent.ExtendedRunnable.run(ExtendedRunnable.java:22)

at java.lang.Thread.run(Thread.java:745)

Caused by: java.lang.ClassCastException: com.backendless.BackendlessUser cannot be cast to java.util.HashMap

at com.backendless.bzzle.events.user_service.GenericUserEventHandler.afterLogin(GenericUserEventHandler.java:124)

Forget about “remove”, I just want to point out that a while ago, when I tested afterLogin, below line of code did not throw error.
HashMap user = result.getResult();

Thanks

Hi!
You receive BackendlessUser object instead of HashMap, so simply cast it. But please be aware that ExceptionResult may be an exception also.

 @Override
 public void afterLogin( RunnerContext context, String login, String password, ExecutionResult result ) throws Exception
 {
 Object obj = result.getResult();
 if (obj instanceof BackendlessUser) {
 BackendlessUser user = (BackendlessUser) obj;
 user.setProperty("loginTime", (double) System.currentTimeMillis());
 }
 }

Doc:
If authentication is successful, the result is the user object,
otherwise if the invocation resulted in an error, it also available
through the ExecutionResult object.

Regards,
Artur Dzidzoiev

Thanks Artur.

Hi, Scott

Thank you for your report, it helped us to discover a new bug.

So please note, that code above is only a temporal workaround. In the next upcoming release it will be fixed and you will receive HashMap instead of BackendlessUser as designed.

Thank you for making Backendless better!

Regards,
Artur.

Hi Arthur,

I wish all the best and hope that your service becomes stable and bugless.

There is one issue that I found today which I wan’t going to report.
I was unable to retrieve relation property for user.
Retrieving all user properties works without a problem, but if querying for relations property, then server responds with null to that property.
The issue can be reproduced from console.
I’ve attached files.

I will keep on reporting if there’s anything.

Regards,
Scott

Hi, Scott,

Could you please also add a screenshot with the user you’re trying to load relations to?

Hi Sergey,
Even if auto load is set?How do I define explicitly?

Sorry, I missed to look into your second screenshot. Please look at my edited comment above.

I am not sure what you are asking for, but I attached user table screenshot.

Above attachment shows that “photo” relation is loaded in “all” , but not in “relation”, both requesting from user with prop uid = ‘1000001’.
This issue can be easily reproduced from console, you can simply add user prop, relation to geoPoint from console and from console, run query like I did.

OK, thank you for reporting. We’ll try to reproduce it and then will inform you about the results.

Thanks Sergey.
It’s just that I could have my code to retrieve all data to get relation prop, but some of the user props are private and shouldn’t be retrieved.

Hi, Scott.

We are glad to inform you that issue has been fixed and you can use ExecutionResult<HashMap> result as documented!

Thanks,
Artur.