cl = Strings.parseInteger(v.get(0));
setPrms(cp, prms, "hdrs." + k, v.toString());
}
InputStream is = httpExchange.getRequestBody();
Process tprc = executor.occupyOrNew();
OutputByteBuffer obb = null;
try {
long read_wait = Strings.parseIntegerNvl(
cntx.getPrmByFullName("read_wait"), 10000);// !!!
TimeoutInputStream tis = new TimeoutInputStream(tprc);
tis.setTimeout(read_wait);
tis.setLimitRead(cl);
tis.setCircleBufferSize(50);
tis.startReadSource(is);
obb = (cl <= 0) ? Process.getByteBuffer(8000, tis)
: Process.getByteBuffer(8000, tis, cl);
} catch (SysException e) {
e.printStackTrace();
tprc.interrupt();
throw new SysRuntimeException(e);
} finally {
executor.free(tprc);
}
try {
setPrms(cp, prms, "body", obb);
if ("POST".equals(httpExchange.getRequestMethod())
&& ct != null
&& ct.indexOf("application/x-www-form-urlencoded") >= 0) {
String enc;
try {
enc = cntx.getPrmNvl("request.encoding", "UTF-8");
if (enc == null || enc.trim().length() == 0)
enc = "UTF-8";
} catch (SysException e2) {
enc = "UTF-8";
}
StringBuffer sb = Strings.getStringBuffer(obb.getIS(),
enc);
setPrms(cp, prms, "postquery", sb);
try {
boolean parse_postquery = cntx.getPrmNvl(
"parse_postquery", false);
if (parse_postquery) {
String[] eqs = Strings.parseXVSLine(
sb.toString(), '/', '&');
for (String eq : eqs) {
int j = eq.indexOf('=');
if (j >= 0)
setPrms(cp, prms,
"post." + eq.substring(0, j),
eq.substring(j + 1));
}
}
} catch (SysException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
} catch (IOException e) {
e.printStackTrace();
throw new SysRuntimeException(e);
}
String enc;
try {
enc = cntx.getPrmNvl("response.encoding", "UTF-8");
if (enc == null || enc.trim().length() == 0)
enc = "UTF-8";
} catch (SysException e2) {
enc = "UTF-8";
}
// if (https) {
// HttpsServer srv = (HttpsServer)
// httpExchange.getHttpContext().getServer();
// SSLContext ssl = srv.getHttpsConfigurator().getSSLContext();
// }
NewTaskInfo nti = getChild();
Context cntx_child = null;
try {
String grp_in = cntx.getPrmString("grp_in");
if (grp_in == null)
grp_in = "in";
String grp_out = cntx.getPrmString("grp_out");
if (grp_out == null)
grp_out = "out";
if (!Strings.parseBooleanNvl(
cntx.getPrmString("save-in-body"), true)) {
prms.remove("body");
}
cntx_child = nti.createAndReadyTask(cntx.ta, cntx,
cntx.id_subject, grp_in, prms);
Object res = null;
if ((cntx_child == null) || (cntx_child.id_task <= 0)) {
res = cntx_child
.getPrmByFullName(((grp_out == null) || (grp_out
.length() == 0)) ? "body" : grp_out
+ "/body");
if (res == null) {
Headers hd = httpExchange.getResponseHeaders();
hd.put("Content-Type",
Arrays.asList("text/plain; charset=" + enc));
httpExchange.sendResponseHeaders(503, 0);
OutputStream w = httpExchange.getResponseBody();
w.write("Обработчик не выбран".getBytes(enc));
w.close();
return;
}
} else {
Process.currentProcess().regResourceName(
cntx_child.id_task, "child.id");
long wait = Strings.parseIntegerNvl(
cntx.getPrmByFullName("wait"), 30000);// !!!
cntx.log(false, "Start waiting (", wait, ")");
cntx_child.ta.waitFinished(cntx_child.id_subject,
cntx_child.id_task, wait);
cntx.log(false, "End waiting");
res = cntx_child
.getPrmByFullName(((grp_out == null) || (grp_out
.length() == 0)) ? "body" : grp_out
+ "/body");
}
if (res != null) {
Map<String, Object> result = cntx_child
.getGroupParams(grp_out);
long l = 0;
if (res instanceof FileInputStream) {
is = (FileInputStream) res;
l = ((FileInputStream) is).getChannel().size();
} else if (res instanceof Element) {
Element el = (Element) res;
obb = new OutputByteBuffer(8000);
XMLFileWaiter.putStream(el, obb, "utf-8");
try {
obb.close();
l = obb.getLength();
} catch (IOException e1) {
e1.printStackTrace();
}
is = obb.getIS();
} else if (res instanceof OutputByteBuffer) {
is = ((OutputByteBuffer) res).getIS();
l = ((OutputByteBuffer) res).getLength();
} else if (res instanceof File) {
File f = (File) res;