in odps-console-public/src/main/java/com/aliyun/openservices/odps/console/pub/HttpSubmitCommand.java [209:278]
public static HttpSubmitCommand parse(String commandString, ExecutionContext sessionContext)
throws ODPSConsoleException {
commandString = commandString.trim();
if (commandString.toUpperCase().matches("HTTP[\\s\\S]*")) {
String[] options = commandString.split("\\s+");
if (options.length < 3 || options.length > 6) {
throw new ODPSConsoleException("illegal parameter");
}
HttpMethod method = null;
try {
method = HttpMethod.valueOf(options[1].toUpperCase());
} catch (Exception e) {
throw new ODPSConsoleException("illegal http method");
}
String[] splits = options[2].split("\\?", 2);
String url = splits[0];
Map<String, String> parameters = new HashMap<String, String>();
if (splits.length == 2) {
String[] paras = splits[1].split("&");
for (int i = 0; i < paras.length; i++) {
String[] keyValue = paras[i].split("=", 2);
// 可能value是没有值的,如 progress&taskname=sql
parameters.put(keyValue[0], keyValue.length == 1 ? null : keyValue[1]);
}
}
HttpSubmitCommand command = new HttpSubmitCommand(commandString, sessionContext, method, url);
command.parameters = parameters;
if (options.length > 3) {
Options opts = initOptions();
CommandLineParser clp = new GnuParser();
CommandLine cl;
try {
cl = clp.parse(opts, options, false);
} catch (Exception e) {
throw new ODPSConsoleException("Unknown exception from client - " + e.getMessage(), e);
}
if (cl.hasOption("header")) {
command.headerFileName = cl.getOptionValue("header");
}
if (cl.hasOption("content")) {
command.fileName = cl.getOptionValue("content");
}
if (cl.hasOption("token")) {
command.token = cl.getOptionValue("token");
}
if (cl.getArgs().length > 3) {
throw new ODPSConsoleException(ODPSConsoleConstants.BAD_COMMAND + "too much parameters");
}
}
return command;
}
return null;
}