Search code examples
javaandroidgoogle-app-enginegoogle-cloud-endpointshttp-status-code-503

Endpoints method not working, why?


When I test my google endpoints API in the api explorer, the saveProfile method throws the 503 Service Unavailable error, but all other methods work fine.

Here is the saveProfile method in my endpoint:

@ApiMethod(name = "saveProfile")
public Profile saveProfile(final ProfileForm profileForm) {
    String firstName = profileForm.getFirstName();
    String lastName = profileForm.getLastName();
    String email = profileForm.getEmail();

    Profile profile = new Profile("124234132", email, firstName, lastName);

    ofy().save().entity(profile).now();

    return profile;
}

Here is the Profile entity class:

@Entity
public class Profile {

    @Id
    private String userId;

    private String email;

    private String firstName;

    private String lastName;

    public Profile(String userId, String email, String firstName, String lastName) {
        this.userId = userId;
        this.email = email;
        this.firstName = firstName;
        this.lastName = lastName;
    }
}

Here is the profileForm class:

public class ProfileForm {

    private String firstName;

    private String lastName;

    private String email;

    public ProfileForm() {}

    public ProfileForm(String firstName, String lastName, String email) {
        this.firstName = firstName;
        this.lastName = lastName;
        this.email = email;
    }

    public String getFirstName() {
        return firstName;
    }

    public String getLastName() {
        return lastName;
    }

    public String getEmail() {
        return email;
    }
}

I have registered the entity and have set the API_EXPLORER_CLIENT_ID as well as the web and android client IDs.

Does somebody understand how to fix this so that the method just returns the profile object as it should?


Solution

  • In order for Profile to be serializable you need to define getters and setters for each of its fields (ex. getUserId(), setUserId(string Id)).

    An Objectify entity must also include a no-arg constructor: https://github.com/objectify/objectify/wiki/Entities

    Let me know if that fixes the error.