getBodyAsBytes() solves the problem.
The following code will run each of the queued DeferredTasks from within a
JUnit test.
String queueName = QueueFactory.getDefaultQueue().getQueueName();
ServletRunner sr = new ServletRunner();
sr.registerServlet(
"/_ah/queue/__deferred__",
com.google.apphosting.utils.servlet.DeferredTaskServlet.class.getCanonicalName());
LocalTaskQueue localTaskQueue =
LocalTaskQueueTestConfig.getLocalTaskQueue();
ServletUnitClient client = sr.newClient();
while (!getQueue().getTaskInfo().isEmpty()) {
TaskStateInfo taskInfo = getQueue().getTaskInfo().iterator().next();
byte[] taskBody = taskInfo.getBodyAsBytes();
String taskName = taskInfo.getTaskName();
WebRequest request = new
PostMethodWebRequest("http:/_ah/queue/__deferred__",
new ByteArrayInputStream(taskBody),
"application/x-binary-app-engine-java-runnable-task");
request.setHeaderField("X-AppEngine-QueueName", queueName);
try {
client.sendRequest(request);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (SAXException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally {
localTaskQueue.deleteTask(queueName, taskName);
}
}
localTaskQueue.flushQueue(queueName);
--
You received this message because you are subscribed to the Google Groups
"Google App Engine for Java" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/google-appengine-java?hl=en.