在遵循Google App Engine for Java的同时获取电子邮件工作时遇到问题

时间:2010-09-28 18:49:43

标签: java google-app-engine email

我一直在研究a Google App Engine教程。

我输入了第6部分中显示的代码,然后尝试按照说明测试功能。

但是,无论我在表格中添加的电子邮件地址是什么: 字段,我得到一个看起来像这样的错误:

Message send failure
HTTP ERROR 404
Problem accessing /_ah/mail/someemail@gmail.com. Reason:
    NOT_FOUND
Powered by Jetty://

事件虽然测试显然失败了,但我将应用程序部署到了appspot.com

在这里,我甚至无法访问/ _ah / mail /,所以我从Outlook发送了一封电子邮件。该应用程序没有收到它,以下反弹 回:

Delivery to the following recipient failed permanently:

     whatever@fromsometutorial.applicationid.appspotmail.com

----- Original message -----

Received: by 10.204.82.130 with SMTP id b2mr13438bkl.0.1285692691837;
        Tue, 28 Sep 2010 09:51:31 -0700 (PDT)
Return-Path: <kessler.bm@gmail.com>
Received: from mail-bw0-f46.google.com (mail-bw0-f46.google.com
[209.85.214.46])
        by gmr-mx.google.com with ESMTP id z25si3874412bku.
5.2010.09.28.09.51.30;
        Tue, 28 Sep 2010 09:51:30 -0700 (PDT)
Received-SPF: pass (google.com: domain of kessler.bm@gmail.com designates 209.85.214.46 as permitted sender) client-ip=209.85.214.46;
Authentication-Results: gmr-mx.google.com; spf=pass (google.com:
domain of kessler.bm@gmail.com designates 209.85.214.46 as permitted
sender) smtp.mail=kessler.bm@gmail.com; dkim=pass (test mode) header.i=@gmail.com
Received: by bwz11 with SMTP id 11so5254251bwz.5
        for <whatever@fromsometutorial.applicationid.appspotmail.com>;
Tue, 28 Sep 2010 09:51:30 -0700 (PDT)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=gamma;
        h=domainkey-signature:received:received:reply-
to:from:to:subject:date
         :organization:message-id:mime-version:content-type
         :content-transfer-encoding:x-mailer:thread-index:x-mimeole;
        bh=5hMmQ/fy4AdMWGj7dA7tHInFNumFfhg24xHggsIZKR4=;
        b=OitMOXiZONheUMpkDU8mVUdWhk2AhUAuBbnSnyqDs1WWOPx0Ao75bWHBZZ/
lhRtOO+
         yMvLhDvrN+/cTDnxuQI6ICBb1KZh9eeExMrgdaQGV+/
pnaBK3PAEotfL8QgX81V1AKFE
         j58cbhxWUH0JSTVckXucribInLNCNJnIqvyD0=
DomainKey-Signature: a=rsa-sha1; c=nofws;
        d=gmail.com; s=gamma;
        h=reply-to:from:to:subject:date:organization:message-id:mime-
version
         :content-type:content-transfer-encoding:x-mailer:thread-index
         :x-mimeole;

b=Adh4j5+8xWF7MKIT6YTBE8PXH2iQG4yi2hulXgQ0QL5ZB1qmTNJiu5U2MlwWzJF7zQ
         DR1uBnwVNu0WtZxzHbneVsZY
+aSH8sPrmgPFTZSHTGcCU0+SXW9UjyZndVJdFhPP2Nfc
         GBeolrTikuhBtU+1F9T23io6wJqEwLg7X6HnU=
Received: by 10.204.58.75 with SMTP id f11mr192120bkh.
138.1285692690387;
        Tue, 28 Sep 2010 09:51:30 -0700 (PDT)
Return-Path: <kessler.bm@gmail.com>
Received: from blackbox (catv-86-101-152-197.catv.broadband.hu
[86.101.152.197])
        by mx.google.com with ESMTPS id 11sm5779682bkj.
23.2010.09.28.09.51.27
        (version=TLSv1/SSLv3 cipher=RC4-MD5);
        Tue, 28 Sep 2010 09:51:29 -0700 (PDT)
Reply-To: <kessler.bm@gmail.com>
From: "Brian Kessler" <kessler.bm@gmail.com>
To: <whatever@fromsometutorial.applicationid.appspotmail.com>
Subject: Go south
Date: Tue, 28 Sep 2010 18:52:12 +0200
Organization: Flux Szerviz BT.
Message-ID: <A878B05D923A4EDEBC8015D3B5448D2F@blackbox>
MIME-Version: 1.0
Content-Type: text/plain;
    charset="us-ascii"
Content-Transfer-Encoding: 7bit
X-Mailer: Microsoft Office Outlook 11
thread-index: ActfLX7QaTtIrEoETYWtToubxBHBOw==
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.5994

Way down south to mexico

--
Brian Kessler
kessler.bm@gmail.com
+36 30 637 1824

根据下面的建议,我修改了教程的

<servlet-mapping>
    <servlet-name>Email</servlet-name>
    <url-pattern>/_ah/mail/*</url-pattern>
</servlet-mapping>

阅读:

<servlet-mapping>
    <servlet-name>Email</servlet-name>
    <url-pattern>/_ah/mail/.+</url-pattern>
</servlet-mapping>

当我尝试在本地服务器上提交电子邮件时,它突然改变了错误:

Message send failure
HTTP ERROR 500
Problem accessing /_ah/mail/kessler.bm@gmail.com. Reason:
    de/vogella/gae/java/todo/dao/Dao
Caused by:
java.lang.NoClassDefFoundError: de/vogella/gae/java/todo/dao/Dao
    at de.vogella.gae.java.todo.EmailServlet.doPost(EmailServlet.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Caused by: java.lang.ClassNotFoundException: de.vogella.gae.java.todo.dao.Dao
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:151)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    ... 28 more
Caused by:
java.lang.ClassNotFoundException: de.vogella.gae.java.todo.dao.Dao
    at java.net.URLClassLoader$1.run(URLClassLoader.java:202)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:190)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:307)
    at com.google.appengine.tools.development.IsolatedAppClassLoader.loadClass(IsolatedAppClassLoader.java:151)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:248)
    at de.vogella.gae.java.todo.EmailServlet.doPost(EmailServlet.java:43)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:713)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:806)
    at org.mortbay.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1166)
    at com.google.appengine.api.blobstore.dev.ServeBlobFilter.doFilter(ServeBlobFilter.java:58)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.apphosting.utils.servlet.TransactionCleanupFilter.doFilter(TransactionCleanupFilter.java:43)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at com.google.appengine.tools.development.StaticFileFilter.doFilter(StaticFileFilter.java:122)
    at org.mortbay.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1157)
    at org.mortbay.jetty.servlet.ServletHandler.handle(ServletHandler.java:388)
    at org.mortbay.jetty.security.SecurityHandler.handle(SecurityHandler.java:216)
    at org.mortbay.jetty.servlet.SessionHandler.handle(SessionHandler.java:182)
    at org.mortbay.jetty.handler.ContextHandler.handle(ContextHandler.java:765)
    at org.mortbay.jetty.webapp.WebAppContext.handle(WebAppContext.java:418)
    at com.google.apphosting.utils.jetty.DevAppEngineWebAppContext.handle(DevAppEngineWebAppContext.java:70)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at com.google.appengine.tools.development.JettyContainerService$ApiProxyHandler.handle(JettyContainerService.java:349)
    at org.mortbay.jetty.handler.HandlerWrapper.handle(HandlerWrapper.java:152)
    at org.mortbay.jetty.Server.handle(Server.java:326)
    at org.mortbay.jetty.HttpConnection.handleRequest(HttpConnection.java:542)
    at org.mortbay.jetty.HttpConnection$RequestHandler.content(HttpConnection.java:938)
    at org.mortbay.jetty.HttpParser.parseNext(HttpParser.java:755)
    at org.mortbay.jetty.HttpParser.parseAvailable(HttpParser.java:218)
    at org.mortbay.jetty.HttpConnection.handle(HttpConnection.java:404)
    at org.mortbay.io.nio.SelectChannelEndPoint.run(SelectChannelEndPoint.java:409)
    at org.mortbay.thread.QueuedThreadPool$PoolThread.run(QueuedThreadPool.java:582)
Powered by Jetty://

但是,根据教程,de.vogella.gae.java.todo.dao.Dao作为枚举而不是类存在。我试图把它改成一个类,但是eclipse立即开始抱怨

Syntax Error on token "INSTANCE".  VariableDeclarator expected after this token.

原始教程是否做错了?我该如何解决?

4 个答案:

答案 0 :(得分:1)

您的web.xml需要一个与/_ah/mail/*匹配的条目,以及一个映射到处理这些地址的servlet。

答案 1 :(得分:1)

教程在web.xml文件中缺少此部分

<security-constraint>
  <web-resource-collection>
    <url-pattern>/_ah/mail/*</url-pattern>
  </web-resource-collection>
  <auth-constraint>
    <role-name>admin</role-name>
  </auth-constraint>
</security-constraint>

检查here

答案 2 :(得分:0)

我有类似的问题(使用Python,所以yaml配置文件而不是XML),原因是因为我把:

- url: /_ah/mail/.+ 
  script: handle_incoming_email.py 
  login: admin
在现有的全包条目之前

- url: /.*
  script: main.py

这会在服务器上显示404,并在发送测试消息时显示“消息发送失败”。

在catch-all条目解决问题后移动它。

答案 3 :(得分:0)

你说:

  

然而,根据教程,de.vogella.gae.java.todo.dao.Dao存在   作为枚举而不是类。我试着把它改成一堂课,但是   日食立即开始抱怨

实际上,java中的枚举被编译成一个类。以下摘自Java Tutorials page on enums

  

枚举声明定义了一个类(称为枚举类型)。枚举   类体可以包括方法和其他字段。编译器   在创建枚举时自动添加一些特殊方法。对于   例如,它们有一个返回数组的静态值方法   按顺序包含枚举的所有值   声明。

将枚举转换为类后所看到的错误是因为行INSTANCE;正在尝试定义枚举常量,而您只能在枚举中执行此操作,而不能在普通类中执行此操作。

原始ava.lang.NoClassDefFoundError只是意味着在运行时缺少已编译的(枚举)类。您需要检查war/WEB-INF/lib/classes以确认Dao.class包中存在编译de.vogella.gae.java.todo.dao

顺便说一下,本教程的作者是using enum for implementing singleton pattern