我正在尝试向GAE中的mapreduce发送post请求。谷歌提供
private String generateHtml(String configXml) {
return "<html>"
+ "<body>"
+ "<form action="/mapreduce/start" method="POST">"
+ "<textarea name="configuration" rows=20 cols=80>"
+ configXml
+ "</textarea>"
+ "<input type="submit" value="Start">"
+ "</form>";
}
如何配置:
String configString = ConfigurationXmlUtil.convertConfigurationToXml(config);
String body = "configuration=" + configString;
这样,当服务器试图获取参数"configuration"时,我会得到null指针异常;
我应该如何构建请求,使其与具有文本区域的html场景相同?
以下是我使用TaskQueue:时的操作方法
import static com.google.appengine.api.datastore.FetchOptions.Builder.withLimit;
import static com.google.appengine.api.taskqueue.TaskOptions.Builder.withUrl;
import com.google.appengine.api.taskqueue.TaskOptions;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.mapreduce.InputFormat;
import org.apache.hadoop.mapreduce.Mapper;
//... other imports
// mapreduce config
Configuration conf = new Configuration(false);
conf.setClass("mapreduce.map.class", YourMapperClass.class, Mapper.class);
conf.setClass("mapreduce.inputformat.class", DatastoreInputFormat.class, InputFormat.class);
// setup callbacks if you need to know when the job is done.
//conf.set(AppEngineJobContext.DONE_CALLBACK_URL_KEY, "/job-done-callback");
// you can also specify a queue. Defaults to "default" :)
//conf.set(AppEngineJobContext.CONTROLLER_QUEUE_KEY, "mrqueue");
//conf.set(AppEngineJobContext.DONE_CALLBACK_QUEUE_KEY, "mrqueue");
//conf.set(AppEngineJobContext.WORKER_QUEUE_KEY, "mrqueue");
conf.set(DatastoreInputFormat.ENTITY_KIND_KEY, 'YourEntityKind');
String xml = ConfigurationXmlUtil.convertConfigurationToXml(conf);
TaskOptions opts = withUrl("/mapreduce/start")
.param("configuration", xml)
.method(TaskOptions.Method.POST)
.header("X-Requested-With", "XMLHttpRequest");
// use our dedicated dbm4g queue
// this needs to be configured by a user
QueueFactory.getQueue("mrqueue").add(opts);
我使用了一个非默认队列来确保我的MapReduce作业不会太多地达到限制。但是您也可以安全地使用默认队列。