不能在Google Cloud Endpoints的Endpoint类中创建多个方法 - java

我一直在尝试在生成的Endpoint类中创建一些新方法,但发现了这种奇怪的行为:我可以向生成的类中添加一个方法,但是无论添加的是哪两个,我都不能添加其中的两个。
这是生成的类的代码,在其中为两个添加的方法添加了代码:

  package it.raffaele.bills;

import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;

import javax.annotation.Nullable;
import javax.inject.Named;
import javax.jdo.PersistenceManager;
import javax.jdo.Query;
import javax.persistence.EntityExistsException;
import javax.persistence.EntityNotFoundException;

import com.google.api.server.spi.config.Api;
import com.google.api.server.spi.response.CollectionResponse;
import com.google.appengine.api.datastore.Cursor;
import com.google.appengine.datanucleus.query.JDOCursorHelper;

@Api(name = "utenteendpoint")
public class UtenteEndpoint {

    /**
     * This method lists all the entities inserted in datastore.
     * It uses HTTP GET method and paging support.
     *
     * @return A CollectionResponse class containing the list of all entities
     * persisted and a cursor to the next page.
     */
    @SuppressWarnings({ "unchecked", "unused" })
    public CollectionResponse<Utente> listUtente(
            @Nullable @Named("cursor") String cursorString,
            @Nullable @Named("limit") Integer limit) {

        PersistenceManager mgr = null;
        Cursor cursor = null;
        List<Utente> execute = null;

        try {
            mgr = getPersistenceManager();
            Query query = mgr.newQuery(Utente.class);
            if (cursorString != null && cursorString != "") {
                cursor = Cursor.fromWebSafeString(cursorString);
                HashMap<String, Object> extensionMap = new HashMap<String, Object>();
                extensionMap.put(JDOCursorHelper.CURSOR_EXTENSION, cursor);
                query.setExtensions(extensionMap);
            }

            if (limit != null) {
                query.setRange(0, limit);
            }

            execute = (List<Utente>) query.execute();
            cursor = JDOCursorHelper.getCursor(execute);
            if (cursor != null)
                cursorString = cursor.toWebSafeString();

            // Tight loop for fetching all entities from datastore and accomodate
            // for lazy fetch.
            for (Utente obj : execute)
                ;
        } finally {
            mgr.close();
        }

        return CollectionResponse.<Utente> builder().setItems(execute)
                .setNextPageToken(cursorString).build();
    }

    /**
     * This method gets the entity having primary key id. It uses HTTP GET method.
     *
     * @param id the primary key of the java bean.
     * @return The entity with primary key id.
     */
    public Utente getUtente(@Named("id") Long id) {
        PersistenceManager mgr = getPersistenceManager();
        Utente utente = null;
        try {
            utente = mgr.getObjectById(Utente.class, id);
        } finally {
            mgr.close();
        }
        return utente;
    }

    /**
     * This inserts a new entity into App Engine datastore. If the entity already
     * exists in the datastore, an exception is thrown.
     * It uses HTTP POST method.
     *
     * @param utente the entity to be inserted.
     * @return The inserted entity.
     */
    public Utente insertUtente(Utente utente) {
        PersistenceManager mgr = getPersistenceManager();
        try {
            if (containsUtente(utente)) {
                throw new EntityExistsException("Object already exists");
            }
            mgr.makePersistent(utente);
        } finally {
            mgr.close();
        }
        return utente;
    }

    /**
     * This method is used for updating an existing entity. If the entity does not
     * exist in the datastore, an exception is thrown.
     * It uses HTTP PUT method.
     *
     * @param utente the entity to be updated.
     * @return The updated entity.
     */
    public Utente updateUtente(Utente utente) {
        PersistenceManager mgr = getPersistenceManager();
        try {
            if (!containsUtente(utente)) {
                throw new EntityNotFoundException("Object does not exist");
            }
            mgr.makePersistent(utente);
        } finally {
            mgr.close();
        }
        return utente;
    }

    /**
     * This method removes the entity with primary key id.
     * It uses HTTP DELETE method.
     *
     * @param id the primary key of the entity to be deleted.
     * @return The deleted entity.
     */
    public Utente removeUtente(@Named("id") Long id) {
        PersistenceManager mgr = getPersistenceManager();
        Utente utente = null;
        try {
            utente = mgr.getObjectById(Utente.class, id);
            mgr.deletePersistent(utente);
        } finally {
            mgr.close();
        }
        return utente;
    }


/********************************ADDED CODE*********************************************/

     @SuppressWarnings({"cast", "unchecked"})
        public List<Bill> getUserBillsByTag(@Named("tag") String tag){
         PersistenceManager mgr = getPersistenceManager();
            Utente utente = null;
            List<Bill> list = new LinkedList<Bill>();
            try {
                Query q = mgr.newQuery(Utente.class);
                q.setFilter("nfcID == '" + tag +"'");
                List<Utente> utenti = (List<Utente>) q.execute();
                if (!utenti.isEmpty()){
                    for (Utente u : utenti){
                        list.addAll(u.getBollettini());
                        break;  //fake loop.
                    }

                }else{
                    //handle error

                }


            } finally {
                mgr.close();
            }
            return list;


        }


     @SuppressWarnings({"cast", "unchecked"})
    public List<Bill> getUserBills(@Named("id") Long id){
         Utente utente = getUtente(id);
         System.out.println(utente);
        List<Bill> list = utente.getBollettini();
        return list;
    }


/*******************************************************************************/       


    private boolean containsUtente(Utente utente) {
        PersistenceManager mgr = getPersistenceManager();
        boolean contains = true;
        try {
            mgr.getObjectById(Utente.class, utente.getId());
        } catch (javax.jdo.JDOObjectNotFoundException ex) {
            contains = false;
        } finally {
            mgr.close();
        }
        return contains;
    }

    private static PersistenceManager getPersistenceManager() {
        return PMF.get().getPersistenceManager();
    }

}

你知道如何帮助我吗?我想念什么吗?

java大神给出的解决方案

您的方法具有相同的api描述(path="utenteendpoint/{param}")。
给他们一个不同的路径:

@ApiMethod(path="utenteendpoint/tag/{tag}/")
public List<Bill> getUserBillsByTag(@Named("tag") String tag) { ... }

@ApiMethod(path="utenteendpoint/user/{id}/")
public List<Bill> getUserBills(@Named("id") Long id) { ... }

当回复有时是一个对象有时是一个数组时,如何在使用改造时解析JSON回复? - java

我正在使用Retrofit来获取JSON答复。这是我实施的一部分-@GET("/api/report/list") Observable<Bills> listBill(@Query("employee_id") String employeeID); 而条例草案类是-public static class…

java.net.URI.create异常 - java

java.net.URI.create("http://adserver.adtech.de/adlink|3.0") 抛出java.net.URISyntaxException: Illegal character in path at index 32: http://adserver.adtech.de/adlink|3.0 虽然n…

java:继承 - java

有哪些替代继承的方法? java大神给出的解决方案 有效的Java:偏重于继承而不是继承。 (这实际上也来自“四人帮”)。他提出的理由是,如果扩展类未明确设计为继承,则继承会引起很多不正常的副作用。例如,对super.someMethod()的任何调用都可以引导您通过未知代码的意外路径。取而代之的是,持有对本来应该扩展的类的引用,然后委托给它。这是与Eric…

如何在Java中以语言环境正确的顺序格式化日期和月份? - java

有没有一种方法可以用Java / Kotlin中的区域设置正确的格式格式化日和月(以紧凑格式)而不格式化年份?因此,对于英语,应为“ 9月20日”,而对于瑞典语为“ 9月20日”。为了进行比较,在Cocoa平台上,我可以执行以下操作(在Swift中):let formatter = DateFormatter() formatter.locale = Loc…

DataSourceTransactionManager和JndiObjectFactoryBean和JdbcTemplate的用途是什么? - java

以下的用途是什么:org.springframework.jdbc.core.JdbcTemplate org.springframework.jdbc.datasource.DataSourceTransactionManager org.springframework.jndi.JndiObjectFactoryBean <tx:annotatio…