Question

i am trying to develop android app with backend using app engine.I already generated endpoints,now i need multitenancy in my app.Here documentation about multitenancy

But i have generated endpoints,not servlet as shown above.How can i implement multitenancy with endpoints?

Was it helpful?

Solution

There are several namespace enabled APIs supported in App Engine i.e. Datastore, Memcache, Task Queue and Search. It is not clear from your question as to how to plan to use the namespaces in your application.

I am assuming that you want to save and/or retrieve the data from a particular namespace, so that the data is well segregated as per your namespace requirements. I do not think that you need to necessarily follow the Filter example that is given in the example.

You can use a startup servlet (one that loads on application start) to set a particular namespace if you desire. Subsequently, you will need to determine what is the qualifying criteria for your namespace value. For e.g. if your Cloud Endpoints are implementing security via the User parameter, then maybe the User Id could be a namespace id. Alternatively, you could retrieve other related/associated data from your datastore to determine what other value is fit for the namespace id.

Just FYI -- behind the scenes the Cloud Endpoints architecture is also Servlets.

OTHER TIPS

I have a web app based on GAE and jsp. I set the namespace per user using Google's UserServiceFactory.

    import com.google.appengine.api.users.UserServiceFactory;
    import com.google.appengine.api.NamespaceManager;
...

        if (NamespaceManager.get() == null) {
              // Assuming there is a logged in user.
              String namespace UserServiceFactory.getUserService().getCurrentUser().getUserId();
              NamespaceManager.set(namespace);
            }
...

Now I try to change to Google Cloud Endpoints and I take the user of the Endpoint API (Using Auth with Endpoints). The code looks like this and works in my test environment.

    import com.google.appengine.api.users.User;
    import com.google.appengine.api.NamespaceManager;
...

    @ApiMethod(name = "scores.insert")
    public Score insert(Score score, User user) throws OAuthRequestException, IOException {
      ...

            if (NamespaceManager.get() == null) {
                  // Assuming there is a logged in user.
                  String namespace = user.getUserId();
                  NamespaceManager.set(namespace);
                }
...

    }
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top