Hello Nick,

Happy to see that my post structure helped and in my turn let me thank you 
for the prompt response.
I am quoting below the code i used for the endpoint called "MyEndpoint'.
I tried to keep the changes at a minimum as the purpose was to test the 
functionality at first.

I will keep in mind your suggestions for similar questions in the future.
Please let me know if additional info is required or if I should move the 
question to Stack Overflow instead.

Thanks!

/*
   For step-by-step instructions on connecting your Android application to this 
backend module,
   see "App Engine Java Endpoints Module" template documentation at
   
https://github.com/GoogleCloudPlatform/gradle-appengine-templates/tree/master/HelloEndpoints
*/

package com.mypackage.project.endpoints;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.config.ApiMethod;
import com.google.api.server.spi.config.ApiNamespace;
import com.google.firebase.FirebaseApp;
import com.google.firebase.FirebaseOptions;
import com.google.firebase.auth.FirebaseCredentials;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;


import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.net.URISyntaxException;
import java.net.URL;
import java.util.logging.Logger;

import javax.inject.Named;
import javax.servlet.ServletContext;

/**
 * An endpoint class we are exposing
 */
@Api(
        name = "newEndpoint",
        version = "v1",
        description = "Some_description",
        namespace = @ApiNamespace(
                ownerDomain = "endpoints.mydomain.mydomain.com",
                ownerName = "endpoints.mydomain.mydomain.com",
                packagePath = ""
        )
)
public class MyEndpoint {

    // +++++++++++++++++++++++++
    // region REGION - VARIABLES
    public static final String stringFBREF_MY_FIREBASE_TABLE = 
"MY_FIREBASE_TABLE";
    static Logger Log = 
Logger.getLogger("com.mypackage.project.endpoints.MyEndpoint");
    // endregion
    // +++++++++


    /**
     * A simple endpoint method that takes a name and says Hi back
     */
    @ApiMethod(name = "sayHi")
    public MyBean sayHi(@Named("name") String name) {

        initializeFirebase();

        MyBean response = new MyBean();
        response.setData("Hi, " + name);

        return response;
    }

    private void initializeFirebase(){

        try {
                       
            FileInputStream serviceAccount = new 
FileInputStream("WEB-INF/myproject-firebase-adminsdk-randomNumbers.json");

            // Initialize the app with a service account, granting admin 
privileges
            FirebaseOptions options = new FirebaseOptions.Builder()
                    
.setCredential(FirebaseCredentials.fromCertificate(serviceAccount))
                    .setDatabaseUrl("https://myproject.firebaseio.com";)
                    .build();

            try {
                FirebaseApp.initializeApp(options);
            } catch (Exception error) {
                Log.info("ERROR: " + error.getMessage());
                Log.info("ERROR: You have already initialized FirebaseApp...");
            }


            try {
                
Log.info("YEAHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHHH");

                // As an admin, the app has access to read and write all data, 
regardless of Security Rules.
                DatabaseReference ref = 
FirebaseDatabase.getInstance().getReference(stringFBREF_MY_FIREBASE_TABLE);

                if(ref != null){
                    Log.info("REFERENCE FOR DB: " + ref.toString());
                    ref.push().setValue("I_can_write_to_firebase!");
                }else{
                    Log.info("Database reference is null :( ");
                }
            } catch (Exception error) {
                Log.info("ERROR: " + error.getMessage());
                Log.info("ERROR: You have already initialized FirebaseApp...");
            }

        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }



    }

}


 

On Thursday, February 9, 2017 at 2:29:47 AM UTC+2, Nick (Cloud Platform 
Support) wrote:
>
> Hey George,
>
> First off, I'll say I'm glad you've taken the time to provide such 
> detailed explanation of what steps you've followed. You'd be surprised how 
> often this level of detail (the minimum really needed to properly analyze 
> an issue) is not given, so thank you very much for that! This should be an 
> example post for other users!
>
> Second, usually specific-issue technical support questions like this 
> should be handled at Stack Overflow on one of our related tags. We monitor 
> there just as consistently as this forum, while this one is both A) less 
> supplied with other helpful users and B) not intended for this 1-on-1 
> format of support. So, you might consider posting questions like this there 
> in the future, or even posting there now, but after we gather some more 
> information necessary to look deeper.
>
> My initial thought about what might be going wrong is that it's difficult 
> to determine without seeing any code. You should gather the code in the 
> endpoints method so we can see why it is that it might return 200 yet fail 
> to write an entity.
>
> Cheers,
>
> Nick
> Cloud Platform Community Support 
>
> On Wednesday, February 8, 2017 at 10:45:52 AM UTC-5, George Sxi wrote:
>>
>> Hello everyone!
>>
>> I would like to pose the following question..
>>
>> I have successfully created a sample backend using cloud endpoints 
>> frameworks which simply performs a REST call using POST and writes a value 
>> in a Firebase folder.
>> In order to do this:
>> 1)  i used the "Hello Endpoints" sample which is created when you add the 
>> module in android studio as a starting point. 
>> 2)  After importing the relevant libraries, annotating the API and adding 
>> the extra functionality I run the backend in my localhost 
>> 3)  To test the process I used the  API explorer *locally* and passed a 
>> value in the "name" field using "Execute without OAuth" 
>> 4) Regardless of the value passed the process should write the same value 
>> in Firebase.
>>
>> Up to this point everything worked like a charm.
>>
>> The next step was to try and deploy the backend on Google App Engine and 
>> try it from there.
>> Using the "*Deploy Module to app engine*" option from Android studio the 
>> backend was successfully deployed on App Engine Standard and started 
>> serving requests.
>>
>> Now doing the exact same thing when I try to use the cloud platform API 
>> explorer (with the myapp.appspot.com link )to test the API I get the 
>> 200OK http answer to my POST but the Firebase entry is not written.
>>
>> Can anyone provide some insight into this?? 
>>
>> Since it is working properly in the localhost deployment but not when 
>> deployed on App Engine I suspect something is happening access-wise but I 
>> cannot find it..
>>
>> Please note that I have also tried it with public read/write Firebase 
>> rules and by using the "*authorize and execute"* option in API explorer.
>>
>> Happy to provide any additional info if required.
>>
>> Thanks!
>>
>
On Thursday, February 9, 2017 at 2:29:47 AM UTC+2, Nick (Cloud Platform 
Support) wrote:
>
> Hey George,
>
> First off, I'll say I'm glad you've taken the time to provide such 
> detailed explanation of what steps you've followed. You'd be surprised how 
> often this level of detail (the minimum really needed to properly analyze 
> an issue) is not given, so thank you very much for that! This should be an 
> example post for other users!
>
> Second, usually specific-issue technical support questions like this 
> should be handled at Stack Overflow on one of our related tags. We monitor 
> there just as consistently as this forum, while this one is both A) less 
> supplied with other helpful users and B) not intended for this 1-on-1 
> format of support. So, you might consider posting questions like this there 
> in the future, or even posting there now, but after we gather some more 
> information necessary to look deeper.
>
> My initial thought about what might be going wrong is that it's difficult 
> to determine without seeing any code. You should gather the code in the 
> endpoints method so we can see why it is that it might return 200 yet fail 
> to write an entity.
>
> Cheers,
>
> Nick
> Cloud Platform Community Support 
>
> On Wednesday, February 8, 2017 at 10:45:52 AM UTC-5, George Sxi wrote:
>>
>> Hello everyone!
>>
>> I would like to pose the following question..
>>
>> I have successfully created a sample backend using cloud endpoints 
>> frameworks which simply performs a REST call using POST and writes a value 
>> in a Firebase folder.
>> In order to do this:
>> 1)  i used the "Hello Endpoints" sample which is created when you add the 
>> module in android studio as a starting point. 
>> 2)  After importing the relevant libraries, annotating the API and adding 
>> the extra functionality I run the backend in my localhost 
>> 3)  To test the process I used the  API explorer *locally* and passed a 
>> value in the "name" field using "Execute without OAuth" 
>> 4) Regardless of the value passed the process should write the same value 
>> in Firebase.
>>
>> Up to this point everything worked like a charm.
>>
>> The next step was to try and deploy the backend on Google App Engine and 
>> try it from there.
>> Using the "*Deploy Module to app engine*" option from Android studio the 
>> backend was successfully deployed on App Engine Standard and started 
>> serving requests.
>>
>> Now doing the exact same thing when I try to use the cloud platform API 
>> explorer (with the myapp.appspot.com link )to test the API I get the 
>> 200OK http answer to my POST but the Firebase entry is not written.
>>
>> Can anyone provide some insight into this?? 
>>
>> Since it is working properly in the localhost deployment but not when 
>> deployed on App Engine I suspect something is happening access-wise but I 
>> cannot find it..
>>
>> Please note that I have also tried it with public read/write Firebase 
>> rules and by using the "*authorize and execute"* option in API explorer.
>>
>> Happy to provide any additional info if required.
>>
>> Thanks!
>>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at https://groups.google.com/group/google-appengine.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-appengine/e49c0fe2-dfb5-456c-bc0e-15b011fba654%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
  • [google-appengine] E... George Sxi
    • [google-appengi... 'Nick (Cloud Platform Support)' via Google App Engine
      • [google-app... George Sxi
        • [google... 'Nick (Cloud Platform Support)' via Google App Engine
          • [go... George Sxi
            • ... 'Nick (Cloud Platform Support)' via Google App Engine
              • ... George Sxi
                • ... 'Nick (Cloud Platform Support)' via Google App Engine

Reply via email to