0
votes

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?

1
Documentation says that, "All HTTP 5xx status codes are converted to be HTTP 503 in the client response." cloud.google.com/appengine/docs/java/endpoints/… - user2004685
You should find information about the error happening under the hood in the request logs in your console. - zapl
user2004685, so how do I get it to return a success code (i think 200 means success). - Tom Finet
zapl, this is one of the things it says: JsonMappingException: No serializer found for class com.example.tomfinet.myapplication.backend.model.Profile and no properties discovered to create BeanSerializer (to avoid exception, disable SerializationConfig.Feature.FAIL_ON_EMPTY_BEANS) - Tom Finet

1 Answers

1
votes

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.