Google App Engine のタスク キューを使用しています。初めてです。チュートリアルを見つけましたが、いくつか問題があります。以下は、タスク キューをチェックするために使用している 2 つのサーブレットです。
public class GAEJSignupSubscriberServlet extends HttpServlet {
private static final Logger _logger = Logger.getLogger(GAEJSignupSubscriberServlet.class.getName());
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
String strCallResult = "";
resp.setContentType("text/plain");
try {
String strEmailId = req.getParameter("emailid");
_logger.info("Got a Signup Subscriber Request for Email ID : " + strEmailId);
//
// PUT YOUR TASK CODE HERE
//
if(strEmailId.equals("mh")){
System.out.println("email-id" + strEmailId);
}
strCallResult = "SUCCESS: Subscriber Signup";
_logger.info(strCallResult);
resp.getWriter().println(strCallResult);
}
catch (Exception ex) {
strCallResult = "FAIL: Subscriber Signup : " + ex.getMessage();
_logger.info(strCallResult);
resp.getWriter().println(strCallResult);
}
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
}
2 番目のサーブレットは次のとおりです。
public class GAEJCreateTaskServlet extends HttpServlet {
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
this.doPost(req, resp);
}
public void doGet(HttpServletRequest req, HttpServletResponse resp)
throws IOException {
resp.setContentType("text/plain");
resp.getWriter().println("Hello, world");
String strCallResult = "";
resp.setContentType("text/plain");
try {
//Extract out the To, Subject and Body of the Email to be sent
String strEmailId = req.getParameter("emailid");
//Do validations here. Only basic ones i.e. cannot be null/empty
if (strEmailId == null) throw new Exception("Email Id field cannot be empty.");
//Trim the stuff
strEmailId = strEmailId.trim();
if (strEmailId.length() == 0) throw new Exception("Email Id field cannot be empty.");
//Queue queue = QueueFactory.getDefaultQueue();
Queue queue = QueueFactory.getQueue("subscription-queue");
queue.add(TaskOptions.Builder.withUrl("/gaejsignupsubscriber").param("emailid",strEmailId));
strCallResult = "Successfully created a Task in the Queue";
resp.getWriter().println(strCallResult);
}
catch (Exception ex) {
strCallResult = "Fail: " + ex.getMessage();
resp.getWriter().println(strCallResult);
}
}
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
doGet(req, resp);
}
}
次の URL で GAEJCreateTaskServlet を呼び出しています。
http://localhost:8080/gaejcreatetask?emailid=romin@rocketmail.com
今問題は、このURLを呼び出すと、タスクが作成されたという出力が表示されますが、開発コンソールではキューにタスクが表示されないことです。両方のサーブレットから doPost 関数を削除すると、キューにタスクが表示されますが、実行しても何も起こらず、タスクはそこに残ります。なぜそうなるのか、どうすればこの問題を解決できますか。前もって感謝します。