2014-04-01 39 views
0

我有一個servlet代碼:谷歌應用程序引擎的cron後端的Java總是給出錯誤

public class BackendServlet extends HttpServlet { 
    private static final Logger LOG = Logger.getLogger(BackendServlet.class.getName()); 
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException { 
     doPost(req, resp); 
    } 

    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { 
     LOG.info("just test backend"); 
    } 
} 

然後,我有一個的web.xml,看起來像以下:

<servlet> 
    <servlet-name>update</servlet-name> 
     <servlet-class>com.google.api.test.backend.BackendServlet</servlet-class> 
    </servlet> 

    <servlet-mapping> 
    <servlet-name>update</servlet-name> 
    <url-pattern>/updatebackend</url-pattern> 
    </servlet-mapping> 

    <security-constraint> 
    <web-resource-collection> 
     <web-resource-name>update</web-resource-name> 
     <url-pattern>/updatebackend</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>admin</role-name> 
    </auth-constraint> 
    </security-constraint> 

    <security-constraint> 
    <web-resource-collection> 
     <web-resource-name>any</web-resource-name> 
     <url-pattern>/*</url-pattern> 
    </web-resource-collection> 
    <auth-constraint> 
     <role-name>*</role-name> 
    </auth-constraint> 
    </security-constraint> 

然後我有cron.xmlbackend.xml,看起來像下面這樣:

cron.xml

<?xml version="1.0" encoding="UTF-8"?> 
<cronentries> 
    <cron> 
    <url>/updatebackend</url> 
    <description>Update on the backend</description> 
    <schedule>every 5 minutes</schedule> 
    <target>updatebackend</target> 
    </cron> 
</cronentries> 

backend.xml

<?xml version="1.0" encoding="UTF-8"?> 
<backends> 
    <backend name="updatebackend"> 
     <class>B1</class> 
     <options> 
      <dynamic>true</dynamic> 
     </options> 
    </backend> 
</backends> 

但是當我上傳這個到App Engine服務器。它總是給我下面的錯誤消息:

/_ah /開始顯示java.lang.NullPointerException在 com.google.api.client.extensions.appengine.auth.oauth2.AbstractAppEngineAuthorizationCodeServlet.getUserId(AbstractAppEngineAuthorizationCodeServlet.java:92 )

如何在應用引擎後端正確使用cron作業運行servlet?是否有任何設置,我做錯了?

謝謝。

回答

0

我知道我的問題在哪裏,我應該首先爲/ _ah/start啓動servlet。

+0

我也有同樣的問題,你能顯示你配置其他servlet的代碼片段嗎?謝謝 –

相關問題