HiddenStage / divide

Apache License 2.0
280 stars 26 forks source link

DAOException: User Doesnt exist #8

Open ansgarm opened 9 years ago

ansgarm commented 9 years ago

Hey, I followed your server getting started and get the following Exception. Did I miss to include some library or something? (I try to login an anonymous user)

2014-10-13 15:06:32.222 /api/auth 401 85ms 0kb Dalvik/1.6.0 (Linux; U; Android 4.4.2; Google Nexus 5 - 4.4.2 - API 19 - 1080x1920 Build/KOT49H) module=default version=1
185.23.225.200 - - [13/Oct/2014:15:06:32 -0700] "PUT /api/auth HTTP/1.1" 401 240 - "Dalvik/1.6.0 (Linux; U; Android 4.4.2; Google Nexus 5 - 4.4.2 - API 19 - 1080x1920 Build/KOT49H)" "xy.appspot.com" ms=85 cpu_ms=70 cpm_usd=0.000027 app_engine_release=1.9.13 instance=00c61b117c315e2c4a0ec476934a4fd149b0ec
E 2014-10-13 15:06:32.218
io.divide.server.endpoints.AuthenticationEndpoint userSignIn: io.divide.shared.server.DAO$DAOException: User Doesnt exist
    at io.divide.shared.server.AuthServerLogic.userSignIn(AuthServerLogic.java:86)
    at io.divide.server.endpoints.AuthenticationEndpoint.userSignIn(AuthenticationEndpoint.java:95)
    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.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_$1.run(Method_.java:179)
    at java.security.AccessController.doPrivileged(Native Method)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.privilegedInvoke(Method_.java:176)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke_(Method_.java:137)
    at com.google.apphosting.runtime.security.shared.intercept.java.lang.reflect.Method_.invoke(Method_.java:45)
    at org.glassfish.jersey.server.model.internal.ResourceMethodInvocationHandlerFactory$1.invoke(ResourceMethodInvocationHandlerFactory.java:81)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher$1.run(AbstractJavaResourceMethodDispatcher.java:151)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.invoke(AbstractJavaResourceMethodDispatcher.java:171)
    at org.glassfish.jersey.server.model.internal.JavaResourceMethodDispatcherProvider$ResponseOutInvoker.doDispatch(JavaResourceMethodDispatcherProvider.java:152)
    at org.glassfish.jersey.server.model.internal.AbstractJavaResourceMethodDispatcher.dispatch(AbstractJavaResourceMethodDispatcher.java:104)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.invoke(ResourceMethodInvoker.java:406)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:350)
    at org.glassfish.jersey.server.model.ResourceMethodInvoker.apply(ResourceMethodInvoker.java:106)
    at org.glassfish.jersey.server.ServerRuntime$1.run(ServerRuntime.java:259)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:271)
    at org.glassfish.jersey.internal.Errors$1.call(Errors.java:267)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:267)
    at org.glassfish.jersey.process.internal.RequestScope.runInScope(RequestScope.java:319)
    at org.glassfish.jersey.server.ServerRuntime.process(ServerRuntime.java:236)
    at org.glassfish.jersey.server.ApplicationHandler.handle(ApplicationHandler.java:1028)
    at org.glassfish.jersey.servlet.WebComponent.service(WebComponent.java:373)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:381)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:344)
    at org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:219)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.apphosting.utils.servlet.ParseBlobUploadFilter.doFilter(ParseBlobUploadFilter.java:125)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.runtime.jetty.SaveSessionFilter.doFilter(SaveSessionFilter.java:35)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.JdbcMySqlConnectionCleanupFilter.doFilter(JdbcMySqlConnectionCleanupFilter.java:60)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.runtime.jetty.AppVersionHandlerMap.handle(AppVersionHandlerMap.java:254)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:923)
    at com.google.apphosting.runtime.jetty.RpcRequestParser.parseAvailable(RpcRequestParser.java:76)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at com.google.apphosting.runtime.jetty.JettyServletEngineAdapter.serviceRequest(JettyServletEngineAdapter.java:146)
    at com.google.apphosting.runtime.JavaRuntime$RequestRunnable.run(JavaRuntime.java:446)
    at com.google.tracing.TraceContext$TraceContextRunnable.runInContext(TraceContext.java:438)
    at com.google.tracing.TraceContext$TraceContextRunnable$1.run(TraceContext.java:445)
    at com.google.tracing.CurrentContext.runInContext(CurrentContext.java:220)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContextNoUnref(TraceContext.java:309)
    at com.google.tracing.TraceContext$AbstractTraceContextCallback.runInInheritedContext(TraceContext.java:301)
    at com.google.tracing.TraceContext$TraceContextRunnable.run(TraceContext.java:442)
    at com.google.apphosting.runtime.ThreadGroupPool$PoolEntry.run(ThreadGroupPool.java:251)
    at java.lang.Thread.run(Thread.java:724)
6thSigma commented 9 years ago

Can you post your Android code where you hit this error please?

ansgarm commented 9 years ago

(The stacktrace I posted was from the Google AppEngine's error log)

I'm using exactly your example code..

// Get anonymous user
UserUtils.getAnonymousUser(this).toBlocking().first();

BackendObject object = new BackendObject();
object.put("comments", "This is awesome!");

BackendServices
    .remote()
    .save(object)
    .subscribe();

Just my application differs..

public class FTApplication extends Application {

    @Override
    public void onCreate() {
        super.onCreate();

        Backend.init(new AndroidConfig(this, "https://xy.appspot.com/api/"));
    }
}
6thSigma commented 9 years ago

With anonymous users, we first try logging in and if the user doesn't exist we create a new one then login again. So that log is actually expected the first time it is run. (We'll change this log to be more clear)

I'm assuming you've run this more than once though, so we need to figure out what's going on. Is it crashing client side?

ansgarm commented 9 years ago

Well it's not crashing on the client side (yay!). But here's the log from Retrofit:

Retrofit:<--- HTTP 200 https://xy.appspot.com/api/auth/key (7092ms)
Retrofit:: HTTP/1.1 200 OK
Retrofit:alternate-protocol: 443:quic,p=0.01
Retrofit:cache-control: private
Retrofit:content-type: application/json
Retrofit:date: Fri, 17 Oct 2014 17:45:27 GMT
Retrofit:OkHttp-Received-Millis: 1413567927461
Retrofit:OkHttp-Response-Source: NETWORK 200
Retrofit:OkHttp-Selected-Protocol: spdy/3.1
Retrofit:OkHttp-Sent-Millis: 1413567920689
Retrofit:server: Google Frontend
Retrofit:vary: Accept-Encoding
Retrofit:
Retrofit:[48,-126,1,34,48,13,6,9,42,-122,72,-122,-9,13,1,1,1,5,0,3,-126,1,15,0,48,-126,1,10,2,-126,1,1,0,-127,-128,-6,11,-24,12,-41,-96,114,-75,-113,-95,97,-85,52,57,51,-77,-43,-73,-6,85,13,-85,1,-82,104,-113,-66,-116,-51,-112,-16,94,110,116,82,30,-6,101,101,62,14,-122,-65,-85,-87,-36,-107,78,-60,-47,-35,115,84,-30,125,55,113,-35,33,-77,84,52,-3,-49,109,26,60,85,-39,-123,-2,-62,-92,-45,106,96,58,-14,74,6,-74,99,34,127,59,67,59,70,36,99,-45,-28,107,-118,-51,-91,15,-104,7,-109,-10,-96,-22,-23,27,77,-94,-111,-13,57,-35,-115,-12,23,16,29,-53,12,-12,117,-76,9,114,-82,-43,18,-93,125,23,5,21,80,7,55,-49,-114,-45,-66,69,-121,-25,-26,-3,-74,117,118,1,-7,-71,-78,-64,62,-126,101,110,29,56,4,77,-95,-114,32,-117,14,-53,-37,72,-19,112,87,-86,-100,35,48,80,-31,15,-123,-13,123,97,37,-62,113,92,-78,78,65,36,57,-62,-41,-91,35,-12,-58,-117,-2,-121,3,61,-125,100,-30,-127,16,-21,-113,62,17,-9,-90,-106,12,-11,79,16,70,106,48,-122,40,-50,22,82,-3,-4,20,-53,-35,-110,51,-21,-94,-33,-84,-122,35,-28,31,-89,114,98,109,-63,28,11,-19,65,125,54,48,61,51,2,3,1,0,1]
Retrofit:<--- END HTTP (1040-byte body)
Retrofit:---> HTTP PUT https://xy.appspot.com/api/auth
Retrofit:Content-Type: application/json; charset=UTF-8
Retrofit:Content-Length: 731
Retrofit:{"isEncrypted":true,"user_data":{},"meta_data":{"modified_date_key":"1413567927469","permissions_key":"{\"groups\":[],\"permissions\":{\"flags\":48}}","object_type":"io_divide_shared_transitory_Credentials","object_key":"c9f79495-20d2-4c91-9ed2-e14d5505aeb9","create_date_key":"1413567920361","email":"32c1c89587e14e48","pw":"AAABACoOdj4ddq6uFkzAXTSrQRaOsGVdp32lb8DRfUV2YJf04183cQNtx3SISNfjylpFpGX4MgeYjSXVJtoS_WNp9SiyGAhP6YiSA0f91-vftdv_A8JwzikmsH1U_e3jx0IeDWQmDJIuiXw98kGuLhU1qSzJYJnQvpiaq4GcdsGR7JEw0vcBDb5OfmEB5mxrBzMxocWUDZ7c5kdCF67f0At4QTeUr_3Cq3sOf9j-pcehm192KI2XeheRaTRxBptxE_OVS99O-__HosHNakNZvuG_7x-W87fa_k-RCKlNR6FwIqV5O5mpZgMYqSgQlFofqLP8cmV-1wqFZe4_-PUiXao7PI-8ZnTfxrjkg9Ske4fhdjH99gPJsSzqbrjdyWJ8uYDYXw\u003d\u003d"}}
Retrofit:---> END HTTP (731-byte body)
Retrofit:afterCall(/auth:PUT: 401 : null
Retrofit:<--- HTTP 401 https://xy.appspot.com/api/auth (816ms)
Retrofit:: HTTP/1.1 401 Unauthorized
Retrofit:alternate-protocol: 443:quic,p=0.01
Retrofit:cache-control: private
Retrofit:content-type: text/html; charset=utf-8
Retrofit:date: Fri, 17 Oct 2014 17:45:28 GMT
Retrofit:OkHttp-Received-Millis: 1413567928297
Retrofit:OkHttp-Response-Source: NETWORK 401
Retrofit:OkHttp-Selected-Protocol: spdy/3.1
Retrofit:OkHttp-Sent-Millis: 1413567927485
Retrofit:server: Google Frontend
Retrofit:vary: Accept-Encoding
Retrofit:
Retrofit:<html><head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>401 Unauthorized</title>
</head>
<body text=#000000 bgcolor=#ffffff>
<h1>Error: Unauthorized</h1>
</body></html>
Retrofit:<--- END HTTP (200-byte body)
6thSigma commented 9 years ago

The .toBlocking() call is synchronous and it appears it's not completing before the object save call.

Can you try running those calls in a separate thread?

        Thread thread = new Thread()
        {
            @Override
            public void run() {
                try {
                    UserUtils.getAnonymousUser(context).toBlocking().first();

                    BackendObject object = new BackendObject();
                    object.put("comments", "This is awesome!");

                    BackendServices
                        .remote()
                        .save(object)
                        .subscribe();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }
        };

        thread.start();

If this works for you, we'll update the Getting Started page.