Java Code Examples for com.google.appengine.api.taskqueue.TaskOptions#Method

The following examples show how to use com.google.appengine.api.taskqueue.TaskOptions#Method . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AsyncTasksTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void assertServletReceivesCorrectMethod(TaskOptions.Method method) {
    MethodRequestHandler handler = new MethodRequestHandler();
    PrintServlet.setRequestHandler(handler);

    Queue queue = QueueFactory.getQueue("tasks-queue");
    waitOnFuture(queue.addAsync(withUrl(URL).method(method)));
    sync();

    assertEquals("Servlet received invalid HTTP method.", method.name(), handler.method);
}
 
Example 2
Source File: TasksTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void assertServletReceivesCorrectMethod(TaskOptions.Method method) {
    MethodRequestHandler handler = new MethodRequestHandler();
    PrintServlet.setRequestHandler(handler);

    Queue queue = QueueFactory.getQueue("tasks-queue");
    queue.add(withUrl(URL).method(method));
    sync();

    assertEquals("Servlet received invalid HTTP method.", method.name(), handler.method);
}
 
Example 3
Source File: TasksTest.java    From appengine-tck with Apache License 2.0 5 votes vote down vote up
private void assertAddThrowsExceptionForMethod(TaskOptions.Method method, Queue queue) {
    try {
        queue.add(withMethod(method));
        fail("Expected InvalidQueueModeException");
    } catch (InvalidQueueModeException e) {
        // pass
    }
}
 
Example 4
Source File: TaskQueueServlet.java    From appengine-java-vm-runtime with Apache License 2.0 4 votes vote down vote up
private void addTask(HttpServletRequest req, HttpServletResponse resp)
    throws ServletException, IOException {
  String queue = req.getParameter("queue");
  Queue q;
  if (queue == null) {
    q = QueueFactory.getDefaultQueue();
  } else {
    q = QueueFactory.getQueue(queue);
  }
  TaskOptions.Method method = TaskOptions.Method.valueOf(req.getParameter("httpmethod"));
  String url = req.getParameter("taskUrl");
  if (url == null) {
    url = req.getServletPath();
  }
  TaskOptions opts =
      TaskOptions.Builder.withUrl(url).header("myheader", "blarg29").method(method);

  if (method == TaskOptions.Method.POST || method == TaskOptions.Method.PUT) {
    opts.payload("this=that");
  } else {
    opts.param("myparam", "yam28");
  }
  String execTimeMs = req.getParameter("execTimeMs");
  if (execTimeMs != null) {
    opts.etaMillis(Long.valueOf(execTimeMs));
  }
  String requestNamespace = req.getParameter("requestNamespace");
  if (requestNamespace != null) {
    /* We could override the current environment and set the request namespace
     * but that's a little overkill and already tested in
     * com.google.appengine.api.taskqueue.TaskQueueTest .
     */
    opts.header(DEFAULT_NAMESPACE_HEADER, requestNamespace);
  }
  String currentNamespace = req.getParameter("currentNamespace");
  if (currentNamespace != null) {
    /* We could also do this:
     * opts.header(CURRENT_NAMESPACE_HEADER, currentNamespace);
     */
    NamespaceManager.set(currentNamespace);
  }
  latch = new CountDownLatch(1);
  TaskHandle handle = q.add(opts);
  resp.getWriter().print(handle.getQueueName());
}