6
votes

I followed the tutorial below.

https://developers.google.com/eclipse/docs/running_and_debugging_2_0

which basically added a GAE backend to my existing app. I then try out the example below, run it on the local development server and I get the exception below which occurs after

Note result = endpoint.insertNote(note).execute();

is called.

com.google.api.client.googleapis.json.GoogleJsonResponseException: 404 Not Found

My code is below.

package com.cloudnotes;

import java.io.IOException;
import java.util.Date;

import android.os.AsyncTask;
import android.content.Context;
import com.cloudnotes.noteendpoint.Noteendpoint;
import com.cloudnotes.noteendpoint.model.Note;
import com.google.api.client.extensions.android.http.AndroidHttp;
import com.google.api.client.http.HttpRequest;
import com.google.api.client.http.HttpRequestInitializer;
import com.google.api.client.json.jackson.JacksonFactory;


import android.os.Bundle;
import android.app.Activity;

import android.view.Menu;

public class MainActivity extends Activity {

    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

      new EndpointsTask().execute(getApplicationContext());
    }

    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        getMenuInflater().inflate(R.menu.activity_main, menu);
        return true;
    }

    public class EndpointsTask extends AsyncTask<Context, Integer, Long> {
        protected Long doInBackground(Context... contexts) {

          Noteendpoint.Builder endpointBuilder = new Noteendpoint.Builder(
              AndroidHttp.newCompatibleTransport(),
              new JacksonFactory(),
              new HttpRequestInitializer() {
              public void initialize(HttpRequest httpRequest) { }
              });
      Noteendpoint endpoint = CloudEndpointUtils.updateBuilder(
      endpointBuilder).build();
      try {
          Note note = new Note().setDescription("Note Description");
          String noteID = new Date().toString();
          note.setId(noteID);

          note.setEmailAddress("E-Mail Address");      
          Note result = endpoint.insertNote(note).execute();
      } catch (IOException e) {
        e.printStackTrace();
      }
          return (long) 0;
        }
    }
}
6
Is your backend running? If you visit localhost:your_port/_ah/api/explorer do you see your APIs running? - Dan Holevoet
@Jake , is the issue still on? The tutorial link you have provided is for web application, but your code is for android application? - tony m
Some additional instructions have been put in the sample. - Les Vogel - Google DevRel
@DanHolevoet no i can't see anything - codepeaker

6 Answers

5
votes

Another possible cause for this problem is not setting the correct applicationId in appengine-web.xml:

<?xml version="1.0" encoding="utf-8"?>
<appengine-web-app xmlns="http://appengine.google.com/ns/1.0">
  <application>APPLICATION_ID_HERE</application>

...

</appengine-web-app>
5
votes

Another possible reason for 404 if you call the method with a null parameter and the method does not accept null parameters.

I had a similar issue with a method with 4 String parameters and I sent null for one of them and all I got was a stupid 404.

Another possible reason for 404 on the development(local) server is that you have a parameter with some strange characters (like a url for example) that the development(local) server does not handle correctly event if it works fine on the app engine live servers. Possible solution: instead of multiple params use a simple java object.

3
votes

I had the same problem and this is how I fixed it.

A little background
I had two versions of the API deployed to App Engine which I believe it should be OK. The admin console didn't show any problem and I was getting the 200 OK code after deploying version 2 of the API in log file.

/_ah/spi/BackendService.getApiConfigs 200 118ms 8kb

but no matter what I tried I was always getting the 404 Not Found error.

I am not sure what the problem was but I think Web Server at App Engine was redirecting all the requests to the version 1. It could be because both versions had the following settings in their web.xml.

<servlet-mapping>
  <servlet-name>SystemServiceServlet</servlet-name>
  <url-pattern>/_ah/spi/*</url-pattern>
</servlet-mapping>

Solution
I removed version 1 and redeployed version 2. Then everything just worked fine.

3
votes

This comes down to the app engine default version being different from the one you've deployed. Go here: https://appengine.google.com/deployment?app_id=s~your-project-id and change your default version

0
votes

this happen because your deploy back-end is not fully deployed. just re-deploy your back-end and make sure you got the message deploy succeed. you can check the detail deploy process on the top page header. also, you can test by visiting the url to check:

https://developers.google.com/apis-explorer/?base=https://[YOUR_PROJECT_ID].appspot.com/_ah/api#p/
0
votes

Try to update your plugin and dependency libraries to the latest version. See https://stackoverflow.com/a/37639701/857346.